// 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;
		}
	}
}

//ajax中的分页函数
function PaginationAjax(txtDivID,thisURL,thisURLpara,thisIsBegin)
{
	CreateXMLHttp();
	var url;
	if (thisIsBegin=="begin")
	{
		url = thisURL + "?txtDivID_ajax=" + txtDivID + "&thisURL_ajax=" + thisURL + "&" + thisURLpara;
	}
	else
	{
		url = thisURL + "?" + thisURLpara;
	}
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest(txtDivID)};
	xmlHttp.send(null);
}
//结束 ajax公共



function GetBrowserInfo()
{
	if(navigator.userAgent.indexOf("MSIE")>0)
	{
		return "MSIE";
	}
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)
	{
		return "Firefox";
	}
	if(isSafari=navigator.userAgent.indexOf("Safari")>0)
	{
		return "Safari";
	}
	if(isCamino=navigator.userAgent.indexOf("Camino")>0)
	{
		return "Camino";
	}
	if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)
	{
		return "Gecko";
	}
}

function GetSysLanguage()
{
	return navigator.systemLanguage?navigator.systemLanguage:navigator.language;
}

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));
}


function IsEmailAddress(sEmail)
{
	if ((sEmail=="")||(sEmail.length<5))
	{
		return false;
	}
	if ((sEmail.charAt(0)==".")||(sEmail.charAt(0)=="@")||(sEmail.indexOf('@', 0) == -1)||(sEmail.indexOf('.', 0) == -1)||(sEmail.lastIndexOf("@")==sEmail.length-1)||(sEmail.lastIndexOf(".")==sEmail.length-1))
	{
		return false;
	}
	return true;
}


function InnerHTML(txtDivID,txtValue)
{
	document.getElementById(txtDivID).innerHTML=txtValue;
}



//搜索
function CF_Search()
{
if ((document.formSearch.q.value == "" )||(document.formSearch.q.value == "Product name or keyword")){
	alert ("Please input a search term.");
	document.formSearch.q.focus();
	return false;
	}
return true;
}


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 GotoShoppingCart()
{
	window.location.href="/app/order.asp"
}



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")
	{
		var txtValue="<img src=\"/images/ico/ico_t.gif\" hspace=\"5\" border=\"0\" align=\"absmiddle\" />";
	}
	else
	{
		var txtValue="<img src=\"/images/ico/ico_f.gif\" hspace=\"5\" border=\"0\" align=\"absmiddle\" /><br />" + str;
	}
	InnerHTML(txtDivID,txtValue);
}


//区域显示、隐藏
//操作单个区域显示隐藏
function AreaShowHide(areaID)
{
	var areaID=document.getElementById(areaID);
	if(areaID.style.display=="none")
	{
		areaID.style.display="";
	}
	else
	{
		areaID.style.display="none";
	}
}

//操作多个区域显示隐藏，无菜单
function AreaMultiShowHide(p_area_prefix,p_sum_area,p_curr_area)
{
	var area_id_current = p_area_prefix + p_curr_area;
	for (i=1;i<p_sum_area+1;i++)
	{
		area_id_circle = p_area_prefix + i;
		if (area_id_current == area_id_circle)
		{
			document.getElementById(area_id_circle).style.display = "";
		}
		else
		{
			document.getElementById(area_id_circle).style.display = "none";
		}
	}
}

//操作多个区域显示隐藏，含切换菜单css
function AreaMultiMenuShowHide(mA,aA,iAll,iA,css_on,css_off)
{
	var m,a,cM,cA;
	cM=mA+iA;
	cA=aA+iA;
	for (i=1;i<iAll+1;i++)
	{
		m=mA+i;
		a=aA+i;
		if (m==cM)
		{
			document.getElementById(m).className = css_on;
			document.getElementById(a).style.display = "";
		}
		else
		{
			document.getElementById(m).className = css_off;
			document.getElementById(a).style.display = "none";
		}
	}
}



function GotoTop(a, t){
//	window.scroll(0,0);
	a = a || 1;
	t = t || 100;

	var x1 = 0;
	var y1 = 0;
	var x2 = 0;
	var y2 = 0;
	var x3 = 0;
	var y3 = 0;

	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	var x3 = window.scrollX || 0;
	var y3 = window.scrollY || 0;

	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));

	var speed = 1 + a;
	window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
	if(x > 0 || y > 0) {
		var f = "GotoTop(" + a + ", " + t + ")";
		window.setTimeout(f, t);
	}
//	var speed=2; var time=100; var dy=0; var by=0; var wy=0; if(document.documentElement){ dy=document.documentElement.scrollTop||0; } wy=window.scrollY||0; var y=Math.max(wy,Math.max(by,dy)); window.scrollTo(0,Math.floor(y/speed)); if(y>0){  setTimeout("GotoTop()",time); }
}



//货币类型转换成数字类型
function GetDecimal2Num(f,c)
{
	var t = Math.pow(10, c);
	return Math.round(f * t) / t;
}


//ajax方式插入登录模块, 暂时停用
function CommonSignIn()
{
	CreateXMLHttp();
	var url = "/ajax/signin.asp";
	xmlHttp.open("GET", url, false);
	xmlHttp.onreadystatechange = function(){HandleRequest("areamain_leftSignIn")};
	xmlHttp.send(null);
}


//input错误警告，ajax方式
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