function addCount(){
	$('#ads').slideDown(2000);
}
function noneAds(){
	$('#ads').slideUp(2000);
}
function SetValue(id,Value) {
	document.getElementById(id).value = Value;
	return;
}
function Submit(formName) {
	setTimeout(doSubmit, 20);
	return true;
}
function checkFormObjAction(value){
	SetFormAction("public_search_movie_list.php");
}
function SetFormAction(val){
	return document.getElementById('formobj').attributes['action'].value = val;
}

function doSubmit() {
	document.forms['formobj'].submit();
}
function GoBack() {
	return history.back(-1);
}
function SetSearchAddre(){
	document.getElementById('city_id_val').value="";
	document.getElementById('province_id_val').value="";
	document.getElementById('country_id_val').value="";
	SetFormAction('public_search_movie_list.php');
}
function PutFormCanUpload() {
	document.getElementById('formobj').enctype = 'multipart/form-data';
}

/* 获得时间*/
function getDate(type){
	currentdate = new Date();
	cy = currentdate.getFullYear();
	cm = currentdate.getMonth() + 1;
	cd = currentdate.getDate();
	ch = currentdate.getHours();
	ci = currentdate.getMinutes();
	cs = currentdate.getSeconds();
	var time_str = '';
	switch(type){
		case 1:
		time_str = cy+'-'+cm+'-'+cd+' '+ch+':'+ci+':'+cs;
		break;
		default:

		break;
	}
	return time_str;
}

/*复制到剪贴板*/
function setCopy(_sTxt){
	try{
		if(window.clipboardData) {
			window.clipboardData.setData("Text", _sTxt);
			alert('复制成功.');
		} else if(window.netscape) {
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
			var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
			if(!clip) return;
			var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
			if(!trans) return;
			trans.addDataFlavor('text/unicode');
			var str = new Object();
			var len = new Object();
			var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
			var copytext = _sTxt;
			str.data = copytext;
			trans.setTransferData("text/unicode", str, copytext.length*2);
			var clipid = Components.interfaces.nsIClipboard;
			if (!clip) return false;
			clip.setData(trans, null, clipid.kGlobalClipboard);
			alert('复制成功.');
		}else{
			alert('复制成功.');
		}
	}catch(e){
		alert('对不起，此浏览器不支持，请手动复制。');
	}
}
function SetSrc(val){
	return $("#show_img").attr("src",val);
}
function correctPNG(){
	if(navigator.appName.indexOf("Microsoft")!=-1){
		for(var i=0; i<document.images.length; i++){
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				i = i-1
			};
		};
	}
};

/* 根据点击国家获得省份 */
function get_province(country_id) {
	document.getElementById("province_list").options.length = 1;
	if (country_id > 0) {
		$.post('../admin_html/admin_province.php', {
			country_id : country_id,
			action : "get_province"
		}, function(data) {
			count = data.length;
			if (count > 0) {
				for (i = 0; i < count; i++) {
					var option = document.createElement("option");
					;
					option.text = data[i]['chinese_name'];
					option.value = data[i]['id'];
					document.getElementById("province_list").options
					.add(option);
				}
				/*
				* if(document.getElementById("city_list") != null){
				* get_city(data[0]['id']); }
				*/
			} else {
				document.getElementById("province_list").options.length = 1;
				if (document.getElementById("city_list") != null) {
					document.getElementById("city_list").options.length = 1;
					document.getElementById("town_list").options.length = 1;
				}
			}
		}, 'json')
	} else {
		document.getElementById("province_list").options.length = 1;
		if (document.getElementById("city_list") != null) {
			document.getElementById("city_list").options.length = 1;
			document.getElementById("town_list").options.length = 1;
		}
	}
}

function get_city(province_id) {
	document.getElementById("city_list").options.length = 1;
	if (province_id > 0) {
		$.post('../admin_html/admin_city.php', {
			province_id : province_id,
			action : "get_city"
		}, function(data) {
			count = data.length;
			if (count > 0) {
				for (i = 0; i < count; i++) {
					var option = document.createElement("option");
					;
					option.text = data[i]['chinese_name'];
					option.value = data[i]['id'];
					document.getElementById("city_list").options.add(option);
				}
				/*
				* if(document.getElementById("town_list") != null){
				* get_town(data[0]['id']); }
				*/
			} else {
				document.getElementById("city_list").options.length = 1;
				if (document.getElementById("town_list") != null) {
					document.getElementById("town_list").options.length = 1;
				}
			}
		}, 'json')
	} else {
		document.getElementById("city_list").options.length = 1;
		if (document.getElementById("town_list") != null) {
			document.getElementById("town_list").options.length = 1;
		}
	}
}

