function trim(str)
{
	var reg = "/^\s*|\s$/";
	return str.replace(reg , '');
}
var remail=/^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;
function checkEmail(fieldvalue){
	if(remail.test(fieldvalue))
			return false;
		else
			return true;
}

function check_postcode(pcode)
 {
   var rand_var = Math.random(); 
   regexp1 = /^([a-z][a-z][0-9] [0-9][a-z][a-z])$/gi;
   regexp2 = /^([a-z][a-z][0-9][0-9] [0-9][a-z][a-z])$/gi;
   regexp3 = /^([a-z][0-9] [0-9][a-z][a-z])$/gi;
   regexp4 = /^([a-z][0-9][0-9] [0-9][a-z][a-z])$/gi;
   

   if ((pcode.match(regexp1) != null) || (pcode.match(regexp2) != null) || (pcode.match(regexp3) != null) || (pcode.match(regexp4) != null))
    {
     return false;
    }
   else
    {
     //alert('Please complete the Post Code in the following format:\n\n"LLN NLL" or "LLNN NLL" or "LN NLL" or "LNN NLL" where L=letter and N=number');
     //$('post_code').focus();
     return true;
    }

   /*alert(pcode)
   if(regexp1.test(pcode))
   {
		alert("1");
		return false;
   }
   else if(regexp2.test(pcode))
   {
	   alert("2");
	   return false;
   }
   else if(regexp3.test(pcode))
   {
	   alert("3");
	   return false;
   }
   else if(regexp4.test(pcode))
   {
	   alert("4");
	   return false;
   }
   else
   {
	   alert("5");
		return true;
   }*/
 }
 
 	<!--
	function go(){
	  if (document.jumpto.pids.options[document.jumpto.pids.selectedIndex].value != "none") {
		location = document.jumpto.pids.options[document.jumpto.pids.selectedIndex].value;
	  }
	}
	
	function confirmAlbum(stuffid){
    var is_confirmed = confirm("Are you sure you want to DELETE this album? (id: " + stuffid + ") \n\nWARNING: All the pictures and comments in this album will \nalso be deleted!");
    if (is_confirmed)
      // Do nothing...
    return is_confirmed;
	} 
	
	function confirmPicture(stuffid) {
    var is_confirmed = confirm("Are you sure you want to DELETE this picture? (id: " + stuffid + ") \nComments will also be deleted.");
    if (is_confirmed)
        // Do nothing...
    return is_confirmed;
	} 
	
	function confirmComment(stuffid) {
    var is_confirmed = confirm("Are you sure you want to DELETE this comment? (id: " + stuffid + ")");
    if (is_confirmed)
        // Do nothing...
	  return is_confirmed;
	} 
	//-->


function ajaxAddProduct(productId,qty,type)
{
	var oXmlHttp	= zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "add_to_cart.php?pid="+productId+"&qty="+qty+"&type=" +type , true);

    oXmlHttp.onreadystatechange = function () 
	{
		if (oXmlHttp.readyState == 4) 
		{
			if (oXmlHttp.status == 200) 
			{
				var result	= oXmlHttp.responseText;

				//alert(result);

				var productItems	= result.split('||');

				var qty				= productItems[1];
				var price			= productItems[2];

				if(productItems[0]=="OK")
				{
					document.getElementById('display_cart').innerHTML = "Items:"+qty+"&nbsp;Subtotal:"+price;
					alert('Product added successfully to cart!');
				}
			}
			else 
			{
				//displayCustomerInfo("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
			}
		 }
    };
    oXmlHttp.send(null);
}




/*function ajaxAddProduct(productId,color,size,qty)
{
	var oXmlHttp	= zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "add_to_cart.php?pid="+productId+"&color=" + color+"&size="+size+"&qty="+qty , true);

    oXmlHttp.onreadystatechange = function () 
	{

        if (oXmlHttp.readyState == 4) 
		{
				if (oXmlHttp.status == 200) 
				{
					var result	= oXmlHttp.responseText;

					//alert(result);

					var productItems	= result.split('||');

					var qty				= productItems[1];
					var price			= productItems[2];

					if(productItems[0]=="OK")
					{
						document.getElementById('display_cart').innerHTML = "Items:"+qty+"&nbsp;Subtotal:"+price;
						alert('Product added successfully to cart!');
					}

				}else 
				{
					//displayCustomerInfo("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
         }            
    };
    oXmlHttp.send(null);
}

function ajaxShopProductAdd(productId,color,size,qty)
{
	var oXmlHttp	= zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "add_shop_to_cart.php?pid="+productId+"&color=" + color+"&size="+size+"&qty="+qty , true);

    oXmlHttp.onreadystatechange = function () 
	{

        if (oXmlHttp.readyState == 4) 
		{
				if (oXmlHttp.status == 200) 
				{
					var result	= oXmlHttp.responseText;

					//alert(result);

					var productItems	= result.split('||');

					var qty				= productItems[1];
					var price			= productItems[2];

					if(productItems[0]=="OK")
					{
						document.getElementById('display_cart').innerHTML = "Items:"+qty+"&nbsp;Subtotal:"+price;
						alert('Product added successfully to cart!');
					}

				}else 
				{
					//displayCustomerInfo("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
         }            
    };
    oXmlHttp.send(null);
}*/

