/************************
*is ie
*************************/
document.domain="qq.com"
var $E=document.getElementById;
var isIE=!!document.all;
function parseXML(st)
{
	if(isIE){
		var result = new ActiveXObject("microsoft.XMLDOM");
		result.loadXML(st);
		if (result.parseError.errorCode != 0) 
		{
			status = "parseXML error";
			setTimeout("status=''",1000);
		}
	}else{
		var parser = new DOMParser();
		var result = parser.parseFromString(st, "text/xml");
	}
	return result;
}
/***************************
*about deal with cookie
****************************/
function getCookie(name)
{
	var r = new RegExp("(^|;|\s)*"+name+"=([^;]*)(;|$)");
	var m = document.cookie.match(r);
	return (!m?"":m[2]);
}

function setCookie(name,value)
{
	document.cookie = name + "=" + value + "; path=/; domain=qq.com";
}

function setFileCookie(name,value){
	var expires=new Date();
	expires.setTime(expires.getTime()+10*12*30*24*3600*1000);
	document.cookie = name + "=" + value + ";expires="+expires.toGMTString()+"; path=/; domain=qq.com";
}

function deleteCookie(name)
{
	document.cookie = name+"=;domain=qq.com;expires="+(new Date(0)).toGMTString();
}
/*********************
*deal with userdata
**********************/
document.documentElement.addBehavior("#default#userdata");


function goOther(uin)
{
	top.document.location.href="othergift.html?uin="+ parseInt(uin);
}

function  saveUserData(key, value){
 	var ex; 
    with(document.documentElement)
	try {
    load(key);
	expires = new Date(new Date()-(-86400000)).toGMTString();
	setAttribute("value", value);
    save(key);
    return  getAttribute("value");
  }
  catch (ex){showError(ex.message)}
}

function loadUserData(key){
  var ex; 
    with(document.documentElement)try{
    load(key);
    return getAttribute("value");
  }
  catch (ex){showError(ex.message);return null;}
}

function  deleteUserData(key){
  var ex; 
    with(document.documentElement)try{
    load(key);
    expires = new Date(new Date()-86400000).toGMTString();
	status=expires;
    save(key);
  }
  catch (ex){showError(ex.message);}
} 

/*****************************
*get url parameter value
******************************/
function getParameter(name)
{
	var r = new RegExp("(\\?|#|&)"+name+"=([^&]*)(&|$)")
	var m = location.href.match(r)
	if(!m || m=="") m = top.location.href.match(r)
	return (!m?"":m[2]);
}

/*****************************
*string prototype function
******************************/
String.prototype.left = function(len)
{
	if(isNaN(len)||len==null)	
		len = this.length;
	else
	{
		if(parseInt(len)<0||parseInt(len)>this.length)
		{
			len = this.length;
		}
	}
	
	return this.substr(0,len);
}
String.prototype.right = function(len)
{
	if(isNaN(len)||len==null)	
		len = this.length;
	else
	{
		if(parseInt(len)<0||parseInt(len)>this.length)
		{
			len = this.length;
		}
	}
	
	return this.substring(this.length-len,this.length);
}

String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");}
String.prototype.getRealLength=function(){	return this.replace(/[^\x00-\xff]/g,"**").length;}

