//copyright
function addOnload(newFunction)
{
	var oldLoad = window.onload;

	if(typeof oldLoad == "function")
	{	
		window.onload = function()
		{
			if(oldLoad )
			{
				oldLoad();
			}
			newFunction();
		}
	}
	else
	{
		window.onload = newFunction();
	}
}

 	function copyinit()
	{
		document.onkeydown = keyhit;
		document.onmousedown = mousedown;
	}
	
	function mousedown()
	{
		document.getElementById("copyrighttable").style.display = "none";
	}

	function keyhit()
	{

		//var thiskey = (evt)?evt.which:window.event.keyCode;
		if(event.ctrlKey && event.keyCode==65)
		{
		document.getElementById("copyrighttable").style.display = "inline";
		//alert("sssssssss");
		}
	}

//异步提交/获取数据
function httpAsync(url, func) {
	var http = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	http.onreadystatechange = function () {
		if (http.readyState == 4) {
			var json = null;
			try {
				var json = eval("(" + http.responseText + ")");
			}
			catch (e) {
				alert("Invalid JSON text:\n\n" + http.responseText);
			}
			if (json != null) {
				func(json);
			}
		}
	};
	http.open("GET", url, true);
	http.send();
}

//给 URL 追加参数。如果已经存在，则替换之
function addUrlParam(url, name, value) {
	var reg = new RegExp("(\\?|&)" + name + "=[^&]*", "g");
	value = encodeURIComponent(value);
	if (reg.test(url)) {
		url = url.replace(reg, "$1" + name + "=" + value);
	} else {
		var separator = url.indexOf("?") == -1 ? "?" : "&";
		url = url + separator + name + "=" + value;
	}
	return url;
}

//删除 URL 中的指定参数
function deleteUrlParam(url, name) {
	var reg1 = new RegExp("(\\?|&)" + name + "=[^&]*&", "g");
	var reg2 = new RegExp("(\\?|&)" + name + "=[^&]*$", "g");
	return url.replace(reg1, "$1").replace(reg2, "");
}

//翻到指定页
function gotoPage(pageIndex) {
	var url = addUrlParam(window.location.href, "mpm.pageIndex", pageIndex);
	window.navigate(url);
}
function gotoPage1(pageIndex) {
	var url = addUrlParam(window.location.href, "acmpm.pageIndex", pageIndex);
	window.navigate(url);
}

//按指定字段排序
function orderByField(field) {
	var url = addUrlParam(window.location.href, "mpm.orderBy", field);
	window.navigate(deleteUrlParam(url, "mpm.pageIndex"));
}

//判断字符串是否空
function isEmpty(s)
{
	return s == null || /^\s*$/.test(s);
}

//判断字符串是否是合法的 email
function isEmail(s)
{
	return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(s);
}

