
function formCheck(product) {

var AttributeValue = new Array("",
"AttributeValue[1]","AttributeValue[2]","AttributeValue[3]",
"AttributeValue[4]","AttributeValue[5]","AttributeValue[6]",
"AttributeValue[7]","AttributeValue[8]","AttributeValue[9]"
);

message="";

if (product == "1EMF") { // Email Forwarding
	var emailadress = document.prodform.elements[1].value;
	var goodEmail = emailaddress.match(/\b(^([A-Za-z0-9\._-]+@)+([A-Za-z0-9\._-])+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.idv)|(\.gov)|(\.org)|(\.biz)|(\.info)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	alert(goodEmail);
	if (goodEmail == 0) {
		return false;
	}
	var emailadress = document.prodform.elements[2].value;
	var goodEmail = emailaddress.match(/\b(^([A-Za-z0-9\._-]+@)+([A-Za-z0-9\._-])+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.idv)|(\.gov)|(\.org)|(\.biz)|(\.info)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	if (goodEmail ==0) {
		return false;
	}
	return true;	
}

return true;
}

function showError(message) {
	alert(message); 
} 




function checkEmail(emailaddress) {
	var goodEmail = emailaddress.match(/\b(^([A-Za-z0-9\._-]+@)+([A-Za-z0-9\._-])+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.idv)|(\.gov)|(\.org)|(\.biz)|(\.info)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	if (goodEmail) { return true; } else {return false; }
}

function checkWebUrl(webaddress) {
	var goodWeb = webaddress.match(/\b(^([A-Za-z0-9\._-]+\.)+([A-Za-z0-9\._-])+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.idv)|(\.gov)|(\.org)|(\.biz)|(\.info)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
	if (goodWeb) {
		return true;
	} else {
		return false;
	}
}

function checkTerms(tandc) {
	if (tandc.checked == false) {
		message = "You must agree to the Terms & Conditions to proceed.";
		showError(message);
		return false;
	}
	return true;
}

function checkDomList(domname) {

	var gotone=false;

	if (domname.length != null) {
		for (i=0; i < domname.length; i++) {
			if (domname[i].checked == true) {
				gotone=true;
			}
		}
	} else if (domname.value != '') {
		if (domname.checked == true) {
			gotone=true;
		}
	}
	if (gotone) {
		return true;
	} else {
		alert("Please select a domain name.");
		return false;
	}
}

function randPass(len) {
  var clist="0123456789abcdefghijklmnopqrstuvwxyz";
  var pass = "";
  while (len--) {
    pass += clist.charAt(Math.floor(Math.random() * clist.length));
  }
  return pass;
}

function fixNexus() {
	
	if ((document.adcform.nexuscategory1.value == "C31") || (document.adcform.nexuscategory1.value == "C32")) {
		document.adcform.nexuscategory.value = document.adcform.nexuscategory1.value + '/' + document.adcform.country.value;
	} else {
		document.adcform.nexuscategory.value = document.adcform.nexuscategory1.value;
	}

	if (document.adcform.authinfo.value == "") { document.adcform.authinfo.value = randPass(8); }

}

function fixNexusMod() {

	if ((document.mdcform.nexuscategory1.value == "C31") || (document.mdcform.nexuscategory1.value == "C32")) {
		document.mdcform.nexuscategory.value = document.mdcform.nexuscategory1.value + '/' + document.mdcform.country.value;
	} else {
		document.mdcform.nexuscategory.value = document.mdcform.nexuscategory1.value;
	}

	document.mdcform.apppurpose.value = document.mdcform.apppurpose1.value;
}


function fixAuthInfo() {
	if (document.buydomform.authinfo.value == "") { 
		document.buydomform.authinfo.value = randPass(8);
	}
}


function showNexus() {

	if (document.mdcform.apppurpose1[0].value == document.mdcform.apppurpose.value)  {
		document.mdcform.apppurpose1[0].selected = true; }
	if (document.mdcform.apppurpose1[1].value == document.mdcform.apppurpose.value)  {
		document.mdcform.apppurpose1[1].selected = true; }
	if (document.mdcform.apppurpose1[2].value == document.mdcform.apppurpose.value)  {
		document.mdcform.apppurpose1[2].selected = true; }
	if (document.mdcform.apppurpose1[3].value == document.mdcform.apppurpose.value)  {
		document.mdcform.apppurpose1[3].selected = true; }
	if (document.mdcform.apppurpose1[4].value == document.mdcform.apppurpose.value)  {
		document.mdcform.apppurpose1[4].selected = true; }

	var tmpcat = document.mdcform.nexuscategory.value;
	var nexcat = tmpcat.substring(0,3);
	
	if (document.mdcform.nexuscategory1[0].value == nexcat)  {
		document.mdcform.nexuscategory1[0].selected = true; }
	if (document.mdcform.nexuscategory1[1].value == nexcat)  {
		document.mdcform.nexuscategory1[1].selected = true; }
	if (document.mdcform.nexuscategory1[2].value == nexcat)  {
		document.mdcform.nexuscategory1[2].selected = true; }
	if (document.mdcform.nexuscategory1[3].value == nexcat)  {
		document.mdcform.nexuscategory1[3].selected = true; }
	if (document.mdcform.nexuscategory1[4].value == nexcat)  {
		document.mdcform.nexuscategory1[4].selected = true; }

}

function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}



function checkDomainOptions(termscheckbox,domainname,emailuser) {
	// Check T&C's
	ok = checkTerms(termscheckbox);
	if (!ok) { return false; }

	return true; // skip rest of section for now

	if (emailuser.length) {  // Check Email Hosting Addresseses
		for (i=0; i < emailuser.length; i++) {

			if (emailuser[i].value != '') {
				ok = checkEmail(emailuser[i].value + '@' + domainname[i].value);
				if (!ok) {
					alert('The ' + emailuser[i].value + ' e-mail address is not valid.');
					return false;
				}
				emspath = 'ems' + i;
				if (document.domainOptions.elements[emspath].checked == false) {
					alert('You must select E-Mail Hosting for ' + emailuser[i].value + '@' + domainname[i].value);	
					return false;
				}
			}
		}
	} else if (emailuser.value != '') {
		ok = checkEmail(emailuser.value + '@' + domainname.value);
		if (!ok) {
			alert('The ' + emailuser.value + ' e-mail address is not valid.');
			return false;
		}
		emspath = 'ems0';
	       	if (document.domainOptions.elements[emspath].checked == false) {
	       		alert('You must select E-Mail Hosting for ' + emailuser.value + '@' + domainname.value);
	       		return false;
	       }
	}

	// Build E-Mail For Miva
	if (document.domainOptions.DomainName.length != null) {
		for (i=0; i < document.domainOptions.DomainName.length; i++) {
			emspath = 'ems' + i;
		       	if (document.domainOptions.elements[emspath].checked == true) {
				if (document.domainOptions.EmailUser[i].value == null || document.domainOptions.EmailUser[i] == '') {
			       		alert('You must give an E-Mail address for ' + document.domainOptions.DomainName[i].value);
			       		return false;
				}
			}
			if (document.domainOptions.EmailUser[i].value != '') {
				document.domainOptions.EmailAddress[i].value = document.domainOptions.EmailUser[i].value + '@' + document.domainOptions.DomainName[i].value;
			}

		}	
	} else if (document.domainOptions.DomainName.value != '') {
		emspath = 'ems0';
	       	if (document.domainOptions.elements[emspath].checked == true) {
			if (document.domainOptions.EmailUser.value == null || document.domainOptions.EmailUser.value == '') {
		       		alert('You must give an E-Mail address for ' +  document.domainOptions.DomainName.value);
		       		return false;
			}
		}
		if (document.domainOptions.EmailUser.value != '') {
			document.domainOptions.EmailAddress.value = document.domainOptions.EmailUser.value + '@' + document.domainOptions.DomainName.value;
		}
	}	
}

function setAffiliate(querystring) {

	var pairs = querystring.split("&"); 

	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {

		// Look for "name=value"
		var pos = pairs[i].indexOf('='); 

		// if not found, skip to next
		if (pos == -1) continue; 

		// Extract the name
		var argname = pairs[i].substring(0,pos); 

		// Extract the value
		var argvalue = pairs[i].substring(pos+1); 

		// do we have affiliate id
		if (argname == "affid") {

			// set the affiliate cookie
			// this is read by all domreg cgis to replace token
			// in generated screens
			var expdate = new Date();
			expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
			document.cookie = "affid" + "=" + escape(argvalue) + ";" +
				  "expires=" + expdate.toGMTString() + ";" +
				  "path=/;" +
				  "domain=encirca.com;";

			// set the affiliate val wherever it occurs
			// this is just a safety measure for non domain products
			// that might be sold in the future
			var numberForms = document.forms.length;
			var formIndex;
			for (formIndex = 0; formIndex < numberForms; formIndex++) {
				if (document.forms[formIndex].Affiliate) {
					document.forms[formIndex].Affiliate.value = argvalue;
					// alert(document.forms[formIndex].Affiliate.value);
				}
			}
		}
	}
}

