﻿
/*
	处理用户网站的一些公共功能
*/

//检查字符串的未尾是否含有指定的字符串
String.prototype.endWith=function(oString){
	var reg=new RegExp(oString+"$");
	return reg.test(this);
}

//系统支持的语种
var LANGS = new Array();

//包含此JS页面的语种标识
//var thisLang = "";

LANGS[0] = "CHS|简体中文";
LANGS[1] = "CHT|繁體中文";
LANGS[2] = "EN|English";
LANGS[3] = "JP|日本語";

//处理语种参数
var par_LANG = QueryString("LANG_SIGN");
if(par_LANG != null && par_LANG != ""){
	SetCookie("LANG_SIGN",par_LANG)
}

//if(thisLang != GetCookie("LANG_SIGN")){
//	SetCookie("LANG_SIGN",thisLang);
//	location.reload();
//}

//根据cookies中记录的当前网站支持的语种，返回语种链接串
function Langs(){
	var outStr       = "";
	var supportLangs = GetCookie("SUPP_LANG");
	//alert(document.cookie);
	if(supportLangs != null && supportLangs != ""){
		var langs = supportLangs.split(",");
		if(langs.length == 1) return null;
		for(var i=0;i<langs.length;i++){
			for(var j=0;j<LANGS.length;j++){
				if(LANGS[j].indexOf(langs[i] + "|") == "0"){
					if(outStr == "") outStr += "<a class=\"LangLinkStyle\" href=\"javascript:ChangLang('"+ langs[i] +"');\">" + Replace(LANGS[j],langs[i] + "|","") + "</a>";
					else             outStr += "&nbsp;|&nbsp;<a class=\"LangLinkStyle\" href=\"javascript:ChangLang('"+ langs[i] +"');\">" + Replace(LANGS[j],langs[i] + "|","") + "</a>";
					j                        = LANGS.length;
				}
			}
		}

		//输出
		document.write(outStr);
	}
}

//重新设置语种，并转移到相应页面
function ChangLang(langSign){
	SetCookie("LANG_SIGN",langSign);
	var hps     = GetCookie("WS_HOMEPAGE").split(",");
	var lgs     = GetCookie("SUPP_LANG").split(",");
	var homeP   = hps[0];

	for(var i=0;i<lgs.length;i++){
		if(langSign == lgs[i] && i < hps.length){
			homeP = hps[i];
		}
	}

	location.href = homeP;
}

//根据用户给出的文件，取出相应文件的网站
//用户提供的文件必须是这样的格式：/（用户文件名称/）文件名称.扩展名
//例如：/images/myphoto.jpg
//ORG_SIGN 网站标识码
//filePath 网站里的文件
function GetFileUrl(ORG_SIGN,filePath){
	var urlStr  = document.location;
	var newUrl  = Replace(urlStr,"http://","");
	return "";
}

//替换字符串中相同的字符为另外一串字符
function Replace(Expression, Find, Replace){

	var temp = Expression;
	var a = 0;
 
	for (var i = 0; i < Expression.length; i++) {
		a = temp.indexOf(Find);
		if (a == -1)
			break
		else
			temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}
 
	return temp;
}

//返回URL参数中某项的值
function QueryString(sName){

	var sSource = String(window.document.location);
	var sReturn = "";
	var sQUS = "?";
	var sAMP = "&";
	var sEQ = "=";
	var iPos;

	iPos = sSource.indexOf(sQUS);

	var strQuery = sSource.substr(iPos, sSource.length - iPos);
	var strLCQuery = strQuery.toLowerCase();
	var strLCName = sName.toLowerCase();

	iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);
	if (iPos == -1){
		iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);
		if (iPos == -1)
		return "";
	}

	sReturn = strQuery.substr(iPos + sName.length + 2,strQuery.length-(iPos + sName.length + 2));
	var iPosAMP = sReturn.indexOf(sAMP);

	if (iPosAMP == -1)
		return sReturn;
	else{
		sReturn = sReturn.substr(0, iPosAMP);
	}

	return sReturn;
}

var updatePath = false;
var updateMenu = false;

