var timer;
var lastTab 											= "";

function showChunk(chunkName) {
	if(lastTab != "" && $("divlayer_"+lastTab) != null) {
		$("divlayer_"+lastTab).hide();
	}
	lastTab 											= chunkName;
	if($("divlayer_"+chunkName) != null) {
		$("divlayer_"+chunkName).show();
	}
}

// PDC DRILL BITS

function resetTabs() {
	clearTimeout(timer);
	$("div1").src 										= "/images/pdc_drill/div.gif";
	$("div2").src 										= "/images/pdc_drill/div.gif";
	$("div3").src 										= "/images/pdc_drill/div.gif";
	$("div4").src 										= "/images/pdc_drill/div.gif";
	$("product").src 									= "/images/pdc_drill/btn_product.gif";
	$("cutting").src 									= "/images/pdc_drill/btn_cutting.gif";
	$("gage").src 										= "/images/pdc_drill/btn_gage.gif";
	$("hydraulics").src 								= "/images/pdc_drill/btn_hydraulics.gif";
	$("other").src 										= "/images/pdc_drill/btn_other.gif";
}

function swapImage(btnName) {
	resetTabs();
	$(btnName).src 										= "/images/pdc_drill/btn_"+btnName+"_ov.gif";
	
	switch(btnName) {
		case "product":
			$("div1").src 								= "/images/pdc_drill/div_product_grey.gif";
			break;
		case "cutting":
			$("div1").src 								= "/images/pdc_drill/div_grey_black.gif";
			$("div2").src 								= "/images/pdc_drill/div_black_grey.gif";
			break;
		case "gage":
			$("div2").src 								= "/images/pdc_drill/div_grey_black.gif";
			$("div3").src 								= "/images/pdc_drill/div_black_grey.gif";
			break;
		case "hydraulics":
			$("div3").src 								= "/images/pdc_drill/div_grey_black.gif";
			$("div4").src 								= "/images/pdc_drill/div_black_grey.gif";
			break;
		default:
			$("div4").src 								= "/images/pdc_drill/div_grey_black.gif";
			break;
	}
}

function swapBack() {
	swapImage(lastTab);
}

function swapImageBack() {
	clearTimeout(timer);
	if(lastTab!="") {
		timer											= setTimeout("swapBack()", 120);
	} else {
		resetTabs();	
	}
}

function callDefault(btnName) {
	swapImage(btnName);
	showChunk(btnName);
}



// ROLLER CONE DRILL BITS

function resetRollerTabs() {
	clearTimeout(timer);
	$("div1").src 										= "/images/roller_cone/div.gif";
	$("div2").src 										= "/images/roller_cone/div.gif";
	$("div3").src 										= "/images/roller_cone/div.gif";
	$("div4").src 										= "/images/roller_cone/div.gif";
	$("div5").src 										= "/images/roller_cone/div.gif";
	$("div6").src 										= "/images/roller_cone/div.gif";
	$("product").src 									= "/images/roller_cone/btn_product.gif";
	$("features").src 									= "/images/roller_cone/btn_features.gif";
	$("technologies").src 								= "/images/roller_cone/btn_technologies.gif";
	$("premium").src 									= "/images/roller_cone/btn_premium.gif";
	$("shirttail").src 									= "/images/roller_cone/btn_shirttail.gif";
	$("journal").src 									= "/images/roller_cone/btn_journal.gif";
	$("open").src 										= "/images/roller_cone/btn_open.gif";
}

function swapImageRoller(btnName) {
	resetRollerTabs();
	$(btnName).src 										= "/images/roller_cone/btn_"+btnName+"_ov.gif";
	
	switch(btnName) {
		case "product":
			$("div1").src 								= "/images/roller_cone/div_features_black.gif";
			break;
		case "features":
			$("div1").src 								= "/images/roller_cone/div_grey_black.gif";
			$("div2").src 								= "/images/roller_cone/div_black_grey.gif";
			break;
		case "technologies":
			$("div2").src 								= "/images/roller_cone/div_grey_black.gif";
			$("div3").src 								= "/images/roller_cone/div_black_grey.gif";
			break;
		case "premium":
			$("div3").src 								= "/images/roller_cone/div_grey_black.gif";
			$("div4").src 								= "/images/roller_cone/div_black_grey.gif";
			break;
		case "shirttail":
			$("div4").src 								= "/images/roller_cone/div_grey_black.gif";
			$("div5").src 								= "/images/roller_cone/div_black_grey.gif";
			break;
		case "journal":
			$("div5").src 								= "/images/roller_cone/div_grey_black.gif";
			$("div6").src 								= "/images/roller_cone/div_black_grey.gif";
			break;
		default:
			$("div6").src 								= "/images/roller_cone/div_grey_black.gif";
			break;
	}
}

function swapRollerBack() {
	swapImageRoller(lastTab);
}

function swapImageRollerBack() {
	clearTimeout(timer);
	if(lastTab!="") {
		timer											= setTimeout("swapRollerBack()", 120);
	} else {
		resetRollerTabs();	
	}
}

function callRollerDefault(btnName) {
	swapImageRoller(btnName);
	showChunk(btnName);
}




// MINING HOME PAGE

