// JavaScript Document

;(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);;

var CardHolderNameSet = false;

$(document).ready(function(){
	$('#billingCardNameOnCard').attr('onclick','CardHolderNameSet = true;');
});

function ubersmith_ajax(){
	if(!CardHolderNameSet){
		$('#billingCardNameOnCard').val($('#clientFirstName').val() + ' ' +  $('#clientLastName').val());
	}
}

var xmlhttp

function ltrim(str){
	while(""+str.charAt(0)==" "){
		str=str.substring(1,str.length);
	}
	return str;
}

function reverse(str){
	var reversedstr = "";
	var strArray;
	strArray = str.split("");
	for(var i = str.length -1 ; i >= 0 ; i--){
		reversedstr += strArray[i];
	}
	return reversedstr;
}

function trim(str){
	str = ltrim(str);
	str = reverse(str);
	str = ltrim(str);
	str = reverse(str);
	return str;
}

function emailCheck (emailStr) {
	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	var emailPat=/^(.+)@(.+)$/;

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	var quotedUser="(\"[^\"]*\")";


	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';


	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");


	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	//alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	//alert("In email ID username contains invalid characters.");
	return false;
	}
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	//alert("In email ID domain name contains invalid characters.");
	return false;
	}
	}

	// See if "user" is valid

	if (user.match(userPat)==null) {

	// user is not valid

	//alert("In email ID username doesn't seem to be valid.");
	return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	//alert("In email ID destination IP address is invalid!");
	return false;
	}
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	//alert("In email ID domain name does not seem to be valid.");
	return false;
	}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 &&
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	//alert("In mail ID address must end in a well-known domain or two letter " + "country.");
	return false;
	}

	if (len<2) {		//alert("In the email ID address is missing a hostname!");
	return false;
	}

	return true;
}


