function addSearchProvider() {
    try {
        window.external.AddSearchProvider('http://www.gunsamerica.com/ga_opensearch.xml');
    }
    catch (e) {
        alert("Currently, the search provider function requires either Firefox 2+ or Internet Explorer 7.");
        return;
    }
}

function bookmarkSite(title,url) {
    if (window.sidebar) // firefox
	    window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print) { // opera
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar');
	    elem.click();
    } 
    else if(document.all)// ie
	    window.external.AddFavorite(url, title);
}

function highlight() {
    var elements = document.getElementsByTagName("input");
    for (i=0; i < elements.length; i++) {
        if((elements[i].getAttribute('type')=="text") || (elements[i].getAttribute('type')=="password")) {
            elements[i].onfocus=function() {
                this.style.borderColor='#000000';
                this.style.backgroundImage='';
                this.style.backgroundColor='#ffff00';
            };

            var checkBoxLogin=false;
            var checkBoxDisplay=false;
            try{
                if(CheckLoginIDBox == elements[i].id)
                    checkBoxLogin=true;
            } catch(e){}
            try{
                if(CheckDisplayNameBox == elements[i].id)
                    checkBoxDisplay=true;
            } catch(e){}
            
            if(checkBoxLogin){
                elements[i].onblur=function() {
                    this.style.borderColor='#000000';
                    this.style.backgroundColor='#ffffff';
                    CheckLoginID(this.value);
                };
            }
            else if(checkBoxDisplay){
                elements[i].onblur=function() {
                    this.style.borderColor='#000000';
                    this.style.backgroundColor='#ffffff';
                    CheckDisplayName(this.value);
                };
            }
            else{
                elements[i].onblur=function() {
                    this.style.borderColor='#000000';
                    this.style.backgroundColor='#ffffff';
                };
            }
        }
        if(elements[i].getAttribute('type')=="textarea") {
            elements[i].onfocus=function() {
                this.style.borderColor='#000000';
                this.style.backgroundImage='';
                this.style.backgroundColor='#ffff00';
            };
            elements[i].onblur=function() {
                this.style.borderColor='#000000';
                this.style.backgroundColor='#ffffff';
            };
        }
    }
}

var helpURL ;
function expandDiv(strDiv) {
	document.getElementById(strDiv).style.display = 'inline';
}

function contractDiv(strDiv) {
	document.getElementById(strDiv).style.display = 'none';
}

function flipDiv(strDiv) {
	if (document.all) {
		if ((document.all[strDiv].style.display == 'none') || (document.all[strDiv].style.display == '')) {
			document.all[strDiv].style.display = 'block';
		} else {
			document.all[strDiv].style.display = 'none' ;
		}
	} else if (document.getElementById) {
		if ((document.getElementById(strDiv).style.display == 'none') || (document.getElementById(strDiv).style.display == '')) {
			document.getElementById(strDiv).style.display = 'inline';
		} else {
			document.getElementById(strDiv).style.display = 'none';
		}
	}
}

function flipAsInfoOpen(num) {
    if(num == 1) {
        flipOpen('popMedium', 'imgRelevantAdInfo', 'To advertise in this location your product or service must be 100% relevant to the firearm or product on this page. So you must be either the manufacturer of this firearm/product or provide something that is 100% relevant to it. <br /><br />Please click the <img src="/images/icon_info_noborder.gif" /> if you wish to submit your advertising request.', '');
    }
    else if(num == 2) {
        flipOpen('popMedium', 'imgAdditionalAdInfo', '<b>GunsAmerica Pay Per Click Advertising</b><br/>Anyone with a legal product or service may advertise in this location.  Please click the <img src="/images/icon_info_noborder.gif" /> to sign up for GunsAmerica Pay Per Click Advertising and we will walk you through the sign up and posting process.<br/><br/><b>Affiliates</b><br/>If you would like to carry this advertisement on your website and receive part of the fee, please go to<br/>gunsamerica.com/Affiliate<br/>to visit our Affiliates page. After a simple application process and basic instructions you can start making profit from your popular website or blog today.', '');
    }
    else if(num == 3) {
        flipOpen('popMedium', 'imgLocalAdInfo', '<b>GunsAmerica Go Local Pay Per Click Advertising</b><br/>These advertisements appear based on the location of your internet connection.  If you would like to advertise to a local market and appear in these links, use the Pay Per Click Advertising Wizard and select the proximity based campaign.<br/><br/>Please click the <img src="/images/icon_info_noborder.gif" /> to sign up for GunsAmerica Pay Per Click Advertising and we will walk you through the sign up and posting process.', '');
    }
}

