// JavaScript Document
function login_check(s,s1){
//alert(s)
	if(s!="1"){
		alert("Please login or register for add to wishlist")
		location.href="login.php"
	}else{
		//alert('sat')
		location.href="add_wishlist.php?id="+s1
	}
}
function valid_registration(regis)
{
	if(trim(regis.name.value) == "")
	{
		alert("please enter first name");
		regis.name.focus();
		return(false);
	}
	
	if(trim(regis.add.value) == "")
	{
		alert("please enter Address");
		regis.add.focus();
		return(false);
	}
	
	if(trim(regis.city.value) == "")
	{
		alert("please enter City");
		regis.city.focus();
		return(false);
	}
	
	if((regis.state.value == "")&&(trim(regis.other.value) ==""))
	{
		alert("please enter State");
		regis.state.focus();
		return(false);
	}
	
	if((regis.country.value == "")&&(trim(regis.othrcountry.value) == ""))
	{
		alert("please enter country");
		regis.country.focus();
		return(false);
	}
	
	if(trim(regis.zpcode.value) == "")
	{
		alert("please enter Zipcode");
		regis.zpcode.focus();
		return(false);
	}
	
	if(isNaN(regis.zpcode.value))
	{
		alert("please enter valid Zipcode");
		regis.zpcode.focus();
		return(false);
	}
	
	if(trim(regis.phone.value) == "")
	{
		alert("please enter Phone Number");
		regis.phone.focus();
		return(false);
	}
	
	/*if(isNaN(regis.phone.value))
	{
		alert("please enter valid Phone Number");
		regis.phone.focus();
		return(false);
	}*/
	
	if(trim(regis.email.value) == "")
	{
		alert("please enter email");
		regis.email.focus();
		return(false);
	}	
	if(checkEmail(regis.email.value)==false)
	{
		alert("please enter valid email");
		regis.email.focus();
		return(false);
	}	

	if(trim(regis.userid.value) == "")
	{
		
		alert("please enter user Id");
		regis.userid.focus();
		return(false);
	}
	if ( containsSpace(regis.userid.value)) 
	{
		alert("Your User ID should not contain any spaces. Please check the User ID");
		return false;
	}

	
	if(trim(regis.password.value) == "")
	{
		alert("please enter Password");
		regis.password.focus();
		return false;
	}
	
	if(regis.password.value != regis.cpass.value)
	{
		alert("Password and Confirm Password are not same");
		regis.cpass.focus();
		return false ;
	}
	return true;
}
function valid_login(login)
{
	if(login.user.value == "")
	{
		alert("please enter username");
		login.user.focus();
		return(false);
	}
	
	if(login.pass.value == "")
	{
		alert("please enter password");
		login.pass.focus();
		return(false);
	}
	return true;
}
function change_image(a1,a2){
	a2.src="backoffice/gallery_images/"+a1
}
function shopage(a1,a2,a3,a4){

	if(a1.value==""){
		alert("Please enter page number")
		return false
	}
	if(isNaN(a1.value)==true){
		alert("Please enter numeric number")
		return false
	}
	//alert(a1.value)
	//alert(a2.value)

	if(	eval(a1.value)>	eval(a2.value)){
		alert("Total Available Pages are "+a2.value)
		return false
	}
	s1=a1.value-1
	if(s1<0){
		s1=0
	}
	location.href="current-listings.php?recnum="+s1+"&keyword="+a3+"&ordb="+a4
}

