﻿function effect_ol(parentObj,tagName,className_enter,className_leave){
	var currentObjs=document.getElementById(parentObj).getElementsByTagName(tagName);
	for(var i=0;i<currentObjs.length;i++){
		if (document.getElementById(currentObjs[i].id.replace("img_li","img_lst")).src.indexOf("noimg.gif") < 0){
			with(currentObjs[i]){
				onmouseleave=function(){
					with(this){
						if (className != className_enter){
							//className=className.replace(' ' + className_enter,'');
						}
						else {
							className=className_leave;
						}
					}
				}
				onmouseenter=function(){
					with(this){
						if (className != className_enter && className != className_leave){
								//className+= ' ' + className_enter;
						}
						else {
							className=className_enter;
						}
					}
				}
				onclick=function(){
					var ObjTabs=document.getElementById(parentObj).getElementsByTagName(tagName);
					for(var k=0;k<ObjTabs.length;k++){
						with(ObjTabs[k]){
							className=className_leave;
						}
					}
					document.getElementById('mainimg').src = document.getElementById(this.id.replace("img_li","img_lst")).src.replace("Small/","");
					this.className = "img_h";
				}
			}
		} else {
				currentObjs[i].style.cursor = 'default';
		}
	}
}

function NumAdd(obj){
	var num = parseInt(document.getElementById(obj).value);
	num += 1;
	if (num <= 0) num = 1;
	document.getElementById(obj).value = num;
}

function NumMinus(obj){
	var num = parseInt(document.getElementById(obj).value);
	num -= 1;
	if (num <= 0) num = 1;
	document.getElementById(obj).value = num;
}

function chkSelectClient(objChkAll) {
	if (!objChkAll.checked )

	if (!confirm("您确认不需要此赠品么？")){
		objChkAll.checked = true;
		return;
	}
}

function openWindow(URL,Width,Height) { 
	var height = 365;	
	if(navigator.appName == "Netscape"){
		height = 378;
	}
	if(navigator.userAgent.indexOf('Chrome') > 0){
		height = 400;
	}
	window.open(URL,'','width=685,height='+height+',resizable=0,scrollbars=yes,status=no,toolbar=no,location=no,menu=no,left=' + (screen.width-685)/2 + ',top=' + (screen.height-height)/2);
}

function openWindowIm(URL,Width,Height) { 
window.open(URL,'','width=800,height=600,resizable=1,scrollbars=yes,status=no,toolbar=no,location=no,menu=no,left=' + (screen.width-800)/2 + ',top=' + (screen.height-600)/2);
}

