// JavaScript Document

// class for ajax
function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }

// validations for registration
function reg_validation()
{
	var frm = document.frmreg;
	if(trim(frm.txtuser.value) == '' && trim(frm.txtuser.value).length <= 6)
	{
		alert("Invalid User Name, it should be more than 6 characters");
		frm.txtuser.focus();
		return false;
	}
	if(trim(frm.txtpass.value) == '' && trim(frm.txtpass.value).length <= 6)
	{
		alert("Invalid Password, it should be more than 6 characters");
		frm.txtpass.focus();
		return false;
	}
	if(trim(frm.txtpass.value) != trim(frm.txtcpass.value))
	{
		alert("Password and Confirm Password should be same");
		frm.txtcpass.focus();
		return false;
	}
	if(trim(frm.txtcompany.value) == '')
	{
		alert("Company Name Should not be Empty");
		frm.txtcompany.focus();
		return false;
	}
	if(!isValidURL(frm.txturl,"valid website URL",'yes'))
	{
		return false;
	}
	
	if(trim(frm.txtfname.value) == '')
	{
		alert("First Name Should not be Empty");
		frm.txtfname.focus();
		return false;
	}
	if(trim(frm.txtlname.value) == '')
	{
		alert("Last Name Should not be Empty");
		frm.txtlname.focus();
		return false;
	}
	if(!isValidEmail(frm.txtemail,'yes'))
	{
		return false;
	}
	if(trim(frm.txtemail.value) != trim(frm.txtcemail.value))
	{
		alert("Email and Confirm Email should be same");
		return false;
	}
	if(trim(frm.txtcity.value) == '')
	{
		alert("City Name Should not be Empty");
		frm.txtcity.focus();
		return false;
	}
	if(trim(frm.txtcountry.value) == '-1')
	{
		alert("Select Country Name");
		frm.txtcountry.focus();
		return false;
	}
	if(trim(frm.txtstate.value) == '-1')
	{
		alert("Select State Name");
		frm.txtstate.focus();
		return false;
	}
	document.getElementById("tdmsg1").innerHTML = '';
	document.getElementById("tdmsg").innerHTML = '';
	show_valid_user();
	if(confirm("Are You Sure You want to submit your registration details"))
	{	
		if(trim(document.getElementById("tdmsg").innerHTML) == '')
			return true;
		else
		{
			document.getElementById("tdmsg").focus();
			return false;
		}
	}
	else
		return false;
}
// validation for send me all details in home page
function validdetials()
{
	var frm = document.detialsfrm;
	if(!isValidEmail(frm.txtmail,'yes'))
	{
		return false;
	}
return true;
}
// validations for login

function login_valid()
{
	var frm = document.loginfrm;
	if(trim(frm.txtuser.value) == '')
	{
		alert("User Name should not be empty");
		frm.txtuser.focus();
		return false;
	}
	if(trim(frm.txtpass.value) == '')
	{
		alert("Password should not be empty");
		frm.txtpass.focus();
		return false;
	}
return true;
}

function visitor_info_valid()
{
 var frm = document.visitorfrm;
 	if(trim(frm.txtname.value) == '')
	{
		alert("Name should not be empty");
		frm.txtname.focus();
		return false;
	}
	if(!isValidEmail(frm.txtemail,'yes'))
	{
		return false;
	}
return true;
}

// validations for tell a friend

function tellafriend_valid()
{
	var frm = document.friendfrm;
	 if(!isValidEmail(frm.txtemail,'yes'))
	  {
		 return false;
	  }
	  if(trim(frm.txttoname.value) == '')
	  {
	  	alert("Please enter To Name ");
		frm.txttoname.focus();
		return false;
	  }
	  if(trim(frm.txtfromname.value) == '')
	  {
	  	alert("Please enter your Name ");
		frm.txtfromname.focus();
		return false;
	  }
	  if(!isValidEmail(frm.txtfromemail,'yes'))
	  {
		 return false;
	  }
	  
	return true;
}

// contact page validations

function contactValid()
{
	var frm = document.contactfrm;
 
 	if(frm.txtname.value=="")
	{
	alert("Please Enter Your Name ");
	frm.txtname.focus();
	return false;
	}
  
	if(!isValidEmail(frm.txtmail,'yes'))
	  {
		 return false;
	  }
  
  	if(frm.txtsub.value=="")
	{
	alert("Please Enter Subject ");
	frm.txtsub.focus();
	return false;
	}

  	if(frm.txtmsg.value=="")
	{
	alert("Please Enter message ");
	frm.txtmsg.focus();
	return false;
	}
 return true;
}

// change password validation (change_password.php)

function chgpwdValid()
{
	var frm = document.chgpwdfrm;
	if(trim(frm.txtnpwd.value) == '')
	{
		alert("Please Enter new Password ");
		frm.txtnpwd.focus();
		return false;
	}
	if(trim(frm.txtnpwd.value) != trim(frm.txtcpwd.value))
	{
		alert("Invalid Confirm Password, Enter a Valid Confirm Password");
		frm.txtcpwd.focus();
		return false;
	}
return true;
}
