﻿//分页
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 company=document.getElementById("company")
	var userName=document.getElementById("userName")
	var phone=document.getElementById("phone")
	var email=document.getElementById("email")	
	var proname=document.getElementById("proname")
	var telreg = /^0?1[35]\d{9}|(0{1,2}\d{2,3}-?)?\d{7}\d?(-\d+)?$/;
	var myReg = /^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig;
	
	
	if (company.value == undefined || company.value == "") {
	alert("请填写公司名称！");
	company.focus();
	return false;
}
if (userName.value == undefined || userName.value == "") {
	alert("请填写您的姓名！");
	userName.focus();
	return false;
}	
if (!telreg.test(phone.value) || phone.value == undefined || phone.value == "") {
	alert("请填写正确电话号码！");
	phone.focus();
	return false;
}

if (!myReg.test(email.value) || email.value == undefined || email.value == "") {
	alert("请输入正确的Email地址！");
	email.focus();
	return false;
}	

return true;
}

function chkfeedbackyy(){
	var Material=document.getElementById("Material")
	var Price=document.getElementById("Price")
	var Plan=document.getElementById("Plan")
	var Software=document.getElementById("Software")	
	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 checkseach(){
	 var keyword=document.getElementById("keyword");
	 if (keyword.value == undefined || keyword.value.replace(/[\s]/g,'') == "" || keyword.value == "请输入产品关键字"){
		 alert("请输入关键词")
		 keyword.focus();
		 return false;
		 }
     return true;
	}
