﻿function xmlGet(url){
	if(window.XMLHttpRequest){
		http_request=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		http_request=new ActiveXObject("Microsoft.XMLHTTP");
	}
	var linkurl=url;
	http_request.open("GET",linkurl,false);
	http_request.send(null);
	return http_request.responseText;
}

function isW(str,len1,len2){
	if(!eval("/^[A-Za-z0-9_-]{"+len1+","+len2+"}$/").test(str)){
		return false;
	}
	return true;
}

function isInt(str){
	if(!eval("/^[0-9]+$/").test(str)){
		return false;
	}
	return true;
}

function isEmail(str){
	if(!(str.length>=5&&str.length<=255)){
		return false;
	}else{
		if(!/^[A-Za-z0-9]+([._]*[-]*[+]*[A-Za-z0-9]+)*@([A-Za-z0-9]+([\-]*[A-Za-z0-9]+)*\.)+[A-Za-z0-9]+$/.test(str)){
			return false;
		}
		return true;
	}
}

function isFramed(){
	if(top.location!=self.location){
		top.location=self.location;
	}
}

function show(t){t.style.display="block";}
function hide(t){t.style.display="none";}
function change_show_hide(t){
	if(t.style.display=="none"){
		t.style.display="block";
	}else{
		t.style.display="none";
	}
	return false;
}

function openwin(url,id,width,height){
	left=(screen.width-width)/2;
	top1=(screen.height-height)/2;
	window.open(url,id,"width="+width+",height="+height+",top="+top1+",left="+left+",toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");
}

function idValueSelected(id,value){
	for(i=0;i<document.getElementById(id).options.length;i++){
		if(document.getElementById(id).options[i].value==value){
			document.getElementById(id).options[i].selected=true;
		}
	}
}

function trim(str){
	str=str.replace(/\\/g,"\\\\");
	str=str.replace(/%/g,"\\%");
	str=str.replace(/\'/g,"\\\'");
	str=str.replace(/\"/g,"\\\"");
	str=str.match(/^\s*(\S+(\s+\S+)*)\s*$/);
	return (str==null)?"":str[1];
}

function getRadioCheckedValue(nameOfRadio){
	var theRadioInputs=document.getElementsByName(nameOfRadio);
	for(var i=0;i<theRadioInputs.length;i++){
		if(theRadioInputs[i].checked){
			return theRadioInputs[i].value;
		}
	}
	return null;
}

function getCheckboxCheckedNumber(nameOfCheckbox){
	var theCheckboxInputs=document.getElementsByName(nameOfCheckbox);
	var checkedNumber=0;
	for(var i=0;i<theCheckboxInputs.length;i++){
		if(theCheckboxInputs[i].checked){
			checkedNumber++;
		}
	}
	return checkedNumber;
}

function floorMultiply(a,b){
	aLength=String(a).length;
	aDecimalIndex=String( a ).lastIndexOf(".");
	aDecimal=aLength-aDecimalIndex-1;
	aMathPow=Math.pow(10,aDecimal);
	
	bLength=String(b).length;
	bDecimalIndex=String( b ).lastIndexOf(".");
	bDecimal=bLength-bDecimalIndex-1;
	bMathPow=Math.pow(10,bDecimal);
	
	result=(a*aMathPow)*(b*bMathPow)/(aMathPow*bMathPow);
	return result;
}

function checkMembersLogin(includesPath){
	var username=document.membersLogin.username.value;
	var password=document.membersLogin.password.value;
	var validateCode=document.membersLogin.validateCode.value;
	if(validateCode==""){
		alert("请输入验证码");return;
	}
	if(isW(username,6,24)==false||isW(password,6,24)==false){
		alert("帐号或密码格式错误");return;
	}
	num=xmlGet(includesPath+"includes/mysqlNumRows.php?code=3&username="+username+"&password="+password);
	if(!(num>0)){
		alert("帐号或密码错误");
	}else{
		document.membersLogin.submit();
	}
}

function checkOnlinecontactaccount(includesPath,title){
	if(title==""){
		alert("请输入客服帐号");return;
	}
	num=xmlGet(includesPath+"includes/mysqlNumRows.php?code=13&title="+title);
	if(!(num>0)){
		alert("客服帐号错误");
	}else{
		alert("客服帐号正确");
	}
}

function CheckboxAllsetCheck(nameOfCheckbox,checkedValue){
	var theCheckboxInputs=document.getElementsByName(nameOfCheckbox);
	var checkedNumber=0;
	if(checkedValue!=true){
		checkedValue=false;
	}
	for(var i=0;i<theCheckboxInputs.length;i++){
		theCheckboxInputs[i].checked=checkedValue;
	}
	return checkedNumber;
}