function flipOpen(strDiv, strAnchor, strHTML, arrHideDivs, intLeft, intTop) {
    var lpos = findPos(document.getElementById(strAnchor))[0] + 20;
    var tpos = findPos(document.getElementById(strAnchor))[1] + 20;
	
	if (intLeft) lpos += intLeft;
	if (intTop) tpos += intTop;
	
	document.getElementById(strDiv).style.left = lpos + "px";
	document.getElementById(strDiv).style.top = tpos + "px";
	
	if (strHTML != 'skip') {
	    // set up the html for the pop...
	    if (strDiv == "popSmall") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popSmall_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='136' height='11' border='0'><br /></td>";
            popHTML += "</tr><tr><td style='background-image:url(/images/bg_popSmall_mid.png); background-repeat:repeat-y; padding-left:10px; padding-right:15px; overflow:scroll; width:136px'>" + strHTML + "</td></tr>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popSmall_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='136' height='16' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else if (strDiv == "popMedium") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popMedium_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='194' height='5' border='0'><br /></td>";
            popHTML += "</tr><tr><td width='194' style='background-image:url(/images/bg_popMedium_mid.png); background-repeat:repeat-y; padding-right:10px;padding-left:10px;padding-top:3px;padding-bottom:5px;overflow:scroll;'>";
            popHTML += "<table width='174' cellpadding='0' cellspacing='0'><tr><td>";
            popHTML +=  strHTML ;
            popHTML += "</td></tr></table>";
            popHTML += "</td></tr>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popMedium_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='194' height='18' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else if (strDiv == "popLarge") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popLarge_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='348' height='8' border='0'><br /></td>";
            popHTML += "</tr><tr><td style='background-image:url(/images/bg_popLarge_mid.png); background-repeat:repeat-y; padding-left:10px; padding-right:15px; overflow:scroll; width:348px;'>";
            popHTML += "<table width='328' cellpadding='0' cellspacing='0'><tr><td>";
            popHTML +=  strHTML ;
            popHTML += "</td></tr></table>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popLarge_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='348' height='18' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popXLarge_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='535' height='8' border='0'><br /></td>";
            popHTML += "</tr><tr><td style='background-image:url(/images/bg_popXLarge_mid.png); background-repeat:repeat-y; padding-left:10px; padding-right:15px; overflow:scroll; width:348px;'>";
            popHTML += "<table width='515' cellpadding='0' cellspacing='0'><tr><td>";
            popHTML +=  strHTML ;
            popHTML += "XXXXXX</td></tr></table>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popXLarge_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='535' height='8' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    }
    	
	    document.getElementById(strDiv).innerHTML = popHTML;
	}
	
	fadeInGA(strDiv, 0);
}

