/**Common Trim Function***/
function Trim(obj) {

  return rTrim( lTrim( obj ) );

}

function lTrim( obj ) {

  while (obj.charAt(0) == " ") {

      obj = obj.substring(1);

  }

 return obj;

}

function rTrim( obj ) {

   while (obj.charAt(obj.length - 1) == " ") {

      obj = obj.substring(0, obj.length - 1);

  }

 return obj;

}
function validateEmail( emailString ){  
		str = emailString;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if ((str.search(/\$/)!=-1)||(str.search(/\*/)!=-1)||(str.search(/\^/)!=-1)||(str.search(/\#/)!=-1)||(str.search(/\!/)!=-1)||(str.search(/\%/)!=-1)||(str.search(/\&/)!=-1)||(str.search(/\?/)!=-1)||(str.search(/\+/)!=-1)||(str.search(/\=/)!=-1)||(str.search(/\|/)!=-1)||(str.search(/\-/)!=-1)||(str.search(/\}/)!=-1)||(str.search(/\]/)!=-1)||(str.search(/\[/)!=-1)||(str.search(/\}/)!=-1)||(str.search(/\~/)!=-1)||(str.search(/\\/)!=-1)||(str.search(/\//)!=-1)||(str.search(/\)/)!=-1)||(str.search(/\(/)!=-1))

		{
			/* $("span#email").hide("slow");
			$("span#email1").show("slow");
			setTimeout("close_msg('span#email1')",3000); 
			alert("Only @, _ and . special characters allowed");        */

			return false

		}

		

		if (str[lstr-1]=="."){

		/*  alert("Invalid E-mail ID")
 		   $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		   $("span#email2").show("slow");
		   setTimeout("close_msg('span#email2')",3000);
*/
		   return false

		}



		if (str.indexOf(at)==-1){

		  /* alert("Invalid E-mail ID")*/
		     $("span#email").hide("slow");
		    $("span#email1").hide("slow");
			$("span#email2").show("slow");
			setTimeout("close_msg('span#email2')",3000);
			 
		   return false

		}



		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		 /*  alert("Invalid E-mail ID")
		    $("span#email").hide("slow");
		    $("span#email1").hide("slow");
			$("span#email2").show("slow");
			setTimeout("close_msg('span#email2')",3000); */
		   return false

		}



		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		   /*  alert("Invalid E-mail ID")
		     $("span#email").hide("slow");
		   $("span#email1").hide("slow");
	
  $("span#email2").show("slow");
  setTimeout("close_msg('span#email2')",3000); */
		    return false

		}



		 if (str.indexOf(at,(lat+1))!=-1){

		  /* alert("Invalid E-mail ID")
		     $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		
  $("span#email2").show("slow");
  setTimeout("close_msg('span#email2')",3000); */ 
		    return false

		 }



		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		   /* alert("Invalid E-mail ID")
		     $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		
		  $("span#email2").show("slow");
		  setTimeout("close_msg('span#email2')",3000); */
		    return false

		 }



		 if (str.indexOf(dot,(lat+2))==-1){

		  /*   alert("Invalid E-mail ID")
		   $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		
	  $("span#email2").show("slow");
	  setTimeout("close_msg('span#email2')",3000);*/
		    return false

		 }

		

		 if (str.indexOf(" ")!=-1){

		 /*  //  alert("Invalid E-mail ID")
		   $("span#email").hide("slow");
		   $("span#email1").hide("slow");
		  
		   $("span#email2").show("slow");
		   setTimeout("close_msg('span#email2')",3000);*/

		    return false

		 }



 		 return true;

}



function show_login(obj)
{
	
	$(document).ready(function(){
    
     $("div").click(function () { 
      $('#login_sec').slideDown('fast'); 
    });

  });
}
function transferpage(obj)
{
	window.location.assign(obj);
	
}
function login_validation(obj)
{
	if(Trim(obj.username.value)=="")
	{
		
		document.getElementById('error_id').style.display="block";
		document.getElementById('error_id').innerHTML="Enter The username";
		obj.username.focus();
		return false;
	}
	else if(Trim(obj.password.value)=="")
	{
		//alert("password");
		document.getElementById('error_id').style.display="block";
		document.getElementById('error_id').innerHTML="Enter the password";
		obj.password.focus();
		return false;
	}
	else
	{
		return true;
	}
	return false;
}


function getShippingService(obj)
{
	
	//var a=document.getElementById('shipMethod').value;
	if(document.getElementById('shipResult').innerHTML.search('ajax-loader.gif') != -1 || document.getElementById('shipResult').innerHTML==''){
		alert("Please be a patient, we are calculating shipping rate for your shipping address..");
		return false;
	/* else if(a==''){
		alert('Please select UPS service method');
		return false;
		
	} */
	}else{
		return true;
	}
	
	return false;
	
}
function check_emailvalid(obj)
{
	if(Trim(obj.email.value)=="")
	{
		document.getElementById('error_id').style.display="block";
		document.getElementById('error_id').innerHTML="Enter The Email";
		obj.email.focus();
		return false;
	}
	else if(!validateEmail(obj.email.value))
	{
		document.getElementById('error_id').style.display="block";
		document.getElementById('error_id').innerHTML="Invalid E-mail";
		obj.email.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function replaceDiv(obj1,obj2){
	document.getElementById(obj1).style.display='block';
	document.getElementById(obj2).style.display='none';
}



function parenthis(obj,obj1){
	var a='';
	if(obj.length>12){		
		document.getElementById(obj1).value=obj.substr(0,12);
	}else{			
		if(obj.length>=3){						 
			a=obj.replace(")","");
			a=a.replace("(","");
			var finalstr="("+a.substring(0,3)+")"+a.substring(3,a.length);
			document.getElementById(obj1).value=finalstr;
		}
	}
}



function getAdd(obj){
	if(obj.firstname.value!=''){
		obj.firstname.className='validate[required,custom[noSpecialCaracters],length[0,20]] text-input';
	}else{
		obj.firstname.className='validate[required] text-input';
	}
	
	if(obj.telephone.value!=''){
		obj.telephone.className='validate[required,custom[telephone]] text-input';
	}else{
		obj.telephone.className='validate[required] text-input';
	}
	
	if(obj.email.value!=''){
		obj.email.className='validate[required,custom[email]] text-input';
	}else{
		obj.email.className='validate[required] text-input';
	}
	
	if(obj.email2.value!=''){
		obj.email2.className='validate[required,confirm[email]] text-input';
	}else{
		obj.email2.className='validate[required] text-input';
	}
	
	if(obj.password.value!=''){
		obj.password.className='validate[required,length[6,11]] text-input';
	}else{
		obj.password.className='validate[required] text-input';
	}
	
	if(obj.password2.value!=''){
		obj.password2.className='validate[required,confirm[password]] text-input';
	}else{
		obj.password2.className='validate[required] text-input';
	}
	
}