//获取对象id
function $(id) {
	return document.getElementById(id);
}
//获取对象名
function $$(objName) {
	return document.getElementsByTagName(objName);
}
//隐藏对象
function hideObj(objid){
	return $(objid).style.display="none";
}
//显示对象
function showObj(objid){
	return $(objid).style.display="block";
}
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    flag=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.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.alt=image.width+"×"+image.height;
        }
    }
}
//收展菜单
function onChange(i,path){
var childSort=document.getElementById("child" + i);
var downgif=document.getElementById("down" + i);
	if (childSort.style.display=="none"){
		 childSort.style.display="block";
		 downgif.src=path+'-.gif';
		 
	}else{
		 childSort.style.display="none";
		 downgif.src=path+'+.gif';
	}
}
//搜索检查
function checkSearSubmit(){
	if(document.formSear.TextKeyword.value==""){
		alert("请输入关键字");
		document.formSear.TextKeyword.focus();
		return false;
	}
}
//订购检查
function checkOrderSubmit(){
	if(document.formOrder.type.value==""){
		alert("请选择类型.");
		document.formOrder.type.focus();
		return false;
	}
	if(document.formOrder.proname.value==""){
		alert("请输入产品名称或者型号.");
		document.formOrder.proname.focus();
		return false;
	}
	if(document.formOrder.name.value==""){
		alert("请输入联系人.");
		document.formOrder.name.focus();
		return false;
	}
	if(document.formOrder.tel.value==""){
		alert("请输入联系电话.");
		document.formOrder.tel.focus();
		return false;
	}
	if(document.formOrder.validate.value==""){
		alert("请输入验证码.");
		document.formOrder.validate.focus();
		return false;
	}
}
//留言检查
function checkMessageSubmit(){
	if(document.formMessage.name.value==""){
		alert("请输入你的姓名.");
		document.formMessage.name.focus();
		return false;
	}
	if(document.formMessage.title.value==""){
		alert("请输入标题.");
		document.formMessage.title.focus();
		return false;
	}
	if(document.formMessage.content.value==""){
		alert("请输入内容.");
		document.formMessage.content.focus();
		return false;
	}
	if(document.formMessage.validate.value==""){
		alert("请输入验证码.");
		document.formMessage.validate.focus();
		return false;
	}
}
//检查登录
function checkLoginSubmit(){
	if(document.formLogin.userid.value==""){
		alert("请输入用户名");
		document.formLogin.userid.focus();
		return false;
	}
	if(document.formLogin.pwd.value==""){
		alert("请输入密码");
		document.formLogin.pwd.focus();
		return false;
	}
}
//判断用户名是否存在
function getUsername(){
	if (document.getElementById('username').value!=''){
	var url="../login.php";//url地址
	var usernameAjax = new webAjax(usernameInfo);
	usernameAjax.post(url,'action=checkuser&userid='+document.getElementById('username').value);
	}
}
function usernameInfo(usernameAjax)
{
	var data = usernameAjax.responseText;
	var note = document.getElementById('username_note');
	if(data != ''){
		if (data==document.getElementById('username').value){
			note.innerHTML='此用户名已经存在．';
		}else{
			note.innerHTML='';
		}
	}else{
		note.innerHTML='';
	}
}
//检查注册
function checkJoinSubmit(){
	if(document.formJoin.username.value==""){
		alert("请输入用户名.");
		document.formJoin.username.focus();
		return false;
	}
	getUsername();
	if (document.getElementById('username_note').innerHTML!=''){
		document.formJoin.username.focus();
		return false;
	}
	if(document.formJoin.pwd.value==""){
		alert("请输入密码.");
		document.formJoin.pwd.focus();
		return false;
	}
	if(document.formJoin.confirm_pwd.value==""){
		alert("请输入确认密码.");
		document.formJoin.confirm_pwd.focus();
		return false;
	}
	if(document.formJoin.confirm_pwd.value!=document.formJoin.pwd.value){
		alert("两次输入密码不符.");
		document.formJoin.confirm_pwd.focus();
		return false;
	}
	if(document.formJoin.company.value==""){
		alert("请输入公司名称.");
		document.formJoin.company.focus();
		return false;
	}
	if(document.formJoin.address.value==""){
		alert("请输入联系地址.");
		document.formJoin.address.focus();
		return false;
	}
	if(document.formJoin.zip_code.value==""){
		alert("请输入邮政编码.");
		document.formJoin.zip_code.focus();
		return false;
	}
	if(document.formJoin.name.value==""){
		alert("请输入联系人.");
		document.formJoin.name.focus();
		return false;
	}
	if(document.formJoin.tel.value==""){
		alert("请输入联系电话.");
		document.formJoin.tel.focus();
		return false;
	}
	if(document.formJoin.email.value==""){
		alert("请输入E-mail地址.");
		document.formJoin.email.focus();
		return false;
	}
	if (document.formJoin.email.value.indexOf("@",0)== -1||document.formJoin.email.value.indexOf(".",0)==-1){
        window.alert("对不起，你输入的E-mail格式有误！")
        document.formJoin.email.focus()
        return false
    }
	if(document.formJoin.content.value==""){
		alert("请输入公司信息.");
		document.formJoin.content.focus();
		return false;
	}
	if(document.formJoin.validate.value==""){
		alert("请输入验证码.");
		document.formJoin.validate.focus();
		return false;
	}
}
//接收地址栏参数
function getParameter(param)
{
var query = window.location.search;
var iLen = param.length;
var iStart = query.indexOf(param);
if (iStart == -1)
　return "";
iStart += iLen + 1;
var iEnd = query.indexOf("&", iStart);
if (iEnd == -1)
　return query.substring(iStart);
return query.substring(iStart, iEnd);
}
//留言ajax
function showMessage(){
	var url="../guestbook.php";
	var pars = '';
	var page = getParameter('page');//接收页数
	var keyword = getParameter('TextKeyword');//接收关键字
	if (page!=''&&keyword!=''){
		pars='page='+page+'&TextKeyword='+keyword;
	}else if (page!=''&&keyword==''){ 
		pars='page='+page;
	}else if (page==''&&keyword!=''){ 
		pars='TextKeyword='+keyword;
	}
	var messageAjax = new webAjax(showMessageInfo);
	messageAjax.get(url,pars);
}
function showMessageInfo(messageAjax)
{
	var data = messageAjax.responseText;
	if(data != ''){
		$('messageDiv').innerHTML = data;
	}
}
//验证是否登录
function checkIsLogin(){
	var url="../../login.php";//url地址
	var isLoginAjax = new webAjax(isLogin);
	isLoginAjax.post(url,'action=getLogin');
}
function isLogin(isLoginAjax)
{
	var data = isLoginAjax.responseText;
	
	if(data != ''){
		if (data=='succeed'){
			document.getElementById('show_download').style.display='block';
		}else{
			document.getElementById('show_download').innerHTML='';
			document.getElementById('show_download').style.display='none';
			location.href='../login.html';
		}
	}
}
//获取登录信息
function getLoginInfo(weburl){
	var url=weburl+"login.php";//url地址
	var loginInfoAjax = new webAjax(logininfo);
	loginInfoAjax.post(url,'action=getLoginInfo');
}
function logininfo(loginInfoAjax)
{
	var data = loginInfoAjax.responseText;
	
	if(data != ''){
		document.getElementById('loginInfo').innerHTML=data;
	}
}
//获取对象左上坐标
function getOffsetLeft(objid){
  var obj=$(objid),
      left=0;
	  while(obj.offsetParent){
		 left+=obj.offsetLeft;
			 obj=obj.offsetParent;                
	  }
	  return left;
}
//获取对象左下坐标
function getOffsetTop(objid){
  var obj=$(objid),
      top=0;
	  while(obj.offsetParent){
		 top+=obj.offsetTop;
			 obj=obj.offsetParent;                
	  }
	  return top;
}