function flipOpenPos(strDiv, strHTML, arrHideDivs, intLeft, intTop, intFade) {
    var lpos = parseInt(intLeft);
    var tpos = parseInt(intTop);
	
	document.getElementById(strDiv).style.left = lpos + "px";
	document.getElementById(strDiv).style.top = tpos + "px";
	
	if (strHTML != 'skip') {
	    // set up the html for the pop...
	    if (strDiv == "popAS") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
	        popHTML += "<td><img src='/images/as/bg_pop_top.png' alt='' width='321' height='20' border='0'><br /></td>";
            popHTML += "</tr><tr><td style='background-image:url(/images/as/bg_pop_mid.png); background-repeat:repeat-y; padding-left:10px; padding-right:15px; overflow:scroll; width:321px'>" + strHTML + "</td></tr>";
            popHTML += "<tr><td><img src='/images/as/bg_pop_btm.png' alt='' width='321' height='5' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else if (strDiv == "popSmall") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popSmall_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='136' height='11' border='0'><br /></td>";
            popHTML += "</tr><tr><td style='background-image:url(/images/bg_popSmall_mid.png); background-repeat:repeat-y; padding-left:10px; padding-right:15px; overflow:scroll; width:136px'>" + strHTML + "</td></tr>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popSmall_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='136' height='16' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else if (strDiv == "popMedium") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popMedium_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='194' height='5' border='0'><br /></td>";
            popHTML += "</tr><tr><td width='194' style='background-image:url(/images/bg_popMedium_mid.png); background-repeat:repeat-y; padding-right:10px;  padding-left:10px;padding-top:3px; overflow:scroll;'>";
            popHTML += "<table width='174' cellpadding='0' cellspacing='0'><tr><td>";
            popHTML +=  strHTML ;
            popHTML += "</td></tr></table>";
            popHTML += "</td></tr>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popMedium_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='194' height='18' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else if (strDiv == "popLarge") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popLarge_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='348' height='8' border='0'><br /></td>";
            popHTML += "</tr><tr><td style='background-image:url(/images/bg_popLarge_mid.png); background-repeat:repeat-y; padding-left:10px; padding-right:15px; overflow:scroll; width:348px;'>";
            popHTML += "<table width='328' cellpadding='0' cellspacing='0'><tr><td>";
            popHTML +=  strHTML ;
            popHTML += "</td></tr></table>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popLarge_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='348' height='18' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else if (strDiv == "popXLarge") {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td style='background-image:url(/images/bg_popXLarge_top.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='535' height='8' border='0'><br /></td>";
            popHTML += "</tr><tr><td style='background-image:url(/images/bg_popXLarge_mid.png); background-repeat:repeat-y; padding-left:10px; padding-right:15px; overflow:scroll; width:348px;'>";
            popHTML += "<table width='515' cellpadding='0' cellspacing='0'><tr><td>";
            popHTML +=  strHTML ;
            popHTML += "</td></tr></table>";
            popHTML += "<tr><td style='background-image:url(/images/bg_popXLarge_btm.png); background-repeat:no-repeat;'><img src='/images/spacer.gif' alt='' width='535' height='18' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    } else {
	        popHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
            popHTML += "<td><img src='/images/bg_popXXLarge_top.png' alt='' width='665' height='16' border='0'><br /></td>";
            popHTML += "</tr><tr><td background='/images/bg_popXXLarge_mid.png' style='padding-left:10px; padding-right:15px; overflow:scroll; width:650;' align='center'>";
            popHTML += "<table width='650' cellpadding='0' cellspacing='0'><tr><td>";
            popHTML +=  strHTML ;
            popHTML += "</td></tr></table>";
            popHTML += "<tr><td><img src='/images/bg_popXXLarge_btm.png' alt='' width='665' height='18' border='0'><br /></td>";
            popHTML += "</tr></table>";
	    }
    	
	    document.getElementById(strDiv).innerHTML = popHTML;
	}
	if (intFade == 1) {
	    fadeInGA(strDiv, 0);
	} else {
	    document.getElementById(strDiv).style.display = "";
	}
}

function flipClose(strDiv) {
    fadeOut(strDiv, 100);
	document.getElementById(strDiv).style.display = "none";
}

function flipAsInfoClose(num) {
    var strDiv = '';
    if(num == 1) {
        strDiv='popMedium';
    }
    else if(num == 2) {
        strDiv='popMedium';
    }
    else if(num == 3) {
        strDiv='popMedium';
    }
    flipClose(strDiv);
}

function flipCloseXXL() {
	document.getElementById("popXXLarge").style.display = "none";
}

function OpenBuyingConsoleDiv(id, AnchorID)
{
try{
    if (openDiv == ""){}
    else
    {
        var divID=document.getElementById(openDiv);
        divID.style.display="none";
    }
    openDiv = id;
    var divID=document.getElementById(id);
    fadeInGA(id,0);
    //divID.style.display="";
    var anchorObj = document.getElementById(AnchorID);
    var pos = findPos(anchorObj);
    divID.style.position = "absolute";
    //alert(pos[0]);
    //alert(pos[1]);
    divID.style.left = 530;
    divID.style.top = 101;
    }
    catch(e){}
}
function CloseBuyingConsoleDiv()
{
    try{
    if (doTimeOut)
    {
        var divID=document.getElementById('divBuyingConsole');
        fadeOut('divBuyingConsole',99);
        //divID.style.display="none";
        var openDiv = "";
    }
    }catch(e){}
}


