// JavaScript Document

var xmlHttp = false;
function CreateXMLHttp() {
try {
	xmlHttp = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
	xmlHttp = false;
}
}
}
//if (!xmlHttp)alert("Error initializing XMLHttpRequest!");
}


function HandleRequest(txtDivID) {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseText;
			document.getElementById(txtDivID).innerHTML = response;
			}
		else if(xmlHttp.status == 404) {
			document.getElementById(txtDivID).innerHTML = "Requested URL is not found.";
		}
		else if (xmlHttp.status == 403) {
			document.getElementById(txtDivID).innerHTML = "Access denied.";
		}
		else{
			document.getElementById(txtDivID).innerHTML = "Status is " + xmlHttp.status;
		}
	}
}


function GetOS(){
	var OsObject = "";
	if(navigator.userAgent.indexOf("MSIE")>0) {
		return "MSIE";       //IE浏览器
	}
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
		return "Firefox";     //Firefox浏览器
	}
	if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
		return "Safari";      //Safan浏览器
	}
	if(isCamino=navigator.userAgent.indexOf("Camino")>0){
		return "Camino";   //Camino浏览器
	}
	if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
		return "Gecko";    //Gecko浏览器
	}   
} 




function GetUrlParameter(para)
{
var retval="",s=location.search.replace("?","");
if(s=="")return "";s = s.split("&");
for(var i=0;i<s.length;i++)
if(s[i].toUpperCase().indexOf(para.toUpperCase() + "=")==0)
retval+=((retval==""?"":", ")+s[i].substr(s[i].indexOf("=")+1,s[i].length));
return retval;
}


function IsDigit(){
	return ((event.keyCode >= 48) && (event.keyCode <= 57));
}



