//Search Related Scripts--------------------------------------------------------------------//

	String.prototype.ltrim = function () {
		return this.replace(/^\s*/, "");
	}
		
	String.prototype.rtrim = function () {
		return this.replace(/\s*$/, "");
	} 
		
	String.prototype.trim  = function () {
		return this.ltrim().rtrim(); 
	}

	function ValidateFormSubmit2() {
		document.frmSearch2.zoom_query.value = document.frmSearch2.zoom_query.value.trim();

		if (document.frmSearch2.zoom_query.value == '') {
			alert('Please enter search text.');
			return false;
		}
		else {
			document.frmSearch2.action = '/search/search.asp';
			document.frmSearch2.target = '_top';
			document.frmSearch2.submit();
		}
	}
	
	
	function SetFocus() {
		document.frmSearch2.zoom_query.focus();
	}

//Popup Script-------------------------------------------------------------------------------//
	var OpenStr;
	function popNewWindow(PopURL,PopHeight,PopWidth,ScrollBar)
		{
			if (OpenStr && OpenStr.open && !OpenStr.closed) 
				{ OpenStr.close(); }
	        modalX = (screen.width-PopWidth) / 2
	        modalY = (screen.height-PopHeight) / 2

	        //Open New Window
	        var WinPlace = '"resizable=yes,scrollbars=' + ScrollBar + ',height=' + PopHeight + ',width=' + PopWidth + ',screenx=' + modalX + ',screenY=' + modalY + ',left=' + modalX + ',top=' + modalY + '"'
			OpenStr = window.open(PopURL, "SMSPopup", WinPlace)
        	OpenStr.focus()
	    }  

		
	function popUnderWindow(PopURL,PopHeight,PopWidth,ScrollBar)
		{
	        modalX = (screen.width-PopWidth) / 2
	        modalY = (screen.height-PopHeight) / 2

	        //Open New Window
	        var WinPlace = '"resizable=yes,scrollbars=' + ScrollBar + ',height=' + PopHeight + ',width=' + PopWidth + ',screenx=' + modalX + ',screenY=' + modalY + ',left=' + modalX + ',top=' + modalY + '"'
			var OpenStr = window.open(PopURL, "SMSPopunder", WinPlace)
        	window.focus();
	    }  

	function jumpto(address)
		{
		document.location=address
		window.focus();
		}

	var onsofo = true
		
//TimeZone Script------------------------------------------------------------//
    function openNewWindow(strURL)
        {
        modalX = (screen.width-780) / 2
        modalY = (screen.height-500) / 2
    
        //Open New Window
        var winHndl = window.open(strURL, "Forum_Pop", "scrollbars,menubar,location,toolbar,status,resizable,height=500,width=780,screenx=" + modalX + ",screenY=" + modalY + ",left=" + modalX + ",top=" + modalY)
        winHndl.focus()
        }            
     
    // set the user's timezone; keep it updated
    var now = new Date();
    var tzo = now.getTimezoneOffset();
    var tzo_i = new Image();
    //tzo_i.src = "tz.asp?tzo=" + tzo;

//Image swap script and preloader------------------------------------------------------------//
	//Best used with the RollOverLink function in sharedfunctions.asp
	var myimages=new Array()
	function preloadimages(){
		for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
		}
	}
	
	function changeImage(btn, img)
	    {
	        var objBtn = eval("document." + btn);
	        objBtn.src = img;
	    }

	function changeButton(btn, img)
	//Same as above, but for use with 'this' in <input> images
	    {
			img.src = btn
	    }

