function popup(url, w, h) 
{
	var options = "width=" + w + ",height=" + h + ",";
	options += "resizable=yes,scrollbars=yes,status=no,";
	options += "menubar=no,toolbar=no,location=no,directories=no,marginwidth=0,marginheight=0";

	var name = Math.round(89999*Math.random() + 10000);
	var popup = window.open(url, name, options);

	// Bring window to front on Navigator 3.0+ and MSIE 4.0+
	if (navigator.appName == "Netscape" && navigator.appVersion.charAt (0) >= 3
	|| navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.charAt (0) >= 4)
	{
		popup.focus();
	}
}

function popup_NoScroll(url, w, h) {
    var options = "width=" + w + ",height=" + h + ",";
    options += "resizable=no,scrollbars=no,status=no,";
    options += "menubar=no,toolbar=no,location=no,directories=no,marginwidth=0,marginheight=0";

    var name = Math.round(89999 * Math.random() + 10000);
    var popup = window.open(url, name, options);

    // Bring window to front on Navigator 3.0+ and MSIE 4.0+
    if (navigator.appName == "Netscape" && navigator.appVersion.charAt(0) >= 3
|| navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.charAt(0) >= 4) {
        popup.focus();
    }
};

function popup_options(url, w, h, r, sb, st, mb, tb, lc, dr, mw, mh)
{
	var options = "width=" + w + ",height=" + h + ",";
	options += "resizable=" + r + ",scrollbars=" + sb + ",status=" + st + ",";
	options += "menubar=" + mb + ",toolbar=" + tb + ",location=" + lc + ",directories=" + dr + ",marginwidth=" + mw + ",marginheight=" + mh;

	var name = Math.round(89999*Math.random() + 10000);
	
	// re-encode # on the querystring to fix "c#" searches
	url = url.replace("c#", "c%23");
	// The replace statement below replaces all + signs with "%2b", the HTML encoded value for +
	url = url.replace(/\+/g, "%2b");

	// Creative Financial staffing needs the '+' signs in the URLs to work properly
	if(url.search("cfstaffing") > -1)
	{
		url = url.replace(/\%2b/g, "+");
	}

	// Do this replace if we are working with Raymour and Flanigan's site
	if(url.search("http://www.pcrecruiter.net/") > -1 && url.search("raymour") > -1)
	{
		// The replace statement below replaces all & signs with "%26", the HTML encoded value for &
		url = url.replace(/\&/g, "%26");
	}

	// for BrassRing, we need to handle a special querystring parameter verityquery= because url parameter is unencoded by javascript when passed to this function
	// For Time Warner
	url = url.replace("&verityquery=PartnerId=391 <#AND> SiteId=36 <#AND> ReqId=", "&verityquery=PartnerId%3D391%20%3C%23AND%3E%20SiteId%3D36%20%3C%23AND%3E%20ReqId%3D");
	// For Emory Healthcare
	url = url.replace("&verityquery=PartnerId=25066 <#AND> SiteId=5039 <#AND> ReqId=", "&verityquery=PartnerId%3D25066%20%3C%23AND%3E%20SiteId%3D5039%20%3C%23AND%3E%20ReqId%3D");
	// For Fairfax Schools
	url = url.replace("&verityquery=PartnerId=25103 <#AND> SiteId=5019 <#AND> ReqId=", "&verityquery=PartnerId%3D25103%20%3C%23AND%3E%20SiteId%3D5019%20%3C%23AND%3E%20ReqId%3D");
	// For American Express
	url = url.replace("&verityquery=PartnerId=505 <#AND> SiteId=216 <#AND> ReqId=", "&verityquery=PartnerId%3D505%20%3C%23AND%3E%20SiteId%3D216%20%3C%23AND%3E%20ReqId%3D");
	// For Archstone
	url = url.replace("&verityquery=PartnerId=25152 <#AND> SiteId=5244 <#AND> ReqId=", "&verityquery=PartnerId%3D25152%20%3C%23AND%3E%20SiteId%3D5244%20%3C%23AND%3E%20ReqId%3D");

	var popup = window.open(url, name, options);

	// Bring window to front on Navigator 3.0+ and MSIE 4.0+
	if (navigator.appName == "Netscape" && navigator.appVersion.charAt (0) >= 3
	|| navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.charAt (0) >= 4)
	{
		popup.focus();
	}
}