//设置当前路径
function SetCurrentPath(val){
	try{
		if(!updatePath && document.all && document.getElementById("CurrentPath") != null){
			if(val != null && val != ""){
				document.getElementById("CurrentPath").innerText += val; //当前路径
			}else{
				document.getElementById("CurrentPath").style.display = "none";
				if(document.getElementById("CurrentPath_HTML") != null) 
					document.getElementById("CurrentPath_HTML").style.display = "none";
			}
			updatePath = true;
		}else{
			the_timeout= setTimeout("SetCurrentPath('"+ val +"');",100);
		}
	}catch(exception){}
}

//设置当前栏目名称
function SetCurrentMenuName(val){
	try{
		if(!updateMenu && document.all && document.getElementById("MenuName") != null){
			if(val != null && val != ""){
				document.getElementById("MenuName").innerHTML += "<b>" + val + "</b>"; 
			}else{
                document.getElementById("MenuName").style.display = "none";
                if(document.getElementById("MenuName_HTML") != null)
					document.getElementById("MenuName_HTML").style.display = "none";
			}
			updateMenu = true;
			
		}else{
			the_timeout= setTimeout("SetCurrentMenuName('"+ val +"');",100);
		}
	}catch(exception){}
}

//设置顶层栏目写意大图片
update_SM_Big_Photo = false;
function Set_SM_Big_Photo(val,isbg){
	try{
		if(!update_SM_Big_Photo && document.all && document.getElementById("SM_BIG_PHOTO") != null){
			if(val != null && val != ""){
				//if(!isbg) document.getElementById("SM_BIG_PHOTO").innerHTML = "<img src=" + val + ">"; 
				//else      document.getElementById("SM_BIG_PHOTO").style.background-image = "url(" + val + ")";
				//val _html = document.getElementById("SM_BIG_PHOTO").innerHTML;
				document.getElementById("SM_BIG_PHOTO").background = val;
				//document.getElementById("SM_BIG_PHOTO").innerHTML = _html;
			}else{
				document.getElementById("SM_BIG_PHOTO").style.display = "none";
				if(document.getElementById("SM_BIG_PHOTO_HTML") != null)
					document.getElementById("SM_BIG_PHOTO_HTML").style.display = "none";
			}
			update_SM_Big_Photo = true;
			
		}else{
			the_timeout= setTimeout("Set_SM_Big_Photo('"+ val +"');",100);
		}
	}catch(exception){}
}

//设置顶层栏目写意小图片
update_SM_Small_Photo = false;
function Set_SM_Small_Photo(val){
	try{
		if(!update_SM_Small_Photo && document.all && document.getElementById("SM_SMALL_PHOTO") != null){
			if(val != null && val != ""){
				document.getElementById("SM_SMALL_PHOTO").innerHTML = "<img src=" + val + ">";
			}else{
				document.getElementById("SM_SMALL_PHOTO").style.display = "none";
				if(document.getElementById("SM_SMALL_PHOTO_HTML") != null){
					document.getElementById("SM_SMALL_PHOTO_HTML").style.display = "none";
				}
			}
			update_SM_Small_Photo = true;
			
		}else{
			the_timeout= setTimeout("Set_SM_Small_Photo('"+ val +"');",100);
		}
	}catch(exception){}
}

//设置当前栏目写意大图片
update_Current_Big_Photo = false;
function Set_Current_Big_Photo(val){
	try{
		if(!update_Current_Big_Photo && document.all && document.getElementById("CURRENT_BIG_PHOTO") != null){
			if(val != null && val != ""){
				document.getElementById("CURRENT_BIG_PHOTO").innerHTML = "<img src=" + val + ">";
			}else{
				document.getElementById("CURRENT_BIG_PHOTO").style.display = "none";
				if(document.getElementById("CURRENT_BIG_PHOTO_HTML") != null){
					document.getElementById("CURRENT_BIG_PHOTO_HTML").style.display = "none";
				}
			}
			update_Current_Big_Photo = true;
			
		}else{
			the_timeout= setTimeout("Set_Current_Big_Photo('"+ val +"');",100);
		}
	}catch(exception){}
}

//设置当前栏目写意小图片
update_Current_Small_Photo = false;
function Set_Current_Small_Photo(val){
	try{
		if(!update_Current_Small_Photo && document.all && document.getElementById("CURRENT_SMALL_PHOTO") != null){
			if(val != null && val != ""){
				document.getElementById("CURRENT_SMALL_PHOTO").innerHTML = "<img src=" + val + ">";
			}else{
				document.getElementById("CURRENT_SMALL_PHOTO").style.display = "none";
				if(document.getElementById("CURRENT_SMALL_PHOTO_HTML") != null){
					document.getElementById("CURRENT_SMALL_PHOTO_HTML").style.display = "none";
				}
			}
			update_Current_Small_Photo = true;
			
		}else{
			the_timeout= setTimeout("Set_Current_Small_Photo('"+ val +"');",100);
		}
	}catch(exception){}
}