var isIE=!!document.all
var div_for_convert_html = document.createElement("DIV");
String.prototype.HTML2Text=function(){
	with(div_for_convert_html){
		innerHTML = this.replace(/&#13;/g,"<br>").replace(/&#32;/g,"&nbsp;");
		return (isIE?innerText:textContent).replace(/\xa0/g," ");
	};
}
String.prototype.Text2HTML=function(){
	if(isIE) {div_for_convert_html.innerText=this;return div_for_convert_html.innerHTML}
	div_for_convert_html.textContent=this;
	return div_for_convert_html.innerHTML.replace(/\x0a/g,"<br>").replace(/ /g,"&nbsp;")
}

String.prototype.encode=function(){
return this.replace(/%/g, '%25').replace(/=/g, '%3D').replace(/&/g, '%26').replace(/\'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\+/g, '%2B').replace(/ /g, '+').replace(/\//g, '%2F').replace(/\\/g, '%5C').replace(/\r/g, '%0D').replace(/\n/g, '%0A')
}

/*****************************************************************************
*如果存在下面的情况：
*	八位字节数在US-ASCII字符集中没有相应的可显示字符:0x80-0xFF 0x00-0x1F 7F 
*	使用相应字符会产生不安全因素:空格 ,“<”, “>”,“"”,“#”,“%”,"{" ,"}", "|" ,"\", "^" ,"~" ,"["  ,"]" 和"`"
*	相应的字符被保留用于特定的URL方案的解释:";","/", "?", ":", "@", "=" 和 "&"
*那么它们必须被编成代码。
******************************************************************************/

var r = /([!-\/:-@[-`{-~])/g
String.prototype.encode=function(){return this.replace(r,function(a){return "%"+a.charCodeAt(0).toString(16)}).replace(/ /g,"+")}

/********************************
* format string
********************************/
function IsAscii(ch)
{
	if(ch > 0 && ch <= 255)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function StrLenOfAscii(str)
{
	var str_len;
	str_len = 0;
	for(var i=0;i<str.length;i++)
	{
		if(IsAscii(str.charCodeAt(i)))
		{
			str_len += 1;
		}
		else
		{
			str_len += 2;
		}
	}
	
	return str_len;
}

function TruncateStr(str,length)
{
	var len,idx;
	len = 0;
	idx = 0;
	if(length>=StrLenOfAscii(str))
		return str;
	var str_result = "";
	length=length-1;
	while (len < length)
	{
		str_result += str.charAt(idx);
		if(IsAscii(str.charCodeAt(idx)))
		{
			len += 1;
		}
		else
		{
			len += 2;
		}
		idx += 1;
	}
	if(len > length)
	{
		str_result = str_result.substr(0,str_result.length-1);
	}
	
	return str_result+".";
}

/*************************
* format number
**************************/
function FormatNumber(srcStr,nAfterDot)
{
	var srcStr,nAfterDot;
	var resultStr,nTen;
	srcStr = ""+srcStr+"";
	strLen = srcStr.length;
	dotPos = srcStr.indexOf(".",0);
	
	if (dotPos == -1)
	{
		resultStr = srcStr+".";
		for (i=0;i<nAfterDot;i++)
		{
			resultStr = resultStr+"0";
		}
		
		return resultStr;
	}
	else
	{
		if ((strLen - dotPos - 1) >= nAfterDot)
		{
			nAfter = dotPos + nAfterDot + 1;
			nTen =1;
			for(j=0;j<nAfterDot;j++)
			{
				nTen = nTen*10;
			}
			resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
			return resultStr;
		}
		else
		{
			resultStr = srcStr;
			
			for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++)
			{
				resultStr = resultStr+"0";
			}
			
			return resultStr;
		}
	}
} 

/*********************
* about time
**********************/
//support format:YYYY-MM-DD  or YYYY-MMDD hh:mm:ss
function Date_Ex(value1)
{
	var strDate = value1;
	if (strDate.length == 0)
		return false;
	
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;   
	var r = strDate.match(reg);
	if (r != null)   
		strDate = strDate + " 00:00:00";
	reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
	r = strDate.match(reg);
	if (r == null){
		return false;
	}
	var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
	return d;
}

/*****************************
*
******************************/

function contheight (sName)
{
	if (parent.document.all[sName]!=null) 
	{
		parent.document.all[sName].style.height = document.body.scrollHeight;
		
	}
}
/********************
*返回页码的内容
*********************/
function ShowPageList(curPage,totalPage,pagesPerList,linkFormat)
{
	var returnStr="";
	if(curPage < 1 || totalPage <= 1 || curPage> totalPage)
	 	return "";
	
	var startPageNo = curPage - parseInt(pagesPerList/2) < 1?1:curPage - parseInt(pagesPerList/2);
	var endPageNo = startPageNo + pagesPerList -1 > totalPage ? totalPage : startPageNo + pagesPerList -1;
	var count=endPageNo-startPageNo+1;
	startPageNo=count!=pagesPerList?(startPageNo-(pagesPerList-count)):startPageNo;
	startPageNo=startPageNo<1?1:startPageNo;
	
	var prePageNo = curPage > 1 ? curPage-1 : 1;
	var nextPageNo = curPage < totalPage ? curPage+1 : totalPage;
	var reg = new RegExp("{no}","g");
	var url;
	var i;
	// output the pre page link
	returnStr+='<div>共'+totalPage+'页</div>'
	url = linkFormat.replace(reg,prePageNo);
	returnStr+='<a href="'+url+'" class="bt-page-pre" title="上一页"><span class="none">上一页</span></a>';
	returnStr+='<div class="page-num">|';
	// output the page list
	for(i=startPageNo;i<=endPageNo;i++)
	{
			url = linkFormat.replace(reg,i);
			if(i == curPage){
				returnStr+='<a class="nowpage">'+i+'</a>|';
				
			}
			else
				returnStr+='<a href="'+url+'">'+i+'</a>|';

	}
	// output the next page link
	returnStr+='</div>';
	url = linkFormat.replace(reg,nextPageNo);
	returnStr+='<a href="'+url+'" class="bt-page-next" title="下一页"><span class="none">下一页</span></a>';//下一页

	return returnStr;
}

/************************************
*输入字符的有郊性判断
************************************/
function validateSpe(theString)
{
	for (var i = 0; i < theString.length; i++)
	{
	  	if (	((theString.charAt(i)>'&')&&(theString.charAt(i)<'('))
	     		|| (theString.charAt(i) == '<')
	     		|| (theString.charAt(i) == '>')
	     		|| (theString.charAt(i) == '\"')
	     		|| (theString.charAt(i) == '\'')
	     	)
  			return false;
 	}
 	return true;
}
/*********
* show msg
**********/
//var loadMsgHTML='<div class="alert bcenter"><div class="alert-tr"><div class="alert-tl"><div class="alert-tm"></div></div></div><div class="alert-mr"><div class="alert-ml">正在处理，请稍后</div></div><div class="alert-br"><div class="alert-bl"><div class="alert-bm"></div></div></div></div>'
var loadMsgHTML='<div class="alert bcenter" onclick="this.style.display=\'none\'"><div class="alert-tr"><div class="alert-tl"><div class="alert-tm"></div></div></div><div class="alert-mr"><div class="alert-ml">正在处理，请稍后</div></div><div class="alert-br"><div class="alert-bl"><div class="alert-bm"></div></div></div></div>';

var opratingMsgDiv = document.createElement("div")
opratingMsgDiv.innerHTML=loadMsgHTML;
//opratingMsgDiv.style.position="absolute";
opratingMsgDiv.style.display="none";

window.attachEvent("onload",function(){document.body.insertBefore(opratingMsgDiv);});
var operating=false;
var opratingMsgTimeout

function showOpratingMsg(text,imageSrc)
{
	disableButtons();
	window.clearTimeout(opratingMsgTimeout);
	text = (!text)?"正在处理，请稍候。。。":text;
	imageSrc = (!imageSrc)?null:imageSrc;
	if (imageSrc) 
	{
		opratingMsgDiv.innerHTML="<img src='"+imageSrc+"' border='0'/>";
	}
	else
	{
		opratingMsgDiv.innerHTML=loadMsgHTML;
		var msgBody = opratingMsgDiv.childNodes[0].childNodes[1].childNodes[0];
		msgBody.innerHTML = text;
	}
	with(opratingMsgDiv.style)
	{
		display="";
		/*
		top=document.body.scrollTop+160;
		backgroundColor="blue"
		if(opratingMsgDiv.offsetWidth){
			left=document.body.clientWidth/2 - opratingMsgDiv.offsetWidth/2;
		}else{
			left=document.body.clientWidth/2 - 115;
		}*/
	}
	operating=true;//放在最后
}

function hideOpratingMsg(){
	opratingMsgDiv.style.display="none";
	enableButtons();
	operating=false;//放在最后
}
function eventHanldeA(){
 return false;
}

function disableButtons(){
	if(typeof(ButtonIdList)=="undefined"||!ButtonIdList || operating) return;
	for(var i=0;i<ButtonIdList.length;i++)
		if($E(ButtonIdList[i])){
			$E(ButtonIdList[i]).disabled=true;
			if($E(ButtonIdList[i]).tagName=="A")
				$E(ButtonIdList[i]).attachEvent("onclick",eventHanldeA);
		}
}
function enableButtons(){
	
	if(typeof(ButtonIdList)=="undefined"||!ButtonIdList || !operating) return;
	for(var i=0;i<ButtonIdList.length;i++)
		if($E(ButtonIdList[i])){
			$E(ButtonIdList[i]).disabled=false;
			if($E(ButtonIdList[i]).tagName=="A"){
				$E(ButtonIdList[i]).detachEvent("onclick",eventHanldeA);
			}
		}

}
function showError(sM,iT){
	if(sM) showOpratingMsg(sM); else showOpratingMsg("服务器忙，请稍候。。。");
	if(iT)opratingMsgTimeout = setTimeout("hideOpratingMsg()",iT);else opratingMsgTimeout = setTimeout("hideOpratingMsg()",3000);
	
}

/*contain confirm button*/

function showErrorV2(sM,iT)
{
	if(sM)
	{
		showOpratingMsg(sM);
	}
	else
	{
		showOpratingMsg("服务器忙，请稍候。。。");
	}
	if(iT)
	{
		opratingMsgTimeout = setTimeout("hideOpratingMsg()",iT);
	}

}

/**************
*购物车里的预览
***************/
function showBagPre(){
	var id = "bagPreDiv";
	if(top.document.getElementById(id)){
		top.document.getElementById("bagPreDiv").style.display="";
		top.document.getElementById("bagPreFrame").src="preview.html";
	}else{
		var div = top.document.createElement("div");
		with(div.style){
			position="absolute";
			display="";
			width="100%";
			height=600;
			zIndex=10;
		}
		div.style.left=top.document.body.scrollLeft;
		/*
		if(top.window.fortop)
			div.style.top=top.document.body.scrollTop+top.window.fortop.document.body.offsetHeight;
		else
			div.style.top=top.document.body.scrollTop+25;
		*/

		div.style.top = 25;
			
		div.innerHTML='<iframe src="preview.html" height="100%" width="100%" id="bagPreFrame" allowtransparency="true" frameborder="0" align="center" hspace="0" marginwidth="0" marginheight="0"></iframe>'
		div.id=id;
		top.document.body.insertBefore(div);
	}
}
function hideBagPre(){
	var id = "bagPreDiv";
	if(top.document.getElementById(id)){
		top.document.getElementById("bagPreDiv").style.display="none";
	}
}
/**********************************
*QQ号码是否合法
***********************************/
function validate_num(qq)
{
	var reg = new RegExp("[0-9]{5,9}", "g");
	if (!qq.match(reg))
		return false;
	return true;
}
/*******
*for cart
********/
function initTextArea(userName,n) {
		if (n == 0 && userName.value == "[50字内]"){userName.value="";userName.style.cssText = "color:#000000";}
		if (n == 1){
			if(userName.value == "[50字内]"){userName.value="";}
			userName.style.cssText = "color:#000000";
		}
		if (n == 2 && userName.value == ""){userName.value = "[50字内]";userName.style.cssText = "color:#AAAAAA";}
		if (n == 3){
			if(userName.value != ""){userName.value="";}
			userName.style.cssText = "color:#000000";
		}
}
// 数字
function CheckNumber( str ){
var reg = /^[1-9]+[0-9]*$/;
if( reg.test(str) )
	return true;
return false;
}
function checkUin(obj)
{
	if(typeof(obj)!="object")return false;
	if(obj.value.length==0){
		showError("请输入对方号码");
		obj.focus();
		return false;
	}
	if(!CheckNumber(obj.value)){
		showError("QQ号码只能为数字且第一个数字不能为0");
		obj.focus();
		return false;
	}
	if(parseInt(obj.value)<10000){
		showError("QQ号码非法，请重新输入");
		obj.focus();
		return false;
	}
	return true;
}
function checkWords(obj)
{
	if(typeof(obj)!="object")return false;
	if(obj.value.length==0){
		showError("请输入留言");
		obj.focus();
		return false;
	}
	if(obj.value.length>50){
		showError("留言信息太长，不能超过50字");
		obj.focus();
		return false;
	}
	if(obj.value.indexOf('<') != -1 || obj.value.indexOf('>') != -1){
		showError("您的留言中可能含有<,>等不安全字符，请重新输入");
		obj.focus();
		return false;
	}	
	return true;
}
/************
*退出登录
*************/
function delLogOut(){
	document.cookie = "uin=; skey=; path=/; domain=qq.com";
	document.cookie = "zzpaneluin=; zzpanelkey=; icokeLogin=; path=/; domain=qq.com";
	deleteCookie("userUin");
	deleteCookie("userNick");
	clear_mall_cart();
}

function saveLogin(){
	top.loader.loadXMLAsyncNoCache("login", "/cgi-bin/cgi_login", null, null,null);
	if(typeof(top.g_XDoc["login"])=="object"&&top.g_XDoc["login"].getElementsByTagName("error").length==0){
		var userObj=top.g_XDoc["login"].getElementsByTagName("userUin");
		if(userObj.length > 0){
			setCookie("userUin",Number(userObj[0].text));
		}
		var userNick=top.g_XDoc["login"].getElementsByTagName("userNick");
		if(userNick.length>0){
			setCookie("userNick",escape(userNick[0].text.trim()));
		}
	}
}
/*****************************
*日期有郊性判断
******************************/
var month_day = [];
month_day[1]=month_day[3]=month_day[5]=month_day[7]=month_day[8]=month_day[10]=month_day[12]=31;
month_day[4]=month_day[6]=month_day[9]=month_day[11] =30;
month_day[2]=29;

function validate_month_day(themonth, theday){
	if ((isNaN(themonth)) || (isNaN(theday))){	
		showError("请您选择正确的数字");
		return false;
	}
	if ((themonth<1) || (themonth>12)){
		showError("请您选择正确的月份");
		return false;
	}
	if ((theday<1) || (theday>month_day[themonth])){
		showError("请您选择正确的天数");
		return false;
	}
	return true;
}










