int_obj = '';
var editId = '';

function loadField(id) {

	if($(id)) {

		attachTooltip(id);
		Highlight(id);
		clearInterval(int_obj);
	}
}

//Baloon functions

function attachTooltip(elementId){
	if($(elementId)){
		Event.observe(elementId, 'focus', onfocusEle, false);
		Event.observe(elementId, 'blur', onblurEle, false);
		//	   Event.observe(elementId, 'mouseover', onfocusEle, false);
		//	   Event.observe(elementId, 'mouseout', onblurEle, false);
	}
};



//only for home page tool-tip

function onblurEle(e){
	var id = Event.element(e).id;
	$(id).className = "inputstyle" ;
	$("h-" + id).className = "field-hint-inactive" ;
};

function onfocusEle(e){

	if($(selected_field)) {
		$("h-" + selected_field).className = "field-hint-inactive" ;
		$(selected_field).className = "inputstyle" ;
	}
	var id = Event.element(e).id;
	$(id).className = "inputstyle-focus" ;
	$("h-" + id).className = "field-hint" ;
};

selected_field = '';

function Highlight(id){
	selected_field = id;
	$(id).focus();
};

function setColor(selectedId, allSelectedId){
  var allSelArr = allSelectedId.split(',');
  for (var i = 0; i < allSelArr.length; i++)
  {
	if(i % 2 == 0) {
		var cls = "lighttableBgcolor";
	}
	else {
		var cls = "ultralighttableBgcolor";
	}
	$('tr_'+allSelArr[i]).className = cls;
  }
  $('tr_'+selectedId).className = 'selectedBgcolor';
}

function setColorBack(allSelectedId){
  var allSelArr = allSelectedId.split(',');
  for (var i = 0; i < allSelArr.length; i++)
  {
	if(i % 2 == 0) {
		var cls = "lighttableBgcolor";
	}
	else {
		var cls = "ultralighttableBgcolor";
	}
	if (i == 0)
	{
		var cls = 'selectedBgcolor';
	}
	$('tr_'+allSelArr[i]).className = cls;
  }
}



function displayAlert(msg)
{
	if(msg) $('msg_div').innerHTML = msg;
	$('alert_div').style.display = '';
	$('global_err').style.display = 'none';
	$('alert_div').className = 'alert_show';

}

function displayAlertLogin(msg)
{
	if(msg) $('msg_div_login').innerHTML = msg;
	$('alert_div_login').style.display = '';
	$('global_err').style.display = 'none';
	$('alert_div_login').className = 'alert_show';

}

function displayAlertAdd(msg)
{
	$('showTr').style.display = '';
	if(msg) $('msg_div_add').innerHTML = msg;
	$('alert_div_add').className = 'alert_show';
}



function setDel(id){
 document.getElementById('tr_'+id).onclick = '';
}




