var cancheckoutdomain = true;
var cancheckoutaddon = true;
var mustsetdomains = new Array();
var mustsetaddons = new Array();
var currentdomainform = "";
var sid;


	var cp2 = new cpaint();
	cp2.set_transfer_mode('get');
	cp2.set_response_type('text');
	//cp2.set_debug(2);

	var locale = "";
	var slURL2 = '/order/cart.php?checkwhois=1&sid='+sid;

	
	function checkDomAvail(xtld, xsld, trans, idn, itemid) {
		if (xsld=="")return;
		domainformitemid = itemid;
		var idnvalue = 0;

		for (idni=0; idni<idn.length; idni++){
			if (idn[idni][0]==xtld){
				idnvalue = idn[idni][1];
			}
		}
		xsld = xsld.toLowerCase();
		var slURL2a = slURL2+"&sld="+xsld+"&tld="+xtld+"&trans="+trans+"&idn="+idnvalue+"&set_locale="+locale+"&ajax=1&shoppingItemID="+itemid+"&"+Math.random();
		setLoading(document.getElementById('whoisCheck'+itemid), "Loading...");
		cp2.call(slURL2a, 'checkDomAvail', checkDomAvailResponse);
		return false;
	}

	function checkDomAvailResponse(result) {
		if (result) {
		
			document.getElementById('whoisCheck'+domainformitemid).innerHTML = result;
			//XKsmoothSize('itemouterdiv'+domainformitemid, 'iteminnerdiv'+domainformitemid);
		} else {
			
			alert("Domain Check Failed");
			
		}
	}
function addDomainProduct(cpid, domain) {
		var exploded = cpid.split("|");

		if (typeof currentdomainform.domainLanguage!="undefined"){
			var domainLanguage = currentdomainform.domainLanguage.options[currentdomainform.domainLanguage.selectedIndex].value;
		} else {
			var domainLanguage = "";
		}
		var addURL = "/order/cart.php?sid="+sid+"&action=25&parentShoppingItemID="+exploded[3]+"&addType=domain&domainLanguage="+domainLanguage+"&";
		if (exploded[0]==""){
			var domaininfo = domain.split("|");
			addURL += "existsld="+domaininfo[0]+"&existtld="+domaininfo[1];
		} else if (exploded[0]=="-2"){
			addURL += "domain="+domain+"&productID="+exploded[1]+"&productVariantID="+exploded[2]+"&cycleID=-2&domainTransferKey="+exploded[4]+"&"+Math.random();
		} else {
			addURL += "domain="+domain+"&productID="+exploded[1]+"&productVariantID="+exploded[2]+"&cycleID="+exploded[0]+"&"+Math.random();
		}
		setLoading(document.getElementById('iteminnerdiv'+exploded[3]), "Loading...");
		//XKsmoothSize('itemouterdiv'+exploded[3], 'iteminnerdiv'+exploded[3]);
		document.location.href = addURL;
		
	}

	function addCartDomain(siid, psiid, sld, tld){
		var addURL = "/order/cart.php?sid="+sid+"&action=25&parentShoppingItemID="+psiid+"&addType=associateDomain&domainShoppingItemID="+siid+"&domainSLD="+sld+"&domainTLD="+tld+"&";
		setLoading(document.getElementById('iteminnerdiv'+psiid), "Loading...");
		XKsmoothSize('itemouterdiv'+psiid, 'iteminnerdiv'+psiid);
		document.location.href = addURL;
	}
	

////////////////////////////////////////


function setLoading(divobj, message){
	if (typeof message=="undefined"){
		message = "Loading...";
	}
	divobj.innerHTML = "<img src='/images/progressbar_green.gif' alt='"+message+"' /><br /> &nbsp;&nbsp;<b>"+message+"</b>";
}


function addDomain(itemid){
	XKdelayedContent = ""; // = document.getElementById('adddomaintemplate').innerHTML;
	document.getElementById('iteminnerdiv'+itemid).innerHTML = document.getElementById('adddomaintemplate').innerHTML;
	XKsmoothSize('itemouterdiv'+itemid, 'iteminnerdiv'+itemid);
}

var execAddon = "";


function cleartext(text)
{
	if(text.value=="Domain Search")
		text.value ='';
}
function changetext(text)
{
	if(text.value=="")
	{
		text.value="Domain Search";
	}
	else
	{
		var domain = check_text(text.value);
		text.value=domain;
	}
}
function cleartext2(text)
{
	if(text.value=="Your Domain")
		text.value ='';
}
function changetext2(text)
{
	if(text.value=="")
	{
		text.value="Your Domain";
	}
	else
	{
		var domain = check_text(text.value);
		text.value=domain;
	}
}
function check_text(str)
{
	if(str.substr(0,4)=="www.")
		str = str.substr(4);

	out = " "; // replace this
	add = ""; // with this
	temp = "" + str; // temporary holder
	while (temp.indexOf(out)>-1)
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	str = temp.toLowerCase();
	return str;
}
function check_val()
{
	if((document.domainform0.regsecondary.value=="")||(document.domainform0.regsecondary.value=="Domain Search"))
	{
		alert("Please enter a Domain Name!");
		return false;
	}
	if(document.domainform0.tld.value !="All")
	{
		document.domainform0.action = "result.php";
	}
}
function check_val2()
{
	if((document.domainform1.regsecondary.value=="")||(document.domainform1.regsecondary.value=="Domain Search"))
	{
		alert("Please enter a Domain Name!");
		return false;
	}
	if(document.domainform1.tld.value !="All")
	{
		document.domainform1.action = "result.php";
	}
}

function show_tips()
{
	var div = document.getElementById("showtips");
	div.style.visibility = "visible";
	new Effect.SlideDown('showtips', {duration:.5});
}
function hide_tips()
{
	new Effect.SlideUp('showtips', {duration:.5});
}
function validate_domain(str)
{
  re=/[&'.,_$>@/%!~#^&*)(|+=?<\:;"}{`]/;
  check=str.search(re);
  len = str.length;
  first = str.substr(0,1);
  last = str.substr(len-1,1);
  sp = str.split(" ");
  if((len>63)||(len<3)||(check>-1)||(first=="-")||(last=="-")||(sp.length>1))
    return 1;
  else
    return 0;            
}


