document.write("<script src='/site/framework/clientside/styley.js' type='text/javascript'></script>");

function doNotDelete(){
	alert('This function should never be called.');
}

function showObject(obj, useiframehelper) {
	if (useiframehelper == null) useiframehelper = true;
	if (typeof(obj) == "string") obj = getObject(obj);
	if (obj) {
		if (getStyleByObj(obj, "display") == "none") {
			obj.displayattribute = "display";
		} else if (getStyleByObj(obj, "visibility") == "hidden") {
			obj.displayattribute = "visibility";
		}
		
		switch (obj.displayattribute) {
			case "visibility":	obj.style.visibility = "visible";
								break;
			
			case "display":		obj.style.display = "block";
								break;
		}
		//could not locate function "showIFrameHelper", not sure what this use to do
		//if (useiframehelper) if ((new RegExp("^(absolute)$","i")).test(getStyleByObj(obj, "position"))) showIFrameHelper(obj);
	}
}

function hideObject(obj, displayattribute) {
	if (typeof(obj) == "string") obj = getObject(obj);
	if (obj) {
		if (displayattribute == null) displayattribute = obj.displayattribute ? obj.displayattribute : (new RegExp("^(absolute)$","i")).test(getStyleByObj(obj, "position")) ? "visibility" : "display";
		switch (displayattribute) {
			case "visibility":	obj.style.visibility = "hidden";
								break;
			case "display":
			default:			obj.style.visibility = "";
								obj.style.display = "none";
								break;
		}
	}
}


var editing = false;
	
function editPopup(itemid){
	if(!editing){
		document.getAcuElementById("editcat_" + itemid).categoryname.select();
		editing = true;
		return true;
	}else{
		return false;
	}
}

// some browser sniffing:
document.version = parseFloat(navigator.appVersion);
document.hostApplication = navigator.appName.substring(0,3);
document.browserClass = parseInt(document.version);
				
if(document.browserClass < 4) 
{
 // redirect -- no CSS support
 // if you used &lt;script language=javascript1.2&gt; 
 // this won't be necessary
 // ALL this code will be ignored!
}
else      // isolate this setup from "modern" browsers!!
if(document.browserClass == 4) // might need to check NN5 browsers as well
{

	if(document.hostApplication == "Net") // got netscape?
	{
		  // need to "fake" the style attribute
		  // so we add a little misdirection
		  // by creating an object that will
		  // intercept the property setting.
		  // we make NN think it's setting properties 
		  // in A style object, when it is actually
		  // redirected to set the property to the actual layer
		   // and you might have thought it couldn't be done...
		 function _style()
		 {
		  this.layerRef = null;    // this will be set when <B style="COLOR: black; BACKGROUND-COLOR: #ffff66">getElementByID</B> is called

		  /* we don't actually need these -- it's just pseudocode
		  this.visibility = "";
		  this.top = 0;
		  this.left = 0;
		  */
						   
		   // very cool method in NN (only) -- 
		   // since these aren't "real" object properties
		   // it's more like a watchdog
		   // for more info -- check Netscape's docs
		  this.watch("visibility", 
		     function(id, old, nval) 
		      {  // set the "real" property of the layer here
		       eval("this.layerRef." + id + " = '" + nval + "'");
		       return nval; });
		        // you must return either old or nval
		  this.watch("top",
		     function(id, old, nval) {
		       eval("this.layerRef." + id + " = '" + nval + "'");
		      return nval;});
		  this.watch("left",
		     function(id, old, nval) {
		       eval("this.layerRef." + id + " = '" + nval + "'");
		      return nval;});
						  
		   // note: all the inline functions are exactly the same
		   //  you can cut'n'paste for each property you need to watch!
		}

	 // here we set up the "appearance" of a style property

	 Layer.prototype.style = new _style();
	  // each time a new layer is created, a new _style() object
	  // is attached to it
				    
	} // end if NN
	
				
	 // here, getElementById is getting declared by BOTH IE4 and NN4 browsers
	document.getAcuElementById = function(name)
	{
		if(document.hostApplication == "Net") // netscape 4
		{
			if (document.browserClass == 4){
				var lyr = eval("document." + name);
						   
			 // only need to do this once, but
			 // what the hey...
			 if(lyr.style != null) lyr.style.layerRef = lyr;
								    
			return lyr;
			}else{
				return document.layers('" + name + "');
			}
		}
		  else // IE
		  {
			return eval("document.all." + name);
		  }
  }
}else // end browserClass == 4
	{
	if(document.hostApplication == "Net"){
		document.getAcuElementById = function(name){
				if(!eval("document." + name)){
					return document.getElementById(name);
				}else{
					return eval("document." + name);
				}
			}
	}else
	{
		document.getAcuElementById = function(name){
				return document.getElementById(name);
			}
	}
}



