var insert = 0;
	// Start of hosting process
	function s1_status(frm,cond){
		
	   frm.domain_name.disabled = cond;
	   //frm.step1.disabled= cond;
	   frm.domain_ext.disabled= cond;
	   if(cond){
	   		frm.step1.value="Edit";
	   }
	   else{
	   		frm.step1.value="Next";	
	  }
	 		   
	}
	function _stepOne(frm,step)
	{
		
		 var has_err = 0;
	    var err_msg = "";
	    
	    if(frm.step1.value == "Edit"){
	      s1_status(frm,false);
	      
	    }else{
			if(is_empty(frm.domain_name))// || !isValidUrl(frm.domain_name.value))
			{
				change_bg(frm.domain_name,"#c1cee1");
				has_err++;
			//	alert(123);
			}
			else{
				change_bg(frm.domain_name,"");
			}
			if (is_empty(frm.domain_ext)){
				change_bg(frm.domain_ext,"#c1cee1");
				has_err++;
		//		alert(124);				
			}
			else{
				change_bg(frm.domain_ext,"");
			}

			if(has_err > 0){
				err_msg = "<span style='color:red'>Please enter valid domain name. e.g. www.mydomain.com</span>";
				document.getElementById("err_msg").innerHTML = err_msg;
				document.getElementById("step_title").src = "images/h_s1.jpg";
				//return false;
			}
			else{
				document.getElementById("err_msg").innerHTML = "";
				document.getElementById("step_title").src = "images/h_s2.jpg";
			    document.getElementById("div_s2").style.display = "block";
				
				s1_status(frm,true);
			}
			
			
		}
		if(err_msg == "" && insert == 0 ){
			insert = 1;
			updatePackage1(step,frm.domain_name.value,frm.domain_ext.value,document.referrer);
		}
		else if(err_msg == "" && insert == 1 ){
			updatePackage1(0,frm.domain_name.value,frm.domain_ext.value,'');
		}
					
	}
	function s2_status(frm,cond){
	   frm.package_type.disabled = cond;

	   if(cond)frm.step2.value="Edit";
	   else frm.step2.value="Next";
	}
	function _stepTwo(frm,step)
	{
	    var err_msg = "";
	    if(frm.step2.value == "Edit"){
	      s2_status(frm,false);
	    }else{
			if(frm.package_type.selectedIndex== 0)
			{
				err_msg = "<span style='color:red'>Please select a hosting package</span>";
				document.getElementById("err_msg2").innerHTML = err_msg;
				document.getElementById("step_title").src = "images/h_s2.jpg";
			}
			else{
				document.getElementById("err_msg2").innerHTML = "";
				document.getElementById("step_title").src = "images/h_s3.jpg";
			    document.getElementById("div_s3").style.display = "block";
				s2_status(frm,true);
			}
		}
		if(err_msg == ""){	
		
			updatePackage2(step,frm.package_type.options[frm.package_type.selectedIndex].text);
		}
		
	}
	function s3_status(frm,cond){
	   frm.package_type.disabled = cond;
	   if(cond)frm.step3.value="Edit";
	   else frm.step3.value="Next";
	}
	function  _stepThree(frm,step)
	{
		
		var _script_body = "";
		for(i = 0;i < frm.elements.length;i++){
	//	  document.getElementById("err_msg3").innerHTML += frm.elements[i].name + " = " + frm.elements[i].value + "<br />";
		  _script_body += frm.elements[i].name + " = " + frm.elements[i].value + "&";
		}  
	    var err_msg = "";
	    var has_err = 0;
	    if(frm.step3.value == "Edit"){
	      s3_status(frm,false);
	    }else{
	        if(is_empty(frm.c_first_name)){
	           has_err++;
               change_bg(frm.c_first_name,"#c1cee1");
	        }else{
	        	change_bg(frm.c_first_name,"");
	        }
	        if(is_empty(frm.c_last_name)){
	           has_err++;
               change_bg(frm.c_last_name,"#c1cee1");	           
	        }else{
               change_bg(frm.c_last_name,"");	           	        	
	        }
	         /*if(is_empty(frm.c_company)){
	           has_err++;
               change_bg(frm.c_company,"#c1cee1");	           
	        }else{
               change_bg(frm.c_company,"");	           	        	
	        }*/
	         if(is_empty(frm.c_country)){
	           has_err++;
               change_bg(frm.c_country,"#c1cee1");	           
	        }else{
               change_bg(frm.c_country,"");	           	        	
	        }
	        if(is_empty(frm.c_address)){
	           has_err++;
               change_bg(frm.c_address,"#c1cee1");	           
	        }else{
               change_bg(frm.c_address,"");	           	        	
	        }
	        if(is_empty(frm.c_city)){
	           has_err++;
               change_bg(frm.c_city,"#c1cee1");	           
	        }else{
               change_bg(frm.c_city,"");	           	        	
	        }
	        if(is_empty(frm.c_prov)){
	           has_err++;
               change_bg(frm.c_prov,"#c1cee1");	           
	        }else{
               change_bg(frm.c_prov,"");	           
	        }
	        if(!is_empty(frm.c_phone) && !check_Phone(frm.c_phone.value)){
	           has_err++;
               change_bg(frm.c_phone,"#c1cee1");	           
	        }else{
               change_bg(frm.c_phone,"");	           	        	
	        }
	        if(!is_empty(frm.c_fax) && !check_Phone(frm.c_fax.value)){
	           has_err++;
               change_bg(frm.c_fax,"#c1cee1");	           
	        }else{
               change_bg(frm.c_fax,"");	           	        	
	        }

	        if(is_empty(frm.c_email) || !isValidEmail(frm.c_email.value)){
	           has_err++;
               change_bg(frm.c_email,"#c1cee1");	           
	        }else{
               change_bg(frm.c_email,"");	           	        	
	        }
	        if(frm.how_find_webrun.selectedIndex == 0){
	           has_err++;
               change_bg(frm.how_find_webrun,"#c1cee1");	           
	        }else{
               change_bg(frm.how_find_webrun,"");	           	        	
	        }
		}	
		if(has_err == 0){
			document.getElementById("err_msg3").innerHTML = "";
			_stepFour(frm);
		}
		else{
			document.getElementById("err_msg3").innerHTML = "<span style='color:red'>Fill in all marked fields.</span>";
			return;
		}
		if(err_msg ==""){
			
			updatePackage3(step,frm.c_first_name.value,frm.c_last_name.value,frm.c_company.value,frm.c_country.value,frm.c_address.value,frm.c_city.value,frm.c_prov.value,frm.c_phone.value,frm.c_fax.value,frm.c_email.value,frm.how_find_webrun.options[frm.how_find_webrun.selectedIndex].text,frm.domain_name.value,frm.domain_ext.value,frm.package_type.options[frm.package_type.selectedIndex].text);
		}
	}	

	function  _stepFour(frm){
		document.getElementById("step_title").src = "images/h_s4.jpg";
		document.getElementById("div_s4").style.display = "block";
		document.getElementById("div_s1").style.display = "none";	
		document.getElementById("div_s2").style.display = "none";
		document.getElementById("div_s3").style.display = "none";
		
						
	}
	function checkConfirm(frm,step,opt){
		if(opt == "yes"){
			
			updatePackage4('4','yes');	
		}
		else{
			
			document.getElementById("div_s1").style.display = "block";	
			document.getElementById("div_s2").style.display = "block";
			document.getElementById("div_s3").style.display = "block";
			document.getElementById("div_s4").style.display = "none";
			s1_status(frm,true);
			s2_status(frm,true);
			s3_status(frm,true);
		}
	}
	
	 function checkFormTwo(fm)
	 { 					
			 if(fm.hostSelect.selectedIndex < 1){
							 return select_menu(fm.hostSelect,"Please select an option");
					}
					//optvalue.value = hostSelect.options[hostSelect.selectedIndex].text;
	 }
   //function for formTwo, changing the select box options
	function setOptions(chosen) 
		{
					var selbox = document.formTwo.billSelect;
 					selbox.options.length = 0;
								if (chosen == " ") {
								  selbox.options[selbox.options.length] = new Option('Please select one of the options',' ');
								 
								}
								if (chosen == "1") {
								  selbox.options[selbox.options.length] = new Option('Monthly $9.95','Monthly $9.95');
								  selbox.options[selbox.options.length] = new Option('Yearly $59.95','Yearly $59.95');
								}
								if (chosen == "2") {
								  selbox.options[selbox.options.length] = new Option('Monthly $11.95','Monthly $11.95');
								  selbox.options[selbox.options.length] = new Option('Yearly $70.95','Yearly $70.95');
								}
								if (chosen == "3") {
								  selbox.options[selbox.options.length] = new Option('Monthly $16.95','Monthly $16.95');
								  selbox.options[selbox.options.length] = new Option('Yearly $79.95','Yearly $79.95');
								}
								if (chosen == "4") {
								  selbox.options[selbox.options.length] = new Option('Monthly $20.95','Monthly $20.95');
								  selbox.options[selbox.options.length] = new Option('Yearly $89.95','Yearly $89.95');
								}
								if (chosen == "5") {
								  selbox.options[selbox.options.length] = new Option('Monthly $25.95','Monthly $25.95');
								  selbox.options[selbox.options.length] = new Option('Yearly $99.95','Yearly $99.95');
								}
								if (chosen == "6") {
								  selbox.options[selbox.options.length] = new Option('Monthly $30.95','Monthly $30.95');
								  selbox.options[selbox.options.length] = new Option('Yearly $109.95','Yearly $109.95');
								}
			}//--end of choose selected box for formTwo
			
	/*function populate(document.formFour, selected) 
		{		
							var stateArray = new Array("('Select State','',true,true)",
							"('Alabama')",
							"('Alaska')",
							"('Arizona')",
							"('Arkansas')",
							"('California')",
							"('Colorado')",
							"('Connecticut')",
							"('Delaware')",
							"('Columbia')",
							"('Florida')",
							"('Georgia')",
							"('Hawaii')",
							"('Idaho')",
							"('Illinois')",
							"('Indiana')",
							"('Iowa')",
							"('Kansas')",
							"('Kentucky')",
							"('Louisiana')",
							"('Maine')",
							"('Maryland')",
							"('Massachusetts')",
							"('Michigan')",
							"('Minnesota')",
							"('Mississippi')",
							"('Missouri')",
							"('Montana')",
							"('Nebraska')",
							"('Nevada')",
							"('New Hampshire')",
							"('New Jersey')",
							"('New Mexico')",
							"('New York')",
							"('North Carolina')",
							"('North Dakota')",
							"('Ohio')",
							"('Oklahoma')",
							"('Oregon')",
							"('Pennsylvania')",
							"('Rhode Island')",
							"('South Carolina')",
							"('South Dakota')",
							"('Tennessee')",
							"('Texas')",
							"('Utah')",
							"('Vermont')",
							"('Virginia')",
							"('Washington')",
							"('West Virginia')",
							"('Wisconsin')",
							"('Wyoming')");
							
							var provinceArray = new Array("('Select Province','',true,true)",
							"('Alberta')",
							"('British Columbia')",
							"('Labrador')",
							"('Manitoba')",
							"('New Brunswick')",
							"('Newfoundland')",
							"('Northwest territories')",
							"('Nove Scotia')",
							"('Nunaut')",
							"('Ontario')",
							"('Prince Edward Island')",
							"('Quebec')",
							"('Saskatchewan')",
							"('Yukon')");
							
							var noArray = new Array("('<--------------------','',true,true)");
							
							if (document.formFour.country.options[document.formFour.country.selectedIndex].value == 'US') 	
							{
										for (var i=0; i < document.formFour.stateArray.length; i++) 
									{
										eval("document.formFour.state.options[i]=" + "new Option" + stateArray[i]);
									}
							}
							
							if (document.formFour.country.options[document.formFour.country.selectedIndex].value== 'CA') 	
							{
										while (document.formFour.provinceArray.length <document.formFour.state.options.length) 
									{
										document.formFour.state.options[(document.formFour.state.options.length - 1)] = null;
									}
										for (var i=0; i < document.formFour.provinceArray.length; i++) 	
										{
										eval("document.formFour.state.options[i]=" + "new Option" + provinceArray[i]);
										}
							}
							
							if (document.formFour.country.options[document.formFour.country.selectedIndex].value== '') 
							{
										while (document.formFour.noArray.length < document.formFour.state.options.length) 
									{
										document.formFour.state.options[(document.formFour.state.options.length - 1)] = null;
									}
										for (var i=0; i < document.formFour.noArray.length; i++) 	
										{
										eval("document.formFour.state.options[i]=" + "new Option" + noArray[i]);
										}
										
							}
					
		}
		
		
		*/
		
		//--function for check formFour
		