//Navigation Script-------------------------------------------------------------------------//

	var currentParent;
	var currentMenu;
	var menuToHide;
	var fadestep;
	var cleared = true;
	var browserdetect;
	
	
	function Pos(thisitem)
	{
		if(typeof(thisitem) != 'object') {thisitem = document.getElementById(thisitem);}
		var ww = thisitem.offsetWidth, hh = thisitem.offsetHeight;
		for (var xx = 0,yy = 0; thisitem != null; xx += thisitem.offsetLeft,yy += thisitem.offsetTop,thisitem = thisitem.offsetParent);
		return {Left:xx, Top:yy, Right:xx + ww, Bottom:yy + hh}
	}
	
	
	function SetParentClass(parentclass)
	{
	    if(currentParent != null)
	    {
	        if(currentParent.parentNode != null)
	        {
	            currentParent.parentNode.className=parentclass;
	            if(currentParent.parentNode.parentNode != null)
	                currentParent.parentNode.parentNode.className=parentclass;
	        }
	    }
	}
    
	function ShowMenu(thisitem, menu)
	{
		cleared = false;
		if (currentParent != thisitem)
		{   
		    SetParentClass('');
		    currentParent = thisitem;
        }
	    SetParentClass('selected');
		if(typeof(menu) != 'object')
			{menu = document.getElementById(menu);}
		if(currentMenu == menu)
			{
				if (!cleared) clearInterval(fadestep);
				currentMenu = null;
			}
		else if(currentMenu != null)
			{
				InstantHide(currentMenu);
				if (!cleared) clearInterval(fadestep);
				currentMenu = null;
			}
		currentMenu = menu;
		browserdetect=menu.filters? "ie" : typeof(menu.style.MozOpacity) == "string" ? "mz" : ""
		if (browserdetect == "ie")
			{currentMenu.filters.alpha.opacity = 100}
		else if (browserdetect == "mz")
			{currentMenu.style.MozOpacity = 1}
		currentMenu.style.left = Pos(currentParent).Left+"px";
		currentMenu.style.top = Pos(currentParent).Bottom+"px";
		currentMenu.style.visibility = 'visible';
	}
	
	
	function HoldMenu()
	{
		ShowMenu(currentParent, currentMenu);
	}
	
	
	function HideMenu(hideMenu)
	{
		if(typeof(hideMenu) != 'object')
			{hideMenu = document.getElementById(hideMenu);}
		if(menuToHide != hideMenu && menuToHide != null)
			{InstantHide(menuToHide);}
		menuToHide = hideMenu;
		FadeMenu();
    }


	function FadeMenu()
	{
		fadestep=setInterval("FadeLevel()",25)
	}
	
	function FadeLevel()
	{
	    if (browserdetect == "ie")
		    {menuToHide.filters.alpha.opacity-=10}
	    else if (browserdetect == "mz")
		    {menuToHide.style.MozOpacity-=.1}
	    else
		    {
		        menuToHide.style.visibility = 'hidden';
		        SetParentClass('');
		    }
			
	    if (menuToHide.style.MozOpacity != null)
	        if (menuToHide.style.MozOpacity == 0.0)
		    {
			        InstantHide(menuToHide);
			        menuToHide = null;
		    }
	    if (menuToHide != null)
	        if (menuToHide.filters != null)
	            if (menuToHide.filters.alpha.opacity == 0)
		        {
			            InstantHide(menuToHide);
			            menuToHide = null;
		        }
	}
	

	function InstantHide(iHideMenu) {
		clearInterval(fadestep);
		cleared=true
		iHideMenu.style.visibility = 'hidden';
        SetParentClass('');
	}
		

	function msdelay(mseconds) { //delay by the input milliseconds
		starttime = new Date()
		while (1) {
			nowtime = new Date()
			diff = nowtime-starttime
			if( diff > mseconds ) {break;}
		}
	}

//Form Submission Script (CSS Buttons)-------------------------------------------------------------------------//

    function submitForm(item)
    {
        // submit called from class button, if class isn't button (ie: buttonlock) then we ignore the click
        if (item.className == 'button')
        {
            // we need to disable all buttons on a page when one is clicked, most of the time only 1 button.
            disableSubmit();
            item.blur();
            return true;
        }
        
        item.blur();
        return false; // return false so it doesn't break the <A> class
    }
    
    function submitFormWithValue (item, frm, ele, val)
    {
        // submit called from class button, if class isn't button (ie: buttonlock) then we ignore the click
        if (item.className == 'button')
        {
            // we need to disable all buttons on a page when one is clicked, most of the time only 1 button.
            disableSubmit();
            document[frm][ele].value = val;
            document[frm].submit();
        }
        
        item.blur();
        return false; // return false so it doesn't break the <A> class    
    }
    
    var smt = 0;
    function enableSubmit()
    {
        if (smt != 1)
        {
            // need to enable all buttonlock items
            var e = document.getElementsByTagName('a');
            for (var i=0; i<e.length; i++)
                if (e[i].className == 'buttonlock') 
                    e[i].className = 'button';
            smt = 1;
        }
    }
    
    function disableSubmit()
    {
        if (smt != 2)
        {
            // need to switch all formsubmit buttons to a locked button
            var e = document.getElementsByTagName('a');
            for (var i=0; i<e.length; i++)
                if (e[i].className == 'button')
                    e[i].className = 'buttonlock';
            smt = 2;
        }
    }
    