//- for auto date footer
today=new Date();
y0=today.getFullYear();

var timeOn = null;
numMenus = 100;
document.onmouseover = hideAllMenus;
document.onclick = hideAllMenus;

//prevent js errors from showing (doesn't work in IE)
window.onerror = null;

// initialize hacks whenever the page loads
window.onload = initializeHacks;

function showMenu(menuNumber, eventObj) {
    hideAllMenus();
	if(document.layers) {
	img = getImage("img" + menuNumber);
 	x = getImagePageLeft(img);
 	y = getImagePageTop(img);
 	menuTop = y + 22; // LAYER TOP POSITION - should be set to the height of the image button
	eval('document.layers["menu'+menuNumber+'"].top="'+menuTop+'"');
 	eval('document.layers["menu'+menuNumber+'"].left="'+x+'"');
	}
	eventObj.cancelBubble = true;
    var menuId = 'menu' + menuNumber;
    if(changeObjectVisibility(menuId, 'visible')) {
		return true;
    } else {
		return false;
    }
}

// MENU MOUSE OVER 
function menuOver() {
 clearTimeout(timeOn);
}

// MENU MOUSE OUT 
function menuOut() {
 if(document.layers) {
 	timeOn = setTimeout("hideAllMenus()", 400);
  }
}

function hideAllMenus() {
    for(counter = 1; counter <= numMenus; counter++) {
		changeObjectVisibility('menu' + counter, 'hidden');
    }
}

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		styleObject.visibility = newVisibility;
		return true;
    } else {
	//we couldn't find the object, so we can't change its visibility
		return false;
    }
} 

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId).style;
    }else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId).style;
    }else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    }else {
		return false;
    }
} 

// SET BACKGROUND COLOR 
function getImage(name) {
  if (document.layers) {
    return findImage(name, document);
  }
  return null;
}