function checkFormFour()
{		
		with (document.formFour)
			{
				    if(is_empty(fName))
					{
						return select(fName,"Please enter your first name!");
			    	}
					if(is_empty(lName))
					{
						return select(lName,"Please enter your last name!");
					}
					if(is_empty(address))
					{
						return select(address,"Please fill in your address!");
			    	}
					if(is_empty(city))
					{
						return select(city,"Please enter your city!");
			    	}
					if(is_empty(zip))
					{
						return select(zip,"Please enter your zip code!");
			    	}
					if(is_empty(pEmail))
					{
						return select(pEmail,"Please enter your Primary Email!");
			    	}
					else if(!isValidEmail(pEmail.value))
					{
 					   return select(pEmail,"invalid Email!");
					}
					
					if(is_empty(dPhone))
					{
						return select(dPhone,"Please enter a daytime phone number, so we can reach you by phone!");
			    	}
					else if(!isValidEmail(pEmail.value))
					{
 					   return select(pEmail,"invalid Email!");
					}
					if(is_empty(uName))
					{
						return select(uName,"Please enter your username name!");
			    	}
					if(is_empty(Pword))
					{
						return select(Pword,"Please enter your password!");
			    	}
					if(is_empty(Vword))
					{
						return select(Vword,"Please verify your password!");
			    	}
					if(is_empty(cardhold))
					{
						return select(cardhold,"Please enter the card holder's name!");
			    	}
				    if(is_empty(card))
					{
						return select(card,"Please enter your card number!");
					}
					if(is_empty(sCode))
					{
						return select(sCode,"Please enter your 4-digits security code!");
			    	}
					 
					if(selectPay.selectedIndex<0)
					{
					   return select_menu(selectPay,"Please select an pay option");
					}
					 if(Exp_Month.selectedIndex<0)
					{
					   return select_menu(Exp_Month,"Please select an expire month");
					}
					 if(Exp_Year.selectedIndex<0)
					{
					   return select_menu(Exp_Year,"Please select an expire month");
					}
					
		}	
}
	