function errorctrl(obj, errormsg){ 
	alert("["+obj.getAttribute("hint")+"] "+errormsg+"！"); 
	if (obj.getAttribute("focusto")!=null && obj.getAttribute("focusto")!=""){
		document.getElementById(obj.getAttribute("focusto")).focus(); 
	}
	else{
		obj.focus(); 
	}
}
function checkOwnRule(objfrm){ 
	var inputObj=navigator.userAgent.indexOf("MSIE")>0?objfrm.getElementsByTagName("input"):document.getElementsByTagName("input"); 
	
	for (i=0;i<inputObj.length;i++){
		//证明该输入框不允许为空,allow为自己在文本框中定义的属性。
		//如<input type="text" name="UserName" allownull="false" hint="用户名">表示用户名不允许为空。Hint属性最好设置，因为在alert的时候会包含该值。
		if (inputObj[i].getAttribute("allownull")=="false"){ 
			if (inputObj[i].getAttribute("relate")!=null && inputObj[i].getAttribute("relate")!=""){
				for (j=0;j<inputObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(inputObj[i].getAttribute("relate").split('|')[j]).checked && inputObj[i].value==""){
						errorctrl(inputObj[i], '不能为空');
						return false; 
					}
				}
			}
			else{
				if (inputObj[i].value==""){ 
					errorctrl(inputObj[i], '不能为空');
					return false; 
				}
			}
		}
		//如果某项的class为digital，表示数字项。则检测是否为数字。 
		if (inputObj[i].getAttribute("className")=="digital"){ 
			if (inputObj[i].getAttribute("relate")!=null && inputObj[i].getAttribute("relate")!=""){
				for (j=0;j<inputObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(inputObj[i].getAttribute("relate").split('|')[j]).checked && inputObj[i].value!="" && isNaN(inputObj[i].value)){
						errorctrl(inputObj[i], '必须为数字');
						return false; 
					}
				}
			}
			else{
				if (inputObj[i].value!=""&&isNaN(inputObj[i].value)){ 
					errorctrl(inputObj[i], '必须为数字');
					return false; 
				} 
			} 
		} 
		//证明该输入框必须输入整数 
		if (inputObj[i].getAttribute("isInt")=="true"){
			if (inputObj[i].getAttribute("relate")!=null && inputObj[i].getAttribute("relate")!=""){
				for (j=0;j<inputObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(inputObj[i].getAttribute("relate").split('|')[j]).checked && inputObj[i].value.indexOf(".")>=0){
						errorctrl(inputObj[i], '必须为整数');
						return false; 
					}
				}
			}
			else{
				if (inputObj[i].value.indexOf(".")>=0){ 
					errorctrl(inputObj[i], '必须为整数');
					return false; 
				} 
			} 
		} 
		//证明该输入框不允许输入0 	
		if (inputObj[i].getAttribute("allowzero")=="false"){ 
			if (inputObj[i].getAttribute("relate")!=null && inputObj[i].getAttribute("relate")!=""){
				for (j=0;j<inputObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(inputObj[i].getAttribute("relate").split('|')[j]).checked && inputObj[i].value==0){ 
						errorctrl(inputObj[i], '不能为0');
						return false; 
					}
				}
			}
			else{
				if (inputObj[i].value==0){
					errorctrl(inputObj[i], '不能为0');
					return false; 
				} 
			} 
		}                                 
		//如果isdate为true，表示该项为日期项，则必须输入日期 
		if (inputObj[i].getAttribute("isdate")=="true"){ 
			if (inputObj[i].getAttribute("relate")!=null && inputObj[i].getAttribute("relate")!=""){
				for (j=0;j<inputObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(inputObj[i].getAttribute("relate").split('|')[j]).checked && inputObj[i].value!="" && !checkdate(inputObj[i].value)){ 
						errorctrl(inputObj[i], '必须为正确的日期格式');
						return false; 
					}
				}
			}
			else{
				if (inputObj[i].value!=""&&!checkdate(inputObj[i].value)){ 
					errorctrl(inputObj[i], '必须为正确的日期格式');
					return false; 
				}
			} 
		}                                
		//如果ismail为true，表示该项为Email格式 
		if (inputObj[i].getAttribute("ismail")=="true"){ 
			if (inputObj[i].getAttribute("relate")!=null && inputObj[i].getAttribute("relate")!=""){
				for (j=0;j<inputObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(inputObj[i].getAttribute("relate").split('|')[j]).checked && inputObj[i].value!="" && !checkmail(inputObj[i].value)){ 
						errorctrl(inputObj[i], '必须为正确的Email格式，格式如：service@newgo5.com');
						return false; 
					}
				}
			}
			else{
				if (inputObj[i].value!=""&&!checkmail(inputObj[i].value)){ 
					errorctrl(inputObj[i], '必须为正确的Email格式，格式如：service@newgo5.com');
					return false; 
				}
			} 
		} 
	}   
	
	//证明该选择框不允许为空
	var selectObj=navigator.userAgent.indexOf("MSIE")>0?objfrm.getElementsByTagName("select"):document.getElementsByTagName("select"); 
	for (i=0;i<selectObj.length;i++){ 
		if (selectObj[i].getAttribute("allownull")=="false"){
			if (selectObj[i].getAttribute("relate")!=null && selectObj[i].getAttribute("relate")!=""){
				for (j=0;j<selectObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(selectObj[i].getAttribute("relate").split('|')[j]).checked && (selectObj[i].value=="" || selectObj[i].value=="0")){ 
						errorctrl(selectObj[i], '不能为空');
						return false; 
					}
				}
			}
			else{
				if (selectObj[i].value=="" || selectObj[i].value=="0"){ 
					errorctrl(selectObj[i], '不能为空');
					return false; 
				} 
			} 
		} 
	}   
	
	//多文本框不允许为空
	var textearaObj=navigator.userAgent.indexOf("MSIE")>0?objfrm.getElementsByTagName("textarea"):document.getElementsByTagName("textarea"); 
	for (i=0;i<textearaObj.length;i++){
		if (textearaObj[i].getAttribute("allownull")=="false"){
			if (textearaObj[i].getAttribute("relate")!=null && textearaObj[i].getAttribute("relate")!=""){
				for (j=0;j<textearaObj[i].getAttribute("relate").split('|').length;j++){ 
					if (document.getElementById(textearaObj[i].getAttribute("relate").split('|')[j]).checked && textearaObj[i].value==""){ 
						errorctrl(textearaObj[i], '不能为空');
						return false; 
					}
				}
			}
			else{
				if (textearaObj[i].value==""){ 
					errorctrl(textearaObj[i], '不能为空');
					return false; 
				}
			} 
		} 
	} 

	return true; 
} 

//该函数为检测是否为日期的函数。 
function checkdate(str){ 
	var reg = /^(\d+)-(\d{1,2})-(\d{1,2})$/; 
	var r = str.match(reg); 
	if(r==null)return false; 
	r[2]=r[2]-1; 
	var d= new Date(r[1], r[2],r[3]); 
	if(d.getFullYear()!=r[1])return false; 
	if(d.getMonth()!=r[2])return false; 
	if(d.getDate()!=r[3])return false; 
	
	return true; 
}
function checkmail(str){ 
	var reg = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 
	var r = str.match(reg); 
	if(r==null)return false; 
	return true; 
}	