function findImage(name, doc) {
  var i, img;
  for (i = 0; i < doc.images.length; i++)
    if (doc.images[i].name == name)
      return doc.images[i];
  for (i = 0; i < doc.layers.length; i++)
    if ((img = findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  return null;
}

function getImagePageLeft(img) {
  var x, obj;
  if (document.layers) {
    if (img.container != null)
      return img.container.pageX + img.x;
    else
      return img.x;
  }
  return -1;
}

function getImagePageTop(img) {
  var y, obj;
  if (document.layers) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  return -1;
}


// ***********************
// hacks and workarounds *
// ***********************

// setup an event handler to hide popups for generic clicks on the document
function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
		&& (navigator.platform.indexOf('Mac') != -1)
		&& getStyleObject('blankDiv')) {
			window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
}

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

var popup = new String("");
var toolbar = new String("");
var resizebar = new String("");
var popupactive = false;
function initPopup(divpopup, divtoolbar, divresizebar, xOffset, yOffset, e){
	if(popupactive)
	{
		return false;
	}else{
		popupactive = true;
	}
	popup = divpopup;
	resizebar = divresizebar;
	toolbar = divtoolbar;
	document.getAcuElementById(toolbar).onmousedown=getPopupPosition;
	
	document.getAcuElementById(popup).style.pixelTop = (event.y - event.offsetY) + yOffset;
	document.getAcuElementById(popup).style.pixelLeft = (event.x - event.offsetX) + xOffset;
	
	try{
	if(document.getAcuElementById('onecolform'))	document.getAcuElementById('onecolform').style.visibility = "hidden";
	if(document.getAcuElementById('twocolform'))	document.getAcuElementById('twocolform').style.visibility = "hidden";
	if(document.getAcuElementById('threecolform'))	document.getAcuElementById('threecolform').style.visibility = "hidden";
	if(document.getAcuElementById('multicolform'))	document.getAcuElementById('multicolform').style.visibility = "hidden";
	}catch (e){}
	document.getAcuElementById(popup).style.visibility = "visible";
	return true;
}
						
function getPopupResizePosition(e)
{
	bMoving = false;
	bResizing = true;
	document.onmouseup=stopPopupResizing;
	document.onmousemove=resizePopupDiv;
	if(gOS() == "MAC"){
		X = event.clientX;
		Y = event.clientY;
	}else{
		X = event.x;
		Y = event.y;
	}
	document.onmousedown=null;	
							
	return true;
}
						
function stopPopupResizing(){
	bResizing = false;
	document.onmousemove=null;
	document.onmouseup=null;
							
	return true;
}
						
function resizePopupDiv(e){
	if(bResizing){
		if(gOS() == "MAC"){
			document.getAcuElementById(popup).style.height = parseInt(document.getAcuElementById(popup).style.height) + eval(event.clientY - Y);
			document.getAcuElementById(popup).style.width = parseInt(document.getAcuElementById(popup).style.width) + eval(event.clientX - X);
		}else{
			document.getAcuElementById(popup).style.height = parseInt(document.getAcuElementById(popup).style.height) + eval(event.y - Y);
			document.getAcuElementById(popup).style.width = parseInt(document.getAcuElementById(popup).style.width) + eval(event.x - X);			
		}
										
		if(gOS() == "MAC"){
			X = event.clientX;
			Y = event.clientY;
		}else{
			X = event.x;
			Y = event.y;
		}
		
		return true;
	}
}
						
function getPopupPosition(e)
{
	bResizing = false;
	bMoving = true;
	document.onmouseup=stopPopupMoving;
	document.onmousemove=movePopupDiv;

	if(gOS() == "MAC"){
		if(parseInt(document.getAcuElementById(popup).style.pixelTop) == 0) document.getAcuElementById(popup).style.pixelTop = event.clientY;
		if(parseInt(document.getAcuElementById(popup).style.pixelLeft) == 0) document.getAcuElementById(popup).style.pixelLeft = event.clientX;
	}else{
		if(parseInt(document.getAcuElementById(popup).style.pixelTop) == 0) document.getAcuElementById(popup).style.pixelTop = event.y;
		if(parseInt(document.getAcuElementById(popup).style.pixelLeft) == 0) document.getAcuElementById(popup).style.pixelLeft = event.x;		
	}
							
	if(gOS() == "MAC"){
		X = event.clientX;
		Y = event.clientY;			
	}else{
		X = event.x;
		Y = event.y;
	}

	document.onmousedown=null;	
	return true;
}
						
function stopPopupMoving(e){
	bMoving = false;
	document.onmousemove=null;
	document.onmouseup=null;
	return true;
}
						
function movePopupDiv(e){
	if(bMoving){
		if(gOS() == "MAC"){
			document.getAcuElementById(popup).style.pixelTop = parseInt(document.getAcuElementById(popup).style.pixelTop) + eval(event.clientY - Y);
			document.getAcuElementById(popup).style.pixelLeft = parseInt(document.getAcuElementById(popup).style.pixelLeft) + eval(event.clientX - X);
		}else{
			document.getAcuElementById(popup).style.pixelTop = parseInt(document.getAcuElementById(popup).style.pixelTop) + eval(event.y - Y);
			document.getAcuElementById(popup).style.pixelLeft = parseInt(document.getAcuElementById(popup).style.pixelLeft) + eval(event.x - X);
		}

		if(gOS() == "MAC"){
			X = event.clientX;
			Y = event.clientY;
		}else{
			X = event.x;
			Y = event.y;
		}
	}
					
	return true;
}

function getOffsetLeft(p) {
	return p.offsetParent != null ? getInt(p.offsetLeft) + getOffsetLeft(p.offsetParent)
		: (/^(absolute)$/i.test(getStyleByObj(p, "position")) ? getInt(p.offsetLeft) : getInt(getStyleByObj(p, "left")));
}
function getOffsetTop(p) {
	return p.offsetParent != null ?	getInt(p.offsetTop) + getOffsetTop(p.offsetParent)
		: (/^(absolute)$/i.test(getStyleByObj(p, "position")) ? getInt(p.offsetTop) : getInt(getStyleByObj(p, "top")));
}

var gIsSafari = false;
function getInt(i) {
	if (gIsSafari)
		return i.toString().replace(/\D+/,"").valueOf();
	else if (/\d/.test(i))
		return parseInt(i);
	else
		return 0;
}

function populateFields(chkThis, frmThis, arFieldsFrom, arFieldsTo){
	var i, j;
	var fefrom;
	var feto;
	var fetorep;
	
	if (chkThis.checked){
		for (i=0; i < arFieldsFrom.length; i++){
			if(frmThis[arFieldsTo[i]]) {
				fefrom = frmThis[arFieldsFrom[i]];
				feto = frmThis[arFieldsTo[i]];
				if (fefrom.tagName.toLowerCase() == "select" && feto.tagName.toLowerCase() == "select") {
					feto.options.length = 1;
					
					for (j=1; j < fefrom.options.length; j++) {
						fetorep = feto.options.add ? feto.options : feto;
						fetorep.add(document.createElement("option"));
						feto.options[feto.options.length-1].value = fefrom.options[j].value;
						feto.options[feto.options.length-1].text = fefrom.options[j].text;
					}
					feto.selectedIndex = fefrom.selectedIndex;
				} else {
					frmThis[arFieldsTo[i]].value = frmThis[arFieldsFrom[i]].value;
				}
			}
		}
	}else{
		for (i=0; i < arFieldsFrom.length; i++){
			if(frmThis[arFieldsTo[i]])
				frmThis[arFieldsTo[i]].value = '';
		}
	}
}



function getObject(objid) {
	var obj = (isAll) ? document.all[objid] : ((isW3C) ? document.getElementById(objid) : null);
	return obj;
}

function addEvent(obj, evtName, fn) {
	try{removeEvent(obj, evtName, fn)}catch(e){}
	if (obj.addEventListener) {
		obj.addEventListener(evtName, fn, false);
	} else if (obj.attachEvent) {
		obj.attachEvent('on' + evtName, fn);
	} else {
		obj['on' + evtName] = fn;
	}
}
						
function removeEvent(obj, evtName, fn) {
	try {
		if (obj.removeEventListener) {
			obj.removeEventListener(evtName, fn, false);
		} else if (obj.detachEvent) {
			obj.detachEvent('on' + evtName, fn);
		} else {
			obj['on' + evtName] = null;
		}
	} catch(e){}
}

//basic show/hide
function showhide (elid){
	var el = document.getElementById(elid);
	if (el.className =="off") {
		el.className = "on";}
	else {
		el.className = "off";}
}

/*********************
* FLASH DISPLAY CODE
*
**********************/

var UseFlash = 0;
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
	// Check for Flash version 4 or greater in Netscape
	var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
	if (plugin && parseInt(plugin.description.substring(plugin.description.indexOf(".")-1))>=4)
		UseFlash = 1;
} else if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	// Assume any Windows IE except for Windows 3.1 supports the OBJECT tag
	UseFlash = 1;
}
// Allow the cookie to override
if (document.cookie && (document.cookie.indexOf("FlashRenderOption=P") >= 0)) {
	UseFlash = 1;
} else if (document.cookie && (document.cookie.indexOf("FlashRenderOption=I") >= 0)) {
	UseFlash = 0;
}
function displayFlash(sFlashSource, sStaticSource, iWidth, iHeight) {
	if (UseFlash) {
		// Use Flash player
		document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+ iWidth +'" height="' + iHeight + '">');
		document.write('<PARAM name="movie" value="' + sFlashSource  + '">');
		document.write('<PARAM name="quality" value="high">');
		document.write('<PARAM name="wmode" value="transparent">');
		document.write('<PARAM name="LOOP" value="false">');
		document.write('<PARAM name="MENU" value="false">');
		document.write('<EMBED src="' + sFlashSource  + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" WMODE="transparent" type="application/x-shockwave-flash" width="'+ iWidth +'" height="' + iHeight + '" loop="false" menu="false">');
		document.write('</EMBED>');
		document.write('</OBJECT>');
		} else {
		document.write('<IMG src="' + sStaticSource + '" width="' + iWidth + '" height="' + iHeight + '" alt="">');
	}
}