function OpenSaveSearchDiv()
{
try{
    if (openDiv == ""){}
    else
    {
        var divID=document.getElementById(openDiv);
        divID.style.display="none";
    }
    openDiv = 'divSaveSearch';
    var divID=document.getElementById('divSaveSearch');
    fadeInGA('divSaveSearch',0);
    //divID.style.display="";
    var anchorObj = document.getElementById('spanSaveSearchLink');
    var pos = findPos(anchorObj);
    divID.style.position = "absolute";
    //alert(pos[0]);
    //alert(pos[1]);
    divID.style.left = pos[0] + 'px';
    divID.style.top = (pos[1] + 14) + 'px';
    }
    catch(e){}
}
function CloseSaveSearchDiv()
{
    try{
    if (doTimeOut)
    {
        var divID=document.getElementById('divSaveSearch');
        fadeOut('divSaveSearch', 99);
        //divID.style.display="none";
    }
    }catch(e){}
}


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  try {
      // IE/Win
      obj.style.filter = "alpha(opacity:"+opacity+")";
      
      // Safari<1.2, Konqueror
      obj.style.KHTMLOpacity = opacity/100;
      
      // Older Mozilla and Firefox
      obj.style.MozOpacity = opacity/100;
      
      // Safari 1.2, newer Firefox and Mozilla, CSS3
      obj.style.opacity = opacity/100;
  }
  catch(e) {
  
  }
}

function fadeInGA(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeInGA('"+objId+"',"+opacity+")", 2);
      try {
        obj.style.display = "";
      }
      catch(e) {
      
      }
    }
  }
}

function fadeOut(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity >= 0) {
      setOpacity(obj, opacity);
      opacity -= 10;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 2);
    } else {
        // faded out...lets just hide the div, shall we?
        obj.style.display = "none";
    }
  }
}

function RedirectClick(redirectURL) {    
    try {
        //BasePage.LogRedirection(redirectURL, confirmRedirection);  // asynchronous call    
        }
    catch (e)
    {}
    
}

  function trimAll(sString) {
        while (sString.substring(0,1) == ' ')
        {
            sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length-1, sString.length) == ' ')
        {
            sString = sString.substring(0,sString.length-1);
        }        
        return sString;
    }

function confirmRedirection(res) {

}

function num2money(n_value) {
    // validate input
    if (isNaN(Number(n_value)))
        return 'ERROR';

    // save the sign
    var b_negative = Boolean(n_value < 0);
    n_value = Math.abs(n_value);
    
    // round to 1/100 precision, add ending zeroes if needed
    var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);
    
    // separate all orders
    var b_first = true;
    var s_subresult;
    while (n_value >= 1) {        
        s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
        s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
        b_first = false;
        n_value = n_value/1e3;
    }
    
    // add at least one integer digit
    if (b_first)
        s_result = '0.' + s_result;

// apply formatting and return
    return b_negative ? '(' + s_result + ')' : '' + s_result;
}

function findPos(obj) {
    try {
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
		    curleft = obj.offsetLeft
		    curtop = obj.offsetTop
		    while (obj = obj.offsetParent) {
			    curleft += obj.offsetLeft
			    curtop += obj.offsetTop
		    }
	    }
	}
	catch (e) {return [0,0];}
	return [curleft,curtop];
}


function helpClose(){
    pd.style.display = "none";
	pd.innerHTML = "";
	isOpen = false
}

function helpPopup(div_id, title, openToTheLeft, width, height, url) {	
//helpPopup('help', '', false, 100, 100, 'PostListingAskingPrice.html')
window.open(helpURL + url,title,"width=" + width +",height=" + height + ",scrollbars=1");
}

//function helpPopup(div_id, title, openToTheLeft, width, height, url) {	
//	if (isOpen) {
//		helpClose()
//	}
//	
//	//width = 150;
//    
//	field = document.getElementById(div_id);

//	mx = 0;
//	my = 0;

//	tempImg = field;

//	while (tempImg!=null) {
//		mx += tempImg.offsetLeft;
//		my += tempImg.offsetTop -1;
//		tempImg = tempImg.offsetParent;
//	}

//	if (!pd) {
//		pd = document.createElement("div");
//		pd.style.position = "absolute";
////		pd.style.backgroundColor = "#" + color_3;
////		pd.style.borderColor = "#" + color_14;
//		pd.style.borderStyle = "solid";
//		pd.style.borderWidth = "1px";
//		pd.style.zIndex = 4999;
//		document.body.appendChild(pd);
//	} else {
//		pd.style.display = "block";
//	}
//    
//	my++
//	var pdwidth = width;
//	var pdheight = height;
//	my+= 6;

//    

