function clearField()
{
	if(document.find_form.find_spec.value == 'Keyword(s) or Part#')
		document.find_form.find_spec.value = '';
}
function checkBlank()  {
	if (document.search.keyword.value == "")  {
		window.alert("Please enter a word or part # to search for")
		return false;
		}
	return true;
}
function clearFieldD()
{
	if(document.find_form_diagram.find_spec.value == 'Keyword(s) or Part#')
		document.find_form_diagram.find_spec.value = '';
}
function checkCatalogRequest()  {
	if (document.catalogRequest.name.value == "")  {
		window.alert("Please enter Name");
		document.catalogRequest.name.focus();
		return false;
		}
	if (document.catalogRequest.address1.value == "")  {
		window.alert("Please enter Address");
		document.catalogRequest.address1.focus();
		return false;
		}
	if (document.catalogRequest.city.value == "")  {
		window.alert("Please enter City");
		document.catalogRequest.city.focus();
		return false;
		}		
	if (document.catalogRequest.postcode.value == "")  {
		window.alert("Please enter Postal Code");
		document.catalogRequest.postcode.focus();
		return false;
		}			
	return true;
}

function checkUsedParts()  {
	if (document.UsedParts.name.value == "")  {
		window.alert("Please enter Name");
		document.UsedParts.name.focus();
		return false;
		}
	if (document.UsedParts.address1.value == "")  {
		window.alert("Please enter Address");
		document.UsedParts.address1.focus();
		return false;
		}
	if (document.UsedParts.city.value == "")  {
		window.alert("Please enter City");
		document.UsedParts.city.focus();
		return false;
		}		
	if (document.UsedParts.state.value == "")  {
		window.alert("Please enter State");
		document.UsedParts.state.focus();
		return false;
		}			
	if (document.UsedParts.postcode.value == "")  {
		window.alert("Please enter Postal Code");
		document.UsedParts.postcode.focus();
		return false;
		}			
	if (document.UsedParts.comments.value == "")  {
		window.alert("Please enter your request");
		document.UsedParts.comments.focus();
		return false;
		}				
	return true;
}

function checkComments()  {
	if (document.commentForm.name.value == "")  {
		window.alert("Please enter Name");
		document.commentForm.name.focus();
		return false;
		}
	if (document.commentForm.FromEmail.value == "")  {
		window.alert("Please enter E-mail Address");
		document.commentForm.FromEmail.focus();
		return false;
		}
	if (document.commentForm.comments.value == "")  {
		window.alert("Please enter your comments");
		document.commentForm.comments.focus();
		return false;
		}					
	return true;
}

//----------------------------------------------------
function valNum(vfield, loVal, hiVal, emessage){
  if (vfield.value != "0" && vfield.value != "00") {
    if(!(vfield.value * 1)){
      window.alert(emessage);
      vfield.focus();
      return false;
    }
  }
  if ( (vfield.value * 1) < loVal || (vfield.value * 1) > hiVal) {
    window.alert(emessage);
    vfield.focus();
    return false;
  }
  return true;
}



//----------------------------------------------------
function countChanges()  {
	var count = 0;
	for (var i=0; i<document.forms.length; i++)
		for (var j=0; j<document.forms[i].elements.length; j++)
			if (document.forms[i].elements[j].name == "ChgFlag")
				if (document.forms[i].elements[j].value == "YES")
					count++;
	return count;
}

function checkNumeric()  {
	for (var i=0; i<document.forms.length; i++)
		for (var j=0; j<document.forms[i].elements.length; j++)
			if (document.forms[i].elements[j].name == "quantity")
				if (!valNum(document.forms[i].elements[j], 0, 99999, "Non-numeric or negative values not allowed"))  {
					return false;
				}
	return true;
}


function prepareAddItemParms(theForm, theAction)  {
	var theParms = "";
	var theCount = countChanges();

	if (theCount == 0)  {
		window.alert("You must specify a quantity to add an item to your order!");
		return false;
	}

	// Make sure all quantities are legitimate
	if (!checkNumeric()) return false;

	// Now build the hidden parms to send to the add macro
	for (var i=0; i<document.forms.length; i++)
		for (var j=0; j<document.forms[i].elements.length; j++)
			if (document.forms[i].elements[j].name == "ChgFlag")  {
				if (document.forms[i].elements[j].value == "YES") {
					var updForm = document.forms[i];
					theParms = theParms + "~" + updForm.quantity.value + "~" + updForm.prrfnbr.value + "~" + 
						updForm.prmenbr.value + "~" + "/cgi-bin/ncommerce3/ExecMacro/AddManyToCart.d2w/report";
				}
			}

	// Replace the last NextUrl to end the add items loop and return to the category page
	replaceSpot = theParms.lastIndexOf("~")
	theParms = theParms.substring(0,replaceSpot)
	theParms = theParms + "~" + "/cgi-bin/ncommerce3/ExecMacro/Ecklers/main.d2w/report?content=home" + "~";  // To send them to the Checkout Page instead use /cgi-bin/ncommerce3/OrderDisplay?status=P&merchant_rn=$(cgmenbr)

	theForm.action = theAction;
	theForm.AddParms.value = theParms;
//	theForm.AddCount.value = theCount;
	theForm.method = "POST";
	return true;
}


