// 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 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 = "btnCurrent";
		}
		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 IsNeedSOQforShoppingCart(isNeedSize,isNeedColor,isNeedQty){
	if (isNeedSize=="Y"){
		if ((oSize.value=="")||(oSize==null)){
			PopupClear();
			document.getElementById("popcon_size_color").innerHTML = "Please select Size/Spec.";
			return PopupShowHide('popcon_size_color');
			return false;
		}
	}
	if (isNeedColor=="Y"){
		if ((oColor.value=="")||(oColor==null)){
			document.getElementById("popcon_size_color").innerHTML = "Please select Color/Style.";
			return PopupShowHide('popcon_size_color');
			return false;
		}
	}
	if (isNeedQty=="Y"){
		if ((oQty.value=="")||(oQty==null)||(oQty.value=="0")){
			document.getElementById("popcon_size_color").innerHTML = "Please input Quantity.";
			return PopupShowHide('popcon_size_color');
			return false;
		}
	}
}


function AddToShoppingCart(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 (isNeedSize=="Y"){
		if ((oSize.value=="")||(oSize==null)){
			document.getElementById("popcon_size_color").innerHTML = "Please select Size/Spec.";
			return PopupShowHide('popcon_size_color');
			return false;
		}
	}
	if (isNeedColor=="Y"){
		if ((oColor.value=="")||(oColor==null)){
			document.getElementById("popcon_size_color").innerHTML = "Please select Color/Style.";
			return PopupShowHide('popcon_size_color');
			return false;
		}
	}
	if (isNeedQty=="Y"){
		if ((oQty.value=="")||(oQty==null)||(oQty.value=="0")){
			document.getElementById("popcon_size_color").innerHTML = "Please input Quantity.";
			return PopupShowHide('popcon_size_color');
			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 = "/inc/ajax_addToFavorites.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 = "/inc/ajax_favorites_refresh.asp";
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest(txtDivID)};
	xmlHttp.send(null);
}


function InputCss(thisInputID,s) {
	if (s=="focus") {
		thisInputID.className="inputFocus";
	}
	else if (s=="error") {
		thisInputID.className="inputError";
	}
	else {
		thisInputID.className="inputNormal";
	}	
}


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 ChooseEffect(thisDivID,s) {
	if (s=="focus") {
		document.getElementById(thisDivID).className="chooseEffectFocus";
	}
	else {
		document.getElementById(thisDivID).className="chooseEffect";
	}
}


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="btnCurrent";
			document.getElementById(a).style.display="";
		}
		else{
			document.getElementById(m).className="btnLink";
			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="ttCurrent";
			document.getElementById(a).style.display="";
		}
		else{
			document.getElementById(m).className="ttEach";
			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 CommonHeaderFunMenu(thisProID){
//	CreateXMLHttp();
//	var url = "/inc/ajax_header_funMenu.asp?thisProID=" + escape(thisProID);
//	xmlHttp.open("GET", url, false);
//	xmlHttp.onreadystatechange = function(){HandleRequest("headerFunMenu")};
//	xmlHttp.send(null);
//}


function CommonSignIn() {
	CreateXMLHttp();
	var url = "/inc/ajax_inc_signin.asp";
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest("areaMainLeftSignIn")};
	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);
}




function GetDecimal2Num(f,c)
{
	var t = Math.pow(10, c);
	return Math.round(f * t) / t;
}

//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;
	}
}

function ProCorrelativeProducts(thisProID){
	CreateXMLHttp();
	var url = "/inc/ajax_proCorrelative.asp?thisProID=" + escape(thisProID);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest("areaCorrelativeProducts")};
	xmlHttp.send(null);
}
//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 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






