/* Use the following line to include:
<script language="JavaScript" src="../ClientIncludes/ClientHelp.js"></script>
*/
/* ------- The strDocTitle client variable defines the default title for every page. ------- 
	To change the page title, you can add a line similar to the following to the page (not the template)
	<script language="JavaScript">strDocTitle+=" - ISA Home Page";</script>
*/
var strDocTitle="Dealer Tire";

// The following function displays the page contents and hides the splash message on all template pages.
function handleSplash() {
	/*bmeloche - 07/18/2006 - Use of getElement function is unnecessary, and causes problems in non-IE browsers.
	Use document.getElementById instead. */
	//var objContent=getElement("tblContent");
	//var objSplash=getElement("divSplash");
	var objContent=document.getElementById("tblContent");
	var objSplash=document.getElementById("divSplash");
	//bmeloche - end change.
	objContent.style.display="block";
	objSplash.style.display="none";
	document.title=strDocTitle;
}

//  The following functions were taken from the legacy Dealer Tire site and are now used in the Marketing application (section)
function popup(url, name, width, height) {
       settings=
       "toolbar=no,location=no,directories=no,"+
       "status=no,menubar=no,scrollbars=yes,"+
       "resizable=yes,width="+width+",height="+height;

       MyNewWindow=window.open(url,name,settings);
 }
 
function popup2(url, name, width, height) {
       settings=
       "toolbar=no,location=no,directories=no,"+
       "status=no,menubar=no,scrollbars=no,"+
       "resizable=no,width="+width+",height="+height;

       MyNewWindow=window.open(url,name,settings);
 }

function submitform(){
	document.Main.submitted.value='yes';
	document.Main.submit();
}

//function validate(){
//	for(var i=0; i < frmItemSearchByItemNumber.txtQuantity1.value.length; i++){
//		var digit = frmItemSearchByItemNumber.txtQuantity1.value.charAt(i);
//		if(digit < "0" || digit > "9"){
//			if (digit == ","){
//				alert("Blah.");
//				return false;
//			} else {
//				return false;
//			}
//		}
//	}
//	return true
//}
 
function LoadMarketImages() {
	MM_preloadImages(
		'../images/Marketing/navbar/nav_r2_c02_f3.gif',
		'../images/Marketing/navbar/nav_r2_c02_f2.gif',
		'../images/Marketing/navbar/nav_r2_c02_f4.gif',
		'../images/Marketing/navbar/nav_r2_c04_f3.gif',
		'../images/Marketing/navbar/nav_r2_c04_f2.gif',
		'../images/Marketing/navbar/nav_r2_c04_f4.gif',
		'../images/Marketing/navbar/nav_r2_c06_f3.gif',
		'../images/Marketing/navbar/nav_r2_c06_f2.gif',
		'../images/Marketing/navbar/nav_r2_c06_f4.gif',
		'../images/Marketing/navbar/nav_r2_c08_f3.gif',
		'../images/Marketing/navbar/nav_r2_c08_f2.gif',
		'../images/Marketing/navbar/nav_r2_c08_f4.gif',
		'../images/Marketing/navbar/nav_r2_c10_f3.gif',
		'../images/Marketing/navbar/nav_r2_c10_f2.gif',
		'../images/Marketing/navbar/nav_r2_c10_f4.gif',
		'../images/Marketing/footer/privacy.gif',
		'../images/Marketing/footer/tsandcs.gif',
		'../images/Marketing/footer/requirements.gif',
		'../images/Marketing/footer/copyright.gif'
	);
}

function LoadMainMenuImages() {
	MM_preloadImages(
		'/DealerTire/images/MainMenu/MainMenu_r2_c1_f2.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c1_f4.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c1_f3.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c3_f2.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c3_f4.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c3_f3.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c5_f2.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c5_f4.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c5_f3.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c7_f2.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c7_f4.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c7_f3.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c9_f2.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c9_f4.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c9_f3.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c11_f2.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c11_f4.gif',
		'/DealerTire/images/MainMenu/MainMenu_r2_c11_f3.gif'
	);
}