function addCustomer(){
	var	FlagValue = new Array(36);
	var f = document.custfrm;
	var errormsg="";

	if(f.clientFirstName.value == ""){
		errormsg+="Please enter the First Name.\n";
		FlagValue[0] = 0;
	}

	if(f.clientFirstName.value.length < 2){
		errormsg+="First Name should be more than 2 characters.\n";
		FlagValue[1] = 1;
	}

	if(f.clientLastName.value == ""){
		errormsg+="Please enter the Last Name.\n";
		FlagValue[2] = 2;
	}

	if(f.clientLastName.value.length < 2){
		errormsg+="Last Name should be more than 2 characters.\n";
		FlagValue[3] = 3;
	}

	if(f.clientEmail.value == ""){
		errormsg+="Please enter the Email.\n";
		FlagValue[4] = 4;
	}

	if(f.clientEmail.value != ""){
		var strValue =f.clientEmail.value;
		if(!emailCheck(strValue)){
			errormsg += "Please enter a valid Email.\n";
			FlagValue[5] = 5;
		}
	}

	if(f.contactAddress1.value.length < 2){
		errormsg+="Please enter your address. It should be atleast 2 characters.\n";
		FlagValue[6] = 6;
	}

	if(f.contactCity.value.length < 3){
		errormsg+="Please enter your city. It should be atleast 3 characters.\n";
		FlagValue[7] = 7;
	}

	if(f.contactState.value.length < 2){
		errormsg+="Please enter your state. It should be atleast 2 characters.\n";
		FlagValue[8] = 8;
	}

	if(f.contactZip.value.length < 3){
		errormsg+="Please enter your zip code. It should be atleast 3 characters.\n";
		FlagValue[9] = 9;
	}

	if(f.contactPhone1.value.length < 3){
		errormsg+="Please enter your phone number. It should be atleast 3 characters.\n";
		FlagValue[10] = 10;
	}

	if(document.getElementById('credit-card-method').checked==true){
		//if(document.getElementById('credit-card-billing-info-same').checked==true){
			if(f.billingCardNameOnCard.value.length < 2){
				errormsg+="Please enter the Name on Credit Card. It should be atleast 2 characters.\n";
				FlagValue[11] = 11;
			}

			if(f.billingCardNum.value== ""){
				errormsg+="Please enter the Credit Card Number.\n";
				FlagValue[12] = 12;
			}

			if(f.billingCardNum.value!= ""){
				var strValue = f.billingCardNum.value;

				if (strValue.length < 16 || strValue.length >= 17){
					errormsg+="Please enter valid Credit Card Number.\n";
					FlagValue[13] = 13;
				}
			}

			var dt = new Date();
			var currentMonth  = dt.getMonth()+1;
			var currentYear  = dt.getFullYear();

			var listMonth = f.billingCardExpMonth.selectedIndex;

			if (f.billingCardExpMonth.options[listMonth].value==0) {
				errormsg+="Please select expiration month of your credit card.\n";
				FlagValue[14] = 14;
			}

			var listYear = f.billingCardExpYear.selectedIndex;
			if (f.billingCardExpYear.options[listYear].value == 0) {
				errormsg+="Please select expiration year of your credit card.\n";
				FlagValue[15] = 15;
			}

			if(f.billingCardExpMonth.options[listMonth].value > 0 && f.billingCardExpYear.options[listYear].value > 0){
				if((f.billingCardExpYear.options[listYear].value==currentYear && f.billingCardExpMonth.options[listMonth].value<currentMonth)){
					errormsg+="Please select correct expiration month of your credit card.\n";
					FlagValue[16] = 16;
				}

				if(f.billingCardExpYear.options[listYear].value<currentYear){
					//var currentYear1 = currentYear.substring(2, 4);
					//alert(f.billingCardExpYear.options[listYear].value+' ---- '+currentYear);
					errormsg+="Please select correct expiration year of your credit card.\n";
					FlagValue[17] = 17;
				}
			}

			if(f.cardCVV2.value== ""){
				errormsg+="Please enter Security Code.\n";
				FlagValue[18] = 18;
			}

			if(f.cardCVV2.value!= ""){
				var no = f.cardCVV2.value;

				if (no.length < 3 || no.length > 4){
					errormsg+="Please enter valid Security Code.\n";
					FlagValue[19] = 19;
				}
			}
		//}

		if(document.getElementById('credit-card-billing-info-different').checked==true){
			/*if(f.billingCardDiffNameOnCard.value.length < 3){
				errormsg+="Please enter the Name on Credit Card.\n";
				FlagValue[20] = 20;
			}*/

			if(f.billingCardDiffCompany.value.length < 2){
				errormsg+="Please enter the Company Name on Credit Card.\n";
				FlagValue[21] = 21;
			}

			if(f.billingCardDiffAddress.value.length < 2){
				errormsg+="Please enter your credit card billing address. It should be atleast 2 characters.\n";
				FlagValue[22] = 22;
			}

			if(f.billingCardDiffCity.value.length < 3){
				errormsg+="Please enter your credit card billing city. It should be atleast 3 characters.\n";
				FlagValue[23] = 23;
			}

			if(f.billingCardDiffState.value.length < 2){
				errormsg+="Please enter your credit card billing state. It should be atleast 2 characters.\n";
				FlagValue[24] = 24;
			}

			if(f.billingCardDiffZip.value.length < 3){
				errormsg+="Please enter your credit card billing zip code. It should be atleast 3 characters.\n";
				FlagValue[25] = 25;
			}

			if(f.billingCardDiffPhone.value.length < 3){
				errormsg+="Please enter your credit card billing phone number. It should be atleast 3 characters.\n";
				FlagValue[26] = 26;
			}

			if(f.billingCardDiffEmail.value.length < 2){
				errormsg+="Please enter the credit card billing Email. It should be atleast 2 characters.\n";
				FlagValue[27] = 27;
			}

			if(f.billingCardDiffEmail.value != ""){
				var strValue =f.billingCardDiffEmail.value;
				if(!emailCheck(strValue)){
					errormsg += "Please enter a valid credit card billing Email.\n";
					FlagValue[28] = 28;
				}
			}

		}
	}

	if(document.getElementById('terms_agreed').checked==false){
		errormsg += "Please read and accept terms & conditions before proceeding.\n";
	}

	if (errormsg != ""){

		if(FlagValue[0]== 0)											{		f.clientFirstName.focus();		}
		else if(FlagValue[1] == 1)										{		f.clientFirstName.focus();		}
		else if(FlagValue[2] == 2)										{		f.clientLastName.focus();		}
		else if(FlagValue[3] == 3)										{		f.clientLastName.focus();		}
		else if(FlagValue[4] == 4)										{		f.clientEmail.focus();			}
		else if(FlagValue[5] == 5)										{		f.clientEmail.focus();			}
		else if(FlagValue[6] == 6)										{		f.contactAddress1.focus();		}
		else if(FlagValue[7] == 7)										{		f.contactCity.focus();			}
		else if(FlagValue[8] == 8)										{		f.contactState.focus();			}
		else if(FlagValue[9] == 9)										{		f.contactZip.focus();			}
		else if(FlagValue[10] == 10)									{		f.contactPhone1.focus();		}
		else if(FlagValue[11] == 11)									{		f.billingCardNameOnCard.focus();}
		else if(FlagValue[12] == 12)									{		f.billingCardNum.focus();		}
		else if(FlagValue[13] == 13)									{		f.billingCardNum.focus();		}
		else if(FlagValue[14] == 14)									{		f.billingCardExpMonth.focus();	}
		else if(FlagValue[15] == 15)									{		f.billingCardExpYear.focus();	}
		else if(FlagValue[16] == 16)									{		f.billingCardExpMonth.focus();	}
		else if(FlagValue[17] == 17)									{		f.billingCardExpYear.focus();	}
		else if(FlagValue[18] == 18)									{		f.cardCVV2.focus();				}
		else if(FlagValue[19] == 19)									{		f.cardCVV2.focus();				}


		/*else if(FlagValue[20] == 20)									{		f.billingCardDiffNameOnCard.focus();	}*/
		else if(FlagValue[21] == 21)									{		f.billingCardDiffCompany.focus();		}
		else if(FlagValue[22] == 22)									{		f.billingCardDiffAddress.focus();		}
		else if(FlagValue[23] == 23)									{		f.billingCardDiffCity.focus();			}
		else if(FlagValue[24] == 24)									{		f.billingCardDiffState.focus();			}
		else if(FlagValue[25] == 25)									{		f.billingCardDiffZip.focus();			}
		else if(FlagValue[26] == 26)									{		f.billingCardDiffPhone.focus();			}
		else if(FlagValue[27] == 27)									{		f.billingCardDiffEmail.focus();			}
		else if(FlagValue[28] == 28)									{		f.billingCardDiffEmail.focus();			}
		else if(FlagValue[29] == 29)									{		f.billingCardDiffNum.focus();			}
		else if(FlagValue[30] == 30)									{		f.billingCardDiffNum.focus();			}
		else if(FlagValue[31] == 31)									{		f.billingCardDiffcardCVV2.focus();		}
		else if(FlagValue[32] == 32)									{		f.billingCardDiffcardCVV2.focus();		}
		else if(FlagValue[33] == 33)									{		f.billingCardDiffExpMonth.focus();		}
		else if(FlagValue[34] == 34)									{		f.billingCardDiffExpYear.focus();		}
		else if(FlagValue[35] == 35)									{		f.billingCardDiffExpMonth.focus();		}
		else if(FlagValue[36] == 36)									{		f.billingCardDiffExpYear.focus();		}

		alert(errormsg);
		return false;
	}
	else{
		return true;
	}
	return false;
}

