// JavaScript Document
function webhosting_initialize(){
}
function swapSteps(step){
	var page='';
	var process="GET";
	if(step==1){
		 page="html-includes/webhosting-step-1.php";
	}else if(step==11){
		page="html-includes/webhosting-step-1.php?platform="+platform;	
	}else if(step==2){
		page="html-includes/webhosting-step-2.php?domain_plan="+domain_plan_val+"&private_domain="+document.getElementById('private_domain').value+"&request_or_via_lbc="+document.getElementById('request_or_via_lbc').value;
	}else if(step == 21){
		page="html-includes/webhosting-step-2.php?domain_plan="+domain_plan_val;
	}else if(step==3){
		var obj_Currency=document.getElementsByName('currency');
		var currency='';
		var term='';
		if(obj_Currency){
			if(obj_Currency.length){
				for(var i=0;i<obj_Currency.length;i++){
					if(obj_Currency[i].checked==true) currency=obj_Currency[i].value;
				}
			}else{
				if(obj_Currency.checked==true) currency=obj_Currency.value;
			}
		}
		page="html-includes/webhosting-step-3.php?currency="+currency;
	}else if(step==31){
		page="html-includes/webhosting-step-3-add.php";
		var objHost_type=document.getElementsByName('host_type');
		var term = 0;
		var host_type = 0;
		if(objHost_type){
			if(objHost_type.length){
				for(var i=0;i<objHost_type.length;i++){
					if(objHost_type[i].checked==true) host_type = objHost_type[i].value;
				}
			}else{
				if(objHost_type.checked==true) host_type = objHost_type.value;
			}
		}
		var objTerm=document.getElementsByName('term');
		if(objTerm){
			if(objTerm.length){
				for(var i=0;i<objTerm.length;i++){
					if(objTerm[i].checked==true) term = objTerm[i].value;
				}
			}else{
				if(objTerm.checked==true) term = objTerm.value;
			}
		}
		page = page + "?host_type=" + host_type + "&term=" + term;
	}else if(step==32){
		page="html-includes/webhosting-step-3-add.php";
	}else if(step==4){
		var obj_addOns=document.getElementsByName('chk_addons[]');
		var addOns='';
		if(obj_addOns){
			if(obj_addOns.length){
				for(var i=0;i<obj_addOns.length;i++){
					if(obj_addOns[i].checked==true){
						if(addOns!='') addOns=addOns+",";
						addOns=addOns+obj_addOns[i].value;
					}
				}
			}else{
				if(obj_addOns.checked==true){
					if(addOns!='') addOns=addOns+",";
					addOns=addOns+obj_addOns.value;
				}
			}
		}
		page="html-includes/webhosting-step-4.php?addOns="+addOns;
	}else if(step==41){
		page="html-includes/webhosting-step-4.php?addOns=";
	}else if(step==412){
		page="html-includes/webhosting-step-4.php";
	}else if(step==42){
		var poststr ='';
		process="POST";
		objForms=document.forms['form_customer'];
		for(i=0;i<objForms.elements.length;i++){
			if(poststr=="")poststr="?" + objForms.elements[i].name + "=" + encodeURI( objForms.elements[i].value ); 
			else poststr = poststr + "&" + objForms.elements[i].name + "=" + encodeURI( objForms.elements[i].value ); 
		}
		page="html-includes/webhosting-step-4-save.php"+poststr;
	}else if(step==5){
		page="html-includes/webhosting-step-5.php";
	}else if(step==6){
		var poststr ='';
		process="POST";
		objForms=document.forms['payment_form'];
		for(i=0;i<objForms.elements.length;i++){
			if(poststr=="")poststr="?" + objForms.elements[i].name + "=" + encodeURI( objForms.elements[i].value ); 
			else poststr = poststr + "&" + objForms.elements[i].name + "=" + encodeURI( objForms.elements[i].value ); 
		}
		page="html-includes/webhosting-step-6.php"+poststr;
	}else if(step==61){
		page="html-includes/webhosting-step-6.php";
	}
	if(page!='')getContent(page,step,process);
}
function getContent(page,step,process){
		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){
					dyCreateAlertWindow("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4){
				content=xmlHttp.responseText;
				if(step!=42)document.getElementById('webhosting_content').innerHTML=content;

				if(step==3){
					document.getElementById('body-subpagemain-fix').style.height='100%';
					var Default_Tab= parseInt(document.getElementById('default_tab').value);
					var numrow= parseInt(document.getElementById('numrow').value);
					TabPannels = new Spry.Widget.TabbedPanels("tp1", { defaultTab:  Default_Tab });	
					tab(Default_Tab,numrow);
					//changeTerms(Term);
				}else if(step==5){
					//document.getElementById('body-subpagemain-fix').style.height='1400px';	
				}else{
					//document.getElementById('body-subpagemain-fix').style.height='1190px';	
				}
				if(step==31 || step==32){
					// var sampleAccordion = new Spry.Widget.Accordion("sampleAccordion");
				}
				if(step==4 || step==41){
					var valid_0 = new Spry.Widget.ValidationTextField("valid_UserName","none", {validateOn:["blur"]});
					var valid_1 = new Spry.Widget.ValidationTextField("valid_FirstName","none", {validateOn:["change","blur"]});
					var valid_2 = new Spry.Widget.ValidationTextField("valid_LastName","none", {validateOn:["change","blur"]});
					var valid_3 = new Spry.Widget.ValidationTextField("valid_Address1","none", {validateOn:["change","blur"]});
					var valid_32 = new Spry.Widget.ValidationTextField("valid_Address2","none", {validateOn:["change","blur"]});
					var valid_4 = new Spry.Widget.ValidationTextField("valid_City","none", {validateOn:["change","blur"]});
					var valid_5 = new Spry.Widget.ValidationTextField("valid_StateProvince","none", {validateOn:["change","blur"]});
					var valid_6 = new Spry.Widget.ValidationTextField("valid_PostCode","none", {validateOn:["change","blur"],maxChars:5, useCharacterMasking:true});
					var valid_7 = new Spry.Widget.ValidationTextField("valid_Email","email", {validateOn:["change","blur"]});
					var valid_8 = new Spry.Widget.ValidationTextField("valid_PhoneNo","phone_number", {validateOn:["change","blur"], useCharacterMasking:true});
					var valid_9 = new Spry.Widget.ValidationSelect("valid_Country","none", {validateOn:["change","blur"]});
					var valid_10 = new Spry.Widget.ValidationSelect("valid_HearAboutUs","none", {validateOn:["change","blur"]});
					var valid_11 = new Spry.Widget.ValidationTextField("valid_HearAboutUsVal","none", {validateOn:["change","blur"]});
					if(document.getElementById('SameAsBilling').checked == false){
						var valid_12 = new Spry.Widget.ValidationTextField("valid_ShippingFirstName","none", {validateOn:["change","blur"]});
						var valid_13 = new Spry.Widget.ValidationTextField("valid_ShippingLastName","none", {validateOn:["change","blur"]});
						var valid_14 = new Spry.Widget.ValidationTextField("valid_ShippingAddress1","none", {validateOn:["change","blur"]});
						var valid_15 = new Spry.Widget.ValidationTextField("valid_ShippingAddress2","none", {validateOn:["change","blur"]});
						var valid_16 = new Spry.Widget.ValidationTextField("valid_ShippingCity","none", {validateOn:["change","blur"]});
						var valid_17 = new Spry.Widget.ValidationTextField("valid_ShippingStateProvince","none", {validateOn:["change","blur"]});
						var valid_18 = new Spry.Widget.ValidationTextField("valid_ShippingPostCode","none", {validateOn:["change","blur"],maxChars:5, useCharacterMasking:true});
						var valid_19 = new Spry.Widget.ValidationSelect("valid_ShippingCountry","none", {validateOn:["change","blur"]});
					}
					
					if(document.getElementById('process').value=="edit"){
						for(i=0;i<document.getElementById('Country').length;i++){
							if(document.getElementById('Country').options[i].value==document.getElementById('current_country').value){
								document.getElementById('Country').options[i].selected=true;
							}
						}
						var found=false;
						var hear_val=document.getElementById('current_hear_about_us').value;
						for(i=0;i<document.getElementById('HearAboutUs').length;i++){
							if(document.getElementById('HearAboutUs').options[i].value==hear_val){
								document.getElementById('HearAboutUs').options[i].selected=true;
								found=true;
							}
						}
						if(found==false && hear_val!='' ){
							document.getElementById('HearAboutUs').options[6].selected=true;
						}
					}
					
					Spry.Widget.Form.onSubmit = function(e, form)
					{
						if (Spry.Widget.Form.validate(form) == false) {
							dyCreateAlertWindow('Please input the required (*) fields properly..');
							return false;
						}
						checkForm(4);
					};
				}
				if(step==42){
					if(content=="1")	swapSteps(5);
					else swapSteps(41);
				}
				if(step==6){
					return false;
				}
			}
		}
		document.getElementById('webhosting_content').innerHTML='<div align="center" style="width:647px;"><img src="'+SITE_URL+'/images/ajax-loader-big.gif"></div>';
		if(process=='GET'){
			xmlHttp.open("GET",page,true);
			xmlHttp.send(null);
		}else{
			xmlHttp.open("POST",page,true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", page.length);
			xmlHttp.setRequestHeader("Connection", "close");			
			xmlHttp.send(page);
		}
}
function checkExt(ext) {
	var checkboxes = document.getElementsByName('d2');
	for (var i=0; i<checkboxes.length; i++) {
		checkboxes[i].checked = false;
	}
	var ext_field = document.getElementsByName('ext')[0];
	ext_field.value = ext.value;
	ext.checked = true;
}
function enableContinue(val) {
	domain_plan_val=val
	var cont_button = document.getElementsByName('continue')[0];
	cont_button.style.cursor = 'pointer';
	cont_button.disabled = false;
	cont_button.src = 'images/buttons/continue.gif';
}
function checkForm(step){
	if(step==2){
		if((hasChecked('hosting_payment','currency')==false)){
			dyCreateAlertWindow("Please select a payment option.");
			return false;
		}else{
			swapSteps(3);
			return false;
		}
	}else if(step==3){
		if((hasChecked('webhosting_form','host_type')==false) || (hasChecked('webhosting_form','term')==false)){
			dyCreateAlertWindow("Please select hosting plan and payment term.");
			return false;
		}else{
			swapSteps(31);
		}
	}else if(step==31){
		if(hasChecked('form_addOns','chk_addons[]')==false){
			dyCreateAlertWindow("Please select an add on.");
		}else{
			swapSteps(4);
			return false;
		}
		
	}else if(step==4){
		form=document.forms['form_customer'];
		if(form.elements['can_submit'].value=='0' && form.elements['process'].value=='add'){
			form.elements['UserName'].className="txbut-contact textfieldInvalidFormatState";
		}else{
			swapSteps(42);
		}
		
	}else if(step==5){
		if(document.forms['payment_form'].terms.checked==false){ 
			dyCreateAlertWindow("In order for us to process your order, you must accept our Disclaimer and Terms of Use.\nPlease read it carefully and continue with the order process.");
			return false;
		}else{
			if(document.getElementById('can_submit').value==true){
				document.forms['payment_form'].submit();	
			}else{
				//swapSteps(6);
				//return false;
				return true;
			}
		}
		
	}

}
function checkDomainForm(frm) {
	if (frm.d1.value == '' || frm.d1.value == 'Check your domain name...') {
		dyCreateAlertWindow("Please supply the domain name field.");
		return false;
	}
	
	if (hasChecked('domain_form', 'd2')==false) {
		dyCreateAlertWindow("Please select the domain extension field.");
		return false;
	}
	
	return true;
}