// functions to submit a form using MSXML objects
    function xmlRfiSignup(div, form, submit)
    {
        /* div is a CSS class that surrounds the form, the entire element
         *  it should contain:  
         *      <div id=div+"form"> this contains the form and submit buttons
         *      <div id=div+"err"> this is the error message if the page doesn't return success
         *      <div id=div+"success"> this is the success message that replaces the form section once submitted
         *
         *  form is the name of the form to be submitted
         */
        
        document.getElementById(div+'err').style.display = 'none';
        var xmlHttp = null;
        if (window.XMLHttpRequest) 
        {
            // If IE7, Mozilla, Safari, and so on: Use native object.
            xmlHttp = new XMLHttpRequest();
        } else {
            if (window.ActiveXObject) 
            {
                // ...otherwise, use the ActiveX control for IE5.x and IE6.
                xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
            }
        }
        
        if (xmlHttp != null)
        {
            var frm = '';
            for (var frmx=0; frmx < document.forms[form].length; frmx++)
            {
                frm += '&' + escape(document.forms[form].elements[frmx].name) + '=' + escape(document.forms[form].elements[frmx].value);
            }
            frm = frm.substring(1);
            xmlHttp.open('POST', '/api/rfi', false);
            xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            xmlHttp.setRequestHeader('Content-length', frm.length);
            xmlHttp.setRequestHeader('Connection', 'close');
            xmlHttp.send(frm);
            
            var res = xmlHttp.responseText;
            switch (res)
            {
                case '-1':
                    // this means there was an error in the data, so we expose the error class
                    document.getElementById(div+'err').style.display = 'inline';
                    break;
                case '1':
                    // this means succes, we hide the form, and display the success
                    document.getElementById(div+'form').style.display = 'none';
                    document.getElementById(div+'success').style.display = 'inline';
                    break;
                default:                
                    // this means the form did not submit, or some other javascript issue.  Send a warning
                    alert ('We were unable to send data to the server, please make sure you have XMLHTTP enabled.');
                    break;
            }
        }
        
        /* return false so that the form doesn't submit from enter key */
        if (submit) return false;
    }
    
    var apiMessage;
    var apiDetail;
    function xmlApiCall(api, submit, callback, form)
    {
        /* api is the URL that is called
         * submit is true/false if a form should be submitted with the request
         * callback is the javascript function that is called when the Shadowbox window is closed (in case they don't want to fill out the info)
         * form is the name of the form to be submitted (optional: but required if submit is true)
         */
         
        var xmlHttp = null;
        if (window.XMLHttpRequest) 
        {
            /* if we have a native object, use it */
            xmlHttp = new XMLHttpRequest();
        } else {
            if (window.ActiveXObject) 
            {
                /* ie 5 & 6 try for ActiveX */
                xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
            }
        }
        
        if (xmlHttp != null)
        {
            if (submit)
            {
                var s = document.getElementById('sbStatus');
                s.innerHTML = '&nbsp;';
                var frm = '';
                for (var frmx=0; frmx < document.forms[form].length; frmx++)
                {
                    frm += '&' + escape(document.forms[form].elements[frmx].name) + '=' + escape(document.forms[form].elements[frmx].value);
                }
                frm = frm.substring(1);
                xmlHttp.open('POST', api, false);
                xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                xmlHttp.setRequestHeader('Content-length', frm.length);
                xmlHttp.setRequestHeader('Connection', 'close');
                xmlHttp.send(frm);
                var x = xmlHttp.responseXML;
                apiMessage = x.getElementsByTagName('Message')[0].childNodes[0].nodeValue;
                apiDetail = x.getElementsByTagName('Detail')[0].childNodes[0].nodeValue;
                if (apiMessage == 'Error')
                {
                    s.innerHTML = apiDetail;
                    document.getElementById('sbStatusSubmit').className = 'button';
                    if (document.getElementById('sbStatusDecline') != null) document.getElementById('sbStatusDecline').className = 'button';
                }  else {
                    Shadowbox.close();
                }
            } else {
                xmlHttp.open('GET', api, false);
                xmlHttp.send();
                var x = xmlHttp.responseXML;
                Shadowbox.open({
                    content: x.getElementsByTagName('Detail')[0].childNodes[0].nodeValue,
                    player: 'html',
                    title: x.getElementsByTagName('Message')[0].childNodes[0].nodeValue,
                    height: 220,
                    width: 525,
                    options: {onClose: callback, enableKeys: false, handleOversize: 'resize'}});
            }
        }
    }
    
    function promoCallback ()
    {
        if (apiMessage == 'OK')
        {
            /* promo can submit from the item or cart pages */
            if (document.forms['itemform'] != null)
            {
                document.itemform.Keycode.value = '';
                document.itemform.submit();
            }
            if (document.forms['MainForm'] != null)
            {
                document.MainForm.action.value = 'Update';
                document.MainForm.submit();
            }
        }
        else
        {
            /* they can't meet the keycode requirement, or have declined to.  So we reset them to a 999999 keycode */
            var kc = document.getElementsByName('Keycode');
            if (kc.length > 0)
                kc[0].value = '999999-9999';
            /* promo can submit from the item or cart pages */
            if (document.forms['itemform'] != null)
                document.itemform.submit();
            if (document.forms['MainForm'] != null)
            {
                document.MainForm.action.value = 'Update';
                document.MainForm.submit();
            }
        }
    }
    
    function upgradeCallback ()
    {
        if (apiMessage == 'OK')
        {
            document.itemform.upgradeserial.value = apiDetail;
            document.itemform.submit();
        }
        else
        {
            /* we were unable to validate the required upgrade serial number, so we don't want to submit the form */
            enableSubmit();
        }
    }
    
        
    function compUpgradeCallback ()
    {
        var f = getUploadFrame();
        if (f.location.href != 'about:blank')
        {
            // IE doesn't let us access an iframe as an XML document
            if (f.getElementsByTagName('Message').length == 0)
            {
                var start = f.body.innerText.indexOf('<Message>');
                var end = f.body.innerText.indexOf('</Message>');
                apiMessage = f.body.innerText.substring(start+9, end);
                start = f.body.innerText.indexOf('<Detail>');
                end = f.body.innerText.indexOf('</Detail>');
                apiDetail = f.body.innerText.substring(start+8, end);
            }
            else
            {
                apiMessage = f.getElementsByTagName('Message')[0].childNodes[0].nodeValue;
                apiDetail = f.getElementsByTagName('Detail')[0].childNodes[0].nodeValue;
            }
            if (apiMessage == 'Error')
            {
                document.getElementById('sbStatus').innerHTML = apiDetail;
                document.getElementById('sbStatusSubmit').className = 'button';
            }
            else
            {
                document.itemform.upgradeserial.value = apiDetail;
                document.itemform.submit();
            }
        }
    }
    
    function getUploadFrame ()
    {
        var ele = document.getElementById('uploadFrame');
        var frame;
        if (ele.contentDocument) {frame = ele.contentDocument;}
        if (ele.contentWindow) {frame = ele.contentWindow.document;}
        else {frame = window.frames['uploadFrame'].document;}
        return frame;
    }
    
    function uploadFile()
    {
        document.getElementById('sbStatus').innerHTML = '&nbsp;';
        document.sbForm.submit();
    }
	
	function openShadowbox(content, player, title, width, height){
	Shadowbox.open({
		content: content,
		player: player,
		title: title,
		width: width,
		height: height
		});
	};


