function loadXMLDoc(url) {
	var req;
	getObject("waitimage").style.display=""
	function processChange() {
	   	if (req.readyState == 4 && req.status == 200) {
   	   		getObject("searchResult").innerHTML = req.responseText;
   	  		getObject("waitimage").style.display="none"
   		}
   	}
   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
   	document.getElementById('abcd').value=new Date();
}

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}

function checkvaluebeforesubmit(){
	if(getObject("field_ohm").length<1 || getObject("field_ohm").value==null || getObject("field_ohm").value==""){
		alert("Please Enter Value for Resistance")
		getObject("field_ohm").focus()
		return false;
	}
	return true;
}

function show_part_picture(picsrc, divnum, divtype, arrtype){
   	image_1 = new Image()
   	image_1.src = picsrc
   	picwidth = image_1.width
   	picheight = image_1.height
   	newheight = picheight
   	newwidth = picwidth
	picaspectratio = picwidth / picheight
   	if(picwidth>400 || picheight>300){
   		if(picwidth>picheight){
   			newwidth = 400
   			newheight = newwidth / picaspectratio
   		} else if(picheight>picwidth){
   			newheight = 400
   			newwidth = newheight / picaspectratio
		}
	}
//	image_1.width = newwidth
//	image_1.height = newheight
//   alert(picwidth + ", " + picheight + ", " + newheight)
	if(divtype=='body'){
		getObject("body"+arrtype+"_div_picture"+divnum).innerHTML = "<img src="+picsrc+" width=" + newwidth + " height=" + newheight + "/>"
	} else {
		getObject("div"+arrtype+"_picture"+divnum).innerHTML = "<img src="+picsrc+" width=" + newwidth + " height=" + newheight + "/>"
	}
}

function checktheurl(){
	var aurl = document.URL
	alert(aurl);
}
function showmenu(elmnt){
	getObject(elmnt).style.visibility="visible"
}
function hidemenu(elmnt){
	getObject(elmnt).style.visibility="hidden"
}



function putinsubjectandbody(url, tp){
	if(tp==1){
		bodytext = "%0AI have noticed that there is an error on your page <b>http://www.gerberelec.com/browse/</b></a> while searching for <b>" + getObject("PartNo").value + "</b>.%0A"
		bodytext += "Would you please check on the following comments and get back to me:%0A%0A"
	} else {
		if(getObject("hiddenpart").value.length>0){
			bodytext = "%0AI have noticed that there is an error on your page <b>http://www.gerberelec.com/browse/</b></a> while searching for <b>" + getObject("hiddenpart").value + "</b>.%0A"
			bodytext += "Would you please check on the following comments and get back to me:%0A%0A"
		} else {
			bodytext = "%0AI have noticed that there is an error on your page <b>http://www.gerberelec.com/browse/</b></a> while browsing <b>" + getObject("hiddenmanu").value + "</b> products.%0A"
			bodytext += "Would you please check on the following comments and get back to me:%0A%0A"
		}
	}
	getObject(url).href="mailto:sales@gerberelec.com?subject=Gerber Electronics - Price Error&body=" + bodytext
}

function killsubjectandbody(url){
	getObject(url).href="mailto:sales@gerberelec.com"
}

