﻿
//IE6下png背景透明解决方法
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. 
{ 
    var arVersion = navigator.appVersion.split("MSIE") 
    var version = parseFloat(arVersion[1]) 
    if ((version >= 5.5) && (document.body.filters)) 
    { 
       for(var j=0; j<document.images.length; j++) 
       { 
          var img = document.images[j] 
          var imgName = img.src.toUpperCase() 
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
          { 
             var imgID = (img.id) ? "id='" + img.id + "' " : "" 
             var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle 
             if (img.align == "right") imgStyle = "float:right;" + imgStyle 
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
             var strNewHTML = "<span " + imgID + imgClass + imgTitle 
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
             img.outerHTML = strNewHTML 
             j = j-1 
          } 
       } 
    }     
} 
window.attachEvent("onload", correctPNG); 

//两div栏的高度能自动相等
function resetDiv()
{ 
	var a=document.getElementById("main1").offsetHeight;
	var b=document.getElementById("main2").offsetHeight;
	var themax=Math.max(a,b)
	document.getElementById("main1").style.height=themax+"px";
	document.getElementById("main2").style.height=themax+"px";
} 

//图片预先加载
function LoadImage(ImgD,id)
{ 
	var image=new Image(); 
	image.src=ImgD.src; 
	if(ImgD.readyState=="complete" || ImgD.complete == true)
	{
		document.getElementById("ImgLoadId-"+id).style.display="none";
		ImgD.style.display="block";
	}
}

//显示跟隐藏
function showsub(sid)
{
	if (document.getElementById("submenu"+sid).style.display == "none")
	{
		document.getElementById("submenu"+sid).style.display = "block";
		document.getElementById("pic"+sid).src="images/open.gif";
	}
	else
	{
		document.getElementById("submenu"+sid).style.display = "none";
		document.getElementById("pic"+sid).src="images/close.gif";
	}
}

//产品展示
function look_pic(id)
{
	if (id!="")
	{ 
		document.getElementById("pic_span").innerHTML="<a href='"+id+"' target=_blank><img src='"+id+"' width='320' border='0' onload='javascript:resizeimg(this,320,260)'  title='Click it for larger photo'></a>";
	}
}
//产品图片
function MouseOver(n)
{        
  document.getElementById("img"+n).className='imgOver';
}  

function MouseOut(n)
{           
  document.getElementById("img"+n).className='imgOut';  
}  
//产品图片

//重新加载验证码，这里必须加入随机数不然地址相同我发重新加载
function reloadcode()
{
	var CheckCode=document.getElementById('CheckCode');
	CheckCode.setAttribute('src','includeFile/getcode.asp?'+Math.random());
}
function reloadcode2()
{
	var CheckCode=document.getElementById('CheckCode');
	CheckCode.setAttribute('src','../includeFile/getcode.asp?'+Math.random());
}

//图片按比例缩放,可输入参数设定初始大小
function resizeimg(ImgD,iwidth,iheight,id) {
     var image=new Image();
     image.src=ImgD.src;
     if(image.width>0 && image.height>0)
	 {
        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;
         }
    }
	
	//图片预先加载
	if(ImgD.readyState=="complete" || ImgD.complete == true)
	{
		document.getElementById("ImgLoadId-"+id).style.display="none";
		ImgD.style.display="block";
	}
}
//图片按比例缩放,可输入参数设定初始大小 

//图片预先加载
function ImgLoad(ImgD,id)
{
	var image=new Image();
    image.src=ImgD.src;
	if(ImgD.readyState=="complete" || ImgD.complete == true)
	{
		document.getElementById("ImgLoadId-"+id).style.display="none";
		ImgD.style.display="block";
	}
}
	
// JavaScript Document
function createXMLHttpRequest()  //针对不同浏览器设置XMLHttpRequest方式
{ 
    xmlhttp = false; 
     
    if(window.XMLHttpRequest)
	{        //for Mozilla 
        xmlhttp = new XMLHttpRequest(); 
        if(xmlhttp.overrideMimeType)
		{ 
            xmlhttp.overrideMimeType("text/xml"); 
        } 
    } 
    else if(window.ActiveXObject)
	{   //for IE 
        try
		{ 
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
        }
		catch(e)
		{ 
            try
			{ 
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
            }
		catch(e)
		{} 
        } 
    } 
}


//检测空字符
function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}
//检测空字符

function CheckEmail(email)
{
	var RegExpStr = /^([\w\_\-\.]{1,})(@)([\w\-\.]{1,})(\.)([a-zA-Z\.]{1,})$/;
	return RegExpStr.test(email);
}