function dispHelp(){
		 var dTop = (screen.height / 4);
		 var dLeft = (screen.width / 3);
		 $('dispHelp').style.top = dTop+'px';
		 $('dispHelp').style.left = dLeft+'px';
		 $('dispHelp').style.width = '450px';
		 //$('dispHelp').style.height = '280px';
		 $('dispEditDiv').style.display = 'none';
		 //$('detailsWindow').style.display = 'none';
		 $('dispMenu').style.display = 'none';
		 $('dispDelDiv').style.display = 'none';
		 Effect.Grow('dispHelp');
}
/*
*
*/
function validate()
{
	//alert("nandan");
	if(alltrim($F('email')) == '')
	{
		displayAlert("Email is blank!");
		$('email').focus();
		//showLoader(0);
		return false;
	}
	
	if(alltrim($F('email')) != '') {
		if(!checkEmail(alltrim($F('email')))) {
			displayAlert("Enter a valid Email!");
			$('email').select();
			$('email').focus();
			return false;
		}
	}	
	if(alltrim($F('password')) == '')
	{
		displayAlert("Password is blank!");
		$('password').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('password')).length < 6)
	{
		displayAlert("Password must have more than 5 characters!");
		$('password').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('confirmpassword')) == '')
	{
		displayAlert("Confirm Password is blank!");
		$('confirmpassword').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('password')) != alltrim($F('confirmpassword')))
	{
		displayAlert("Confirm Password does not match !");
		$('confirmpassword').focus();
		$('confirmpassword').select();
		return false;
	}
	if(alltrim($F('customer_name')) == '')
	{
		displayAlert("Name is blank!");
		$('customer_name').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('phone')) == '')
	{
		displayAlert("Phone is blank!");
		$('phone').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('address1')) == '')
	{
		displayAlert("Address1 is blank!");
		$('address1').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('town')) == '')
	{
		displayAlert("Town is blank!");
		$('town').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('postcode')) == '')
	{
		displayAlert("Postcode is blank!");
		$('postcode').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('billing_address1')) == '')
	{
		displayAlert("Billing Address1 is blank!");
		$('billing_address1').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('billing_town')) == '')
	{
		displayAlert("Billing Town is blank!");
		$('billing_town').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('billing_postcode')) == '')
	{
		displayAlert("Billing Postcode is blank!");
		$('billing_postcode').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('shipping_name')) == '')
	{
		displayAlert("Shipping Name is blank!");
		$('shipping_name').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('shipping_address1')) == '')
	{
		displayAlert("Shipping Address 1 is blank!");
		$('shipping_address1').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('shipping_town')) == '')
	{
		displayAlert("Shipping Town is blank!");
		$('shipping_town').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('shipping_postcode')) == '')
	{
		displayAlert("Shipping Postcode is blank!");
		$('shipping_postcode').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('shipping_phone')) == '')
	{
		displayAlert("Shipping Phone is blank!");
		$('shipping_phone').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('shipping_email')) == '')
	{
		displayAlert("Shipping Email is blank!");
		$('shipping_email').focus();
		//showLoader(0);
		return false;
	}
}
/*
*This function is used to cpoy address and set it to the billing address
*/
function copyaddress()
{
	if($('billing_address').checked)
	{
		$('billing_address1').value = $F('address1');
		$('billing_address2').value = $F('address2');
		$('billing_town').value = $F('town');
		$('billing_postcode').value = $F('postcode');
	}
	else
	{
		$('billing_address1').value = '';
		$('billing_address2').value = '';
		$('billing_town').value = '';
		$('billing_postcode').value = '';
	}
}
/*
*This function is used to copy billing address and set it to the shipping address
*/
function copybillingaddress()
{
	if($('shipping_address').checked)
	{
		$('shipping_name').value = $F('customer_name');
		$('shipping_address1').value = $F('billing_address1');
		$('shipping_address2').value = $F('billing_address2');
		$('shipping_town').value = $F('billing_town');
		$('shipping_postcode').value = $F('billing_postcode');
		$('shipping_phone').value = $F('phone');
		$('shipping_email').value = $F('email');
	}
	else
	{
		$('shipping_name').value = '';
		$('shipping_address1').value = '';
		$('shipping_address2').value = '';
		$('shipping_town').value = '';
		$('shipping_postcode').value = '';
		$('shipping_phone').value = '';
		$('shipping_email').value = '';
	}
}
function loginvalid()
{
	//alert("nandan");
	if(alltrim($F('login_email')) == '')
	{
		displayAlertLogin("Email is blank!");
		$('login_email').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('login_email')) != '') {
		if(!checkEmail(alltrim($F('login_email')))) {
			displayAlertLogin("Enter a valid Email!");
			$('login_email').select();
			$('login_email').focus();
			return false;
		}
	}
	if(alltrim($F('login_password')) == '')
	{
		displayAlertLogin("Password is blank!");
		$('login_password').focus();
		//showLoader(0);
		return false;
	}
}
/*
*
*/
function forgotPasswordValid()
{
	if(alltrim($F('forgotpassword_email')) == '')
	{
		displayAlertLogin("Email is blank!");
		$('forgotpassword_email').focus();
		//showLoader(0);
		return false;
	}
	if(alltrim($F('forgotpassword_email')) != '') {
		if(!checkEmail(alltrim($F('forgotpassword_email')))) {
			displayAlertLogin("Enter a valid Email!");
			$('forgotpassword_email').select();
			$('forgotpassword_email').focus();
			return false;
		}
	}
}