function getData() {
	var req;
	getObject("waitimage").style.display=""
	function processChange() {
	   	if (req.readyState == 4 && req.status == 200) {
   	   		getObject("searchResult").innerHTML = req.responseText;
   	  		getObject("waitimage").style.display="none"
   		}
   	}
   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   if (req != null) {
   	  url = "/utility/datafromtable2.php?PartNo=" + getObject("PartNo").value;
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
   	document.getElementById('abcd').value=new Date();
}

function validateInputForFuse(){
	
}

function validateInputForPowerSupply(){
	
}

function validateInputForSearch(tp)
{
	if(tp=="capi"){
		var field_pf = document.getElementById("field_pf").value;
		if(field_pf.length == 0){
			alert("Please provide value for Capacitance to search Capacitors!");
			document.getElementById("field_pf").focus();
			return false;
		} else if (checkIsNumeric(field_pf)==false){
			alert("Please provide NUMERIC value for Capacitance to search Capacitors!");
			document.getElementById("field_pf").focus();
			return false;
		}
		var field_volts = document.getElementById("field_volts").value;
		if (field_volts.length > 0 && checkIsNumeric(field_volts)==false){
			alert("Please provide NUMERIC value for Voltage to search Capacitors!");
			document.getElementById("field_volts").focus();
			return false;
		}	
	} else if(tp == "resi"){
		var field_ohm = document.getElementById("field_ohm").value;
		if(field_ohm.length == 0){
			alert("Please provide value for Capacitance to search Resistors!");
			document.getElementById("field_ohm").focus();
			return false;
		} else if (checkIsNumeric(field_ohm)==false){
			alert("Please provide NUMERIC value for Capacitance to search Resistors!");
			document.getElementById("field_ohm").focus();
			return false;
		}
		var field_watt = document.getElementById("field_watt").value;
		if (field_watt.length > 0 && checkIsNumeric(field_watt)==false){
			alert("Please provide NUMERIC value for Watts to search Resistors!");
			document.getElementById("field_watt").focus();
			return false;
		}	
	} else if(tp == "fuse"){
		var field_amp = document.getElementById("field_amp").value;
		if(field_amp.length == 0){
			alert("Please provide value for Current to search Fuses!");
			document.getElementById("field_amp").focus();
			return false;
		} else if (checkIsNumeric(field_amp)==false){
			alert("Please provide NUMERIC value for Current to search Fuses!");
			document.getElementById("field_amp").focus();
			return false;
		}
		var field_volt = document.getElementById("field_volt").value;
		if (field_volt.length > 0 && checkIsNumeric(field_volt)==false){
			alert("Please provide NUMERIC value for volts to search fuses!");
			document.getElementById("field_volt").focus();
			return false;
		}	
	} else if(tp == "ps"){
		var field_volt = document.getElementById("field_volt").value;
		var field_watt = document.getElementById("field_watt").value;
		var field_output_1 = document.getElementById("field_output_1").value;
		var field_output_2 = document.getElementById("field_output_2").value;
		var field_output_3 = document.getElementById("field_output_3").value;
		var field_output_4 = document.getElementById("field_output_4").value;
		if(field_volt == "ANY" && field_watt.length < 1 && field_output_1.length < 1 && field_output_2.length < 1 && field_output_3.length < 1 && field_output_4.length < 1){
			alert("Please provide value in one of the fields!");
			return false;
		}
		if (field_watt.length > 0 && checkIsNumeric(field_watt)==false){
			alert("Please provide NUMERIC value for power to search power supplies!");
			document.getElementById("field_watt").focus();
			return false;
		}
		if (field_output_1.length > 0 && checkIsNumeric(field_output_1)==false){
			alert("Please provide NUMERIC value for output voltage to search power supplies!");
			document.getElementById("field_output_1").focus();
			return false;
		}
		if (field_output_2.length > 0 && checkIsNumeric(field_output_2)==false){
			alert("Please provide NUMERIC value for output voltage to search power supplies!");
			document.getElementById("field_output_2").focus();
			return false;
		}
		if (field_output_3.length > 0 && checkIsNumeric(field_output_3)==false){
			alert("Please provide NUMERIC value for output voltage to search power supplies!");
			document.getElementById("field_output_3").focus();
			return false;
		}
		if (field_output_4.length > 0 && checkIsNumeric(field_output_4)==false){
			alert("Please provide NUMERIC value for output voltage to search power supplies!");
			document.getElementById("field_output_4").focus();
			return false;
		}
	} else if(tp == "wire") {
		var field_awg	=	document.getElementById("field_awg").value;
		if(field_awg.length < 1)
		{
			alert("You must specify AWG to search Wires");
			document.getElementById("field_awg").focus();
			return false;
		} else if(checkIsNumeric(field_awg)==false) {
			alert("You must specify a numeric value for AWG to search Wires");
			document.getElementById("field_awg").focus();
			return false;
		}
	}
	return true;
}

function checkIsNumeric(sText){
   var ValidChars = "0123456789.+-/";
   var IsNumber=true;
   var Char;
   sText = sText.replace(" ", "+");
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}