//----------------------------------------------------
function markItemChanged(theObject)  {
	theObject.form.ChgFlag.value = "NO";
	if (theObject.form.quantity.value > 0) {
		theObject.form.ChgFlag.value = "YES";
	}
}


//----------------------------------------------------
//   addUrlParm()
//   
//   Adds current location (href) to the 'url=' paramet
//        er off the Ancher call this
//
//	P.S.  This was a major pain to write .....
//   
//   Date Created: 8/7/00 - Cory Haney
//	theLink.href += "&url=";
//----------------------------------------------------
function addUrlParm(theLink) {
	theLocation = location.href
	if (theLocation.indexOf("https") == -1) {
		theLocation = "https" + theLocation.substring(4, theLocation.length)
	}
	theLink.href += "&url=" + escape(theLocation)
	return true;
}


//----------------------------------------------------
// Preload Images
//----------------------------------------------------
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];}}
}


//----------------------------------------------------
// Swap Image
//----------------------------------------------------
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_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;
}

//----------------------------------------------------
// Change property function
//----------------------------------------------------
function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

function MM_findObj(n, d) { //v3.0
  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); return x;
}


//----------------------------------------------------
// Show/Hide Layers
//----------------------------------------------------
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

//----------------------------------------------------
// Netscape 4.0 Resize fix
//----------------------------------------------------
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);

//----------------------------------------------------
// Display Status Message
//----------------------------------------------------
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

//----------------------------------------------------
// Set Text of Layer with intermediate function to adjust font in Netscape
//----------------------------------------------------
function setText(objName,x,newText){
  msg = '<font face="Arial" size="1" color="#FFFFFF">' + newText + '</font>'
  MM_setTextOfLayer(objName,x,msg)
}

