﻿function $(o){return document.getElementById(o);}
function c$(o){return document.createElement(o);}
String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
String.prototype.ltrim = function(){return this.replace(/(^\s*)/g, "");}
String.prototype.rtrim = function(){return this.replace(/(\s*$)/g, "");}
function CheckMobileVali(strMobile){//检验手机号码是否正确
	var blVali = true;
	var re = /0755\d{8}/gi;
	if(strMobile.length==11){re = /01[^3\D]\d{8}|0[^1\D]\d{9}|13\d{9}|15\d{9}/gi;}
	else if(strMobile.length==12)
	{re = /01[^3\D]\d{9}|0[^1\D]\d{10}/gi;}
	else return false;
	if(strMobile.match(re)){blVali = true;}
	else {blVali = false;}
	return blVali;
}

//设置URL参数
function setUrlParam(param,value,url){
var i,j,pt;
if (!url) url= window.location.href.replace(/\#/g,"");
pt = "&"+param+"=";i=url.indexOf(pt);
if (i<0){
	pt = "?"+param+"="; i=url.indexOf(pt);
	if (i<0){if (url.indexOf("?")>0) url += "&"+param+"="+value;else url += "?"+param+"="+value;return url;}}
j = url.indexOf("&",i+1);
if (j>0) url=url.substring(0,i)+pt+value+url.substring(j,url.length);
else url=url.substring(0,i)+pt+value;
return url;}

function getUrlParam(param){
var  url=window.location.href;
var re = new RegExp("(\\\?|&)" + param + "=([^&#]+)(&|$|#)", "i");
var m = url.match(re);
if (m) return m[2];
else return '';
}

function getScrollX(){
var x=document.body.scrollLeft;
if(x==0) x=document.documentElement.scrollLeft;
return x;
}
function getScrollY(){
var y=document.body.scrollTop;
if(y==0) y=document.documentElement.scrollTop;
return y;
}
function popWhere(evt,width,height){
	var p = new Object();
	p.x=p.y=0;
	if (evt.x){
		if (document.body.clientWidth < evt.x + width + 1) p.x = parseInt(evt.x) - width;
		else  p.x = parseInt(evt.x);
		p.x = Math.max(2, p.x);
		if ((document.body.clientHeight < evt.y + height) && (parseInt(evt.y) > height)) p.y = parseInt(evt.y) - height;
		else p.y = parseInt(evt.y);
		p.y = p.y + getScrollY();
	}
	else if(evt.pageX){
		if (window.innerWidth < evt.pageX + width) p.x = evt.pageX - width;
		else p.x = evt.pageX;
		if ((window.innerHeight  + window.pageYOffset < evt.pageY + height) && (evt.pageY > height)) p.y = evt.pageY - height;
		else p.y = evt.pageY;
	}
	return p;
}

function getXMLHTTPRequest(){
var xRequest=null;
if(window.XMLHttpRequest) xRequest=new XMLHttpRequest();
else if(typeof ActiveXObject != "undefined") xRequest = new ActiveXObject("Microsoft.XMLHTTP");
return xRequest;
}

function getXMLDocument(){
	var xDoc=null;
	if(document.implementation && document.implementation.createDocument) xDoc=document.implementation.createDocument("","",null);
	else if(typeof ActiveXObject != "undefined"){
		var msXmlAx=null;
		try{msXmlAx = new ActiveXObject("Msxml2.DOMDocument");}
		catch(e){msXmlAx = new ActiveXObject("Msxml.DOMDocument");}
		xDoc=msXmlAx;
	}
	if (xDoc==null|| typeof xDoc.load=="undefined") xDoc=null;
	return xDoc
}

function IeTrueBody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
function _replaceHF( full )
{
 return full.replace(/０/g,'0').replace(/１/g,'1').replace(/２/g,'2').replace(/３/g,'3').replace(/４/g,'4').replace(/５/g,'5').replace(/６/g,'6').replace(/７/g,'7').replace(/８/g,'8').replace(/９/g,'9');   
}

function showcheckcode(divId,imgId,vldUrl){
var odiv = $(divId);
if (odiv.className=="vldCode2"){return;}
odiv.className="vldCode2";
var timenow = new Date().getTime();
$(imgId).src = vldUrl+'&t='+timenow;
}

function newverifypic(imgId,vId){
var timenow = new Date().getTime();
$(imgId).src='vldcd.aspx?i='+vId+'&t='+timenow;
}

var scrollElem,stopscroll,stoptime,preTop,leftElem,currentTop,marqueesHeight;
function marque(width,height,marqueName,marqueCName){
try{
	marqueesHeight=height;
	stopscroll=false;
	scrollElem=$(marqueName);
	with(scrollElem){
		style.width=width;
		style.height=marqueesHeight;
		style.overflow='hidden';
		noWrap=true;
	}
	scrollElem.onmouseover=new Function('stopscroll = true');
	scrollElem.onmouseout=new Function('stopscroll = false');
	preTop=0;
	currentTop=0;
	stoptime= 0;
	leftElem=$(marqueCName);
	scrollElem.appendChild(leftElem.cloneNode(true));
	init_srolltext();
}catch(e){}
}
function init_srolltext(){
	scrollElem.scrollTop=0;
	setInterval('scrollUp()',14);
}
function scrollUp(){
	if(stopscroll) return;
	currentTop+=1;
	if(currentTop==marqueesHeight+1){
		stoptime+=1;
		currentTop-=1;
		if(stoptime==(marqueesHeight)*4){
			currentTop=0;
			stoptime=0;
		}
	}else{
		preTop=scrollElem.scrollTop;
		scrollElem.scrollTop+=1;
		if(preTop==scrollElem.scrollTop){
			scrollElem.scrollTop=marqueesHeight;
			scrollElem.scrollTop+=1;
		}
	}
}

//消息框
function ShowMsg(msg,x,y,width,height,hasClose){
	var divT = $("divMsg");
	if(divT) CloseMsg();
	var divMsg = c$("div");
	divMsg.className = "ShowMsgDiv";
	divMsg.id = "divMsg";
	divMsg.style.width=width+"px";
	divMsg.style.height=height+"px";
	var iframeMsg = c$("iframe");
	iframeMsg.id = "iframeMsg";
	iframeMsg.setAttribute("frameBorder","0");
	iframeMsg.setAttribute("scrolling","no");
	iframeMsg.setAttribute("src","javascript:false;");
	iframeMsg.style.position = "absolute";
	iframeMsg.style.zIndex = "998";
	var spanMsg = c$("option");
	spanMsg.id = "spanMsg";
	spanMsg.innerHTML = msg + "<br/>";
	spanMsg.style.fontSize = "12pt";
	divMsg.appendChild(spanMsg);

	document.body.appendChild(iframeMsg);
	document.body.appendChild(divMsg);
	divMsg.style.top = iframeMsg.style.top = y+"px";
	divMsg.style.left = iframeMsg.style.left = x+"px";

	if(hasClose && hasClose == true){
		var spanMsgClose = c$("span");
		spanMsgClose.innerHTML = "［关闭］";
		spanMsgClose.className = "ShowMsgClose";
		spanMsgClose.onclick = CloseMsg;
		divMsg.appendChild(spanMsgClose);
	}
	iframeMsg.style.width = divMsg.offsetWidth;
	iframeMsg.style.height = divMsg.offsetHeight;
}

//关闭消息框
function CloseMsg(){
	var divMsg = $("divMsg");
	var iframeMsg = $("iframeMsg");
	if(divMsg){
		document.body.removeChild(divMsg);
		divMsg = null;
	}
	if(iframeMsg){
		document.body.removeChild(iframeMsg);
		iframeMsg = null;
	}
}

function CheckAll(form) {
for (var i=0;i<form.elements.length;i++) {
	var e = form.elements[i];
	if (e.name != 'chkall' && e.type=='checkbox')
		e.checked = form.chkall.checked;
	}
}
function McndSearch(){
if($("SearchClassId").selectedIndex==0)
	{
		var srchUrl="../srchMcnd.aspx";
		srchUrl=setUrlParam("c","0",srchUrl); 
		srchUrl=setUrlParam("q",escape($("SearchKeyword2").value),srchUrl);
		var mode=getUrlParam("m");
		srchUrl=setUrlParam("m",mode,srchUrl); 
		window.location.href=srchUrl;
	}
	else
	{
		var shopUrl="../srchShop.aspx";
		shopUrl=setUrlParam("c","0",shopUrl);
		shopUrl=setUrlParam("q",escape($("SearchKeyword2").value),shopUrl);
		window.location.href=shopUrl;
	}
}
function HotSearch(q){
$("SearchKeyword2").value=q;
McndSearch();
}
function EnterSearch(){
	if(event.keyCode==13) McndSearch();
}
function setCookie(cName,cValue)
{
	var date=new Date();
	document.cookie=cName+"="+cValue+";";
}
function getCookie(cName)
{
	var c=document.cookie.split("; ");
	for(var i=0; i<c.length; i++)
	{
		var cA=c[i].split("=");
		if(cName==cA[0])
		return cA[1];
	}
	return null;
}

function switchTab(tabpage,tabid){
	var oItem = $(tabpage);
	for(var i=0;i<oItem.childNodes.length;i++){
		var x = oItem.childNodes[i];
		x.className = "";
	}
	$(tabid).className = "Selected";
	var dvs=$("cnt").getElementsByTagName("div");
	for (var i=0;i<dvs.length;i++){
	  if (dvs[i].id==('d'+tabid)) dvs[i].style.display='block';
	  else dvs[i].style.display='none';
	}
}
function TabSwitch(groupName,groupId,tabCssShow,tabCssHide,ContentCss){
	var c = $(groupName+"Content"+groupId);
	var p = c.parentNode;
	for(var i=0;i<p.childNodes.length;i++){
		if(p.childNodes[i].className!=undefined)
			p.childNodes[i].className = "Hide";
	}
	c.className = ContentCss;

	c = $(groupName+"Tab"+groupId);
	p = c.parentNode;
	for(var i=0;i<p.childNodes.length;i++){
		if(p.childNodes[i].className!=undefined)
			p.childNodes[i].className = tabCssHide;
	}
	c.className = tabCssShow;
}
function SwitchDiv(id){	
	var i=0;
	while(i<=MaxTabCount){
		$("tab_"+i).className="";
		i++;
	}
	$("tab_"+id).className="current";
	i=0;
	if(id!=0){
		while(i<=MaxTabCount){
			$("Title_"+i).className="Hide";
			$("TabDiv_"+i).className="Hide";
			i++;
		}
		$("TabDiv_"+id).className="zi_box0";
	}
	if(id==0){
		while(i<=MaxTabCount){
			$("TabDiv_"+i).className="zi_box0";
			$("Title_"+i).className="zhong_1";
			$("Title_"+id).className="Hide";
			i++;
		}
	}
}
function log(p){window.top.location='../log'+p+'.aspx?ReturnUrl='+escape(window.top.location);}
Date.prototype.fomat=function(){
	var d=new Date();
	var s=d.getFullYear()+"-";
	s+=(d.getMonth()+1)+"-";
	s+=d.getDate()+" ";
	s+=d.getHours()+":";
	s+=d.getMinutes()+":";
	s+=d.getSeconds();
	return s;
}

function tbLoginShow(){
	$("TB_iframeContent").src="login.aspx?close=1";
	$("TB_Login").style.display="block";
	$("TB_Login").style.width= window.screen.width;
}
function tbLoginClose(){
	$("TB_iframeContent").src="";
	$("TB_Login").style.display="none";
}

function NewMsg(msg,vldCode, pageTag, type, dstId, path){
	if(msg.length<1){
		alert("请输入留言！");
		return;
	}
	else if(msg.length>0 && msg.length<20){
		alert("点评字数不得少于20！");
		return;
	}
	if(vldCode.length<4){
		alert("请注意，验证码长度为4位！");
		return;
	}
	var rqt = getXMLHTTPRequest();
	var url = (path) ? path+"/AddMsg.ashx" : "AddMsg.ashx";
	url += "?m="+escape(msg)+"&v="+escape(vldCode)+"&p="+pageTag+"&t="+type+"&d="+dstId
	rqt.open("GET",url,true);
	rqt.send("");
	rqt.onreadystatechange =function() {
		if (rqt.readyState==4) {
			if (rqt.statusText =="OK") {
				if(rqt.responseText.substring(0,2)=="0,"){
					if(MsgSuccess){MsgSuccess(rqt.responseText.substring(2,rqt.responseText.length));}
					else {
						alert("留言成功！");
						window.location.href=window.location.href;
					}
				}
				else {
					if(rqt.responseText.indexOf("登录")>=0){
						if(tbLoginShow) {tbLoginShow();}
						else {
							alert(rqt.responseText);
							window.location.href=
							((path) ? path+"/login.aspx" : "login.aspx")+"?ReturnUrl="+escape(window.location.href);
						}
					}
					else alert(rqt.responseText);
				}
			}
		}
	}
}

function Time2Str(time){
	return time.getYear()+'-'+time.getMonth()+'-'+time.getDate()+' '+time.getHours()+':'+time.getMinutes()+":"+time.getSeconds();
}

function AddRmk(vldCode,rmkString,type,DstId,f1,f2,f3,f4,f5,memo,PageTag)
{
	if(vldCode.length<4){
		alert("请注意，验证码长度为4位！");
		return;
	}
	if(rmkString.length<1){
		alert("请输入评论内容！");
	}
	if(f1=="") {alert("请为"+$("RemarkQuestion0").innerHTML+"打分"); return;}
	if(f2=="") {alert("请为"+$("RemarkQuestion1").innerHTML+"打分"); return;}
	if(f3=="") {alert("请为"+$("RemarkQuestion2").innerHTML+"打分"); return;}
	if(f4=="") {alert("请为"+$("RemarkQuestion3").innerHTML+"打分"); return;}
	var obj = getXMLHTTPRequest();
	url = "../addRmk.ashx?v="+escape(vldCode)+"&r="+escape(rmkString)+"&d="+DstId+"&p="+PageTag+"&f1="+f1+"&f2="+f2+"&f3="+f3+"&f4="+f4+"&f5="+f5+"&m="+memo+"&t="+type;
	obj.open("GET",url,true);
	obj.send("");
	obj.onreadystatechange=function() {
		if(obj.readyState==4) {
			if(obj.statusText=="OK") {
				if(obj.responseText.substring(0,2)=="0,") {
					alert("评论成功！");
					window.location.href=window.location.href;
				}
				else{
					if(obj.responseText.indexOf("登录")>=0){
						if(tbLoginShow) {tbLoginShow();}
						else {
							alert(obj.responseText);
							window.location.href="login.aspx"+"?ReturnUrl="+escape(window.location.href);
						}
					}
					else alert(obj.responseText);
				}
			}
		}
	}
}