function charCount(str) {
// counts the number of unicode characters, which may differ from
str.length
var esc = escape(str); // escape more robust than encodeURI
return esc.replace(/%uD[C-F]../g,'')
.replace(/%u..../g,'"')
.replace(/%../g,"'")
.length;
}

function validateMemberAddress(formName){
	
	if(formName.sel_title.value=="")
	{
		alert("Please select title!");
		formName.sel_title.focus();
		return false;
	}else if(formName.fname.value=="")
	{
		alert("Please select First Name!");
		formName.fname.focus();
		return false;
	}else if(formName.lname.value=="")
	{
		alert("Please select Last Name!");
		formName.lname.focus();
		return false;
	}else if(formName.bemail.value=="")
	{
		alert("Please enter valid email address!");
		formName.bemail.focus();
		return false;
	}else if(checkEmail(formName.bemail.value))
	{
		alert("Please enter the valid email id");
		formName.bemail.focus();
		return false;			
	}else if(formName.member_id.value=="")
	{
		if(formName.username.value=="")
		{
			alert("Please enter the username !");
			formName.username.focus();
			return false;
		}else if(formName.passwd.value=="")
		{
			alert("Please enter password!");
			formName.passwd.focus();
			return false;
		}else if (charCount(formName.passwd.value)<6)
		{
			alert("Please enter minimum 6 character password!");
			formName.passwd.focus();
			return false;
		}else if(formName.cnpasswd.value=="")
		{
			alert("Please re-enter password!");
			formName.cnpasswd.focus();
			return false;
		}else if(formName.passwd.value!=formName.cnpasswd.value)
		{
			alert("Please enter correct password!");
			formName.cnpasswd.focus();
			return false;
		}
	}else if(formName.baddr.value=="")
	{
		alert("Please enter billing address!");
		formName.baddr.focus();
		return false;
	}else if(formName.bcity.value=="")
	{
		alert("Please enter billing city!");
		formName.bcity.focus();
		return false;
	}else if(formName.bstate.value=="")
	{
		alert("Please enter billig state!");
		formName.bstate.focus();
		return false;
	}else if(formName.bcntry.value=="")
	{
		alert("Please select billing country!");
		formName.bcntry.focus();
		return false;
	}else if(formName.bzipcode.value=="")
	{
		alert("Please enter billing zipcode!");
		formName.bzipcode.focus();
		return false;
	}else if(formName.btelno.value=="")
	{
		alert("Please enter billing telephone number!");
		formName.btelno.focus();
		return false;
	}
	
	if(formName.radShipping[1].checked==true){
		if(formName.saddr.value=="")
		{
			alert("Please enter shipping address!");
			formName.saddr.focus();
			return false;
		}else if(formName.scity.value=="")
		{
			alert("Please enter shipping city!");
			formName.scity.focus();
			return false;
		}else if(formName.sstate.value=="")
		{
			alert("Please enter shipping state!");
			formName.sstate.focus();
			return false;
		}else if(formName.scntry.value=="")
		{
			alert("Please select shipping country!");
			formName.scntry.focus();
			return false;
		}else if(formName.szipcode.value=="")
		{
			alert("Please enter shipping zipcode!");
			formName.szipcode.focus();
			return false;
		}else if(formName.stelno.value=="")
		{
			alert("Please enter shipping telephone number!");
			formName.stelno.focus();
			return false;
		}else{
			
			formName.hidAction.value="register_member";
			formName.submit();
		}
	}else{
			
			formName.hidAction.value="register_member";
			formName.submit();
	}

}

function validateMyLogin(formName){

	if(formName.user_name.value=="")
	{
		alert("Please enter valid email address!");
		formName.user_name.focus();
		return false;
	}else if(formName.user_pasword.value=="")
	{
		alert("Please enter valid password!");
		formName.user_pasword.focus();
		return false;
	}//else if(formName.gotopage.value!="")
	//{
		//checkLoginDetails(formName.user_email.value,formName.user_pasword.value,formName.del_id.value,formName.gotopage.value);
	//}
	else{
		checkLoginDetails(formName.user_name.value,formName.user_pasword.value,'','');
	}
}

function checkLoginDetails(user_id,pwd,delivery_id,gotopage)
{
	var oXmlHttp	= zXmlHttp.createRequest();
	
	oXmlHttp.open("get", "check_login_details.php?uid="+user_id+"&pwd=" + pwd , true);

    oXmlHttp.onreadystatechange = function () 
	{

        if (oXmlHttp.readyState == 4) 
		{
				if (oXmlHttp.status == 200) 
				{
					var result	= oXmlHttp.responseText;

					if(result == 0)
					{
						// display error message
						msg		= "<font color='#FF0000' size='2'>Invalid Login Details!</font>";
						document.getElementById('error_message').innerHTML = msg;
						document.getElementById('error_message').style.display = 'Block';
					}else if(result==1){

						if(gotopage=="cust_account")
						{
							document.frmMyAccount.action = 'customer_registration.php';
							document.frmMyAccount.submit();
							
						}else{

							document.frmMyAccount.action = 'customer_registration.php';
							document.frmMyAccount.submit();
						}
					}
					
				}else 
				{
					//displayCustomerInfo("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
         }            
    };
    oXmlHttp.send(null);
}


