function sppReg() {
	theForm = document.getElementById("sppRegionSelector");
	sel = theForm.region.selectedIndex;
	region = theForm.region.options[sel].value;
	if (region == "apac") {
		regTarget = "https://partnerreg.seagate.com/sppregnewuser/Index.jsp?countrycode=IN&lang=en-US";
	} else if (region == "emea") {
		regTarget = "https://partnerreg.seagate.com/sppregnewuser/Index.jsp?countrycode=GB&lang=en-GB";
	} else if (region == "amer") {
		regTarget = "https://partnerreg.seagate.com/sppregnewuser";
	} else {
		document.getElementById("regionSelectError").innerHTML = "<p style='color:black;font-weight:bold'>Please select a region</p>";
		return false;
	}
	theForm.action = regTarget; 
	theForm.submit();
}

function custReg() {
	theForm = document.getElementById("customerSelector");
	sel = theForm.customer.selectedIndex;
	customerType = theForm.customer.options[sel].value;
	if (customerType != "none") { 
		regTarget = "https://partnerreg.seagate.com/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType="+customerType;
		theForm.action = regTarget; 
		theForm.submit(); 
	} else {
		document.getElementById("customerSelectorError").innerHTML = "<p style='color:black;font-weight:bold'>Please select a customer type</p>";
		return false;
	}
}

function IsNumeric(strString) {
	var regExp8 = /\d\d\d\d\d\d\d\d/;
	var blnResult = false;
	if (strString.length == 8) {	
		if (regExp8.test(strString)) {
			blnResult = true;
		}
	}  
	return blnResult;
}

/*
function valid_direct_cust() { 
	theForm = document.getElementById("customerSelector");
	sel = theForm.customer.selectedIndex;
	customerType = theForm.customer.options[sel].value;
	var error = 0; 
	regTarget = "https://partnerreg.seagate.com/sbm/BizSolo/PartnerRegistration/Start.jsp";
	
	jQuery(".customerSelectorError").hide();
	
	if (customerType == "none") { 
		jQuery("#error1").show("medium");
		error = 1;
	} else if (theForm.customerNumber.value == "" || theForm.customerNumber.value == jQuery("#customerNumberLabel").text()) { 
		jQuery("#error2").show("slow");
		error = 1;
	} else if (customerType == "DESIGN_PARTNER") {
		if (theForm.customerNumber.value != "918273645") { 
			jQuery("#error3").show("slow"); 
			error = 1;
		}
	} else {
		if (IsNumeric(theForm.customerNumber.value) == false) {
			jQuery("#error3").show("slow");
			error = 1;
		}
	} 
		
	if (error == 0) {
		regTarget = "https://partnerreg.seagate.com/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType="+customerType;
		theForm.action = regTarget; 
		theForm.submit();
	}		
}
*/

var xmlHttp;
function valid_direct_cust() {
	var error = 0; 
	theForm = document.getElementById("customerSelector");
	sel = theForm.customer.selectedIndex;
	customerType = theForm.customer.options[sel].value;
	jQuery(".customerSelectorError").hide();
	if (customerType == "none") { 
		jQuery("#error1").show("medium");
		error = 1;
	} else if (theForm.customerNumber.value == "" || theForm.customerNumber.value == jQuery("#customerNumberLabel").text()) { 
		jQuery("#error2").show("slow");
		error = 1;
	} else if (customerType == "DESIGN_PARTNER") {
		if (theForm.customerNumber.value != "918273645") { 
			jQuery("#error3").show("slow"); 
			error = 1;
		}
	} 
	if (error == 0) {
		var billto = document.getElementById("customerNumber").value;
		//The url should be changed according to the different env. 
		//Predev:  "/ww/custnumber.jsp?billto="+billto;
		//Staging:	
		//Production:
		var url="/ww/custnumber.jsp?billto="+billto;
		if(window.XMLHttpRequest){
			xmlHttp = new XMLHttpRequest();
		}
		else if(window.ActiveXObject){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlHttp.open("Get",url,true);
		xmlHttp.onreadystatechange = callback;
		xmlHttp.send(null);
	}
	
}		
function callback() {
	//xmlHttp.readyState = 0, Has not finished the initialization of object XMLHttpRequest
	//xmlHttp.readyState = 1, Is sending the XMLHttpRequest
	//xmlHttp.readyState = 2, Has finished the sending of XMLHttpRequest
	//xmlHttp.readyState = 3, XMLHttpRequest is getting the server response
	//xmlHttp.readyState = 4, XMLHttpRequest has finished the getting of server response
	if( xmlHttp.readyState==4 ){
		//mlHttp.status = 1xx,  Information
		//mlHttp.status = 2xx,  Successful
		//mlHttp.status = 3xx,  Redirection
		//mlHttp.status = 4xx,  Client side error
		//mlHttp.status = 5xx,  Server side error
		if (xmlHttp.status==300){
			alert('Redirection Error, please contact with System Administrator');			
		}else if (xmlHttp.status==400 || xmlHttp.status==500){
			alert('Web Service Error, please contact with System Administrator');
		}else if( xmlHttp.status==200 ) {		
			var respText = xmlHttp.responseText;
			if (respText == 'VALID'){
	      		var billto = document.getElementById("customerNumber").value;
	      		//document.customerSelector.action should be changed according to the different BPAS env.
	      		//Predev:		'http://okdev2.okla.seagate.com:58594/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType=OEM&CustNo='+billto;
	      		//Staging:  	'http://bpatst2.okla.seagate.com/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType=OEM&CustNo='+billto;
	      		//Production:	'http://bpa.okla.seagate.com/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType=OEM&CustNo='+billto;
	      		var url = window.location.href;
	      		//alert(url);
	      		if (url.indexOf('dev') != -1){
		      		document.customerSelector.action = 'http://okdev2.okla.seagate.com:58594/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType='+customerType+'&CustNo='+billto;
	      			
	      		}else if(url.indexOf('tst') != -1){
	      			document.customerSelector.action = 'http://bpatst2.okla.seagate.com/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType='+customerType+'&CustNo='+billto;
	      		}else{
		      		document.customerSelector.action = 'http://partnerreg.seagate.com/sbm/BizSolo/PartnerRegistration/Start.jsp?UserPartnerType='+customerType+'&CustNo='+billto;
	      		}
	      		document.customerSelector.submit();
		    }else{
		    	//Alert message will be changed...
		    	jQuery("#error3").show("slow");
		    }				
		}
	}
}