// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
// Function to Clear intial value in a form field
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
// Function for buy bits popup page
function buyBit(what){
	if(what == 'yes'){
		opener.location = "/carbide_bits.htm"
	}
	window.close();
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function chkEmail(objName){
// Check for @ and .
	var checkStr = objName;
	var hasAt = false;
	var hasDot = false;
	for (i = 0;  i < checkStr.value.length;  i++){
		ch = checkStr.value.charAt(i);
		if (ch == "@")
			hasAt = true;
		if (ch == ".")
			hasDot = true;
	}
	if (!hasAt){	
		return false;
	}
	if (!hasDot){	
		return false;
	}
}
function validateRequestInfo() {
	e = true;
	alert_str = 'Your information request had the following errors:';
	if(document.requestForm.name.value == '') {
		alert_str += '\nMISSING Company Name.';
		e = false;
	}
	if(document.requestForm.address.value == '') {
		alert_str += '\nMISSING Address.';
		e = false;
	}
	if(document.requestForm.city.value == '') {
		alert_str += '\nMISSING City.';
		e = false;
	}
	if(document.requestForm.state.value == '') {
		alert_str += '\nMISSING State/Province.';
		e = false;
	}
	if(document.requestForm.country.value == '') {
		alert_str += '\nMISSING Country.';
		e = false;
	}				
	if(document.requestForm.phone.value == '') {
		alert_str += '\nMISSING Phone Number.';
		e = false;
	}
	else {
		if(document.requestForm.phone.value.length < 7) {
			alert_str += '\nINVALID Phone Number.';
			e = false;
		}	
	}
	if(document.requestForm.email.value == '') {
		alert_str += '\nMISSING E-Mail Address.';
		e = false;
	}
	else {
		if(chkEmail(document.requestForm.email) == false) {
			alert_str += '\nINVALID E-Mail Address.';
			e = false;
		}
	}
	if(e)
		return true;
	else {
		alert(alert_str);
		return false;
	}
}		

function validate_reg() {
		e = true;
		alert_str = 'ERROR, your application could not be submitted:\n';
		if(document.form1.firstname.value == '') {
			alert_str += 'MISSING First Name.\n';
			e = false;
		}
		if(document.form1.lastname.value == '') {
			alert_str += 'MISSING Last Name.\n';
			e = false;
		}
		if(document.form1.address1.value == '') {
			alert_str += 'MISSING Address line 1.\n';
			e = false;
		}
		if(document.form1.city.value == '') {
			alert_str += 'MISSING City.\n';
			e = false;
		}
		if(document.form1.phone.value == ''){
			alert_str += 'MISSING Phone Number.\n';
			e = false;
		}
		if(document.form1.emailaddress.value == '') {
			alert_str += 'MISSING Email Address.\n';
			e = false;
		}
		if(document.form1.UserName.value == '') {
			alert_str += 'MISSING UserName.\n';
			e = false;
		}
		if(document.form1.password.value == '') {
			alert_str += 'MISSING Password.\n';
			e = false;
		}
		else {
			if(document.form1.password.value != document.form1.confirmpassword.value ) {
				alert_str += 'Password and Password Confirmation do not match!\n';
				e = false;
			}
		}
		if(e)
			return true;
		else {
			alert(alert_str);
			return false;
		}
}		

function open_win(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function close_window() {
    window.close();
}
// Function for Pricing pages - Collapsable Repeaters
 function ToggleDisplay(id)
  {
    var elem = document.getElementById('d' + id);
    if (elem) 
    {
      if (elem.style.display != 'block') 
      {
        elem.style.display = 'block';
        elem.style.visibility = 'visible';
      } 
      else
      {
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
      }
    }
  }

//Track Search
//created Kevin Innes
//date: 5/11/2007
 var http_request = false; 
   function makeRequest(search) 
   { 
       if (window.XMLHttpRequest) {
           http_request = new XMLHttpRequest(); 
       } else if (window.ActiveXObject) {
           http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 
       var URL = "../_controls/Ajax-Track.aspx";
       var theData = "search=" + search;
       http_request.open('POST', URL, true); 
       http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
       http_request.send(theData); 
   } 

var imgs = new Array('/images/bg/satifaction-guarantee.gif','/images/bg/savings.gif','/images/bg/secure-connection.gif','images/bg/shipping.gif');
var alt = new Array('Satisfaction Guaranteed or your money back','Savings up to 70% on your order','Online shopping over a secure connection','Same-day shipping on all orders');
function randomImage() {
	var num = Math.floor(Math.random()*(imgs.length));
	document.write('<img src="'+imgs[num]+'" alt="'+alt[num]+'" width="541" height="111" id="image-rotator" name="image-rotator"/>')	
}