//	if(openToTheLeft)
//		pd.style.left = tempX - pdwidth + "px";
//	else
//		pd.style.left = tempX + "px";


//	pd.style.top = tempY + "px";
//	pd.style.padding = "0px";
//	pd.style.width = pdwidth + "px";
//	//pd.style.height = pdheight + "px";
//	var strHTML = '<div style="width:' + pdwidth + 'px;"> <table  cellpadding="0" cellspacing="0" border="0" class="help_tipwindow"> ';
//	strHTML = strHTML + '<tr><td class="help_tiptitle">' + title + '</td>  <td class="help_xclosebox" align="center" valign="middle"> &nbsp;<a href="#" onClick="helpClose();return false;" >&nbsp;X&nbsp;</a> </td> </tr>';
//	strHTML = strHTML + '<tr><td colspan="2" class="help_tiptext"><div id="hlp'+div_id+'" >' + 'loading...<br>loading...<br>loading...<br>loading...<br>loading...<br>' + '</div> </td></tr> </table> </div>';
//	pd.innerHTML = strHTML;
//	isOpen = true;
//	loadHelp(div_id, url)
//}

function loadHelp(div_id, url) {
    x = div_id
    x = x.replace(/ /g, '+')
    GetHelp(div_id, url);
    //makeHttpRequest('help.aspx', div_id);
	//alert('')
}


function GetHelp(div_id, help_file)
{
    pdiv_id = div_id;
    BasePage.GetHelp(help_file, GetHelpCallback);
}

function GetHelpCallback(res, div_id) { 
    document.getElementById('hlp' + pdiv_id).innerHTML = res.value; 
}


/*END FILE*/

/*TAKEN FROM MASTERPAGE*/

    function ValidateCheck(checkBoxName) {
               
        if(document.getElementById(checkBoxName).checked) {
           
            return true;
        }
        else {
             alert("Please check the checkbox to agree to the terms.");
            return false;
        }
    }
    
    function ValidateCheck(checkBoxName, message) {
               
        if(document.getElementById(checkBoxName).checked) {
           
            return true;
        }
        else {
            if(message != '')
             alert(message);
            return false;
        }
    }
    
    function SearchThis(text)
    {
        if (text=="")
        {
            alert("Enter words to search for.");
        }
        else
        {
            while(text.indexOf('&') > -1) {
                text = text.replace('&','%26');
            }
            self.location= "/Search.htm?SearchText=" + text;
        }
        return false;
    }
     
    function SetUserCookie()
    {
        if (readCookie('Resolution') == null)
        {
            var curCookie = "Resolution=" + window.screen.width + ";path=/;";
            document.cookie = curCookie;
        }
        else{
            var curCookie=readCookie('Resolution');
            if(curCookie != window.screen.width){
                curCookie = "Resolution=" + window.screen.width + ";path=/;";
                document.cookie = curCookie;
            }
        }
    }

    function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

    function ValidateSearch()
    {
        var str = document.getElementById("SearchText").value;
        str = str.replace(/^\s*|\s*$/g,"");
        
        if (str == "")
        {
            alert("Please type words to search for.");
            document.getElementById("SearchText").focus();
            return false;
        }
        else
        {
            while(str.indexOf('&') > -1) {
                str = str.replace('&','%26');
            }
            self.location='/Search.aspx?T=' + str;
        }
            
        return false;
    }
    
     function ValidateLoginMP()
    {
        var userIDMP = document.getElementById("LoginIDMP").value;
        userIDMP = userIDMP.replace(/^\s*|\s*$/g,"");
        
        var pwMP = document.getElementById("PasswordMP").value;
        pwMP = pwMP.replace(/^\s*|\s*$/g,"");
        
        if (userIDMP == "" || pwMP == "")
        {
            alert("Please complete your login information.");
            return false;
        }
        else
        {
            self.location='/Login.aspx?LoginNow=1&LoginID=' + userIDMP + '&Password=' + pwMP + '&ReturnToMP=' + document.getElementById("ReturnToMP").value;
        }
            
        return false;
    }
    
    
    function ValidateDelete()
    {
        return confirm("Are you sure you want to delete?");    
    }
    function ValidateArchive()
    {
        return confirm("Are you sure you want to archive?");    
    }
    function ValidateDeleteRedirect(url)
    {
        if (ValidateDelete())
        {
            self.location=url;
            return false;
        }
        else
        {
            return false;
        }
    }
    
    function OpenWindow(url)
    {
        window.open(url);
    }
    
    function ReportBug(url)
    {
        window.open(url + '?url=' + document.URL,'','height=400,width=400,toolbar=0;');
        return false;
    }