function hasSelectedExt(ext) {
	var cnt = 0;
	for(var i = 0; i<ext.length; i++) {
		if (ext[i].checked) {
			cnt++;
		}
	}
	return cnt;
}
function rezisetab(dis,count)
{
    for(var i=0; i < count; i++)
	{
		if(i!=dis)
		{
	    	document.getElementById('t'+i).style.width = '110px';
	    } else {
	         document.getElementById('t'+i).style.width = '150px';
        }
	}
}
function tab(id,count){
	rezisetab(id,count);
	TabPannels.showPanel(id); return false;
}
function change_hearAboutUs(SelectedValue){
	if(SelectedValue){
		if(SelectedValue=='Other'){
			document.getElementById('valid_HearAboutUsVal').style.visibility='visible';
			document.getElementById('HearAboutUsVal').focus();
			document.getElementById('HearAboutUsVal').value='';
		}else{
			document.getElementById('valid_HearAboutUsVal').style.visibility='hidden';
			document.getElementById('HearAboutUsVal').value=SelectedValue;
		}
	}else{
		document.getElementById('valid_HearAboutUsVal').style.visibility='hidden';
		document.getElementById('HearAboutUsVal').SelectedValue='';
	}		
}
function checkUserName(form,objUserName){
	if(objUserName.value!="" && objUserName.value!="<?=$row['username']?>"){
		var xmlHttp2;
		try{
			// Firefox, Opera 8.0+, Safari
			xmlHttp2=new XMLHttpRequest();
		}catch (e){
			// Internet Explorer
			try{
				xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e){
				try{
					xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e){
					dyCreateAlertWindow("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		xmlHttp2.onreadystatechange=function(){
			if(xmlHttp2.readyState==4){
				response=xmlHttp2.responseText;
				if(response=="0"){
						form.elements['can_submit'].value='1';
						document.getElementById('loading').innerHTML='Username is available..';
						objUserName.className="txbut-contact";
				}else{
					if(response=="1"){
						form.elements['can_submit'].value='0';
						document.getElementById('loading').innerHTML='Username is unavailable..';
						objUserName.focus();
						objUserName.className="txbut-contact textfieldInvalidFormatState";
					}else{
						form.elements['can_submit'].value='0';
						document.getElementById('loading').innerHTML='';
						objUserName.focus();
						objUserName.className="txbut-contact textfieldInvalidFormatState";
						dyCreateAlertWindow('Error on checking username..');
					}
				}
			}
		}
		document.getElementById('loading').innerHTML='<img src="'+SITE_URL+'/images/progIndicator.gif">Checking availability...';
		xmlHttp2.open("GET","includes/webhosting-checkUserName.php?username="+objUserName.value,true);
		xmlHttp2.send(null);
	}else{
		objUserName.className="txbut-contact";
	}	
}

function checkDomainAvailability(){
	if(checkDomainForm(document.forms['domain_form'])==true){
		var xmlHttp2;
		try{
			// Firefox, Opera 8.0+, Safari
			xmlHttp2=new XMLHttpRequest();
		}catch (e){
			// Internet Explorer
			try{
				xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e){
				try{
					xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e){
					dyCreateAlertWindow("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		xmlHttp2.onreadystatechange=function(){
			if(xmlHttp2.readyState==4){
				document.getElementById('domainResult').innerHTML=xmlHttp2.responseText;
				document.getElementById('loading').style.display="none";
				if(xmlHttp2.responseText.indexOf('Congratulations')>=0){
					var plans = document.getElementsByName("domain_plan");
					plans[0].disabled = false;
					plans[1].disabled = true;
					plans[2].disabled = false;
				}else{
					var plans = document.getElementsByName("domain_plan");
					plans[0].disabled = true;
					plans[1].disabled = false;
					plans[2].disabled = false;
				}
			}
		}
		document.getElementById('loading').style.display="block";
		xmlHttp2.open("GET","includes/check-domain.php?d1="+document.getElementById('d1').value+"&ext="+document.getElementById('ext').value,true);
		xmlHttp2.send(null);
	}	
}

function setDomainCheckBox(value){
	objCheckBoxes=document.getElementsByName('d2');
	if(objCheckBoxes){
		value_str=value.substr(value.indexOf("."),value.length);
		if(objCheckBoxes.length){
			for(i=0;i<objCheckBoxes.length;i++){
				if(value_str==objCheckBoxes[i].value && value_str!=''){
					var ext_field = document.getElementsByName('ext')[0];
					ext_field.value = objCheckBoxes[i].value;
					objCheckBoxes[i].checked=true;
				}else{
					objCheckBoxes[i].checked=false;
				}
			}
		}else{
			if(value_str==objCheckBoxes.value && value_str!=''){
				objCheckBoxes.checked=true;
				var ext_field = document.getElementsByName('ext')[0];
				ext_field.value = objCheckBoxes.value;
			}else{
				objCheckBoxes.checked=false;
			}
		}
	}
}
function changeAddon(value)
{
	if(document.getElementById(value).checked==false)
	{
		document.getElementById(value).checked=true;
	}else{
		document.getElementById(value).checked=false;
	}	
}

function changeTerms(value,count,countTotal)
{
	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){
				dyCreateAlertWindow("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
				document.getElementById('change-payment-terms-'+count).innerHTML= xmlHttp.responseText;
		}
	}
	for(i=0;i<countTotal;i++){
		document.getElementById('change-payment-terms-'+i).innerHTML='';
	}
	xmlHttp.open("GET","html-includes/change-payment-terms.php?id="+value,true);
	xmlHttp.send(null);
}
function res(t,v){
      var w = "";
      for (i=0; i < t.value.length; i++) {
        x = t.value.charAt(i);
        if (v.indexOf(x,0) != -1)
         w += x;
      }
         t.value = w;
   }

function avail_private_domain(obj){
	if(obj.checked == true){
		document.getElementById('domain_plan').checked = true;
		document.getElementById('domain_plan').click();
		document.getElementById('private_domain').value= 1;
	}else{
		document.getElementById('domain_plan').checked = false;
		document.getElementById('private_domain').value= 0;
	}
	
}  
function request_official_receipt(obj){
	if(obj.checked == true){
		document.getElementById('request_or_via_lbc').value= 1;
	}else{
		document.getElementById('request_or_via_lbc').value= 0;
	}
	
}  
function hideShipping(obj){
	if(obj.checked == true){
		document.getElementById('shipping-information-removed').style.display="none";
		document.getElementById('ShippingFirstName').value = document.getElementById('FirstName').value;
		document.getElementById('ShippingLastName').value = document.getElementById('LastName').value;
		document.getElementById('ShippingAddress').value = document.getElementById('Address').value;
		document.getElementById('ShippingAddress2').value = document.getElementById('Address2').value;
		document.getElementById('ShippingCity').value = document.getElementById('City').value;
		document.getElementById('ShippingStateProvince').value = document.getElementById('StateProvince').value;
		document.getElementById('ShippingPostalCode').value = document.getElementById('PostalCode').value;
		document.getElementById('ShippingCountry').value = document.getElementById('Country').value;
	}else{
		document.getElementById('shipping-information-removed').style.display="block";
		document.getElementById('ShippingFirstName').value = '';
		document.getElementById('ShippingLastName').value = '';
		document.getElementById('ShippingAddress').value = '';
		document.getElementById('ShippingAddress2').value = '';
		document.getElementById('ShippingCity').value = '';
		document.getElementById('ShippingStateProvince').value = '';
		document.getElementById('ShippingPostalCode').value = '';
		document.getElementById('ShippingCountry').value = '';
	}
}