//打开购买窗口，但需要传入编号
function Buy(sign){
	window.open("/OrderList.aspx?SIGN=" + sign,"","width=600,height=400,status=no");
}

//取指定键名的COOKIE值
//这个方法只适用于本站
function getCookie(name){

	var cookieValue = "";
	var search      = name + "=";
	var cks         = document.cookie;

	//确定参数正确和cookies存在
	if(name != null && name != "" && cks.length > 37){

		var cksArr = new Array();
		    cksArr = cks.split(";");
		var cksStr = cks;
		var chaval = new Array();
		
		for(var i=0;i<cksArr.length;i++){
			var oIndex = cksArr[i].indexOf("=");
			if(oIndex == 37){
				cksStr = cksArr[i];
				i      = cksArr.length;
			}
		}

		cksStr = cksStr.substring(38,cksStr.length);
		chaval = cksStr.split("&");
		for(var i=0;i<chaval.length;i++){
			if(chaval[i].indexOf(search) == 0){
				cookieValue = Replace(chaval[i],search,"");
				i           = chaval.length;
			}
		}
	}

	return unescape(cookieValue);
}

//设置cookies中的值
function SetCookie(name,value) { 
　 var exp = new Date("December 31, 9999 23:59:59");
　 document.cookie=name+"="+ value +" ; expires="+exp.toGMTString()+" ; path=/"; 
} 

//取cookies中相应键名的值
function GetCookie (name) { 

	var strArg=name+"="; 
	var nArgLen=strArg.length; 
	var nCookieLen=document.cookie.length; 
	var nEnd; 
	var i=0; 
	var j; 

	while (i<nCookieLen) { 

		j=i+nArgLen; 
		if (document.cookie.substring(i,j)==strArg) { 
			nEnd=document.cookie.indexOf (";",j); 
			if (nEnd==-1) nEnd=document.cookie.length; 
			if(name == "WS_TITLE"){
				return unescape(document.cookie.substring(j,nEnd)); 
			}else{
				return document.cookie.substring(j,nEnd); 
			}
		} 

		i=document.cookie.indexOf(" ",i)+1; 
		if (i==0) break;
	}

	return null;
}

//编码程序 
function CodeCookie(str) {
	var strRtn="";
	for (var i=str.length-1;i>=0;i--) {
		strRtn+=str.charCodeAt(i);
		if (i) strRtn+="{}";
	}
	return strRtn;
} 

//解码程序 
function DecodeCookie(str) {
	if(str.endWith("{}")) str = str.substring(0,str.length-2)
	var strArr; 
	var strRtn=""; 
	strArr=str.split("{}"); 
	for (var i=strArr.length-1;i>=0;i--){
		strRtn += String.fromCharCode(eval(strArr[i])); 
	}
	return str + "\n" + CodeCookie("易传数字化管理"); 
} 

//产生指定位数的随机数
function RandNum(numCount){
	if(parseInt(digcount)==parseInt(digcount)){
		return Math.round(Math.random()*Math.pow(10,parseInt(digcount)));
	}else{
		return null;
	}
}

//打印指定区域的内容
//title 欲设定的标题
//area  欲打印的区域
function PrintDocument(title,area){

	var doc = document.getElementById("path_HTML_FOR_INFO").innerHTML;
	if(area != null && ares != "" && document.getElementById(area) != null)
		doc = document.getElementById(area).innerHTML;

	var pop = window.open("","printWin",",resizable=yes,toolbar=yes,scrollbars=yes,menubar=yes,top=0,left=0,width="+ window.screen.width +",height=" + window.screen.height);
	if(pop != null){
		pop.document.write("<html><head>");

		//处理标题
		if(title != null && title != ""){
			pop.document.write("<title>"+ title +"</title>");
			pop.document.write("<div align=\"center\" style=\"font-size:20;font-weight:BOLD\">"+ title +"</div><br><br>");
		}

		//doc = Replace(doc,"打印本文档","");
		//doc = Replace(doc,"打印当前文档","");
		doc = Replace(doc,"<a href=\"javascript:PrintDocument","<a style=\"display:none;\" href=\"javascript:PrintDocument");
		doc = Replace(doc,"<a href=javascript:PrintDocument","<a style=\"display:none;\" href=javascript:PrintDocument");
		doc = Replace(doc,"<A href=\"javascript:PrintDocument","<a style=\"display:none;\" href=\"javascript:PrintDocument");
		doc = Replace(doc,"<A href=javascript:PrintDocument","<a style=\"display:none;\" href=javascript:PrintDocument");
		doc = Replace(doc,"<A HREF=\"javascript:PrintDocument","<a style=\"display:none;\" href=\"javascript:PrintDocument");
		doc = Replace(doc,"<A HREF=javascript:PrintDocument","<a style=\"display:none;\" href=javascript:PrintDocument");
		
		pop.document.write("</head><body>");
		pop.document.write(doc);
		pop.document.write("</body></html>");
		pop.location.reload();
		pop.window.print();
	}
}