var xmlHttp;

function updateHosting(ref)
{ 
	var url="dohosting_packageupdate.php?step=0"+"&ref="+ref;	
	
	xmlHttp=GetXmlHttpObjectH(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
}
function updatePackage1(step,name,ext,ref)
{ 
	var url="dohosting_packageupdate.php?step=" + step + "&name=" + name +"&ext=" + ext+"&ref="+ref;	
	xmlHttp=GetXmlHttpObjectH(stateChangedS1);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 
 
function updatePackage2(step,p)
{ 
	var url="dohosting_packageupdate.php?step=" + step + "&package=" + p;
	xmlHttp=GetXmlHttpObjectH(stateChangedS2);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 

function updatePackage3(step,fname,lname,country,company,address,city,prov,phone,fax,email,how_find_webrun,name,ext,pa)
{ 
	
	
	var url="dohosting_packageupdate.php?step=" + step + "&f=" + fname+ "&l=" + lname+ "&co=" + company+"&c=" + country+ "&a=" +address+ "&ci=" + city+ "&pr=" + prov+ "&p=" + phone+ "&fa=" + fax+ "&e=" + email+ "&h=" + how_find_webrun+ "&name=" + name +"&ext=" + ext + "&package=" + pa;
		
	xmlHttp=GetXmlHttpObjectH(stateChangedS3);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 
function updatePackage4(step,opt)
{ 
	var url="dohosting_packageupdate.php?step=" + step+"&opt="+opt;
	xmlHttp=GetXmlHttpObjectH(stateChangedS4);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 

function stateChanged() 
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		//document.getElementById("err_msgm").innerHTML=xmlHttp.responseText; 
	}
}
function stateChangedS4() 
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		document.getElementById("information").innerHTML=xmlHttp.responseText; 
	}
}

function stateChangedS3() 
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		document.getElementById("information").innerHTML=xmlHttp.responseText; 
	}
} 

function stateChangedS1() 
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		
		document.getElementById("err_msg").innerHTML=xmlHttp.responseText; 
		
	}
} 

function stateChangedS2() 
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{		
		document.getElementById("err_msg2").innerHTML=xmlHttp.responseText; 
	}
} 

function GetXmlHttpObjectH(handler)
{ 
	var objXmlHttp=null;

	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This example doesn't work in Opera"); 
		return; 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler; 
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled"); 
			return; 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
} 

	
			