/*
	Global js file for ragar company.inc
	Nick Gundry,
*/ 

document.write("<script type=\"text/javascript\" src=\"/_jscripts/dropmenu.js\"></"+"script>");
document.write("<script type=\"text/javascript\" src=\"/_jscripts/validate.js\"></"+"script>");
document.write("<script type=\"text/javascript\" src=\"/_jscripts/cart.js\"></"+"script>");

function switchDiv(div_id)
{
  var style_sheet = getStyleObject(div_id);
  if (style_sheet)
  {
    changeObjectVisibility("net");
  }
  else 
  {
    alert("sorry, this only works in browsers that do Dynamic HTML");
  }
}

function checkNet(cookie){
	if ((cookie.value == "NET 30") || (cookie.value == "Request NET 30 Terms") || (cookie.value == "COD")){
		changeObjectVisibility("net", "hidden");
	} else {
		changeObjectVisibility("net", "visible");
	}
}


function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get the object's stylesheet
    var styleObject = getStyleObject(objectId);

    // then if we find a stylesheet, set its visibility
    // as requested
    //
	//if (styleObject.visibility == "hidden"){
	//	var newVisibility = "visible";
	//} else {
	//	var newVisibility = "hidden";
	//}
	
    if (styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	return false;
    }
}
function CheckBrowser() {
	
	if (document.getElementById) {
		browser = 'dom';
	} else if (document.layers) {
		browser = 'nn4';
	} else if (document.all) {
		browser = 'ie4';
	} 
	return browser;
}

var nav = CheckBrowser();

// -----------------------------------------------------------------
function quickSearch() {
 // just add the location, and put in some validation if required
 alert("this will perform the quick search");
 // document.quickSearch.submit();
}


// ----------------------------------------------------------------
function rollOver(imgName,state) {

	switch(state) {
	
		case "over":
			if(document.images) {
			// get the image type
				suffixType = imgName.src.substring(imgName.src.lastIndexOf("."),imgName.src.length);
				// swap to new image
				if (imgName.src.indexOf("_over") == -1) {
					imgName.src = imgName.src.substring(0,(imgName.src.indexOf(suffixType))) + "_over" + suffixType;
				}
			}
		break;
		
		case "out":
			if(document.images) {
				// get the image type
				suffixType = imgName.src.substring(imgName.src.lastIndexOf("."),imgName.src.length);
				
				// swap image back to original
				if (imgName.src.indexOf("_over") != -1) {
					imgName.src = imgName.src.substring(0,(imgName.src.indexOf("_over"))) + suffixType;
				}
			}		
		break;	
	} 

}

// ------------------------------------------------------------------------
// function to suppress javascript errors, (Nobody's perfect ;) )
function noErrorMessages () { return true; }
window.onerror = noErrorMessages;


function phoneFilter(form, format) {

	var input = form.value;

	if(input.length > 0) { //do not perform if empty input

		var numbers = ""; //store all the numbers here

		//process to remove non-numbers and spaces
		for(var i = 0; i < input.length; i++) {
			var chars = input.charAt(i);
			if(!(isNaN(chars) || chars == " ")) numbers += chars;
		}

		//remove country code, if any
		if(numbers.substring(0, 2) == "47") numbers = numbers.substring(2, numbers.length);

		var output = ""; //assign numbers here

		//assign numbers to chosen format
		var n = 0, i = 0;
		while(i < format.length && n < numbers.length) {
			var chars = format.charAt(i);
			if(chars == "#") {
				output += numbers.charAt(n++)
			} else {
				output += chars;
			}
			i++;
		}

		//give alert if length is less than 8.
		if(numbers.length < 10) {
			alert("The number must be 10 digits");
			form.select();
		}

		form.value = output; //output to form
	}
}


function printpage() {
window.print();  
}

function changeColor(color_id) {

	document.addToCart.colorbox.value = color_id;

}


function copyFields(checkField) {	

  mailingFields = new Array('b_address1','b_address2', 'b_suite', 'b_city', 'b_zip')
  shippingFields = new Array('s_address1','s_address2', 's_suite', 's_city', 's_zip')

	if (document.mainForm.orderShippingUseMailing.checked == true) {
		for (i=0; i <mailingFields.length; i++) {
			fieldOne = "document.mainForm."+shippingFields[i]+"";
			fieldTwo = "document.mainForm."+mailingFields[i]+"";
			eval(""+fieldOne+".value = "+fieldTwo+".value");
		}
			fieldCountry = "document.mainForm.s_country.selectedIndex = document.mainForm.b_country.selectedIndex";
			fieldState = "document.mainForm.s_state.selectedIndex = document.mainForm.b_state.selectedIndex";
			eval(fieldState);
			eval(fieldCountry);

	} 
}

function openpopup(){
var popurl="/catalog/sizechart.php"
winpops=window.open(popurl,"","width=655,height=820,scrollbars='no',resizable,")
}