function resetMiningTabs() {
	clearTimeout(timer);
	$("div1").src 										= "/images/mining/hometabs/div.gif";
	$("div2").src 										= "/images/mining/hometabs/div.gif";
	
	$("coal").src 										= "/images/mining/hometabs/btn_coal.gif";
	$("copper").src 									= "/images/mining/hometabs/btn_copper.gif";
	$("gold").src 										= "/images/mining/hometabs/btn_gold.gif";
}

function swapImageMining(btnName) {
	resetMiningTabs();
	$(btnName).src 										= "/images/mining/hometabs/btn_"+btnName+"_ov.gif";
	
	switch(btnName) {
		case "coal":
			$("div1").src 								= "/images/mining/hometabs/div_white_gray.gif";
			break;
		case "copper":
			$("div1").src 								= "/images/mining/hometabs/div_gray_white.gif";
			$("div2").src 								= "/images/mining/hometabs/div_white_gray.gif";
			break;
		default:
			$("div2").src 								= "/images/mining/hometabs/div_gray_white.gif";
			break;
	}
}

function swapMiningBack() {
	swapImageMining(lastTab);
}

function swapImageMiningBack() {
	clearTimeout(timer);
	if(lastTab!="") {
		timer											= setTimeout("swapMiningBack()", 120);
	} else {
		resetMiningTabs();	
	}
}

function callMiningDefault(btnName) {
	swapImageMining(btnName);
	showChunk(btnName);
}



function CompareDate(a, b) {
	datA = new Date(a[0]);
	datB = new Date(b[0]);
	if (datA < datB) { 
		return -1; 
	} else {
		if (datA > datB) {
			return 1; 
		} else {
			return 0; 
		}
	}
}

var requestCatalog = function() {
	var theForm = document.frmSubscribe;
	
	if(!theForm.chkBlasthole.checked &&  !theForm.chkRidgeback.checked) {
		alert("Please select a catalog.");
		return false;
	}

	if(!theForm.chkPDF.checked &&  !theForm.chkCopy.checked) {
		alert("Please select delivery method.");
		return false;
	}

	var temp = theForm.first.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please first name.");
		theForm.first.focus();
		return false;
	}
	
	var temp = theForm.last.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please last name.");
		theForm.last.focus();
		return false;
	}
	
	var temp = theForm.title.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter job title.");
		theForm.title.focus();
		return false;
	}
	
	var temp = theForm.company.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter company.");
		theForm.company.focus();
		return false;
	}
	
	var temp = theForm.city.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter city.");
		theForm.city.focus();
		return false;
	}
	
	var temp = theForm.country.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please select country.");
		theForm.country.focus();
		return false;
	}
	
	var temp = theForm.phone.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter phone.");
		theForm.phone.focus();
		return false;
	}
	
	var temp = theForm.fax.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter fax.");
		theForm.fax.focus();
		return false;
	}
	
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	var temp = theForm.email.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter email.");
		theForm.email.focus();
		return false;
	}
	
	if(((temp.search(exclude) != -1)||(temp.search(check)) == -1)||(temp.search(checkend) == -1)) {
		alert("Invalid email address.");
		theForm.email.focus();
		return false;
	}
	
	var temp = theForm.reemail.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter email again.");
		theForm.reemail.focus();
		return false;
	}
	
	if(((temp.search(exclude) != -1)||(temp.search(check)) == -1)||(temp.search(checkend) == -1)) {
		alert("Invalid re-verify email address.");
		theForm.reemail.focus();
		return false;
	}
	
	if(theForm.email.value != theForm.reemail.value) {
		alert("Email doesn't match.");
		theForm.reemail.focus();
		return false;
	}
}

var checkSubscribe = function() {
	var theForm = document.frmSubscribe;
	
	var temp = theForm.txtFirstName.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please first name.");
		theForm.txtFirstName.focus();
		return false;
	}
	
	var temp = theForm.txtLastName.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please last name.");
		theForm.txtLastName.focus();
		return false;
	}
	
	var temp = theForm.txtJobTitle.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter title.");
		theForm.txtJobTitle.focus();
		return false;
	}
	
	var temp = theForm.txtCompany.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter company.");
		theForm.txtCompany.focus();
		return false;
	}
	
	var temp = theForm.txtCity.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter city.");
		theForm.txtCity.focus();
		return false;
	}
	
	var temp = theForm.cboCountry.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please select country.");
		theForm.cboCountry.focus();
		return false;
	}
	
	var temp = theForm.txtPhone.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter phone.");
		theForm.txtPhone.focus();
		return false;
	}
	
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	var temp = theForm.txtEmail.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter email.");
		theForm.txtEmail.focus();
		return false;
	}
	
	if(((temp.search(exclude) != -1)||(temp.search(check)) == -1)||(temp.search(checkend) == -1)) {
		alert("Invalid email address.");
		theForm.txtEmail.focus();
		return false;
	}
	
	var temp = theForm.txtVerify.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter email again.");
		theForm.txtVerify.focus();
		return false;
	}
	
	if(((temp.search(exclude) != -1)||(temp.search(check)) == -1)||(temp.search(checkend) == -1)) {
		alert("Invalid re-verify email address.");
		theForm.txtVerify.focus();
		return false;
	}
	
	if(theForm.txtEmail.value != theForm.txtVerify.value) {
		alert("Email doesn't match.");
		theForm.txtEmail.focus();
		return false;
	}
}