function popup_formasquerystring(frm, page, width, height, url) {

    var qryString = "";
    var url = url;
	var checkboxName = "";
	var checkboxElementsCount = 0;
    var elementsCount = 0; 
	var item;
	var cbItem;
	var checkboxGroupsProcessed = "";
	var optsCount = 0;
	var opts;
	var opt;
    var originalLength = 0;

    
    originalLength = url.length;
    
    for (var elementsCount = 0; elementsCount < frm.elements.length; elementsCount++)
    {
        item = frm.elements[elementsCount];
        //alert("item=" + item.tagName + ": " + item.name + ": " + item.type);
        switch(item.type)
        {
        
            case "button":
                break;
                
            case "radio":
                if (item.checked)
                {
                    qryString = item.name + "=" + item.value;
                }
                break;

            case "checkbox":  
            
                // get the base name without the trailing numerics
                checkboxName = trimTrailingNumbers(item.name)
                
                // check if the group has already been processed - use semi-colon (;} as separator
                if (checkboxGroupsProcessed.indexOf(";" + checkboxName + ";") == -1)
                {
                    // add the name to the list of checkbox groups processed
                    checkboxGroupsProcessed += ";" + checkboxName + ";"
                    
                    // loop and find all "checked" checkboxes with that base name
                    for (var checkboxElementsCount = 0; checkboxElementsCount < frm.elements.length; checkboxElementsCount++)
                    {
                        cbItem = frm.elements[checkboxElementsCount];
                    
                        if (cbItem.type == "checkbox" && checkboxName == trimTrailingNumbers(cbItem.name) && (cbItem.checked))
                        {
                            if (qryString.length > 0)
                            {
                                qryString += "," + cbItem.value; 
                            }
                            else
                            {
                                qryString = checkboxName + "=" + cbItem.value;
                            }
                        }
                    }
                }

                break;

           case "select-multiple":
           
                opts = item.options; 

                for (optsCount=0; optsCount < opts.length; optsCount++)
                { 
                    opt = opts[optsCount];
                    
                    if (opt.selected == true)
                    { 
                        if (qryString.length > 0)
                        {
                            qryString += "," + opt.value; 
                        }
                        else
                        {
                            qryString = item.name + "=" + opt.value; 
                        }
                    }
                }

                isContinuation = false;                                                            
                break;

            case "select-one":
            case "hidden":
            case "text":
                if (item.value.length > 0) {
                    qryString = item.name + "=" + item.value;
                }
                isContinuation = false;
                break;           

            default:
                //alert("default: " + item.tagName + ": " + item.name + ": " + item.type);
                isContinuation = false;
                break;           
        }

        if (qryString.length > 0)
		{
		    if (isContinuation == false || continuationCount == 1)
		    {
                // determine if first URL or not
                if (url.length > originalLength)
      		    {
      			    url += "&" + qryString;
      		    }
		        else 
			    {
				    url += "?" + qryString;
			    }   
			}         
			else
			{
			    url += qryString;			
			}
			qryString = "";
			
		}
    }
    
	popup(url, width, height);    
} 
function trimTrailingNumbers(psValue){

    var sValue = "";
    var numCount = 0;
    
    // find the first alpha from the left
    for (numCount = (psValue.length - 1); numCount > 0; numCount--)
    {   
        if (isNaN(psValue.substring(numCount, numCount + 1)))
        {
            sValue = psValue.substring(0, numCount + 1);
            numCount=-1;
        }
    }

    return sValue;
}