//for eng check
function OnlyEng(thisID){
	var inputObjStr,strlen,strExp,newObjStr,newObjStrRe;
	inputObjStr=thisID.value;
	newObjStr=thisID.value;
	newObjStrRe=newObjStr.replace(/'/g,"")
	newObjStrRe=newObjStrRe.replace(/"/g,"")
	newObjStrRe=newObjStrRe.replace(/&/g,"")
	newObjStrRe=newObjStrRe.replace(/</g,"")
	newObjStrRe=newObjStrRe.replace(/>/g,"")
	newObjStrRe=newObjStrRe.replace(/\//g,"")
	newObjStrRe=newObjStrRe.replace(/\\/g,"")
	newObjStrRe=newObjStrRe.replace(/\r\n/g,"")

	for (i=0; i < newObjStrRe.length; i++){
		var CheckChar = newObjStrRe.charAt(i);
		var NewChar = CheckChar;
		var thisStrLen = CheckChar.length;
		strExp="/[\\x00-\\xff]{"+thisStrLen+"}/.test('"+CheckChar+"')";
		if (!eval(strExp)) {
		NewChar ="";
		}
	newObjStr = newObjStr.replace(CheckChar,NewChar);
	}

	if (inputObjStr!=newObjStr) {
		thisID.value = newObjStr;
	}
}


function ReplaceSpecialPunctuation(sChar) {
	var nChar=sChar;
	nChar=nChar.replace(/ /g,"?")
	nChar=nChar.replace(/'/g,"")
	nChar=nChar.replace(/"/g,"")
	nChar=nChar.replace(/&/g,"")
	nChar=nChar.replace(/</g,"")
	nChar=nChar.replace(/>/g,"")
	nChar=nChar.replace(/\//g,"")
	nChar=nChar.replace(/\\/g,"")
	nChar=nChar.replace(/\r\n/g,"")
	return nChar;
}


function SchNav(Idname,sType){
	var i ;
	for (i=1;i<=4;i++)
	{
		var navId = "nav"+i;
		if (navId === Idname )
		{
			document.getElementById(Idname).className = "mac_t_cur";
		}
		else
		{
			document.getElementById(navId).className = "btn";
		}
	}
	document.getElementById("sType").value = sType;
}




//search check
function ReSerarchList()
{
if (document.formSearch.q.value == "" ){
	alert ("Please input a search term.");
	document.formSearch.q.focus();
	return false;
	}
return true;
}



function OpenWindow(url,name,iWidth,iHeight)
{
var url;
var name;
var iWidth;
var iHeight;
var iTop = (window.screen.availHeight-30-iHeight)/2;
var iLeft = (window.screen.availWidth-10-iWidth)/2;
window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}



function ImgZoom(thisImgURL,thisImgType,thisW,thisH)
{
if ((thisW!=0)&(thisW!="")&(thisH!=0)&(thisH!="")) {
var whAdd=100
var w = Number(thisW)+whAdd
var h = Number(thisH)+whAdd
}
else {
var w = (window.screen.width)*0.8
var h = (window.screen.height)*0.8
}
window.open("/app/imageZoom.html?thisImgURL="+thisImgURL+"&thisImgType="+thisImgType,"","toolbar=no,location=no,status=no,menubar=no,resizable=no,width="+w+",height="+h)
}


function GotoGetPassword(){
	window.open("/app/getPassword.asp");
//	window.location="/app/getPassword.asp";
}



function GotoShoppingCart(){
//	var w = (window.screen.width)*0.8
//	var h = (window.screen.height)*0.8
	window.location.href="/app/order.asp"
}

function ViewShoppingCartBrief(){

}


function IsOrderNeedSize(isNeedSize){
	var oSize=document.getElementById("oSize");
	if (isNeedSize=="Y"){
		if ((oSize.value=="")||(oSize==null)){
			document.getElementById("alert_o_need_size").innerHTML = "Please select Size/Spec.";
			document.getElementById("pro_b_item_size").className="pro_b_item_e";
			return false;
		}
		else {
			document.getElementById("alert_o_need_size").innerHTML = "";
			document.getElementById("pro_b_item_size").className="pro_b_item";
		}
	}
}
function IsOrderNeedColor(isNeedColor){
	var oColor=document.getElementById("oColor");
	if (isNeedColor=="Y"){
		if ((oColor.value=="")||(oColor==null)){
			document.getElementById("alert_o_need_color").innerHTML = "Please select Color/Style.";
			document.getElementById("pro_b_item_color").className="pro_b_item_e";
			return false;
		}
		else {
			document.getElementById("alert_o_need_color").innerHTML = "";
			document.getElementById("pro_b_item_color").className="pro_b_item";
		}
	}
}
function IsOrderNeedQty(isNeedQty){
	var oQty=document.getElementById("oQty");
	if (isNeedQty=="Y"){
		if ((oQty.value=="")||(oQty==null)||(oQty.value=="0")){
			document.getElementById("alert_o_need_qty").innerHTML = "Please input Quantity.";
			document.getElementById("pro_b_item_qty").className="pro_b_item_e";
			return false;
		}
		else {
			document.getElementById("alert_o_need_qty").innerHTML = "";
			document.getElementById("pro_b_item_qty").className="pro_b_item";
		}
	}
}


function ShoppingCartAdd(ProID,AddMethod,isNeedSize,isNeedColor,isNeedQty){
//var strOrderExpand="";
if (AddMethod=="Single"){
	var oSize=document.getElementById("oSize");
	var oColor=document.getElementById("oColor");
	var oQty=document.getElementById("oQty");

	if ((IsOrderNeedSize(isNeedSize)==false)||(IsOrderNeedColor(isNeedColor)==false)||(IsOrderNeedQty(isNeedQty)==false)) {
		if (IsOrderNeedSize(isNeedSize)==false) {
			alert("Please select Size/Spec.");
			return false;
		}
		if (IsOrderNeedColor(isNeedColor)==false) {
			alert("Please select Color/Style.");
			return false;
		}
		if (IsOrderNeedQty(isNeedQty)==false) {
			alert("Please input Quantity.");
			return false;
		}
		return false;
		}

	if ((oSize!="")&&(oSize!=null)){
		document.formOrderAdd.oSize.value=oSize.value;
	}
	if ((oColor!="")&&(oColor!=null)){
		document.formOrderAdd.oColor.value=oColor.value;
	}
	if ((oQty!="")&&(oQty!=null)){
		document.formOrderAdd.oQty.value=oQty.value;
	}
	document.formOrderAdd.ProID.value=ProID;
}
document.formOrderAdd.AddMethod.value=AddMethod;
document.formOrderAdd.Action.value="Add";
document.formOrderAdd.submit();
//window.location.href="/app/order.asp?ProID="+ProID+strOrderExpand+"&Action=Add"
}


function AddToFavorites(ProID,txtDivID){
	CreateXMLHttp();
	var url = "/ajax/add_to_favorites.asp?psid=" + escape(ProID);
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest(txtDivID)};
	xmlHttp.send(null);
	
	MyFavoritesRefresh("num_MyFavorites");
}


function MyFavoritesRefresh(txtDivID){
	CreateXMLHttp();
	var url = "/ajax/refresh_favorites.asp";
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest(txtDivID)};
	xmlHttp.send(null);
}


function InputCss(thisInputID,s) {
	if (s=="focus") {
		thisInputID.className="input_focus";
	}
	else if (s=="error") {
		thisInputID.className="input_error";
	}
	else {
		thisInputID.className="input_normal";
	}	
}


function InputCheckInnerHTML(txtDivID,s,str) {
	if (s=="ok"){
		document.getElementById(txtDivID).innerHTML="<img src=\"/images/icon/ico_t.gif\" hspace=\"5\" border=\"0\" align=\"absmiddle\" />";
	}
	else{
		document.getElementById(txtDivID).innerHTML="<img src=\"/images/icon/ico_f.gif\" hspace=\"5\" border=\"0\" align=\"absmiddle\" /><br />"+str;
	}
}



function ParaChooseEffect(thisDivID,s) {
	if (s=="focus") {
		document.getElementById(thisDivID).className="para_choose_focus";
	}
	else {
		document.getElementById(thisDivID).className="para_choose_static";
	}
}


function AreaTrShowHide(areaID)
{
	var areaID=document.getElementById(areaID);
	if(areaID.style.display=="none"){
		areaID.style.display="";
	} else {
		areaID.style.display="none";
	}
}


function ParaAreaShowHide(mA,aA,iA){
	var m,a,iOn;
	iOn=iA+1;
	for (i=1;i<iOn;i++){
		m="mpi"+i;
		a="api"+i;
		if (m==mA){
			document.getElementById(m).className="mac_t_cur";
			document.getElementById(a).style.display="";
		}
		else{
			document.getElementById(m).className="mac_t_each";
			document.getElementById(a).style.display="none";
		}
	}
}


function PaShowHide(mA,aA,iAll,iA){
	var m,a,cM,cA,iOn;
	iOn=iAll+1;
	cM=mA+iA;
	cA=aA+iA;
	for (i=1;i<iOn;i++){
		m=mA+i;
		a=aA+i;
		if (m==cM){
			document.getElementById(m).className="tt_cur";
			document.getElementById(a).style.display="";
		}
		else{
			document.getElementById(m).className="tt_each";
			document.getElementById(a).style.display="none";
		}
	}
}



function SerialAreaShowHide(iCurrent,iAll,aPrefix) {
	var a;
	for (i=1;i<iAll+1;i++){
		a=aPrefix+i;
		if (i==iCurrent){
			document.getElementById(a).style.display="";
		}
		else{
			document.getElementById(a).style.display="none";
		}
	}
}


function GetDecimal2Num(f,c)
{
	var t = Math.pow(10, c);
	return Math.round(f * t) / t;
}




function CommonSignIn() {
	CreateXMLHttp();
	var url = "/ajax/signin.asp";
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest("areamain_leftSignIn")};
	xmlHttp.send(null);
}


function PaginationAjax(txtDivID,thisURL,thisURLpara,thisIsBegin) {
	CreateXMLHttp();
	var url;
	if (thisIsBegin=="begin"){
		url = thisURL + "?" + thisURLpara + "&txtDivID_ajax=" + txtDivID + "&thisURL_ajax=" + thisURL;
	}
	else {
		url = thisURL + "?" + thisURLpara;
	}
	xmlHttp.open("GET", url, false);
//	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest(txtDivID)};
	xmlHttp.send(null);
//	if (xmlHttp.readyState == 4) {
//		if (xmlHttp.status == 200) {
		// alert(xmlhttp.responseText);
//		} else {
//			alert("您所请求的页面有异常。");
//		}
//	}
	if(GetOS()=="Firefox"){
		document.getElementById(txtDivID).innerHTML = "";
		document.write("<script type=\"text/javascript\" src=\"/ajax/pro_rev_list_all.asp?"+thisURLpara+"\"></script>")
		}
}

function ProRelatedProductsByKeywods(thisProID){
	CreateXMLHttp();
	var url = "/ajax/pro_correlative_by_kw.asp?thisProID=" + escape(thisProID);
//	xmlHttp.open("GET", url, true);
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest("areaCorrelativeProducts")};
	xmlHttp.send(null);
}


//begin comment js for products detail
function ProSignleSubTotal(thisInputID,thisInputValueOri,ProPrice,thisSpanID,PriceCurrency)
{
	var thisInputValue;
	var thisSubTotalValue;
	var txt_thisSpan="";
	thisInputValue=thisInputID.value;
	if ((ProPrice!="")&&(ProPrice!=null)&&(ProPrice!=0)){
		thisSubTotalValue=GetDecimal2Num(thisInputValue*ProPrice,2);
		txt_thisSpan=PriceCurrency+thisSubTotalValue;
		document.getElementById(thisSpanID).innerHTML = txt_thisSpan;
	}
	else if (thisInputValue==thisInputValueOri){
		document.getElementById(thisSpanID).innerHTML = txt_thisSpan;
	}
}
//end



//beign js for sub dir menu
function MenuSubDirShowHide(menuIDcur,menuIDsub)
{
var menuIDc=document.getElementById(menuIDcur);
var menuIDs=document.getElementById(menuIDsub);
if(menuIDs.style.display=="none"){
	menuIDs.style.display="";
//	menuIDcur.className="";
	} else {
	menuIDs.style.display="none"; 
//	menuIDcur.className="";
	}
}



function CheckUserLogin(){
	if (document.getElementById("Username").value == "" ){
		alert ("Please input your User ID or E-mail Address! Thanks.");
		document.getElementById("Username").focus();
		return false;
	}
	if (document.getElementById("Password").value == "" ){
		alert ("Please input your Password! Thanks.");
		document.getElementById("Password").focus();
		return false;
	}
	return true;
}




function CheckFormGetOrderInfo()
{

var OrderEmail=document.getElementById("OrderEmail");
if (OrderEmail.value == ""){
	alert ("Please input E-Mail (this e-mail is that you submited with the order.). Thanks.");
	OrderEmail.focus();
	return false;
}
if ((OrderEmail.value.charAt(0)==".")||(OrderEmail.value.charAt(0)=="@")||(OrderEmail.value.indexOf('@', 0) == -1)||(OrderEmail.value.indexOf('.', 0) == -1)||(OrderEmail.value.lastIndexOf("@")==OrderEmail.value.length-1)||(OrderEmail.value.lastIndexOf(".")==OrderEmail.value.length-1)||(OrderEmail.length<5)){
	alert ("Please check your E-Mail Address.\nYour email address should look like ab@cd.com.");
	OrderEmail.focus();
	return false;
}

var OrderSN=document.getElementById("OrderSN");
if ((OrderSN.value == "") || (OrderSN.value == "Order Serial No.") )
{
	alert ("Please input Order Serial Number (digital). Thanks.");
	OrderSN.focus();
	return false;
}

return true;

}


//begin js for input text div alert
function AlertInputTxt(is_error,id_input,id_span,str_error){
	if (is_error=="yes"){
		InputCss(id_input,'error');
		InputCheckInnerHTML(id_span,"ng",str_error);
		return false;
	}
	else {
		InputCss(id_input,'');
		InputCheckInnerHTML(id_span,"ok","");
		return true;
	}
}



//begin js for proup
var millisec = 250;
var timeoutId;
var visiblePopup = null;

function PopupShowHide(popdivId)
{
	if(document.getElementById)
	{
		var obj = document.getElementById(popdivId);
		if(obj.style.visibility == "hidden" || obj.style.visibility == "")
		{
			obj.style.visibility = "visible";
    		PopupHide();
			visiblePopup=popdivId;
		}
		else
			PopupHide();
	}
	return false;
}

function HideDelay()
{
	PopupClear();
	timeoutId = setTimeout(function(){PopupHide()}, millisec);
}

function PopupHide()
{
	PopupClear();
	if(visiblePopup!=null)
	{
		var o = document.getElementById(visiblePopup);		
		visiblePopup=null;
		o.style.visibility = "hidden";
	}
	return false;
}

function PopupClear()
{
	if(typeof timeoutId != "undefined")
	{
		clearTimeout(timeoutId);
	}
}
//end for popup





function CreateFlash(idad, swfurl, wad, had, vs){
var str = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + wad + "\" height=\"" + had + "\" id=\"" + idad + "\" align=\"middle\">";
str += "<param name=\"allowScriptAccess\" value=\"always\">";
str += "<param name=\"quality\" value=\"high\">";
str += "<param name=\"movie\" value=\"" + swfurl + "\">";
str += '<param name=\"wmode\" value=\"transparent\">';
str += "<param name=\"flashvars\" value=\"" + vs + "\"><param name=\"SCALE\" value=\"exactfit\">";
str += "<embed src=\"" + swfurl + "\" flashvars=\"" + vs + "\" scale=\"exactfit\" wmode=\"transparent\" quality=\"high\" width=\"" + wad + "\" height=\"" + had + "\" name=\"" + idad + "\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";
str += "</object>";
document.write(str);
}