function get_town(city_id) {
	document.getElementById("town_list").options.length = 1;
	if (city_id > 0) {
		$.post('../admin_html/admin_town.php', {
			city_id : city_id,
			action : "get_town"
		}, function(data) {
			count = data.length;
			if (count > 0) {
				for (i = 0; i < count; i++) {
					var option = document.createElement("option");
					;
					option.text = data[i]['chinese_name'];
					option.value = data[i]['id'];
					document.getElementById("town_list").options.add(option);
				}
			} else {
				document.getElementById("town_list").options.length = 1;
			}
		}, 'json')
	} else {
		document.getElementById("town_list").options.length = 1;
	}
}

//验证身份证号码
function checkIdcard(idcard,obj_id){
	var obj = document.getElementById(obj_id);
	var Errors=new Array(
	"此身份证号可以使用。",
	"您输入的身份证号码不正确，请重新输入。",
	"您输入的身份证号码不正确，请重新输入。",
	"您输入的身份证号码不正确，请重新输入。",
	"您输入的身份证号码不正确，请重新输入。"
	);
	var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
	var idcard,Y,JYM;
	var S,M;
	var idcard_array = new Array();
	idcard_array = idcard.split("");
	if(area[parseInt(idcard.substr(0,2))]==null) {obj.innerHTML =Errors[4];return false;}
	switch(idcard.length){
		case 15:
		if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
			ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;
		} else {
			ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;
		}
		if(ereg.test(idcard)){
			obj.innerHTML= '';
			return true;
		}else{
			obj.innerHTML= Errors[2];
		}
		break;
		case 18:
		if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){
			ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式
		} else {
			ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式
		}
		if(ereg.test(idcard)){
			S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
			+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
			+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
			+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
			+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
			+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
			+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
			+ parseInt(idcard_array[7]) * 1
			+ parseInt(idcard_array[8]) * 6
			+ parseInt(idcard_array[9]) * 3 ;
			Y = S % 11;
			M = "F";
			JYM = "10X98765432";
			M = JYM.substr(Y,1);
			if(M == idcard_array[17]) {
				obj.innerHTML= '';
				return true;
			}
			else obj.innerHTML= Errors[3];
		}else obj.innerHTML=  Errors[2];
		break;
		default:obj.innerHTML=  Errors[1];break;
	}
	return false;
}
//相册
function ShowPhoto() {
	var browse = window.navigator.appName.toLowerCase();
	var MyMar;
	var speed = 1; //速度，越大越慢
	var spec = 1; //每次滚动的间距, 越大滚动越快
	var minOpa = 50; //滤镜最小值
	var maxOpa = 100; //滤镜最大值
	var spa = 2; //缩略图区域补充数值
	var w = 0;
	spec = spec * 87 * 7;
	function $(e) {return document.getElementById(e);}
	function goleft() {$('photos').scrollLeft -= spec;}
	function goright() {$('photos').scrollLeft += spec;}
	function setOpacity(e, n) {
		if (browse.indexOf("microsoft") > -1) e.style.filter = 'alpha(opacity=' + n + ')';
		else e.style.opacity = n/100;
	}
	$('goleft').style.cursor = 'pointer';
	$('goright').style.cursor = 'pointer';
	$('mainphoto').onclick = function() {location = this.getAttribute('name');}
	$('goleft').onmouseover = function() {this.src = '../templates/public_pages/language/chinese/image/goleft2.gif';}
	$('goleft').onclick = function(){ goleft();}
	$('goleft').onmouseout = function() {this.src = '../templates/public_pages/language/chinese/image/goleft.gif';}
	$('goright').onmouseover = function() {this.src = '../templates/public_pages/language/chinese/image/goright2.gif';}
	$('goright').onclick = function(){ goright();}
	$('goright').onmouseout = function() {this.src = '../templates/public_pages/language/chinese/image/goright.gif';}
	setOpacity($('mainphoto'), maxOpa);
	var rHtml = '';
	var p = $('showArea').getElementsByTagName('img');
	for (var i=0; i<p.length; i++) {
		if(i == 0){
			$('des').innerHTML = p[i].getAttribute('alt')?p[i].getAttribute('alt'):'该照片暂无描述';
			$('mainphoto').setAttribute('name', p[i].getAttribute('src'));
			$('mainphoto').setAttribute('target','_blank');
		}
		w += parseInt(p[i].getAttribute('width')) + spa;
		setOpacity(p[i], minOpa);
		//p[i].onclick = function() {location = this.getAttribute('name');}
		p[i].onmouseover = function(){
			setOpacity(this, maxOpa);
		}
		p[i].onclick = function() {
			setOpacity(this, maxOpa);
			$('mainphoto').src = this.getAttribute('rel');
			$('mainphoto').setAttribute('name', this.getAttribute('src'));
			$('mainphoto').setAttribute('target','_blank');
			setOpacity($('mainphoto'), maxOpa);
			$('des').innerHTML = this.getAttribute('alt')?this.getAttribute('alt'):'该照片暂无描述';;
		}
		p[i].onmouseout = function() {
			setOpacity(this, minOpa);
		}
		rHtml += '<img src="' + p[i].getAttribute('rel') + '" width="0" height="0" alt="" />';
	}
	$('showArea').style.width = parseInt(w) + 'px';
	var rLoad = document.createElement("div");
	$('photos').appendChild(rLoad);
	rLoad.style.width = "1px";
	rLoad.style.height = "1px";
	rLoad.style.overflow = "hidden";
	rLoad.innerHTML = rHtml;
}