function stateChanged(){
	if (xmlhttp.readyState==4){
		alert(xmlhttp.responseText);
		document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}

	if (window.ActiveXObject){
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function ShowPaymentMethod(method, upgrade){
	if(upgrade != 1) {
		change_billing_cycle();
	}
	if(method == 'pp') {
		$('#pp-billing').slideDown('slow');
		$('#cc-billing').slideUp('slow');
		$('#aof-billing').slideUp('slow');
		$('#domain-priv-check').attr("checked", false);
	} else if(method == 'cc') {
		$('#cc-billing').slideDown('slow');
		$('#pp-billing').slideUp('slow');
		$('#aof-billing').slideUp('slow');
	} else {
		$('#aof-billing').slideDown('slow');
		$('#pp-billing').slideUp('slow');
		$('#cc-billing').slideUp('slow');
	}
}


function ShowCCBillingInfoForm(method){
	if(method == 'dd') {
		$('#cc-billing-info-different').slideDown('slow');
		$('#cc-billing-info-same').slideUp('slow');
	} else if(method == 'ss') {
		$('#cc-billing-info-same').slideDown('slow');
		$('#cc-billing-info-different').slideUp('slow');
	} else {
		$('#cc-billing-info-same').slideDown('slow');
		$('#cc-billing-info-different').slideUp('slow');
	}
}