function MM_setTextOfLayer(objName,x,newText) { //v3.0
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (navigator.appName=='Netscape') {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

//----------------------------------------------------
// Open Browser Window
//----------------------------------------------------

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//----------------------------------------------------
// Jump Menu
//----------------------------------------------------
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//----------------------------------------------------
// Simplified Extranet Navigation Functions (no dependency of previous position)
//----------------------------------------------------
function scrollOver(){
  if(navigator.appName == "Netscape"){
    MM_changeProp('bottomhalf','','top','173','LAYER')
  }
  else{
    MM_changeProp('bottomhalf','','style.top','173','LAYER')
  }
}

function scrollOut(){
  if(navigator.appName == "Netscape"){
    MM_changeProp('bottomhalf','','top','143','LAYER')
  }
  else{
    MM_changeProp('bottomhalf','','style.top','143','LAYER')
  }
}

//----------------------------------------------------
// Validate search box
//----------------------------------------------------
function validate_search ( )
{
    var valid = true;
	var errors= "";
	var modelID = parseInt(document.find_form.model.value);
	var year = document.find_form.m_year.value;
	
    if ( document.find_form.find_spec.value == "" || document.find_form.find_spec.value == "Keyword(s) or Part#" )
	{
        errors += "Please enter a value in the search box.\n";
        valid = false;
    }

	if(isNaN(modelID) && year != "ALL")
    {
        errors += "Please Select a Model.\n";
        valid = false;
    }
	
	if(valid == false)
	{
		alert(errors);	
	}
    return valid;
}
//----------------------------------------------------
// Validate buy quantity
//----------------------------------------------------
function validate_qty ( )
{
    valid = true;

    if ( document.Product.qty.value == "" )
    {
        alert ( "Please enter a valid quantity." );
        valid = false;
    }

    return valid;
}
function m_validate_qty ( form)
{
    valid = true;

    if ( form.qty.value == "" )
    {
        alert ( "Please enter a valid quantity." );
        valid = false;
    }

    return valid;
}
//----------------------------------------------------
// Set Car Year Cookie
//----------------------------------------------------
function set_car_year ( )
{
	var sel_idx = document.find_form.m_year.selectedIndex
	var caryear = document.find_form.m_year.options[sel_idx].value
	var theurl = location.href
	var path = location.pathname
	
	theurl = theurl.replace("PageNumber","PG");
	
	document.cookie = "CarYear=" + caryear;
	
	if (path != "/Default.asp" && path != "/")
	{
		location.href = theurl;
	}
}

//----------------------------------------------------
// Set results per page
//----------------------------------------------------
function changePageSize(page_size)
{
	var theurl = location.href
	var path = location.pathname
	
	theurl = theurl.replace("PageNumber","PG");
	
	document.cookie = "PageSize=" + page_size;
	
	if (path != "/Default.asp" && path != "/")
	{
		location.href = theurl;
	}
}

//----------------------------------------------------
// Retrieve Car Year Cookie
//----------------------------------------------------

function readCookie(cookieName){
  var searchName = cookieName + "="
  var cookies = document.cookie
  var start = cookies.indexOf(cookieName)
  if (start == -1){ // cookie not found 
    return ""
    }
  start += searchName.length  // start of cookie data  
  var end = cookies.indexOf(";", start)
  if (end == -1){
    end = cookies.length
    }
  return cookies.substring(start, end)
  }

//----------------------------------------------------
// Position cursor for product page
//----------------------------------------------------
	function product_onload()
	{
	document.Product.qty.focus();
	}

//----------------------------------------------------
// Media Player funcions
//----------------------------------------------------
   function StartMeUp()
   {
	   Player.controls.play();
   }

   function ShutMeDown()
   {
	   Player.controls.stop();
   }

//----------------------------------------------------
// Popup for size chart - cutter&buck
//----------------------------------------------------
function popuponcb()
{
	mywindow = window.open('sizechart_cb.asp','mywindow','width=800,height=500,status=no,scrollbars=yes,menubar=no,left=100,right=100');
} 

//----------------------------------------------------
// Popup for size chart - MH
//----------------------------------------------------
function popuponmh()
{
	mywindow = window.open('sizechart_mh.asp','mywindow','width=800,height=500,status=no,scrollbars=yes,menubar=no,left=100,right=100');
} 

//----------------------------------------------------
// Info Pop Up Window
//----------------------------------------------------
function Infopop(theURL)
{
	window.open(theURL,'400x200','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=450,height=250')
}
//----------------------------------------------------
// Dealer Info Pop Up Window
//----------------------------------------------------
function dealer_info() 
{
   chrome = "width=600," 
	 + "height=400," 
	 + "location=0," 
	 + "menubar=0,"
	 + "resizable=0,"
	 + "scrollbars=0,"
	 + "status=0," 
	 + "titlebar=0,"
	 + "toolbar=0,"
	 + "hotkeys=0,"
	 + "left=450,"
	 + "top=100";
   x=window.open('http://216.207.18.85/wholesale.htm','',chrome);
   x.focus();
}
//----------------------------------------------------
// International shipping info Pop Up Window
//----------------------------------------------------
function intl(weight,country) 
{
   
   chrome = "width=600," 
	 + "height=325," 
	 + "location=0," 
	 + "menubar=0,"
	 + "resizable=0,"
	 + "scrollbars=0,"
	 + "status=0," 
	 + "titlebar=0,"
	 + "toolbar=0,"
	 + "hotkeys=0,"
	 + "left=450,"
	 + "top=100";
   x=window.open('/intl.asp?ship_to_country=' + country + '&weight=' + weight,'',chrome);
   x.focus();
}	

//----------------------------------------------------
// Rush shipping info Pop Up Window
//----------------------------------------------------
function rush() 
{
   chrome = "width=600," 
	 + "height=200," 
	 + "location=0," 
	 + "menubar=0,"
	 + "resizable=0,"
	 + "scrollbars=0,"
	 + "status=0," 
	 + "titlebar=0,"
	 + "toolbar=0,"
	 + "hotkeys=0,"
	 + "left=450,"
	 + "top=100";
   x=window.open('/forms/rush.htm','',chrome);
   x.focus();
}

//----------------------------------------------------
// Rush shipping info Pop Up Window
//----------------------------------------------------
function cpnhelp() 
{
   chrome = "width=400," 
	 + "height=300," 
	 + "location=0," 
	 + "menubar=0,"
	 + "resizable=0,"
	 + "scrollbars=0,"
	 + "status=0," 
	 + "titlebar=0,"
	 + "toolbar=0,"
	 + "hotkeys=0,"
	 + "left=450,"
	 + "top=100";
   x=window.open('/forms/cpn_help.html','',chrome);
   x.focus();
}
//----------------------------------------------------
// Delivery Surcharge info Pop Up Window
//----------------------------------------------------
function ext_Shipping() 
{
   chrome = "width=600," 
	 + "height=200," 
	 + "location=0," 
	 + "menubar=0,"
	 + "resizable=0,"
	 + "scrollbars=0,"
	 + "status=0," 
	 + "titlebar=0,"
	 + "toolbar=0,"
	 + "hotkeys=0,"
	 + "left=450,"
	 + "top=100";
   x=window.open('http://www.ecklers.com/ex_shipping.htm','',chrome);
   x.focus();
}