function functionpagechange(a1,a2,a3){
	location.href="current-listings.php?recnum="+a2+"&keyword="+a3+"&ordb="+a1.value

}
function validate_search(s1){
	if((s1.keyword.value=="")||(s1.keyword.value=="Enter city, state OR zip")){
		alert("Pleae enter your city,state or Zip code")
		s1.keyword.focus()
		return false
	}
}
function form_validate1(s1){

	if(trim(s1.name.value)=="")
	{
	
		alert("Plese enter your name")
		s1.name.focus()
		return false
	}
	if(trim(s1.email.value)=="")
	{
		alert("Plese enter your emailid")
		s1.email.focus()
		return false
	} else {
			
					st=s1.email.value;
					if(checkEmail(st)==false)
					{
						alert("Please Enter Correct Email")
						s1.email.focus();
						return false
					}
	
	}
	if(trim(s1.f_name.value)=="")
	{
		alert("Plese enter your address")
		s1.f_name.focus()
		return false
	}
	if(trim(s1.f_email.value)=="")
	{
		alert("Plese enter your phone no.")
		s1.f_email.focus()
		return false
	} 
	if(trim(s1.msg.value)=="")
	{
		alert("Plese enter your message")
		s1.msg.focus()
		return false
	} 
}
function validate_this_contact(s1){

	if(trim(s1.textfield2.value)=="")
	{
	
		alert("Plese enter your name")
		s1.textfield2.focus()
		return false
	}
	if(trim(s1.textfield22.value)=="")
	{
	
		alert("Plese enter street")
		s1.textfield22.focus()
		return false
	}
	if(trim(s1.textfield23.value)=="")
	{
	
		alert("Plese enter city")
		s1.textfield23.focus()
		return false
	}
	if(trim(s1.textfield232.value)=="")
	{
	
		alert("Plese enter pin/zip code")
		s1.textfield232.focus()
		return false
	}
	if(trim(s1.textfield2322.value)=="")
	{
	
		alert("Plese enter phone")
		s1.textfield2322.focus()
		return false
	}
	if(trim(s1.textfield4.value)=="")
	{
	
		alert("Plese enter emailid")
		s1.textfield4.focus()
		return false
	}else{
					st=s1.textfield4.value;
					if(checkEmail(st)==false)
					{
						alert("Please Enter Correct Email")
						s1.textfield4.focus();
						return false
					}
	}
	if(trim(s1.textfield5.value)=="")
	{
	
		alert("Plese enter message")
		s1.textfield5.focus()
		return false
	}


}
function form_validate(s1)
{


	
	if(trim(s1.name.value)=="")
	{
	
		alert("Plese enter your name")
		s1.name.focus()
		return false
	}
	if(trim(s1.email.value)=="")
	{
		alert("Plese enter your emailid")
		s1.email.focus()
		return false
	} else {
			
					st=s1.email.value;
					if(checkEmail(st)==false)
					{
						alert("Please Enter Correct Email")
						s1.email.focus();
						return false
					}
	
	}
	if(trim(s1.f_name.value)=="")
	{
		alert("Plese enter your friend name")
		s1.f_name.focus()
		return false
	}
	if(trim(s1.f_email.value)=="")
	{
		alert("Plese enter your friend emailid")
		s1.f_email.focus()
		return false
	} else {
			
					st=s1.f_email.value;
					if(checkEmail(st)==false)
					{
						alert("Please Enter Correct Email")
						s1.f_email.focus();
						return false
					}
	
	}
}

function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}


function trim(str)
{
   return RTrim(LTrim(str));
}

function checkEmail(str)
{
		if((str.indexOf("@")==-1) || (str.indexOf(".")==-1))
		{
			fstr="Please Enter @ or .";
			return false;
		}
		else
		{
		if((str.indexOf("@") == 0) || (str.indexOf(".") == 0))
		{
			fstr="@ or . Cannot Be first";
			return false;
		}
		if((str.indexOf("@") == (str.length-1)) || (str.indexOf(".") == (str.length-1)))
		{
			fstr="@ or . Cannot Be Last";
			return false;
		}

	/*	if(str.indexOf("@") > str.indexOf("."))
		{
			fstr="@ Should be After .";
			return false;
		}*/
		if((str.indexOf("@")+1) == str.indexOf("."))
		{
			fstr="@. IS Invalid Email";
			return false;
		}
		}
		var cp=0;					
	
		if(cp==2)
		{
			fstr="@ cannnot be repeated";
			return false;
		}
		return true;
	}
function check_fun(s1){
		if(s1.value==""){
			alert("Please enter your userid")
			s1.focus()
		} else {
			location.href="forgot_pwd.php?uid="+s1.value
		}
		
	}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}