/*********************
* END FLASH DISPLAY CODE
*
**********************/

//get the value of a parameters from the query string
function getQueryParam(name)
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

/*
replaceQueryParam finds and replaces a query string parameter in a url
*/
function replaceQueryParam(url,param,value) {
	var delim = '&'; if(url.indexOf('?') == -1) delim = '?'; 
	var re = new RegExp("([?|&])" + param + "=.*?(&|$)","i");
	
	if (url.match(re))
		return url.replace(re,'$1' + param + "=" + value + '$2');
	else
		return url + delim + param + "=" + value;
}

//get the value of a cookie by name, making this cookie check case-insensitive
function getCookieValue(name) {
    var nameEQ = name.toLowerCase() + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
	    var c = ca[i].toLowerCase();
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/*
get the value of a cookie by 
 name - cookie name
 value - value to set
 expire days - number of days after which this should expire
*/
function setCookieValue(name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=name + "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString() + '; path=/');
}

//set a test cookie
setCookieValue('testcookie','y',30);

/*
check to see if the client supports cookes
    returns true/false
*/
function cookiesSupported()
{
    if(getCookieValue('testcookie')!=null)
        return true;
        
    return false;
}

/*
check to see if we need to redirect to the choose country page
*/
function pclpCountryCheck(changecountry) {
    var countryID = getCookieValue('countryID');
    var countryName = ''; 
    var countryNotSet;
    countryNotSet = (countryID == null);
    
    //if(document.domain.indexOf('proclip') == -1)
    //    return;
    if(document.domain.indexOf('proclipusa.com') != -1) {
        countryID='0'; countryName='USA';
    }
    else if (document.domain.indexOf('proclipcanada.com') != -1) {
        countryID = '998'; countryName = 'Canada';
    }
    else if (document.domain.indexOf('tomtom-proclip.com') != -1) {
        countryID = '0'; countryName = 'USA';
    }
    else if (document.domain.indexOf('ipaqcarkits.com') != -1) {
        countryID = '0'; countryName = 'USA';
        setCookieValue('countryID', countryID, 30);
        setCookieValue('countryname', countryName, 30);
        countryNotSet = false;
    }
    else if(document.domain.indexOf('acumium') != -1) {
        countryID='0'; countryName='USA';
    }
    else if (document.domain.indexOf('localhost') != -1) {
        countryID = '0'; countryName = 'USA';
    }
    if ((cookiesSupported() && countryNotSet) || changecountry == 1) {
        var url = '/choosecountry.aspx';
        if (parent.location.protocol && window.location.hostname)
            url = parent.location.protocol + '//' + window.location.hostname + url;
        showProtoWindow("choosecountry", url);
    }
}
			
function showProtoWindow(id, a_href){
	var name = id + 'Proto';
	var win = new Window(name, {
		className: "dialog", 
		width:350, 
		height:140, 
		draggable:false, 
		minimizable:false, 
		maximizable:false, 
		resizable:false,
		closable:false, 
		url: a_href, 
		destroyOnClose:true, 
		zIndex:3000
	});
	win.showCenter(true, 275);
}


//for results paging
function populateDropdowns(form, currentperpage, currentpage, totalresults, ppfrom, ppstep, ppto, pplist) {
    var lst2 = form.pg;
    if (lst2 != null) {
        for (i = lst2.length; i >= 1; i--) {
            lst2.options[i] = null;
        }
        lst2.options.length = 1;
        index = 2;
        pages = totalresults / currentperpage - 1;
        for (i = 0; i < pages; i++) {
            var opt = document.createElement('option');
            opt.value = index;
            opt.text = index;
            lst2.options[index - 1] = opt;
            if ((currentpage > 0) && (index == currentpage)) {
                lst2.options[index - 1].selected = true;
            }
            index = index + 1;
        }
    }
    var lst = form.pp;
    if (lst != null) {
        if (ppfrom != '' && ppstep != '' && ppstep != '') {
            var val;
            var index, i;
            i = 0;
            for (val = ppfrom; val <= ppto; val = val + ppstep) {
                var opt = document.createElement('option');
                opt.value = val;
                opt.text = val;
                lst.options[i] = opt;
                if (val == currentperpage) {
                    lst.options[i].selected = true;
                }
                i++;
            }
        } else {
            var pparray = pplist.split('|');
            var num = pparray.length;
            var i;
            var val;
            for (i = 0; i < num; i++) {
                var opt = document.createElement('option');
                if (pparray[i] == 'All') {
                    val = totalresults;
                }
                else {
                    val = pparray[i];
                }
                opt.value = val;
                opt.text = pparray[i];
                lst.options[i] = opt;
                if (val == currentperpage)
                    lst.options[i].selected = true;
            }
        }
    }
}
