function checkOrderDetail(shipping_charge, pgateway) {
	//alert(shipping_charge);
	//alert(pgateway);
	if(shipping_charge && pgateway) {
		//return true;
		document.submit();
	}
	if(!shipping_charge) {
		alert('please choose shipping carrier!');
		//return false;
	}
	if(!pgateway) {
		alert('please choose Payment gateway!');
		//return false;
	}
	return false;
}

function checkCart(grand_total) {
	//alert(grand_total);
	if(grand_total) {
		return true;
	}
	else {
		alert('Your cart is empty');
	}
}
function checkLogin(sessid) {
	if(!sessid) {
		var conf=confirm('You cannot checkout without login. Would you like to login now?');
		if(conf)
			top.location="main.php?page=myaccount";
		else
			return false;
	}
	else {
		top.location="main.php?page=checkout";
	}
	
}

function checkLogin1(sessid,grand_total) {
	//alert(grand_total);
	if(grand_total) {
		if(!sessid){
			var conf=confirm('You cannot checkout without login. Would you like to login now?');
			if(conf)
				top.location="main.php?page=myaccount";
			else
				return false;
		}
		else {
			location.href="main.php?page=checkout";
		}
	}
	else {
		alert('Your cart is empty. You cannot checkout!');
		return false;
	}
}


function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
      e.style.display = 'none';
   else
      e.style.display = 'block';
}


function MemberRegistration(){
	//alert('im here');
	var firstname = document.getElementById('firstname').value;
	//alert(firstname);
	var	lastname = document.getElementById('lastname').value;
	var address1 = document.getElementById('address1').value
	var city = document.getElementById('city').value
	var country = document.getElementById('country').value
	var phone = document.getElementById('phone').value;
	var comment = trim(document.getElementById('comment').value, " ");
	
	var err=false;
	var msg="";
	var i=1;
	if(firstname == "")
		{
			//alert("Please enter the first name");
			msg = i + '. Please enter first name\n';
			i++;
			//document.getElementById('fname').focus();
			//return false;
		}
		
	if(lastname == "")
		{
			//alert("Please enter the last name");
			msg += i + '. Please enter last name\n';
			i++;
			//document.getElementById('lname').focus();
			//return false;
		}
		
	if(address1 == "")
		{
			//alert("Please enter the address1");
			msg += i + '. Please enter address1\n';
			i++;
			//document.getElementById('add1').focus();
			//return false;
		}
		
	
	if(city == "")
		{
			//alert("Please enter the city");
			//document.getElementById('city').focus();
			//return false;
			msg += i + '. Please enter City\n';
			i++;
		}
	
	if(country == "")
		{
			/*alert("Please select the country");
			document.getElementById('country').focus();
			return false;*/
			msg += i + '. Please enter country\n';
			i++;
		}
		
	if(phone == "")
		{
			/*alert("Please select the country");
			document.getElementById('country').focus();
			return false;*/
			msg += i + '. Please enter Phone No\n';
			i++;
		}
		
	if(comment == "Eg: UK, Manchester" || comment == "Eg: Australia, Queensland" || comment == "")
	{
		msg += i + '. Please enter comment\n';
		//i++;
	}
		
	
	//submit();  //requires if submit is to be done on a non ajax javascript because in the form page return false is done.  return err is not required after this
	if(msg){
		return msg;
	}
}

/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}