function selectRegion(regionValue) {
	//document.getElementById("regionSelectError").innerHTML = "";
	//document.getElementById("regionSelectError").style.display = "none";
	document.getElementById("sppRegionSelectorSubmit").style.marginTop = "2px";
	var countrySelect = "<select name='country' style='margin-top: 2px;'>";
	countrySelect = countrySelect + "<option value=''>Select a Language</option>";
	if (regionValue == "apac") {
		countrySelect = countrySelect + "<option value='en-AU'>English</option>";
		countrySelect = countrySelect + "<option value='zh-CN'>简体中文</option>";
		countrySelect = countrySelect + "<option value='zh-TW'>繁體中文</option>";
		countrySelect = countrySelect + "<option value='ja-JP'>日本語</option>";
		countrySelect = countrySelect + "<option value='ko-KR'>한국어</option>";
	} else if (regionValue == "emea") {
		countrySelect = countrySelect + "<option value='de-DE'>Deutsch</option>";
		countrySelect = countrySelect + "<option value='es-ES'>Español</option>";
		countrySelect = countrySelect + "<option value='fr-FR'>Français</option>";
		countrySelect = countrySelect + "<option value='it-IT'>Italiano</option>";
		countrySelect = countrySelect + "<option value='ru-RU'>Русский</option>";
		countrySelect = countrySelect + "<option value='pl-PL'>Polski</option>";
		countrySelect = countrySelect + "<option value='tr-TR'>Türkçe</option>";
		countrySelect = countrySelect + "<option value='en-GB'>English</option>";
	} else if (regionValue == "amer") {
		countrySelect = countrySelect + "<option value='en-US'>English</option>";
		//countrySelect = countrySelect + "<option value='es-LA'>Español</option>";
		//countrySelect = countrySelect + "<option value='pt-BR'>Português</option>";
	}
	countrySelect = countrySelect + "</select>";
	if (regionValue == "none") {
		countrySelect = "";
	}
	jQuery("#CountryDiv").html(countrySelect);
}

function sppReg() {
	theForm = document.getElementById("sppRegionSelector");
	sel = theForm.region.selectedIndex;
	region = theForm.region.options[sel].value;
	
	if (region == "apac" 
		|| region == "emea"
			|| region == "amer") {
		var country = "";
		if (theForm.country) {
			sel_country = theForm.country.selectedIndex;
			country = theForm.country.options[sel_country].value;
		}
		if (country != "") {
			var countrycode = "US";
			var lang = country;
			countrycode = country.split("-")[1];
			//alert("https://partnerreg.seagate.com/sppregnewuser/Index.jsp?countrycode=" + countrycode + "&lang=" + lang);
			//return false;
			regTarget = "https://partnerreg.seagate.com/sppregnewuser/Index.jsp?countrycode=" + countrycode + "&lang=" + lang;
			if (country == "en-US") {
				regTarget = "https://partnerreg.seagate.com/sppregnewuser/";
			}
		} else {
			//document.getElementById("regionSelectError").style.display = "";
			//document.getElementById("regionSelectError").innerHTML = "<p style='color:black;font-weight:bold;'>Please select a country</p>";
			alert("Please select a language");
			return false;
		}
	} else {
		//document.getElementById("regionSelectError").style.display = "";
		//document.getElementById("regionSelectError").innerHTML = "<p style='color:black;font-weight:bold;'>Please select a region</p>";
		alert("Please select a region");
		return false;
	}
	theForm.region.value = "none";
	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;
		
		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;
	      		
	      		var url = window.location.href;
	      		//alert(url);
	      		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");
		    }				
		}
	}
}
