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]$/;
	
	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';
     }
}

var lastChecked = "";

function checkForm()
{
	var theone;	
	if ((document.getElementById("domainaction").checked==true) && (document.StandardOrderForm.domain.value!="") && (document.StandardOrderForm.freedomain.value=="")){
		alert("Please add the domain name to the order list");
		return false;
	}
	if (StandardOrderForm.domain.value==""){
		alert("Please enter a domain name");
		StandardOrderForm.domain.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.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.country.value==""){
		alert("Please select country.");
		StandardOrderForm.country.focus();
		return false	
	}
	if (document.StandardOrderForm.phone.value==""){
		alert("Please enter phone number");
		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) 
			theone=i;
	
		if (document.StandardOrderForm.paymethod[theone].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.checkbox.checked==false)
	{
		alert("You have to read the terms and conditions, before you proceed");
		return false;
	}
}

function addo()
{
	var Odetails = document.getElementById("odetails")
	var OPdetails = document.getElementById("opdetails")
	//Odetails.innerHTML = "<font color=#009933 size=2> + " + document.getElementById("domain").value; "</font>";
	document.StandardOrderForm.freedomain.value=document.getElementById("domain").value;
	document.StandardOrderForm.selecteddomain.value=document.getElementById("domain").value;
}

function radioc()
{
	var domainName = document.getElementById('domain').value;
	if ((document.getElementById("domainaction").checked==true) && (domainName!=""))
	{
		goCheckAvail()
	}
}

function radioc1()
{
	var Odetails = document.getElementById("odetails")
	var OPdetails = document.getElementById("opdetails")
	OPdetails.innerHTML="";
	Odetails.innerHTML="";
	document.StandardOrderForm.freedomain.value="";
	
}
function getHTTPObject() { 
	var xmlhttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlhttp=new XMLHttpRequest();
	}
	catch (e){
		// Internet Explorer
		try{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlhttp;
}
 // We create the HTTP Object 
var http = getHTTPObject();

function handleHttpResponse() {
	if (http.readyState == 4) {
    	// Split the comma delimited response into an array
		var domain = document.getElementById("domain").value;
	    var results = http.responseText;
	
		//If domain is valid
		if(results == '0'){
			var is_show = '<font color="#0000FF"><b>Invalid Domain '+domain+' Name.</b></font>';
		} else {
			if(results == '1'){
				var is_show = '<font color="#0000FF"><b>Domain Name '+domain+' Is Avaliable. <a href="javascript: void(0)" onclick="return addo()" class="link_menu_darkorange">Add to my order</a></b></font>';
			} else {
				var is_show = '<font color="#FF0000"><b>Sorry, Domain Name '+domain+' Is already registered, please try another name.</b></font>';
			}
		}
		var notationS = document.getElementById("results")
		notationS.innerHTML = is_show;
	}
}

function checkAvailDomain(domainName)
{
	
	var arr=new Array('.com','.net','.org','.info','.us','.biz','.in');
	var val=true;
	var dotPos=domainName.lastIndexOf(".");
	var domainName1=domainName.substring(0,dotPos);
	var tld=domainName.substring(dotPos,domainName.length);
	
	if(dotPos>1&&dotPos<57){
		for(var i=0;i<arr.length;i++){
			if(tld==arr[i]){
			val=true;break;
			}
			else{
				val=false;
			}
		}
		if(val==false){
			return false;
		}
		else{
			for(var j=0;j<domainName1.length;j++){
				var p=domainName1.charAt(j);
				var p2=p.charCodeAt(0);
				if((p2>47&&p2<59)||(p2>64&&p2<91)||(p2>96&&p2<123)||p2==45||p2==46){
					if((j==0||j==domainName1.length-1)&&p2==45){
						return false;
					}
				}
				else{
					return false;
				}
			}
		}
	}
	else{
		return false;
	}
	return true;
}

function checkDomain(domainName){
	if (verifyIP(domainName)==true)
		return true;

	var arr=new Array('.li','.mobi','.hu.com','.ac','.aero','.ag','.am','.as','.at','.au','.be','.biz','.edu.cn','.br','.br.com','.bz','.ca','.cc','.cd','.ch','.ck','.bt','.cl','.cn','.cn.com','.co.nz','.co.uk','.com','.com.br','.coop','.cx','.cz','.de','.de.com','.dk','.edu','.ee','.eu','.eu.com','.fi','.fj','.fm','.fr','.gb.com','.pt','.gb.net','.gg','.gm','.gov','.gov.il','.gov.uk','.pl','.gs','.hk','.hm','.hu','.id','.bg','.ac.uk','.id.au','.ie','.arpa','.il','.in','.info','.int','.ir','.is','.ru','.it','.je','.jp','.ke','.kr','.la','.lk','.lt','.ve','.lu','.lv','.mc','.mil','.ms','.mu','.museum','.mx','.my','.name','.nc','.net','.nl','.no','.no.com','.nu','.nz','.org','.pw','.qc.com','.re','.ro','.ru.com','.sa.com','.se','.se.com','.se.net','.sg','.sh','.si','.sk','.sm','.st','.tc','.tf','.th','.tj','.tm','.to','.tr','.tv','.tw','.ua','.uk','.uk.com','.uk.net','.us','.us.com','.uy.com','.vg','.web.com','.ws','.za.com');
}

function goCheckAvail()
{
	//if ((document.getElementById("domainaction").checked==true) && (document.getElementById('domain').value!=""))
	//{
		var domainName = document.getElementById('domain').value;	
	
		if (domainName!="" && checkAvailDomain(domainName))
		{	
			var url = "ajax_callback.php?d=";

			//Create Temporary message
			var notationS = document.getElementById("results")
			notationS.innerHTML = '<img src="../images/please_wait.gif"> Please Wait While We Check The Availability...';
			
			//Check domain here	
			var word_value = document.getElementById("domain").value;
			http.open("GET", url + escape(word_value), true);
			http.onreadystatechange = handleHttpResponse;
			http.send(null);
		}
	//}
}
