<!--

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_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_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 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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// AJAX FUNCTIONS
function getXMLHTTP()
 {
 	try {
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(ex) {
		//either this is not IE, or it is a version of IE which does not support XMLHTTP
		var notIECompatibleXMLHTTP=true;
	}
	if (notIECompatibleXMLHTTP==true) {
		try {
			request_o = new XMLHttpRequest();
		} catch(ex) {
			//we can't use AJAX because this browser is not compatible.
			request_o = false;
		}
	}

	return request_o;
}

var responseObjectId = null;		// the id of the object to receive the response data
var useCustomFn = false;			// use a custom function to process the results - calling page must have function: processResults(response)
var showLoading = false;			// whether to display the loading div
function sendAjaxRequest(url,objId,loading,customFn) {
		responseObjectId = objId;
		useCustomFn = customFn;
		showLoading = loading;
		
		if (showLoading)
			toggleLayer('loading',true);
			
		http = getXMLHTTP();
		if (http) {
			http.open('get',  url);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

			/* Define a function to call once a response has been received. This will be our
				handleProductCategories function that we define below. */
			http.onreadystatechange = receiveAjaxResponse;
			/* Send the data. We use something other than null when we are sending using the POST
				method. */
			http.send(null);
		} else {
			alert("xmlHTTP cannot be created");
		}
		
}

function receiveAjaxResponse() {
	if (http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element
			that we can find: innerHTML. */
			//alert(response);
		if (!useCustomFn) {
			document.getElementById(responseObjectId).value = response;
			//alert(response);
		} else {
			processResults(response);		// this function must exist in the calling page
		}
		
		if (showLoading)
			toggleLayer('loading',false);
	}
}

function numericOnly(myfield, e, dec)
{	// numericOnly(this,event,true/false);
	var key;
	var keychar;

	if (window.event)
 		key = window.event.keyCode;
	else if (e)
 		key = e.which;
	else
 		return true;

	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) )
 		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
 		return true;
	// decimal point jump
	else if (dec && (keychar == "."))
 	{
 		myfield.form.elements[dec].focus();
 		return false;
 	}
	else
 		return false;
}
//-


function toggleLayer(whichLayer,on) {
  	var elem, vis;
  	if (document.getElementById) // this is the way the standards work
    	elem = document.getElementById(whichLayer);
  	else if (document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  	else if (document.layers) // this is the way nn4 works
    	elem = document.layers[whichLayer];
  	vis = elem.style; 
  	// if the style.display value is blank we try to figure it out here
//  	if (vis.display=='' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
//    	vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
//  	vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
	vis.display = (on ? 'block' : 'none');
}

function highlightRow(rowId,sclass) {
	if (document.getElementById(rowId))
		document.getElementById(rowId).className = sclass;
}


// ------------------- Floating Layer at Cursor Position 
// http://bontragerconnection.com/ and http://www.willmaster.com/
// Version: July 28, 2007
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; } 
function AssignPosition(d) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	} 
	else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	if(document.all) {
		cX += rX; 
		cY += rY; 
	}
	d.style.left = (cX+10) + "px";
	d.style.top = (cY+10) + "px";
}
function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none"; 
}
function ShowContent(d,helpIdx) {
	if(d.length < 1) { return; }
	var h = document.getElementById('fieldHelp');
	h.innerHTML = arrHelp[helpIdx];
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block"; 
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") { dd.style.display = "block"; }
	else { dd.style.display = "none"; }
}

function disableField(disable, fieldName) {
	var fld = document.getElementById(fieldName);
	
	if (fld) {
		fld.style.backgroundColor = (disable ? "#CCCCCC" : "#FFFFFF");
		fld.disabled = disable;
	} 
}

function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }

   return IsNumber;
}

/* ----- accordion vertical menu ----- */

var openAccordion = '';
var openTap = '';
var TimeToSlide = 300.0;
function runAccordion(index, contentHeight)
{
  var nID = "Accordion" + index + "Content";
  var clickedTap = "tap" + index;
  if(openAccordion == nID) {
    nID = '';
	clickedTap = '';
  }

  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "'," + contentHeight + ", '" + openTap + "', '" + clickedTap + "')", 33);

  openAccordion = nID;
  openTap = clickedTap;
}

function animate(lastTick, timeLeft, closingId, openingId, ContentHeight, closingTap, openingTap)
{
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;

  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);

  if(timeLeft <= elapsedTicks)
  {
    if(opening != null) {
        opening.style.height = 'auto';  //opening.style.height = ContentHeight + 'px';
        if (document.getElementById(openingTap)) document.getElementById(openingTap).innerHTML = '-&nbsp;';
    }
    if(closing != null)
    {
        //closing.style.display = 'none';
        closing.style.height = '0px';
        if (document.getElementById(closingTap)) document.getElementById(closingTap).innerHTML = '+';
    }
    return;
  }

  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }

  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft + ",'"
      + closingId + "','" + openingId + "'," + ContentHeight + ", '" + closingTap + "', '" + openingTap + "');");
}

function retrieveStores(currentSelection) {
     var state = document.getElementById('state');	
     if (state) { 
         if (state.value.length >= 2 && state.value.length <= 3) { 
             sendAjaxRequest('contact_store.php?s='+state.value+'&c='+currentSelection,'td_stores',false,true);
         }
     }
}

function processResults(response) {  
     var s = document.getElementById('td_stores');
     if (s) {
         s.innerHTML = response;
     }
}
-->
