// 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);
}

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浏览器
	}
}
//结束 ajax公共





//开始 公共
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 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 CF_Search()
{
if ((document.formSearch.q.value == "" )||(document.formSearch.q.value == "关键字")){
	alert ("请输入您要查询的关键字。");
	document.formSearch.q.focus();
	return false;
	}
return true;
}

//精确查询
function CF_Search_Exact()
{
if ((document.formSearch_Exact.q_itemno.value == "" )||(document.formSearch_Exact.q_itemno.value == "品名或货号")){
	alert ("请输入精确查询相关的品名或货号。");
	document.formSearch_Exact.q_itemno.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 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