//去掉字串两边的空格 add by borce
function trim(str) 
{ 
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 

//判断是否是数字 add by borce
function isInteger(thistext)
{
 if (event.keyCode<48 || event.keyCode>57 )
  return false ;
 else 
  return true ; 
}

//去掉非法字符 add by borce
function RemoveLawlessStr(s)
{
	return s.replace(/\'+|\"+|\~+|\<+|\>+|\%+|\*+|\{+|\}+|\[+|\]+|\(+|\)+|\?+|\`+|\!+|\@+|\#+|\$+|\^+|\&+|\:+|\;+|\,+|\.+|\/+|\|+|\\+/g,"");
}

//关键字高亮显示
function setHighLight(keys) {
	if (keys == null) {
		return;
	}
	keys = keys.split(" ");
	var bookmark;
	var fillColor = "#FFC000";
	if (document.createRange) {
		var range = document.createRange();
	} else {
		var range = document.body.createTextRange();
		bookmark = range.getBookmark();
	}
	var key;
	for (var i = 0; key = keys[i]; i++) {
		if (range.findText) {
			range.collapse(true);
			range.moveToBookmark(bookmark);
			while (range.findText(key)) {
				range.pasteHTML(range.text.fontcolor(fillColor));
			}
		} else {
			var s, n;
			s = window.getSelection();
			s.collapse(document.body, 0);
			while (window.find(key)) {
				var n = document.createElement("SPAN");
				n.style.color = fillColor;
				s.getRangeAt(0).surroundContents(n);
			}
		}
	}
}

function substr(str) 
{
	if(str == null) return;
	if(str.length > 4) 
		return str.substring(0, 4) + "...";
	else
		return str;
}

function getCookie(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i");
	if (document.cookie.match(re)){
		return document.cookie.match(re)[0].split("=")[1];
	}else{
		return "";
	}		
}

function delCookie(logouturl)
{
	window.navigate(logouturl);
}

function showMoreCommon(gotoUrl, title) 
{
	$.blockUI({ 
		message: $('#popdiv'),
		css: 
		{
            top:  (jQuery(window).height() - 500) /2 + 'px',
            left: (jQuery(window).width() - 500) /2 + 'px',
            width: '550px'
        }
	});

	var bannode = null;
	if(document.getElementById("bannode") != null)
		bannode = document.getElementById("bannode").value;

	banNode(bannode);
}

function gotoCase(gotoUrl)
{
	var cFrame = document.getElementById("contentFrame");
	cFrame.document.getElementById("pm02").src="images/pm02.jpg";
	cFrame.document.getElementById("pm03").src="images/pm03.jpg";
	cFrame.document.getElementById("pm04").src="images/pm04.jpg";
	cFrame.document.getElementById("pm05").src="images/pm05.jpg";
	cFrame.document.getElementById("pm06").src="images/pm06.jpg";
	cFrame.document.getElementById("pm07").src="images/pm07.jpg";
	cFrame.document.getElementById("pm09").src="images/pm09.jpg";
	cFrame.document.getElementById("pm10").src="images/pm10.jpg";
	cFrame.document.getElementById("pm11").src="images/pm11.jpg";
	cFrame.document.getElementById("pm12").src="images/pm12.jpg";
	switch(gotoUrl)
	{
		case "getMoreRelatedScenery.action":
			{cFrame.document.getElementById("pm02").src="images/pm02a.jpg";break;}
		case "getMoreSamePriceScenery.action":
			{cFrame.document.getElementById("pm03").src="images/pm03a.jpg";break;}
		case "getMoreSameCityTravel.action":
			{cFrame.document.getElementById("pm04").src="images/pm04a.jpg";break;}
		case "getMoreSamePriceTravel.action":
			{cFrame.document.getElementById("pm05").src="images/pm05a.jpg";break;}
		case "getMoreTravelNews.action":
			{cFrame.document.getElementById("pm06").src="images/pm06a.jpg";break;}
		case "getMoreSubjectScenery.action":
			{cFrame.document.getElementById("pm07").src="images/pm07a.jpg";break;}
		case "getMoreSubjectPath.action":
			{cFrame.document.getElementById("pm09").src="images/pm09a.jpg";break;}
		case "getMoreCommendHotel.action":
			{cFrame.document.getElementById("pm10").src="images/pm10a.jpg";break;}
		case "getMoreSceneryAroundSeeAndEat.action":
			{cFrame.document.getElementById("pm11").src="images/pm11a.jpg";break;}
		case "getMoreRelatedNews.action":
			{cFrame.document.getElementById("pm12").src="images/pm12a.jpg";break;}
	}
}

function resetHeight(obj1, obj2)
{
	if(obj1==null || obj2==null) return;
	if(obj1.offsetHeight < obj2.offsetHeight)
		obj1.style.height = obj2.offsetHeight;
	else
		obj2.style.height = obj1.offsetHeight;
}

function login()
{
	window.navigate("${base}/login.action?rurl="+encodeURIComponent(location.href));
}

var returnUrl;
function loginLocal(url)
{
	//统计曝光数，登录广告特殊处理  add by borce
	if(typeof(displayAnalyseForLogin)=="function")
		displayAnalyseForLogin();
	
	$.blockUI({message: $('#login_wrapper'),
		css: 
		{
            top:  (jQuery(window).height() - 500) /2 + 'px',
            left: (jQuery(window).width() - 500) /2.5 + 'px',
            width: '610px'
        }
	});
	$('#closebtn').click($.unblockUI);
	$('#smallbtn').click($.unblockUI);
	
	if(url != null)
	{
		returnUrl = url;
	}	
	else
		returnUrl = window.location.href;
}

function pop(url, feather)
{
	if(feather == null)
		window.open (url, 'newwindow', 'height=540,width=650,top=100,left=200, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes')
	else
		window.open (url, 'newwindow', feather)
}

var winOpen;
function openCond()
{
	if(typeof(winOpen) == "object")
		winOpen.close();
}
function showMostSimple(id,flag)
{
	openCond();
	flag = flag == null ? "" : "&flag=" + flag;
	winOpen = window.open("sceneryView.action?objType=10&pageType=4&objId=" + id + flag + "&r=" + Math.random(),"","height=450, width=750,top=120,left=170, Directories=no,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}

function showMostSimpleCommon(id,objType)
{
	openCond();
	if(objType==3){
		winOpen = window.open("travelView.action?simple=1&objId=" + id + "&r=" + Math.random(),"","height=650, width=780,top=120,left=170, Directories=no,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
	}else if(objType==4){
		winOpen = window.open("newsView.action?simple=1&objId=" + id + "&r=" + Math.random(),"","height=487, width=660,top=100,left=170, Directories=no,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
	}else if(objType==10){
		showMostSimple(id,4);
	}
}

function openEdit(objType,objId,isiframe)
{
	isiframe = isiframe == null ? "" : "&isiframe=" + isiframe;
	window.open("playerEdit.action?objType=" + objType + "&objId=" + objId + isiframe,"","height=610, width=820,top=45,left=100, Directories=no,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}

function JSONscriptRequest(fullUrl) {
     this.fullUrl = fullUrl;
     this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
     this.headLoc = document.getElementsByTagName("head").item(0);
     this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

JSONscriptRequest.scriptCounter = 1;

JSONscriptRequest.prototype.buildScriptTag = function () {
     this.scriptObj = document.createElement("script");
     this.scriptObj.setAttribute("type", "text/javascript");
     this.scriptObj.setAttribute("charset", "utf-8");
     this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
     this.scriptObj.setAttribute("id", this.scriptId);
}

JSONscriptRequest.prototype.removeScriptTag = function () {
     this.headLoc.removeChild(this.scriptObj);  
}

JSONscriptRequest.prototype.addScriptTag = function () {
     this.headLoc.appendChild(this.scriptObj);
}

function gotorecommendlist()
{
	document.getElementById("recommendlistproxy").click();
}


var oPopup = window.createPopup();
function fnDef()
{ 
oPopup.document.body.innerHTML = "<DIV STYLE=\"background:#ffffcc; border:1px solid black; padding:4px;font-family:verdana; font-size:70%;color=#111; width:250px;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#0099FF', EndColorStr='#00FFFF'\">"+event.srcElement.sss+"</div>";
var popupBody = oPopup.document.body;
oPopup.show(0, 0, 250, 50);
var realHeight = popupBody.scrollHeight;
oPopup.hide();
oPopup.show(0, 35 , 250, realHeight, event.srcElement);
}
function fnclos()
{
	oPopup.hide();
}
