﻿function validate_required(field,alerttxt){
	with (field){
		if (value==null||value==""||value=="seqarator"){
			alert(alerttxt);return false
		}
		else {return true}
	}
}

function validate_email(field,alerttxt){
	with (field){
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2){
			alert(alerttxt);return false}
		else {return true}
	}
}

//Create XmlHttp Object
function GetXmlHttpObject(){ 
  var objXMLHttp=null
  if (window.XMLHttpRequest){
    objXMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject){ // IE Browser
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
	return objXMLHttp
} 


function validate_form(thisform){
	with (thisform){
		// First Name
		if (validate_required(first_name,"Please fill in all necessary information.")==false){
			first_name.focus();return false}
		
		// Last Name
		if (validate_required(last_name,"Please fill in all necessary information.")==false){
			last_name.focus();return false}
		
		// Country
		//if (validate_required(country_reg,"Please fill in all necessary information.")==false){
		//	country_reg.focus();return false}
		
		// Email address
		if (validate_required(email_addr,"Please fill in all necessary information.")==false){
			email_addr.focus();return false}
		
		if (validate_email(email_addr,"Download link for trial version will be sent to you by mail, \nso please provide a correct e-mail address.")==false){
			email_addr.focus();return false}
		
		if (validate_required(product,"Please select a product that you want to download.")==false){
			product.focus();return false}
	}
}


//Action
var getProductListURL = '/cgi-bin/productlist.cgi?major=7';
var txtProduct = '<textarea name="product" id="product" cols="50" rows="6"></textarea><input type="hidden" name="chkErrorStat" id="chkErrorStat" value="True" />';
var txtProductTip = '(Please type the Product Name and version that you want to download in text box above)';
var sltProductTip = '(Click on right arrow to display list of available downloads.)<input type="hidden" name="chkErrorStat" id="chkErrorStat" value="False" />';
var xmlErrMsg = '<result>ERROR</result>';
var txtFormID = '<strong>Description</strong>';
var sltFormID = '<strong>Product</strong>';

function DispProductList(){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			DispInfo2HTML(txtProduct,txtProductTip,txtFormID);
			return
		}
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET",getProductListURL,true);
		xmlHttp.send(null);
}

function stateChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		var strRespTxt = xmlHttp.responseText;
		var strNotPrt = encodeURIComponent(strRespTxt).length;
		if (encodeURIComponent(strRespTxt).length<73){		
			DispInfo2HTML(txtProduct,txtProductTip,txtFormID);
		}
		else{
			DispInfo2HTML(strRespTxt,sltProductTip,sltFormID);
		}
   	}	
} 

//Update HTML Page
function DispInfo2HTML(strHTMLCode1,strHTMLCode2,strHTMLCode3){
	document.getElementById("ProductSltTR").style.display="";
	document.getElementById("ProductSltObj").innerHTML = strHTMLCode1;
	document.getElementById("ProvidePRTInfoTR").style.display="";
	document.getElementById("ProvidePRTInfoDIV").innerHTML = strHTMLCode2;
	document.getElementById("PrtFormID").innerHTML = strHTMLCode3;
}

function RefProductList(getAjaxPrtURL){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			DispInfo2HTML(txtProduct,txtProductTip,txtFormID);
			return
		}
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.open("GET",getAjaxPrtURL,true);
		xmlHttp.send(null);
}

function ModifyDispProductList(){
	var PrtCatID = document.getElementById("product_category").value;
	var PlatformID = document.getElementById("os_version").value;
	var getPrtCGI = '/cgi-bin/productlist.cgi?'+'proid='+PrtCatID+'&platformcode='+PlatformID;
	//if (PlatformID=="win32"){ //Windows 平台	
	//	var getPrtCGI = '/cgi-bin/productlist.cgi?'+'proid='+PrtCatID;}
	//else{
	//	var getPrtCGI = '/cgi-bin/productlist.cgi?'+'proid='+PrtCatID+'&platformcode='+PlatformID;}
	DispInfo2HTML("<br /><img src='images/ajx-loading.gif' border='0' />","","");
	RefProductList(getPrtCGI);
	//document.getElementById("product").focus();
}