// begin absolutely positioned scrollable area object scripts 
// Extension developed by David G. Miles 
// Original Scrollable Area code developed by Thomas Brattli 
// Additional feature added by Karl Dirck, MCP
function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion;
    this.dom=document.getElementById?1:0;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	this.ie=(document.all)?1:0;
	this.ns=(document.layers)?1:0;
    return this 
} 
bw=new verifyCompatibleBrowser() 
 
var speed=50 
 
var loop, timer 
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 
function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 
var initialised; 
function InitialiseScrollableArea(){ 
    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 
    initialised=true; 
} 
// end absolutely positioned scrollable area object scripts

/* ------- Additional useful functions (Cross Browser) -------*/

  // If true, IE4
  var allSupport = document.all!=null

  function getElement(elName) {
    // Get an element from its ID
    if (allSupport) {
      return document.all[elName] }
    else {}
      return document.layers[elName]
  }
  
  
  function setVisibility(el, bDisplay) {
    // Hide or show to tip
    if (bDisplay)
      if (allSupport)
        el.style.visibility = "visible" 
      else
        el.visibility = "show";
    else
      if (allSupport)
        el.style.visibility = "hidden"
      else
        el.visibility = "hidden"
  }
  
function setPosition(el) {
    // Set the position of an element
    src = window.event.srcElement
    if (allSupport) {
      el.style.pixelTop = getOffset(src, "Top")
      el.style.pixelLeft = getOffset(src, "Left")
    } else
    {
      el.top = src.y + 20 
      el.left = src.x 
    }
  }

/* ---------------- Client functions for ISA Dealers Online panel ---------------- */

function initDealersOnline() {
	// Set "Dealers Online" click to refresh
	objTable = document.all.tblContent.rows(0).cells(0).firstChild; // Get tblDealshipsOnline table element of tblContent
	objTd = objTable.rows(3).cells(0); // Get "Dealers Online" table cell
	objTd.onclick=refreshDealersOnline; // Set OnClick to refresh function - this is late bound in case the table loads before the script file.
	// Expand last Region by default
	expandDealersOnline();
	// Set Table readystatechange event to fire expand function after data refresh
	tblDealersOnline.onreadystatechange=expandDealersOnline;
}
function refreshDealersOnline() {
	xmlDealersOnline.src=xmlDealersOnline.src; // Reapply src to reload data
	//window.setTimeout("expandDealersOnline();", 1000);
}
function expandDealersOnline() {
	objDO = document.all.tblDealersOnline; // Get XML bound table element of Dealers Online
	if(objDO.readyState == "complete") {
		colRegionTbodies = objDO.children; // XML Bound tables automatically create TBODY tags
		if(colRegionTbodies.length>0) { // if TBODY tags exist
			objLastRegionRow = colRegionTbodies(colRegionTbodies.length-1).firstChild; // Get Last Region Row
			objLastRegionRow.click(); // fire click event to toggleDealer and display node
			objNextRow = objLastRegionRow.nextSibling; // Get next row containing child table
			objNextTable = objNextRow.all[3]; // Get child table skipping TD and two (2) comments
			colCarlineTbodies = objNextTable.children;  // Get TBODY tags from carline table
			if(colCarlineTbodies.length>0) { // if TBODY tags exist
				for (i=0; i<colCarlineTbodies.length; i++) { // Loop through Carline TBODY tags
					objCarlineRow = colCarlineTbodies(i).firstChild; // Get Row
					objCarlineRow.click(); // fire click event to toggleDealer and display node
				}
			}
		}
	}
}

/* ---------------- End of Client functions for ISA Dealers Online panel ---------------- */


	function getFocus(f){
	  if (f.UpdateData.value == 'yes') {
		f.UpdateData.value = 'no';
		f.submit();
	  }
	}

	function submitform2() {
		document.Main.submitted.value='yes';
		document.Main.alternative.value='yes';
		document.Main.submit();
	}