function CheckFormat(re,s,lenght){
	var b;
	b = true;
	for (i = 0; i < lenght; i++){
		if (s.substring(i,i+1).match(re) == null){
			b = false;
		}
	}
	return b;
}
function LoadCity(obj){
	LoadType(obj, 'dplCity', 'dplCountry', 'city')
}
function LoadCountry(obj){
	LoadType(obj, 'dplCountry', '', 'country')
}
function LoadType(currentObj, id, nextid, type) {
	new Ajax.Request(
		'../Ajax/DropDownListCate.aspx',
		{
			queue: {position: 'end', scope: 'command'},
			method: 'post',
			postBody: 'id='+currentObj.options[currentObj.selectedIndex].value+'&type=' + type,
			onComplete: function(response) {
				if (isNaN(response.responseText)) {
					var dvList = response.responseText.split('##@##');
					$(id).options.length = 0;
					for (var i = 1; i < dvList.length; ++i){	
						$(id).options[$(id).options.length] = new Option(dvList[i].split('$$%$$')[1], dvList[i].split('$$%$$')[0]);
					} 
					if (nextid != '') {
						$(nextid).disabled = "disabled";
						$(nextid).selectedIndex = 0;
					}
					else {
						$(id).disabled = "";
					}
				}
			}
		}
	);
}
function CommentOperate(id, type, op) {
	new Ajax.Request(
		'../Ajax/CommentOperate.aspx',
		{
			queue: {position: 'end', scope: 'command'},
			method: 'post',
			postBody: 'id='+id+'&type=' + type+'&op=' + op,
			onComplete: function(response) {
				switch (response.responseText) {
					case "0":
							if (op == "s") {
								$("op_supp" + id).innerText = parseInt($("op_supp" + id).innerText) + 1;
							}
							else {
								$("op_oppo" + id).innerText = parseInt($("op_oppo" + id).innerText) + 1;
							}
							$("aop_supp" + id).className = "op_supp_off";
							$("aop_oppo" + id).className = "op_oppo_off";
						break;
					case "1":alert("系统出现错误，请联系管理人员！");
						break;
					case "3":alert("您已经发表过一次您的观点了！");
						break;
					default:alert("非法操作！");
						break;
				}
			}
		}
	);
}
function nchangeImg(Id){
	$("Verify" + Id).src = "../User/Validate.aspx?type=1&id=" + Math.random();
}
function ReplyComment(Id, uid, type) {
	if ($("message" + Id).innerHTML != ""){
		$("message" + Id).innerHTML ="";
	}
	else {
		new Ajax.Request(
			'../Ajax/Reply.aspx',
			{
				queue: {position: 'end', scope: 'command'},
				method: 'post',
				postBody: 'id=' + Id + '&type=' + type + '&uid=' + uid,
				onComplete: function(response) {
					var obj = $("n_msg").getElementsByTagName("p");
					for(var i=0;i<obj.length;i++){
						if(obj[i].className == "c_msgpanel") obj[i].innerHTML = "";
					}
					$("message" + Id).innerHTML = response.responseText;
				}
			}
		);
	}
}
function Validate(Id, uid, type){
	if (checkOwnRule(document.Form1)){
		Save(Id, uid, type)
	}
	else{
		if (window.event){
			event.returnValue = false;
		}
		
		return false;
	}
	
}
function Save(Id, uid, type){
	var strbody = "";
	if (type == 'a') {
		strbody += "&txtContent=" + escape($("txtContent").value);
		strbody += "&txtName=" + escape($("txtName").value);
		strbody += "&txtPass=" + escape($("txtPass").value);
		strbody += "&txtVaild=" + escape($("txtVaild").value);
		if ($("cboAnonymous").checked){strbody += "&cboAnonymous=1";}
	}
	
	new Ajax.Request(
            '../Ajax/Reply.aspx',
	        {
				queue: {position: 'end', scope: 'command'},
        		method: 'post',
                postBody: 'action=save&id=' + Id + '&type=' + type + '&uid=' + uid + strbody,
		        onComplete: function(response) {
					switch (response.responseText) {
						case "0":alert("非法操作！");
							break;
						case "1":alert("数据库出现错误，请联系管理人员！");
							break;
						case "2":alert("文章评论内容不能为空，请重新输入！");
							break;
						case "3":alert("用户名和密码错误，请重新输入！");
							break;
						case "4":alert("来源地址错误！");
							break;
						case "5":alert("验证码错误，请重新输入！");
							break;
						case "6":alert("系统出现错误，请联系管理人员！");
							break;
						default:
								$("message" + Id).innerHTML = "";
								$("c_reply" + Id).innerHTML = response.responseText;
							break;
					}
				}
        	}
	);
}

function common_swf(fw,fh,_src,_id, vars){
	var html = ''
		+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="'+_id+'" width="'+fw+'" height="'+fh+'" align="middle">\n'
		+ '<param name="allowScriptAccess" value="always" />'
		+ '<param name="movie" value="'+_src+'" />\n'
		+ '<param name="quality" value="high" />\n'
		+ '<param name="scale" value="exactfit" />\n'
		+ '<param name="wmode" value="transparent" />\n'
		+ '<embed src="'+_src+'" wmode="transparent" scale="exactfit" quality="high" width="'+fw+'" height="'+fh+'" id="'+_id+'" name="'+_id+'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n'
		+ '<\/object>\n';
	document.write(html);
}