//    var dvAdHolderID;
//    function GetAdURL(inputStr) {                
//        BasePage.GetAdvertisement(inputStr, fnWriteAdvertisement);
//    }
//    
//    function fnWriteAdvertisement(enteredVal)   {    
//        document.getElementById(dvAdHolderID).innerHTML = enteredVal.value;    
//        //alert('xx');
//    }

    function GetAdURL(inputStr,  resultDiv) {           
        var https = window.location.toString();
        if (https.substring(0,5)=="https")
        {
            return;
        }
        var inputStr = inputStr + "|" + resultDiv;
        //BasePage.GetAdvertisement(inputStr, fnWriteAdvertisement2);
    }
    
    function fnWriteAdvertisement2(enteredVal)   {    
        var retArray = enteredVal.value.split("~!~");
        var resultDiv = retArray[1];
        enteredVal = retArray[0];
        try
        {
            document.getElementById(resultDiv).innerHTML = enteredVal;
        }
        catch(e)
        {        
        }
    }    
    
/**************************************************/



// +----------------------------------------------------------------+
// | Array functions that are missing in IE 5.0                     |
// | Author: Cezary Tomczak [www.gosu.pl]                           |
// | Free for any use as long as all copyright messages are intact. |
// +----------------------------------------------------------------+

// Removes the last element from an array and returns that element.
if (!Array.prototype.pop) {
    Array.prototype.pop = function() {
        var last;
        if (this.length) {
            last = this[this.length - 1];
            this.length -= 1;
        }
        return last;
    };
}

// Adds one or more elements to the end of an array and returns the new length of the array.
if (!Array.prototype.push) {
    Array.prototype.push = function() {
        for (var i = 0; i < arguments.length; ++i) {
            this[this.length] = arguments[i];
        }
        return this.length;
    };
}

// Removes the first element from an array and returns that element.
if (!Array.prototype.shift) {
    Array.prototype.shift = function() {
        var first;
        if (this.length) {
            first = this[0];
            for (var i = 0; i < this.length - 1; ++i) {
                this[i] = this[i + 1];
            }
            this.length -= 1;
        }
        return first;
    };
}

// Adds one or more elements to the front of an array and returns the new length of the array.
if (!Array.prototype.unshift) {
    Array.prototype.unshift = function() {
        if (arguments.length) {
            var i, len = arguments.length;
            for (i = this.length + len - 1; i >= len; --i) {
                this[i] = this[i - len];
            }
            for (i = 0; i < len; ++i) {
                this[i] = arguments[i];
            }
        }
        return this.length;
    };
}

// Adds and/or removes elements from an array.
if (!Array.prototype.splice) {
    Array.prototype.splice = function(index, howMany) {
        var elements = [], removed = [], i;
        for (i = 2; i < arguments.length; ++i) {
            elements.push(arguments[i]);
        }
        for (i = index; (i < index + howMany) && (i < this.length); ++i) {
            removed.push(this[i]);
        }
        for (i = index + howMany; i < this.length; ++i) {
            this[i - howMany] = this[i];
        }
        this.length -= removed.length;
        for (i = this.length + elements.length - 1; i >= index + elements.length; --i) {
            this[i] = this[i - elements.length];
        }
        for (i = 0; i < elements.length; ++i) {
            this[index + i] = elements[i];
        }
        return removed;
    };
}