//获取点击数
function GetHits(id,tb)
{
	//alert(tb);
	var xmlHttp = createXMLHttpRequest();
	var getURL = "../template/hits.asp?tb="+tb+"&action=get&id="+id;
	xmlhttp.open("GET",getURL,true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xmlhttp.onreadystatechange=function() 
	{
		if ( xmlhttp.readyState==4 || xmlhttp.readyState=='complete' )
		{
			document.getElementById("hits").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//更新点击数
function UpdateHits(id,tb)
{
	//alert(tb);
	var xmlHttp = createXMLHttpRequest();
	var getURL = "../template/hits.asp?tb="+tb+"&action=up&id="+id;
	xmlhttp.open("get",getURL,true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xmlhttp.send(null);
}


function infor_insert()
{
	var Msg="ok";
	var subject=document.form.subject.value;
	var name=document.form.name.value;
	var company=document.form.company.value;
	var email=document.form.email.value;
	var address=document.form.address.value;
	var telphone=document.form.telphone.value;
	var fax=document.form.fax.value;
	var content=document.form.content.value;
	var getcode=document.form.getcode.value;
	
	if (checkspace(subject))
	{
		Msg="err";
		alert("请输入合作事项");
		document.form.subject.focus();
		return false;
	}
	if (checkspace(name))
	{
		Msg="err";
		alert("请输入您的姓名");
		document.form.name.focus();
		return false;
	}
	if (checkspace(email))
	{
		Msg="err";
		alert("请输入电子邮箱");
		document.form.email.focus();
		return false;
	}
	if (!CheckEmail(email))
	{
		Msg="err";
		alert("请输入正确的邮件地址");
		document.form.email.focus();
		return false;
	}
	if (checkspace(telphone))
	{
		Msg="err";
		alert("请输入联系电话");
		document.form.telphone.focus();
		return false;
	}

	if (checkspace(content))
	{
		Msg="err";
		alert("请输入定购信息");
		document.form.content.focus();
		return false;
	}
	if (checkspace(getcode))
	{
		Msg="err";
		alert("请按要求输入验证码");
		document.form.getcode.focus();
		return false;
	}
	if (checkspace(getcode)||getcode.length!=4)
	{
		Msg="err";
		alert("请根据要求填写验证码！");
		document.form.getcode.focus();
		return false;
	}

	if (Msg=="ok")
	{
		var xmlHttp = createXMLHttpRequest();
		var getURL = "template/cn_OrderSave.asp";
		var posturl = "action=add_infor&subject="+subject+"&company="+company+"&name="+name+"&email="+email+"&address="+address+"&telphone="+telphone+"&fax="+fax+"&content="+content+"&getcode="+getcode;
		xmlhttp.open("POST",getURL,true);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		xmlhttp.onreadystatechange=function() 
		{
			if ( xmlhttp.readyState==4 || xmlhttp.readyState=='complete' )
			{
				if(xmlhttp.responseText=="ok")
				{
					alert("您的网上订购提交成功,我们将尽快的跟你联系,谢谢!");
					location.href='cn_order.html';
				}
			}
		}
		xmlhttp.send(posturl);
	}
	else
	{
		alert("请根据要求填写完整信息！");
		return false;
	}
}


function infor_insert2()
{
	var Msg="ok";
	var subject=document.form.subject.value;
	var email=document.form.email.value;
	var telphone=document.form.telphone.value;
	var content=document.form.content.value;
	var getcode=document.form.getcode.value;
	
	if (checkspace(subject))
	{
		alert("请输入留言标题");
		document.form.subject.focus();
		return false;
	}
	if (checkspace(email))
	{
		alert("请输入电子邮箱");
		document.form.email.focus();
		return false;
	}
	if (!CheckEmail(email))
	{
		alert("请输入正确的邮件地址");
		document.form.email.focus();
		return false;
	}
	if (checkspace(telphone))
	{
		alert("请输入联系电话");
		document.form.telphone.focus();
		return false;
	}

	if (checkspace(content))
	{
		alert("请输入定购信息");
		document.form.content.focus();
		return false;
	}
	if (checkspace(getcode))
	{
		alert("请按要求输入验证码");
		document.form.getcode.focus();
		return false;
	}
	if (checkspace(getcode)||getcode.length!=4)
	{
		alert("请根据要求填写验证码！");
		document.form.getcode.focus();
		return false;
	}
}

function infor_insert3()
{
	var company=document.form.company.value;
	var contact=document.form.contact.value;
	var telphone=document.form.telphone.value;
	var moblie=document.form.moblie.value;
	var email=document.form.email.value;
	var address=document.form.address.value;
	var getcode=document.form.getcode.value;
	
	if (checkspace(company))
	{
		alert("请输入公司名称");
		document.form.company.focus();
		return false;
	}
	if (checkspace(contact))
	{
		alert("请输入联系人");
		document.form.contact.focus();
		return false;
	}
	if (checkspace(telphone))
	{
		alert("请输入联系电话");
		document.form.telphone.focus();
		return false;
	}
	if (checkspace(moblie))
	{
		alert("请输入联系手机");
		document.form.moblie.focus();
		return false;
	}
	if (checkspace(email))
	{
		alert("请输入电子邮箱");
		document.form.email.focus();
		return false;
	}
	if (!CheckEmail(email))
	{
		alert("请输入正确的邮件地址");
		document.form.email.focus();
		return false;
	}
	if (checkspace(address))
	{
		alert("请输入联系地址");
		document.form.address.focus();
		return false;
	}
	if (checkspace(getcode))
	{
		alert("请按要求输入验证码");
		document.form.getcode.focus();
		return false;
	}
	if (checkspace(getcode)||getcode.length!=4)
	{
		alert("请根据要求填写验证码！");
		document.form.getcode.focus();
		return false;
	}
}

//快速报价
function infor_Quotation()
{
	if (checkspace(document.form.email.value))
	{
		alert("请输入电子邮箱");
		document.form.email.focus();
		return false;
	}
	if (!CheckEmail(document.form.email.value))
	{
		alert("请输入正确的邮件地址");
		document.form.email.focus();
		return false;
	}
	if (checkspace(document.form.content.value))
	{
		alert("请输入内容备注");
		document.form.content.focus();
		return false;
	}
	if (checkspace(document.form.getcode.value))
	{
		alert("请按要求输入验证码");
		document.form.getcode.focus();
		return false;
	}
	if (checkspace(document.form.getcode.value)||document.form.getcode.value.length!=4)
	{
		alert("请根据要求填写验证码！");
		document.form.getcode.focus();
		return false;
	}
}
