//
var isSSL="";
function passDomain(n,x,h,dc,q,s) {//n=domain name; x=domain extension (.com, .net, etc); h=host path; dc=domain cost; q=query string (if applicable); s=ssl enabled
	var ex=new Array(".com",".net",".biz",".org",".info");
	var isWhois={'com':'whois.crsnic.net','net':'whois.crsnic.net','biz':'whois.biz','org':'whois.pir.org','info':'whois.afilias.net'};
	var isKeyword={'com':'No match for','net':'No match for','biz':'Not found','org':'NOT FOUND','info':'NOT FOUND'};
	var isDom=document.getElementById(n).value;
	var isEx=document.getElementById(x).value;
	for(var e=0;e<ex.length;e++) {
		if(isDom.indexOf(ex[e])!=-1) {
			var brkDom=isDom.split(ex[e]);
			isDom=brkDom[0];
			document.getElementById(n).value=isDom;
			delete brkDom;
			break;
		}
	}
	var fullDomain=isDom+"."+isEx;
	isSSL=s;
	checkDom(h,fullDomain,isWhois[isEx],isKeyword[isEx],dc,q);
}
function newSearch() {
	document.getElementById('domainCheckDiv').style.display="block";
	document.getElementById('domainResultDiv').style.display="none";
	document.getElementById('domainResultDiv').innerHTML="";
}
function cancelSearch() {
    try{
		rq.abort();
	}catch(er) {
		//
	}
	newSearch();
}
var gotDomain="";
function checkDom(h,ds,ss,sk,dc,q) {//h=host path; ds=domain to search; ss= whois service to scan; sk=search keyword/phrase; dc= domain cost; q=query string
	try{
		rq.abort();
	}catch(er) {
		//
	}
	var rq=null;
    if(window.XMLHttpRequest) {
        rq=new XMLHttpRequest();
    }else if(window.ActiveXObject) {
        try {
            rq=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (er) {
            try {
                rq=new ActiveXObject("Microsoft.XMLHTTP");
            }catch (er) {
                alert("It appears your Internet Explorer has ActiveX disabled or is not supported.\nPlease enable your ActiveX or update your Internet Explorer to a version that supports it.");
                return false;
            }
        }
    }else{
        alert("It appears your browser does not support the XMLHttpRequest or ActiveX.\nTo utilize this option, please use a browser with one of the support.");
        return false;
    }
    h=(h=="hosting.freelancerlisting.net" ? h : h+"/hosting");
    var theURL="http"+isSSL+"://"+h+"/modules/domain_checker.php";
    var params="domainsearch="+ds+"&searchserver="+ss+"&searchkey="+sk;
    rq.open('POST',theURL,true);
    rq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    rq.setRequestHeader("Content-Length",params.length);
    rq.setRequestHeader("Connection","close");
    //
    rq.onreadystatechange=function() {
        if(rq.readyState==4) {
            if(rq.status==200) {
                myInfo=rq.responseText;
                if(myInfo!="") {
                    if(myInfo=="Not available") {
                        var showButtons=" &nbsp;<input type=\"button\" name=\"new_dom_search\" value=\"new search\" class=\"mt5 floatR px11\" onclick=\"newSearch();\" />";
                    }else{
                        var showButtons=" &nbsp;<input type=\"button\" name=\"new_dom_search\" value=\"new search\" class=\"mt5 floatR px11\" onclick=\"newSearch();\" />&nbsp;<input type=\"button\" name=\"secure_domain\" id=\"secureDomain\" value=\"Secure this domain\" class=\"mt5 floatR px13\" style=\"color: #ff0000;\" onclick=\"saveDomain(this,'"+q+"');\" />";
                        gotDomain=ds;
                    }
                	document.getElementById('domainResultDiv').innerHTML=(myInfo=="failed-connection" ? "Service is currently not available" : "Domain '"+ds+"' is "+myInfo+showButtons);
                }
            }else{
            	try{
            		rq.abort();
            	}catch(er) {
            		//
            	}
            	checkDom(h,ds,ss,sk,dc,q);
            }
        }else{
        	document.getElementById('domainCheckDiv').style.display="none";
        	document.getElementById('domainResultDiv').style.display="block";
        	document.getElementById('domainResultDiv').innerHTML="<img src=\"images/icon_loading.gif\" border=\"0\" class=\"valignM\" /> &nbsp; Please wait while I do a search... &nbsp;<input type=\"button\" name=\"new_dom_search\" value=\"cancel search\" class=\"mt5 floatR px11\" onclick=\"cancelSearch();\" />";
        }
    }
    rq.send(params);
}
function domainSearchBar(t) {
    if(t.id=="domOwnN") {
        document.getElementById('domainCheckDiv').style.display="block";
        document.getElementById('domainOwnDiv').style.display="none";
    }else{
        document.getElementById('domainCheckDiv').style.display="none";
        document.getElementById('domainOwnDiv').style.display="block";
        document.getElementById('pmtDomainCost').value=0;
        reCalc();
    }
    document.getElementById('domainResultDiv').innerHTML="";
}
function secureDom(d,dc) {//d=domain name; dc=domain cost
    var secureText="<img src=\"images/checkmark.jpg\" border=\"0\" /><input type=\"hidden\" name=\"new_domain_secured\" id=\"newDomainSecured\" value=\""+d+"\" />";
    secureText+=" <strong>"+d+"</strong>";
    document.getElementById('domainResultDiv').innerHTML=secureText;
    document.getElementById('pmtDomainCost').value=dc;
    reCalc();
}
/*====================================================*/
function swapStates(d,c,s,t) {//d=div id of object to rewrite; c=country; s=state; t=display option as abbreviation (true/false)
    if(c=="US") {
		var st={"AL":"Alabama","AK":"Alaska","AZ":"Arizona","AR":"Arkansas","CA":"California","CO":"Colorado","CT":"Connecticut","DE":"Delaware","FL":"Florida","GA":"Georgia","HI":"Hawaii","ID":"Idaho","IL":"Illinois","IN":"Indiana","IA":"Iowa","KS":"Kansas","KY":"Kentucky","LA":"Louisiana","ME":"Maine","MD":"Maryland","MA":"Massachusetts","MI":"Michigan","MN":"Minnesota","MS":"Mississippi","MO":"Missouri","MT":"Montana","NE":"Nebraska","NV":"Nevada","NH":"New Hampshire","NJ":"New Jersey","NM":"New Mexico","NY":"New York","NC":"North Carolina","ND":"North Dakota","OH":"Ohio","OK":"Oklahoma","OR":"Oregon","PA":"Pennsylvania","RI":"Rhode Island","SC":"South Carolina","SD":"South Dakota","TN":"Tennessee","TX":"Texas","UT":"Utah","VT":"Vermont","VA":"Virginia","WA":"Washington","WV":"West Virginia","WI":"Wisconsin","WY":"Wyoming"};
	}else{
		var st={"AB":"Alberta","BC":"British Columbia","MB":"Manitoba","NB":"New Brunswick","NL":"Newfoundland","NT":"Northwest Territories","NS":"Nova Scotia","NU":"Nunavut","ON":"Ontario","PE":"Prince Edward Island","QC":"Quebec","SK":"Saskat","YT":"Yukon Territory","AB":"Alberta","BC":"British Columbia","MB":"Manitoba","NB":"New Brunswick","NL":"Newfoundland","NT":"Northwest Territories","NS":"Nova Scotia","NU":"Nunavut","ON":"Ontario","PE":"Prince Edward Island","QC":"Quebec","SK":"Saskat","YT":"Yukon Territory"};
	}
	document.getElementById(d).options.length=0;
	var allSt="";
	for(var i in st) {
        var show=(t==true ? i : st[i]);
        var newIndex=document.getElementById(d).options.length;
        var isSelect=(i==s ? true : false);
        document.getElementById(d).options[newIndex]=new Option(show,i,true,isSelect);
        //(i==s ? "<option value=\""+i+"\" selected>"+show+"</option>" : "<option value=\""+i+"\">"+show+"</option>");
    }

}
//
function reCalc() {
    var isIP=document.getElementById('pmtIP').value;
    var isAmt=document.getElementById('pmtAmount').value;
    var isSetup=document.getElementById('pmtSetup').value;
    var isNewDom=document.getElementById('pmtDomainCost').value;
    var isNewSubtotal=(isAmt*1)+(isIP*1);
    var isNewTotal=(isAmt*1)+(isNewDom*1)+(isSetup*1)+(isIP*1);
    document.getElementById('pmtSubtotal').value=isNewSubtotal.toFixed(2);
    document.getElementById('pmtTotal').value=isNewTotal.toFixed(2);
}
//
function calcIP(t) {
    var isIP=(t.value*1);
    document.getElementById('pmtIP').value=isIP.toFixed(2);
    reCalc();
}
//
function errorCheck(t) {
    var isEM=document.getElementById('pmtEM').value;
    if(isEM.indexOf('@')!=-1) {
        var isAt=isEM.split("@");
        if(isAt[1].indexOf('.')!=-1) {
            var isDot=isAt[1].split(".");
        }else{
            alert("The Email Address does not appear to be a proper email.");
            return false;
        }
        if(isAt[0]=="" || isAt.length<2 || isDot.length<2 || isDot[1]=="") {
            alert("The Email Address does not appear to be a proper email.");
            return false;
        }
    }else{
        alert("The Email Address does not appear to be a proper email.");
        return false;
    }
    var isRequired=new Array("pmtFN","pmtLN","pmtEM","pmtStreet","pmtCity","pmtZip","pmtCCNum","pmtCCCVC");
    var isSelected=new Array("pmtCountry","pmtState","pmtExpM","pmtExpY");
    if(document.getElementById('domOwnN').checked==false && document.getElementById('domOwnY').checked==false) {
        alert("Please choose a Domain Name option.");
        return false;
    }
    for(var i=0;i<isRequired.length;i++) {
        var cleanIt=document.getElementById(isRequired[i]).value.replace(/ /g,'');
        if(cleanIt=="") {
            alert("All fields are required.");
            return false;
            break;
        }
    }
    for(var i=0;i<isSelected.length;i++) {
        if(document.getElementById(isSelected[i]).selectedIndex==0) {
            alert("All fields are required.");
            return false;
        }
    }
    if(document.getElementById('tos').checked==false) {
        alert("You must agree to the TOS (terms & conditions)");
        return false;
    }
}
//
function verifyEmail(h,e) {
    try{
		rq.abort();
	}catch(er) {
		//
	}
	var rq=null;
    if(window.XMLHttpRequest) {
        rq=new XMLHttpRequest();
    }else if(window.ActiveXObject) {
        try {
            rq=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (er) {
            try {
                rq=new ActiveXObject("Microsoft.XMLHTTP");
            }catch (er) {
                alert("It appears your Internet Explorer has ActiveX disabled or is not supported.\nPlease enable your ActiveX or update your Internet Explorer to a version that supports it.");
                return false;
            }
        }
    }else{
        alert("It appears your browser does not support the XMLHttpRequest or ActiveX.\nTo utilize this option, please use a browser with one of the support.");
        return false;
    }
    h=(h=="hosting.freelancerlisting.net" ? h : h+"/hosting");
    var theURL="http://"+h+"/modules/verifier.php?verify=email&value="+e;
    //
    rq.onreadystatechange=function() {
        if(rq.readyState==4) {
            if(rq.status==200) {
                myInfo=rq.responseText;
                if(myInfo!="") {
                	//
                }
            }else{
            	try{
            		rq.abort();
            	}catch(er) {
            		//
            	}
            	verifyEmail(h,e)
            }
        }
    }
    rq.send(null);
}

//WHEN DOMAIN IS SEARCHED AND 'SECURED'
function saveDomain(t,q) {//t=self reference; q=query string
    var appendQ=(q!="" ? "&"+q : "");
    window.location.replace("hostingplans.php?secure="+gotDomain+appendQ);
}
//
function popTOS(s) {
    var ww=screen.width;
    var hh=screen.height;
    var isWW=(ww/2)-220;
    var isHH=(hh/2)-175;
    window.open(s,'',config='width=440,height=450,scrollbars=yes,statusbar=no,left='+isWW+',top='+isHH+',resizable=0');
}
