// JavaScript Document

function valid_form(frm)
{
	var flag=0;
	for(var i=0; i<9; i++){
		if(document.getElementById("domain_name"+i).checked)
			flag=1;
	}
	if(flag==0)
	{
		alert("Please select domain(s).")
		return false;
	}
	return true;
}

function valid_smallsearch(frm)
{
	if(frm.domain.value=="")
	{
		alert("Please enter domain.");
		frm.domain.focus();
		return false;
	}
	else
	{
		var val=true;
		var domainName = frm.domain.value;
		var dotPos=domainName.lastIndexOf(".");
		var domainName1=domainName.substring(0,dotPos);
		var tld=domainName.substring(dotPos,domainName.length);
		
		if(domainName1=="" && tld!="")
		{
			alert("Please enter domain as 'yahoo.com'.");
			frm.domain.focus();
			return false;
		}
	}
	return true;
}

function validate_domainform(frm)
{
	if(frm.domain.value=="")
	{
		alert("Please enter domain name.")
		frm.domain.focus();
		return false;
	}
	var flag=0;
	for(var i=0; i<frm.domainSearch.length; i++){
		if(frm.domainSearch[i].checked)
			flag=1;
	}
	//alert(flag);
	if(flag==0)
	{
		alert("Please select domain extension(s).")
		return false;
	}
	return true;
}

function Validatechar(str)
{
	var reg =/^[a-z][-a-z_ ]{0,49}$/i;
	
	if (!reg.test(str))
		return true;
	return false;
}

function ValidatePhone(str)
{
	var reg =/^[0-9]|\+?[0-9]|\(?[0-9]\)|[0-9\-0-9]$/;
	//alert(reg.test(str))
	if (!reg.test(str))
		return true;
	return false;
}
function checkEmail(val)
{
	var patt = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
	var result;
	
	result = patt.test(val);
	return result;
}
function showlaptop(theTable)
{
     if (document.getElementById(theTable).style.display == 'none')
     {
          document.getElementById(theTable).style.display = 'block';
     }
}
function hidelaptop(theTable)
{
     if (document.getElementById(theTable).style.display == 'none')
     {
          document.getElementById(theTable).style.display = 'none';
     }
     else
     {
          document.getElementById(theTable).style.display = 'none';
     }
}
function showstate(val)
{
	var divIndia = document.getElementById("stateIndia").style;
	var divOther = document.getElementById("other").style;

	if(val!="others")
	{
		divIndia.display = "block";
		divOther.display = "none";
	}
	else
	{
		divIndia.display = "block";
		divOther.display = "block";
	}
}
function checkFormAll()
{ 
	if (document.StandardOrderForm.hosting.value=="---"){
		alert("Please select hosting plan.");
		document.StandardOrderForm.hosting.focus();
		return false	
	}
	if (document.StandardOrderForm.firstname.value==""){
		alert("Please enter your first name");
		document.StandardOrderForm.firstname.focus();
		return false	
	}
	else if(Validatechar(document.StandardOrderForm.firstname.value))
	{ 
		alert("Invalid ! first name.");
		document.StandardOrderForm.firstname.focus();
		return false;
	}
	
	if (document.StandardOrderForm.lastname.value==""){
		alert("Please enter your last name");
		document.StandardOrderForm.lastname.focus();
		return false	
	}
	else if(Validatechar(document.StandardOrderForm.lastname.value))
	{ 
		alert("Invalid ! last name.");
		document.StandardOrderForm.lastname.focus();
		return false;
	}
	
	if (document.StandardOrderForm.companyname.value==""){
		alert("Please enter company name");
		document.StandardOrderForm.companyname.focus();
		return false	
	}
	if (document.StandardOrderForm.street.value==""){
		alert("Please enter address");
		document.StandardOrderForm.street.focus();
		return false	
	}
	if (document.StandardOrderForm.city.value==""){
		alert("Please enter city name");
		document.StandardOrderForm.city.focus();
		return false	
	}
	if (document.StandardOrderForm.state.value==""){
		alert("Please select a state");
		document.StandardOrderForm.state.focus();
		return false	
	}
	else if(document.StandardOrderForm.state.value=="others"){
		if(document.StandardOrderForm.state1.value=="")
		{
			alert("Please enter a state name for Non-Indian State");
			document.StandardOrderForm.state1.focus();
			return false	
		}
	}
	
	if (document.StandardOrderForm.zip.value==""){
		alert("Please enter zipcode.");
		document.StandardOrderForm.zip.focus();
		return false	
	}

	if (document.StandardOrderForm.country.value==""){
		alert("Please select country.");
		document.StandardOrderForm.country.focus();
		return false	
	}

	if (document.StandardOrderForm.phone.value==""){
		alert("Please enter phone number");
		document.StandardOrderForm.phone.focus();
		return false	
	}
	else if(ValidatePhone(document.StandardOrderForm.phone.value))
	{ 
		alert("Invalid ! phone number allowes '+,(,),0-9'.");
		document.StandardOrderForm.phone.focus();
		return false;
	}

	if (document.StandardOrderForm.email.value==""){
		alert("Please enter email");
		document.StandardOrderForm.email.focus();
		return false	
	}
	else if(!checkEmail(document.StandardOrderForm.email.value)){
		alert("Invalid ! email ID.");
		document.StandardOrderForm.email.focus();
		return false	
	}
	
	for (i=0; i<document.StandardOrderForm.paymethod.length; i++){
		if(document.StandardOrderForm.paymethod[i].checked==true){
			if (document.StandardOrderForm.paymethod[i].value=="Check/Money Order"){
				if(document.StandardOrderForm.payment_details.value==""){
					alert("Enter your Payment details");
					document.StandardOrderForm.payment_details.focus();
					return false
				}
			}
		}
	}

	if(document.StandardOrderForm.paymethod.checked==false)
	{
		alert("Please select the Payment Method in Billing Information.");
		return false;
	}
	else if(document.StandardOrderForm.paymethod.checked==true)
	{	
		if(document.StandardOrderForm.payment_details.value=="")
		{
			alert("Please enter the Payment Details");
			return false;
		}
	}
	
	if(document.StandardOrderForm.checkbox.checked==false)
	{
		alert("You have to read the terms and conditions, before you proceed");
		return false;
	}
	return true;
}

