﻿//分页
function setPage(s, i)
{
	return s.replace('{p}', i.toString());
}

function ongoto(url,maxpage)
{
	
	var page = document.getElementById("gotopage").value;
	//alert(maxpage+page);
	if (isNaN(page) || page<1)
	{
		page = "1";
	}
	else if (Number(page)>Number(maxpage))
	{
		page=maxpage;
	}
	location.href = setPage(url, page);
}

//图片按比例缩放
//调用：<img src="图片" onload="javascript:DrawImage(this,100,100)">
var imgflag=false;
function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    imgflag=true;
	
	if(image.width/image.height<= iwidth/iheight){
	 if(image.width>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }
		else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
		ImgD.style.width=image.width; 
		ImgD.style.height=image.height; 
		//ImgD.style.padding=""+(200-image.height)/2+"px "+(300-image.width)/2+"px "+(200-image.height)/2+"px "+(300-image.width)/2+"px"; 
		//ImgD.style.margin-top=(200-image.height)/2; 
        }
        //ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }
		else{
        ImgD.width=image.width;
        ImgD.height=image.height;
		ImgD.style.width=image.width;
		ImgD.style.height=image.height;
		//ImgD.style.padding=""+(200-image.height)/2+"px "+(300-image.width)/2+"px "+(200-image.height)/2+"px "+(300-image.width)/2+"px"; 
		//alert(""+(200-image.height)/2+"px "+(300-image.width)/2+"px "+(200-image.height)/2+"px "+(300-image.width)/2+"px"); 
        }
        //ImgD.alt=image.width+"×"+image.height;
        }
    }
} 

function chkfeedback(){
	var Material=document.getElementById("Material")
	var Price=document.getElementById("Price")
	var Plan=document.getElementById("Plan")	
	var UserName=document.getElementById("UserName")
	var Phone=document.getElementById("Phone")
	var Email=document.getElementById("Email")
	var Content=document.getElementById("Content")
	
	if (Material.checked == false & Price.checked == false & Plan.checked == false) {
	alert("请选择需要的产品信息(单选或多选)");
	UserName.focus();
	return false;
}
if (UserName.value == undefined || UserName.value == "") {
	alert("用户名不能为空！");
	UserName.focus();
	return false;
}	
if (Phone.value == undefined || Phone.value == "") {
	alert("联系方式不能为空！");
	Phone.focus();
	return false;
}
if (Email.value == undefined || Email.value == "" || !str.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)) {
	alert("请正确输入Email地址！");
	Email.focus();
	return false;
}
if (Content.value == undefined || Content.value == "" || Content.value.length>600) {
	alert("内容不能为空,且应小于500个字！");
	Content.focus();
	return false;
}
return true;
}

function menuChange(obj,menu)
{
	if(menu.style.display=="none")
	{
		obj.setAttribute("style","");
		obj.src='images/img.jpg'
		//obj.onmouseover=function(){this.className='menu_title2';};
		//obj.onmouseout=function(){this.className='menu_title';};
		menu.style.display="";
	}else{
	obj.src='images/img1.jpg'
		obj.setAttribute("style","background-image:url(/admin_manage/images/admin_title_bg_hide.gif)");
		//obj.onmouseover=function(){this.className='menu_title';};
		//obj.onmouseout=function(){this.className='menu_title2';};
		menu.style.display="none";
	}
}


//密码强度检验
function chkpwd(obj){
	var t=obj.value;
	var id=getResult(t);
	
	//定义对应的消息提示
	var msg=new Array(4);
	msg[0]="密码过短。";
	msg[1]="密码强度差。";
	msg[2]="密码强度良好。";
	msg[3]="密码强度高。";
	
	var sty=new Array(4);
	sty[0]=-45;
	sty[1]=-30;
	sty[2]=-15;
	sty[3]=0;
	
	var col=new Array(4);
	col[0]="gray";
	col[1]="red";
	col[2]="#ff6600";
	col[3]="Green";
	
	//设置显示效果
	var bImg="images/pwd.gif";//一张显示用的图片
	var sWidth=300;
	var sHeight=15;
	var Bobj=document.getElementById("passwordtext");
	Bobj.style.fontSize="12px";
	Bobj.style.color=col[id];
	Bobj.style.width=sWidth + "px";
	Bobj.style.height=sHeight + "px";
	Bobj.style.lineHeight=sHeight + "px";
	Bobj.style.background="url(" + bImg + ") no-repeat left " + sty[id] + "px";
	Bobj.style.textIndent="20px";
	Bobj.innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;检测提示：" + msg[id];
}

//定义检测函数,返回0/1/2/3分别代表无效/差/一般/强
function getResult(s){
	if(s.length < 6){
		return 0;
	}
	var ls = 0;
	if (s.match(/[a-z]/ig)){
		ls++;
	}
	if (s.match(/[0-9]/ig)){
		ls++;
	}
	if (s.match(/(.[^a-z0-9])/ig)){
		ls++;
	}
	if (s.length < 6 && ls > 0){
		ls--;
	}
	return ls
}


