// 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 GetCookies(sMainName,sSubName)
{ 
var sCookieName = sMainName + "=";
var sSubCookieName = (sSubName)?sSubName + "=":null;
var sCookie;
var sWholeCookie = document.cookie;

var nValueBegin = sWholeCookie.indexOf(sCookieName);
if(nValueBegin!=-1)
{
var nValueEnd = sWholeCookie.indexOf(";",nValueBegin);
if(nValueEnd == -1)
nValueEnd = sWholeCookie.length;

var sValue = sWholeCookie.substring(nValueBegin + sCookieName.length,nValueEnd);

if(sSubCookieName)
{ 
var nSubValueBegin = sValue.indexOf(sSubCookieName);
if(nSubValueBegin!=-1)
{
var nSubValueEnd = sValue.indexOf("&",nSubValueBegin);
if(nSubValueEnd == -1)
nSubValueEnd = sValue.length;
var sSubValue = sValue.substring(nSubValueBegin + sSubCookieName.length,nSubValueEnd);
return unescape(sSubValue);
} 
} 
if(!sSubCookieName) 
return unescape(sValue); 
} 
return null; 
}


//no cookies aggregate
function GetUnitCookie(cookieUnitName){
	var allcookies = document.cookie;
	var cookie_pos = allcookies.indexOf(cookieUnitName);

	if (cookie_pos != -1){
		cookie_pos += cookieUnitName.length + 1;
		var cookie_end = allcookies.indexOf(";",cookie_pos);
		if (cookie_end == -1){
			cookie_end = allcookies.length;
		}

	var value = unescape(allcookies.substring(cookie_pos,cookie_end));
	}
	return value;
}



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,"&nbsp;")
	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 AddToShoppingCart(ProID,AddMethod){
//var strOrderExpand="";
if (AddMethod=="Single"){
	var oSize=document.getElementById("oSize");
	var oColor=document.getElementById("oColor");
	var oQty=document.getElementById("oQty");

	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 AddToShoppingCartSimple(ProID,ProName,ItemNo){
window.location.href="/app/order_sim.asp?ProID=" + ProID + "&ProductName=" + escape(ProName) + "&ItemNo=" + escape(ItemNo);
}


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);
	
	CommonHeaderFunMenu(0);
}



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 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);
}





//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=thisInputValue*ProPrice;
		txt_thisSpan="&nbsp;&nbsp;&nbsp;<b>Sub Total: </b><b class=\"red px14 verdana\">"+PriceCurrency+thisSubTotalValue+"</b>"
		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="";
	}
}



//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