function check()
{	
   var yourname1=document.getElementById('txt_name').value;
   var email1=document.getElementById('txt_email').value;
   var phone1=document.getElementById('txt_phone').value;
   var msg=document.getElementById('txt_mssg').value;
   var interest=document.getElementById('interest').value;
   
   if(yourname1=="")
   { 
     alert("Please Enter your Name:");
	 document.getElementById('txt_name').focus();
	 return false;
   }  
   
	if(email1=="")
	{
		alert("Please Enter your Email-Id :");
		document.getElementById('txt_email').focus();
		return false;
	}
   var m = document.getElementById('txt_email').value
   var cnt=0,spc=0,dot=0;
   for(var i=1;i<=m.length;i++)
   {
		if(m.charAt(i)=="@")
			cnt++;
		if(m.charAt(i)==" ")
			spc++;
		if(m.charAt(i)==".")
			dot++;
   }
  lnm=m.length
  if(cnt==0||cnt>1||spc!=0||dot==0 ||lnm<=2 )
  {
		alert("Invalid mail address.Mail id should have an @,no spaces and a '.'   ");
		document.getElementById('txt_email').focus()
		return false;
  }

   
   if(phone1=="")
   {
      alert("Please Enter Your Phone Number:");
	  document.getElementById('txt_phone').focus();
	  return false;
   }
   
   if(interest=="0")
   {
      alert("Please Select the Interest:");
	  document.getElementById('interest').focus();
	  return false;
   }
   
   if(msg=="")
   {
      alert("Please Select the Message:");
	  document.getElementById('txt_mssg').focus();
	  return false;
   }
	return true;
}

function popup(url)
{
	window.open(url,"View","width=500,height=400,resizable=1,scrollbars=1,location=0");
}

function popup1(url,name)
{
	window.open(url,name,"width=680,height=380,resizable=0,scrollbars=1");
}