/*AJAX*/
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable 
function CreateXmlHttp()
{
    //Creating object of XMLHTTP in IE
    try
    {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari
    if(!XmlHttp && typeof XMLHttpRequest != "undefined")
    {
        XmlHttp = new XMLHttpRequest();
    }
    
    //return XmlHttp;
}

/*
function CreateXmlHttp(newInstance)
{
    //Creating object of XMLHTTP in IE
    var xmlHttp_;
    try
    {
        xmlHttp_ = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlHttp_ = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {
            xmlHttp_ = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari
    if(!xmlHttp_ && typeof XMLHttpRequest != "undefined")
    {
        xmlHttp_ = new XMLHttpRequest();
    }
    
    return xmlHttp_;
}
*/

var searchQueryString;

function SaveSearch() {

    if (document.getElementById('txtSavedSearchTitle').value == '') {
        alert('Enter a name.');
        return;
    }
    else {
        
         var requestUrl = document.getElementById('aSaveSearch') + '&Title=' + document.getElementById('txtSavedSearchTitle').value;
        CreateXmlHttp();
       
        // If browser supports XMLHTTPRequest object
        
        if(XmlHttp)
        {
            //Setting the event handler for the response
            //XmlHttp.onreadystatechange = HandleResponse;
           
            //Initializes the request object with GET (METHOD of posting),
            //Request URL and sets the request as asynchronous.
            XmlHttp.open("GET", requestUrl,  true);
            
            //Sends the request to server
            XmlHttp.send(null);
            document.getElementById('txtSavedSearchTitle').value = '';
            document.getElementById('divSaveSearch').innerHTML='Search Saved.';
            doTimeOut=true;
            window.setTimeout('CloseSaveSearchDiv()',600);
        }
        else {
            alert('Save unsuccessful. There was an error contacting the server.');
        }
    }
}

var openDiv="";
var doTimeOut=false;


function OpenDivGenericNoPosition(divToOpen, anchorID, idsToClose, DoFade) {
    var divID=document.getElementById(divToOpen);
    if(DoFade) {
        fadeInGA(divToOpen, 0);
    }
    else {
        divID.style.display="";
    }
}

function OpenDivGeneric(divToOpen, anchorID, idsToClose, XOffset, YOffset, DoFade) {
    
    var divID=document.getElementById(divToOpen);
    if(DoFade) {
        fadeInGA(divToOpen, 0);
    }
    else {
        setOpacity(divID, 100);
        divID.style.display="";
    }
    var pos = findPos(document.getElementById(anchorID));
    divID.style.position = "absolute";
    divID.style.left = pos[0] + XOffset;
    divID.style.top = pos[1] + YOffset;
}

function SetCloseTimeout(id, DoFade, delay) {
    window.setTimeout('CloseDivGeneric(\'' + id + '\', ' + DoFade + ');', delay);
    doTimeOut=true;
}

function CloseDivGeneric(id, DoFade)
{
    try{
        if (doTimeOut)
        {
            var divID=document.getElementById(id);
            if(DoFade) {
                fadeOut(id, 99);
            }
            else {
                divID.style.display="none";
            }
        }
    } catch(e){}
}


function ValidateDropDown(object, arguments)  {
    if(document.getElementById(object).value == '') {
        arguments.IsValid = false;
    }
    else {
        arguments.IsValid = true;
    }
}

function ValidateCheckBox(object, arguments) {
    if(document.getElementById(object).checked) {
        arguments.IsValid = true;
    }
    else {
        arguments.IsValid = false;
    }
}

function ValidateDate(fld) {
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    if ((fld.match(RegExPattern)) && (fld!='')) {
        return true;
    } else {
        return false;
    } 
}

function HideDropDowns(list){
    HideDropDownsArray = list.split(',');
    for(var i=0; i<HideDropDownsArray.length;i++){
        try{
            document.getElementById(HideDropDownsArray[i]).style.display='none';   
        }catch(e){}
    }
}

function ShowDropDowns(){
    try{
        for(var i=0; i<HideDropDownsArray.length;i++){
            document.getElementById(HideDropDownsArray[i]).style.display='none';   
        }
    }catch(e){}
}

var HideDropDownsArray;

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 36;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementById("divBodyForGrayOut");
    
    if (!tbody) 
    {
        tbody = document.getElementsByTagName("body")[0];
    }
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
     ShowDropDowns();
  }
}

function RefreshLocation(){
    self.location=self.location;
}

var popGAOpen;
var toGA;