//检验用户名是否可注册
function createxmlhttprequest()
{
	var xmlhttp=false;
	try
	{
		xmlhttp=new ActiveXObject('Msxm12.XMLHTTP');
	}
	catch(e)
	{
		try
		{
			xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(e)
		{
			try
			{
				xmlhttp=new XmlHttpRequest();
			}
			catch(e)
			{
			}
		}
	 }
	return xmlhttp;
}
function checkuser()
{
	if (out_username()){
	var xmlhttp=createxmlhttprequest();
	var obj=document.getElementById("usernametext");
	var username=document.getElementById('username');
	var chk=true;
	xmlhttp.open('get','member_class.asp?action=chkusername&UName='+username.value);
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
		
			if(xmlhttp.status==200)
			{
				if(xmlhttp.responseText=="false")
				{  
					chk=false;
					obj.innerHTML=obj.innerHTML+'该用户名已经存在';
					obj.style.color="#ff0000";
					document.getElementById('username').focus();
				}
				else
				{	
					obj.innerHTML=obj.innerHTML+'并且该用户名可以注册';					
				}
			}
		}
	}
	xmlhttp.send(null);
	return chk;
	}
}


//用户名是否输入
function out_username(){
	var obj=document.getElementById("usernametext");
	var str=document.getElementById("username").value;
	var chk=true;
	//alert(str);
	if (str==''|| !str.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){chk=false}
	if (chk){
		obj.innerHTML='用户名已经输入 ';
		obj.style.color="#72AC42";
	}else{
		obj.innerHTML='请使用常用邮箱做为登录用户名';
		obj.style.color="#ff0000";
	}
	return chk;
}

//密码是否已经输入
function out_password(){
	var obj=document.getElementById("passwordtext");
	var str=document.getElementById("password").value;
	var chk=true;
	//alert(str);
	if (str=='' || str.length<6 || str.length>14){chk=false;}
	if (chk){
		obj.innerHTML='密码已经输入';
		obj.style.color="#72AC42";
	}else{
		obj.innerHTML='&nbsp;&nbsp;&nbsp;&nbsp;请输入6-14位非空格数字、字母和字符';
		obj.style.color="#ff0000";
	}
	return chk;
}


//旧密码是否已经输入
function out_oldpassword(){
	var obj=document.getElementById("oldpasswordtext");
	var str=document.getElementById("oldpassword").value;
	var chk=true;
	//alert(str);
	if (str=='' || str.length<6 || str.length>14){chk=false;}
	if (chk){
		obj.innerHTML='旧密码已经输入';
		obj.style.color="#72AC42";
	}else{
		obj.innerHTML='请输入旧密码';
		obj.style.color="#ff0000";
	}
	return chk;
}

function out_repassword(){
	var obj=document.getElementById("repasswordtext");
	var str=document.getElementById("repassword").value;
	var chk=true;
	if (str!=document.getElementById("password").value||str==''){chk=false;}
	if (chk){		
		obj.innerHTML='重复密码输入正确';
		obj.style.color="#72AC42";
	}else{
		
		obj.innerHTML='请重复输入上面的密码';
		obj.style.color="#ff0000";
	}
	return chk;
}

//用户名是否输入
function out_email(){
	var obj=document.getElementById("emailtext");
	var str=document.getElementById("email").value;
	var chk=true;
	//alert(str);
	if (str==''|| !str.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){chk=false}
	if (chk){
		obj.innerHTML='邮箱已经输入 ';
		obj.style.color="#72AC42";
	}else{
		obj.innerHTML='请使用常用邮箱，如webmaster@163.com';
		obj.style.color="#ff0000";
	}
	return chk;
}

//注册表单检验
function chkregist(){
	var chk=true
	if (!out_username()){chk=false}
	if (!checkuser()){chk=false}	
	if (!out_password()){chk=false}
	if (!out_repassword()){chk=false}
	if(chk==false){
		return false;
		}
	else
	{
	return true;
	}
}


//用户修改检验
function chkmodify(){
	var chk=true
	if (!out_oldpassword()){chk=false}	
	if (document.getElementById('password').value!='')
	{
		if (!out_password()){chk=false}
		if (!out_repassword()){chk=false}
	}
	
	if(chk==false){
		return false;
		}
	else
	{
	return true;
	}
}

function orderchk(){
	if (document.getElementById('orderno').value== undefined || document.getElementById('orderno').value==''||document.getElementById('orderno').value=='输入订单号查询订单')
	{
		alert('请输入订单号');
		return false;
	}
		return true;
}

function chklogin()
{
	var username = document.getElementById("user_name").value;
	var password = document.getElementById("user_password").value;

	if (username == undefined || username == "") {
		alert("用户名不能空！");
		document.getElementById("user_name").focus();
		return false;
	}			
	if (password == undefined || password == "") {
		alert("密码不能为空！");
		document.getElementById("user_password").focus();
		return false;
	}
	return true;
}
