﻿function $(obj){return document.getElementById(obj);}

function oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy");}

function AjaxPost(m,posturl,data,callback)
{
	var req=(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	data=data+"&m="+Math.random()
	if (m=="1"){
		req.open("POST",posturl,true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.setRequestHeader("CharSet","GB2312");
		req.send(data);
	}else{
		req.open("GET",posturl+"?"+data,true);
		req.send(null);
	}
	req.onreadystatechange = function() {
		if (req.readyState == 4 && req.status == 200) {
			var reqtext=req.responseText;
			if(callback!="vPros"){$(callback).innerHTML=reqtext;}
		}
	}	
}
function setHits(ID,aTy){
	AjaxPost(1,"/Hits.asp","Act=UpdateHits&ID="+ID+"&aTy="+aTy,aTy);
}

function setSrc(){
	$("kFrame").width="710";
	$("kFrame").height="450";
	$("kFrame").src="http://www.kefid.com/Inquiry-ru.html?w="+document.URL;
}

function showCon(cID,tID){
	$("nv_"+cID).className="crta1";$("nc_"+cID).style.display="block";
	for(var i=0;i<tID;i++){if(i!=cID){$("nv_"+i).className="crta0";$("nc_"+i).style.display="none";}}
}

function IsCheck(oID){
	var isChk=false;
	var oL=document.getElementsByName(oID);
	if(oL!=null){if(oL.length>0){for(var i=0;i<oL.length;i++){if(oL[i].checked==true){isChk=true;break;}}}}
	return isChk;
}
function chkGuide(oID){
	if(!IsCheck(oID)){alert("Выбирайте те продукты, которые вас интересуют !");return false;}
}

function setDes(obj){if(obj.value=="other"){$("mDesSpan").style.display="";}else{$("mDesSpan").style.display="none";}}
function chkPGuide(){
	$("mTypebg").style.background="";
	$("mMaxbg").style.background="";
	$("mDesbg").style.background="";
	$("mCapbg").style.background="";
	$("mNamebg").style.background="";
	$("mCountrybg").style.background="";
	$("mEmailbg").style.background="";
	if(!IsCheck("mType") && $("omType1").value=="" && $("omtype2").value==""){$("mTypebg").style.background="#EDB39D";alert("Please select or input Material Type !");return false;}
	if($("mMax").value==""){$("mMaxbg").style.background="#EDB39D";alert("Please input Maximum Feed Size !");$("mMax").focus();return false;}
	if($("aType").value!="supporting machine"){
		if($("mDes").value==""){$("mDesbg").style.background="#EDB39D";alert("Please input Products Desired !");$("mDes").focus();return false;}
	}
	if($("mCap").value==""){$("mCapbg").style.background="#EDB39D";alert("Please input Capacity of Plant required !");$("mCap").focus();return false;}
	if($("mName").value==""){$("mNamebg").style.background="#EDB39D";alert("Please input your Name !");$("mName").focus();return false;}
	if($("mCountry").value==""){$("mCountrybg").style.background="#EDB39D";alert("Please select your Country !");$("mCountry").focus();return false;}
	if($("mEmail").value==""){$("mEmailbg").style.background="#EDB39D";alert("Please input your Email !");$("mEmail").focus();return false;}else{if(!isEmail($("mEmail").value)){$("mEmailbg").style.background="#EDB39D";alert("Your E-Mail is error !");$("mEmail").focus();return false;}}
}

function isEmail(strEmail) {
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function setHits(ID,aTy){
	AjaxPost(1,"/Hits.asp","Act=UpdateHits&ID="+ID+"&aTy="+aTy,aTy);
}

var flag=false;
function DrawImage(ImgD,ImgW,ImgH){
	var image=new Image();
	var iwidth = ImgW;
	var iheight = ImgH;
	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;
		}
		}
	else{
		if(image.height>iheight){  
		ImgD.height=iheight;
		ImgD.width=(image.width*iheight)/image.height;		
		}else{
		ImgD.width=image.width;  
		ImgD.height=image.height;
		}
		}
	}
}