function flipOpenGA(strDiv, strHTML, intLeft, intTop, intFade, strHelpLink) {
    keepOpenGA();
    
    if (intLeft == null) { intLeft = getMouseX(); }
    if (intTop == null) { intTop = getMouseY(); }
        
    var lpos = parseInt(intLeft);
    var tpos = parseInt(intTop);
    
    document.getElementById(strDiv).style.left = lpos + "px";
    document.getElementById(strDiv).style.top = tpos + "px";
    
    popHTML = "<table cellpadding='0' cellspacing='0' width='430' border='0'>";
	popHTML += "<tr>";
	popHTML += "<td class='transparent_png' style='width:166px;height:31px;background:url(/images/as/pop_top_left.png) no-repeat;'>&nbsp;</td>";
	popHTML += "<td class='transparent_png' style='width:221px;background:url(/images/as/pop_top_ctr.png) repeat-x;'>&nbsp;</td>";
	if (strHelpLink) {
	    popHTML += "<td class='transparent_png' style='width:20px;height:31px;background:url(/images/as/pop_top_right_q.png) no-repeat;vertical-align:bottom;'><a href=''><img src='/images/spacer.gif' alt='' width='20' height'31' border='0' /></a><a href='javascript:void(0);' onclick=''><img src='/images/spacer.gif' alt='' width='20' height'31' border='0' /></a></td>";
	} else {
	    popHTML += "<td class='transparent_png' style='width:20px;height:31px;background:url(/images/as/pop_top_ctr.png) repeat-x;'><img src='/images/spacer.gif' alt='' width='20' height'31' border='0' /><br /></td>";
	}
	popHTML += "<td class='transparent_png' style='width:23px;height:31px;background:url(/images/as/pop_top_right_x.png) no-repeat;vertical-align:bottom;'><a href='javascript:void(0);' onclick='closeGA();'><img src='/images/spacer.gif' alt='' width='20' height'31' border='0' /></a><img src='/images/spacer.gif' alt='' width='3' height'31' border='0' /></td>";
	popHTML += "</tr><tr><td colspan='4'>";
	popHTML += "<table cellpadding='0' cellspacing='0' width='430'><tr><td class='transparent_png' style='width:4px;background:url(/images/as/pop_mid_left.png) repeat-y;'>&nbsp;</td><td style='padding:10px;background:#feffe8;'>";
	popHTML += strHTML;
	popHTML += "</td><td class='transparent_png' style='width:4px;background:url(/images/as/pop_mid_right.png) repeat-y;'>&nbsp;</td></tr></table>";
	popHTML += "</td></tr><tr>";
	popHTML += "<td class='transparent_png' style='width:166px;height:34px;background:url(/images/as/pop_btm_left.png) no-repeat;'>&nbsp;</td>";
	popHTML += "<td class='transparent_png' style='background:url(/images/as/pop_btm_ctr.png) repeat-x;'>&nbsp;</td>";
	popHTML += "<td colspan='2' class='transparent_png' style='width:43px;height:34px;background:url(/images/as/pop_btm_right.png) no-repeat;'>&nbsp;</td>";
	popHTML += "</tr>";
	popHTML += "</table>";
	popHTML += "<div id='popGA_arrow' class='transparent_png' style='position:relative;left:300px;top:-34px;width:31px;height:34px;z-index:66;background: url(/images/as/pop_btm_arrow.png) no-repeat;'><img src='/images/spacer.gif' width='31' height='34' alt='' /></div>";
    
    document.getElementById(strDiv).innerHTML = popHTML;
    
    if (intFade == 1) {
        fadeInGA(strDiv, 0);
    } else {
        document.getElementById(strDiv).style.display = "";
    }
    
    popGAOpen = true;
}

function flipOpenGARel(strDiv, strHTML, intLeft, intTop, intOffsetLeft, intOffsetTop, strHelpLink) {
    if (intLeft == null) { intLeft = tempX; }
    if (intTop == null) { intTop = tempY; }
    
    var lpos = parseInt(intLeft) + parseInt(intOffsetLeft);
    var tpos = parseInt(intTop) + parseInt(intOffsetTop);
    
    flipOpenGA(strDiv, strHTML, lpos, tpos, 0, strHelpLink);
}


function keepOpenGA() {
    try {
        window.clearTimeout(toGA);
    } catch(e) {
        alert(e);
    }
    popGAOpen = true;
}

function flipCloseGA(intDelay) {
    if ((parseInt(intDelay) > 0) && (popGAOpen == false)) {
        toGA = window.setTimeout('closeGA()',parseInt(intDelay));
    }
}

function closeGA() {
    document.getElementById("popGA").style.display = "none";
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    try {
        tempX = event.clientX + document.body.scrollLeft
        tempY = event.clientY + document.body.scrollTop
    } catch(e) {
        
    }
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  
  return true
}

function ForceInitialSpaceInTextBox(id){
    if(document.getElementById(id).value == ''){
        document.getElementById(id).value = ' ';
    }
    else if(document.getElementById(id).value[0] != ' '){
        var curval=document.getElementById(id).value;
        document.getElementById(id).value = ' ' + curval;
    }
}