//将指定编号和名称的产品信息装入询盘列表
//proName 产品名称
//proSign 产品编号
//olaFile 询盘车路径，如果自己定义了询盘车页面，需要提供页面路径
function AddForOLA(proName,proSign,olaFile,ORG_SIGN){
	if(proName != null && proSign != null){
		var _file = "/Public/OLA.aspx";
		if(olaFile != null) _file = olaFile;

		var _orgSign = QueryString("ORG_SIGN");
		if(ORG_SIGN != null) _orgSign = ORG_SIGN;
		
		var href = _file + "?ORG_SIGN="+ _orgSign +"&PN="+ escape(proName) +"&PS=" + escape(proSign);
		
		var width=600,height=400,left,top;
		
		left = (window.screen.width - width)/2;
		top  = (window.screen.height - height)/2;
		
		window.open(href,"","width="+ width +",height="+ height +",left="+ left +",top="+ top +",resizabled=yes,scrollbars=yes");
	} 
}

//打开发布新反馈的窗口
function AddGB(fileQue){
	if(fileQue != null){
		var width=600,height=400,left,top;
		
		left = (window.screen.width - width)/2;
		top  = (window.screen.height - height)/2;
		
		window.open(fileQue,"","width="+ width +",height="+ height +",left="+ left +",top="+ top +",resizabled=yes,scrollbars=yes");
	} 
}

//显示客户端电脑上的时间
function ShowDateTime(){
	
		var now     = new Date();
		var hours   = now.getHours();
		var minutes = now.getMinutes();
		var seconds = now.getSeconds();
		var months  = now.getMonth() + 1;
		var dates   = now.getDate();
		var years   = now.getYear();
		
		document.write("<span style=\"letter-spacing:2px\">" + years + "-" + months + "-" + dates + " " + hours + ":" + minutes + ":" + seconds + "</span>");
}

//显示一串符串的前几个字符
function SubString(pn,viewLen){
	if(pn.length>viewLen && pn.length > 0){
		document.write(pn.substring(0,viewLen) + "...")
	}else{
		document.write(pn)
	}
}

//弹出显示等大小的图片
function ol(img,imgName){

	var temp = "";
	
	var _imgName = imgName
	
	if(_imgName == null || _imgName == "") _imgName = "台州东方太阳城";
	
	temp += "<html>";

	temp += "<head>";
	temp += "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>";
	temp += "<title>"+ _imgName +"</title>";
	temp += "</head>";

	temp += "<body topmargin=\"0\" leftmargin=\"0\" onload=\"\" bgcolor=\"#EAEAEA\">";
	temp += "<p><table cellpadding=0 cellspacing=0 width=100% height=100%><tr><td><img border=\"1\" name=\"pic\" src=\"/Website/SUNTOWND-8EDX-4REG-TXEX-846EA0CF64CD/"+ img +"\"></td></tr></table>";
	temp += "</body>";
	
	temp += "<script language=\"javascript\">";
	temp += "	function move(){";
	temp += "		window.resizeTo(window.screen.width,window.screen.height-30);";
	temp += "		window.moveTo(0,0);";
	temp += "	}";
	temp += "	move();";
	temp += "</script>";

	temp += "</html>";
	
	var pop = window.open("","viewImg",",resizable=yes,toolbar=no,scrollbars=yes,menubar=yes,top=0,left=0,width=200,height=200");
	if(pop != null){
		pop.document.write(temp);
	}
}