function CheckChoice(whichbox)
{
	with (whichbox.form)
	{
		//Handle differently, depending on type of input box.
		if (whichbox.type == "radio")
		{
			//First, back out the prior radio selection's price from the total:
			hiddentotal.value = eval(hiddentotal.value) - eval(hiddenpriorradio.value);
			//Then, save the current radio selection's price:
			hiddenpriorradio.value = eval(whichbox.price);
			//Now, apply the current radio selection's price to the total:
			hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price);
		}
		else
		{
			//If box was checked, accumulate the checkbox value as the form total,
			//Otherwise, reduce the form total by the checkbox value:
			if (whichbox.checked == false)
				{ hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value); }
			else 	{ hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value); }
		}

		//Ensure the total never goes negative (some browsers allow radiobutton to be deselected):
		if (hiddentotal.value < 0)
			{
			InitForm();
			}

		//Now, return with formatted total:
		return(formatCurrency(hiddentotal.value));
	}
}

//Define function to format a value as currency:
function formatCurrency(num) {
   // Courtesy of http://www7.brinkster.com/cyanide7/
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	   num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
			  num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

//Trims the spaces at the beginning and end of a string
function trim(string) {
string = string.replace(/^\s*/,'').replace(/\s*$/, '');
return string;
}

//Opens a window that displays a loading please wait message
function OpenLoadingPleaseWaitWindow() {
	LoadingPleaseWaitWindow = window.open("/DealerInfo/LoadingPleaseWait.cfm", "LoadingPleaseWait", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=300,height=150");
	//bmeloche - 05/19/2005 - If a popup blocker is working, this window would never have opened.  Test for the window before attempting to apply focus.
	//LoadingPleaseWaitWindow.focus();
	if(LoadingPleaseWaitWindow!=null) LoadingPleaseWaitWindow.focus();
}

//Close the LoadingPleaseWait Window
function CloseLoadingPleaseWaitWindow() {
	if(LoadingPleaseWaitWindow!=null) LoadingPleaseWaitWindow.close();
}


//Opens a window that displays a loading please wait message
function OpenPopupMessageWindow() {
	LoadingPopupMessageWindow = window.open("/DealerInfo/LoadingPopupMessage.cfm", "LoadingPopupMessage", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=300,height=250");
	LoadingPopupMessageWindow.focus();
}
function OpenPopupMessageWindow() {
	LoadingPopupMessageWindow = window.open("/DealerInfo/LoadingPopupMessage.cfm", "LoadingPopupMessage", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=300,height=240");
	LoadingPopupMessageWindow.focus();
}

//Close the LoadingPleaseWait Window
function ClosePopupMessageWindow() {
	if(LoadingPopupMessageWindow!=null) LoadingPopupMessageWindow.close();
}


// ******************************************************************
// This function accepts a string variable and verifies if it is a
// proper date or not. It validates format matching either
// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
// has the proper number of days, based on which month it is.

// The function returns true if a valid date, false if not.
// ******************************************************************

function isDate(dateStr) {

    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) {
        alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
        return false;
    }

    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];

    if (month < 1 || month > 12) { // check month range
        alert("Month must be between 1 and 12.");
        return false;
    }

    if (day < 1 || day > 31) {
        alert("Day must be between 1 and 31.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert("Month "+month+" doesn't have 31 days!")
        return false;
    }

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            alert("February " + year + " doesn't have " + day + " days!");
            return false;
        }
    }
    return true; // date is valid
}

//SUGGESTED ORDERING
function helpPopup(helpStr){
	//You must have a div with an ID of help declared on the page that calls
	
	

	// Set-up to use getMouseXY function onMouseMove
	
	document.all['help'].style.visibility='visible';
	
	
	document.all['help'].style.left = event.clientX + document.body.scrollLeft;
	document.all['help'].style.top = event.clientY + document.body.scrollTop;
	document.all['help'].innerHTML = helpStr + "<a nohref onClick=javascript:document.all.help.style.visibility=\'hidden\';><p align=right>[X]close help</a>";
}

//CUSTOMER CONTACT


function CCStepAction(theForm, newOpt, currVal){
	var box = theForm['action'];
	var box2 = theForm['step'];
	
	if(box2.value.length > 0){
		box.disabled=false;
		 
	}else{
		box.options[0] = new Option('--SELECT A PROCESS STEP--', '');	
		box.selectedIndex = 0;
		box.disabled=true;
		return 1;
	}
	
	list = newOpt;
					
	for(i=0;i<list.length-2;i+=2)
	{
		box.options[i/2+1] = new Option(list[i], list[i+1]);
		//alert(box.options[i/2+1].text);
		if(box.options[i/2+1].text == currVal){
			
			box.selectedIndex = i/2+1;
		}
	}	
	box.options.length=list.length/2;
	
	return 1;
}

function CCDisableForm(theForm){
	var box = theForm.elements;
	for (var i=0;i<box.length;i++)
	{
		box[i].disabled = true;
	}	
	return true;
}

function textAreaCount( field, countfield, maxlimit ) {

    tempCount = maxlimit - field.value.length;
	
	if(tempCount < 0){
		countfield.style.color = 'red'; 
		countfield.style.fontWeight = 'bold';
		countfield.value = (tempCount*-1) + ' characters passed limit!'; 
	}
	else{
		countfield.style.color = 'black';
		countfield.style.fontWeight = 'normal';
		countfield.value = tempCount + ' characters available.';	
	}
	
}
function textAreaCountDown( field, countfield, maxlimit ) {

    tempCount = maxlimit - field.value.length;
	
	if(tempCount < 0){
		countfield.style.color = 'red'; 
		countfield.style.fontWeight = 'bold';
		countfield.value = (tempCount*-1) + ' characters passed limit!'; 
		alert('You exceeed the allowable limit');
		countfield.blur() = 'true';
	}
	else{
		countfield.style.color = 'black';
		countfield.style.fontWeight = 'normal';
		countfield.value = tempCount + ' characters available.';	
	}
	
} 

function CCContact(theform,jtitle,jfname,jlname,jwphone,jextphone,jcphone,jfax,jchamp,jemail,jactive,jcontactid){
	
	theform.title.value =jtitle;
	theform.fname.value = jfname;
	theform.lname.value = jlname;
	theform.wphone.value = jwphone;
	theform.cphone.value = jcphone;
	theform.extphone.value = jextphone;
	theform.fax.value = jfax;
	theform.email.value = jemail;
	if(jactive == 0){
		theform.active.checked = true;
	}
	if(jchamp == 1){
		theform.programchampion.checked = true;
	}	
	theform.contactid.value = jcontactid;
	document.images['error1'].src = document.images['blank'].src;
	document.images['error2'].src = document.images['blank'].src;
	document.images['error3'].src = document.images['blank'].src;
	document.images['error4'].src = document.images['blank'].src;
}

function CCContactReset(which){

	var pass=true
	var first=-1
	if (document.images){
	for (i=0;i<which.length;i++){
	var tempobj=which.elements[i]
	 if (tempobj.type=="text"){
	  eval(tempobj.value="")
	  if (first==-1) {first=i}
	 }
	 else if (tempobj.type=="checkbox") {
	  eval(tempobj.checked=0)
	  if (first==-1) {first=i}
	 }
	 else if (tempobj.col!="") {
	  eval(tempobj.value="")
	  if (first==-1) {first=i}
	 }
	}
	}
	return false
}


function CCStepcontact(theForm, newOpt, currVal){
	var box = theForm['Q#questionByID.questionsID#_$'];
	var box2 = theForm['Q#questionByID.questionsID#_$'];
	var box3 = theForm['Q#questionByID.questionsID#_$'];
	if(box2.value.length > 0){
		box.disabled=false;
		 
	}else{
		box.options[0] = new Option('--SELECT --', '');	
		box.selectedIndex = 0;
		box.disabled=true;
		return 1;
	}
	
	list = newOpt;
					
	for(i=0;i<list.length-2;i+=2)
	{
		box.options[i/2+1] = new Option(list[i], list[i+1]);
		//alert(box.options[i/2+1].text);
		if(box.options[i/2+1].text == currVal){
			
			box.selectedIndex = i/2+1;
		}
	}	
	box.options.length=list.length/2;
	
	return 1;
}