//图片缩放
function DrawImage(ImgD,nw,nh){
	var flag=false;
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= nw/nh){
			if(image.width>nw){
				ImgD.width=nw;
				ImgD.height=(image.height*nh)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}else{
			if(image.height>nh){
				ImgD.height=nh;
				ImgD.width=(image.width*nh)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
}

/*设为主页*/
function SetHome(Url){
	if (document.all){
               document.body.style.behavior='url(#default#homepage)';
               document.body.setHomePage(Url);
	 }else if (window.sidebar){
	        if(window.netscape){
	             try{
	                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
	           } 
	             catch (e){
	                alert("抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”，点击“将互动世界设为首页”后忽略安全提示，即可设置成功。"); 
	            }
	       } 
	    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
	    prefs.setCharPref('browser.startup.homepage',Url);
	}
}

/*添加到收藏夹*/
function AddFavorite(sURL, sTitle){
    try{
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e){
        try{
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e){
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function getOs()
{
	var OsObject = "";
	return navigator.userAgent;
	if(navigator.userAgent.indexOf("MSIE")>0) {
		return "MSIE";
	}
	if(navigator.userAgent.indexOf("Firefox")>0){
		return "Firefox";
	}
	if(navigator.userAgent.indexOf("Safari")>0) {
		return "Safari";
	}
	if(navigator.userAgent.indexOf("Camino")>0){
		return "Camino";
	}
	if(navigator.userAgent.indexOf("Gecko")>0){
		return "Gecko";
	}

}
function topMouseOut(obj,e){
	if(obj!=null){
		var ieObj=obj;
		var browserType=getOs();
		if(browserType=="MSIE")
		{
			if(!ieObj.contains(event.toElement))
			{
				ieObj.style.display="none";
				return true;
			}
		}
		else
		{
			if(typeof(HTMLElement)!="undefined")    //给firefox定义contains()方法，ie下不起作用
			{
				HTMLElement.prototype.contains=function(obj)
				{
					while(obj!=null&&typeof(obj.tagName)!="undefind"){ //通过循环对比来判断是不是obj的父元素
						if(obj==this)return true;
						obj=obj.parentNode;
					}
					return false;
				};
			}
			if(!ieObj.contains(e.relatedTarget))
			{
				ieObj.style.display="none";
				return true;
			}
		}
	}
}

function is_ie6(){
	if(navigator.userAgent.indexOf("MSIE 6.0")>0){
		return true;
	}
}

function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function add_views(m_id){
	$.post('http://www.taagoo.com/common_ajax.htm', 
		{
			id: m_id,
			action : "add_views"
		}
	);
}
function getStrLength(str){
	var chineseRegex = /[^\x00-\xff]/g;
	var strLength = str.replace(chineseRegex,"**").length;
	return strLength;
} 
function obj_correctPNG(obj){
	if(navigator.appName.indexOf("Microsoft")!=-1){
		for(var i=0; i<obj.length; i++){
			var img = obj[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				i = i-1
			};
		};
	}
};
