function closePopUpWindow(){
	if (window.openedWindow && !window.openedWindow.closed){
		window.openedWindow.close();
	}
}

function popUpWindow(theURL,winName,features) {
	window.onunload = closePopUpWindow;
	closePopUpWindow();
	window.openedWindow = window.open(theURL,'form',features+",resizable,width=780,height=600,scrollbars,left=160,top=10,screenX=138,screenY=13");
	return (window.openedWindow);
}

function  getSearchElements(searchString)
{
    var ss = searchString;
    var paramArray = new Array();
    var param_string = ss.substr(ss.indexOf("?") + 1);
    var param_list = param_string.split("&");

    for (num = 0; num < param_list.length; num++) {
        var pair = param_list[num].split("=");
        paramArray[pair[0]] = pair[1];
    }
    return (paramArray);
}

function storeCampaignCode(expDays)
{
    if (expDays == null)
    {
        expDays = 30;
    }
    var expDate = new Date();
    expDate.setDate(expDate.getDate() + expDays);
    var cookie = location.search;
    document.cookie = "qs=" + escape(cookie) + ";expires=" + expDate.toGMTString() + ";path=/;";
}

function getCookie()
{
    var cookie = unescape(document.cookie);
    var cookieVals = new Array();
    var cookieStr = cookie.substr(cookie.indexOf("?") + 1);
    var cookieList = cookieStr.split("&");

    for (num = 0; num < cookieList.length; num++)
    {
        var pair = cookieList[num].split("=");
        cookieVals[pair[0]] = pair[1];
    }
return (cookieVals);
}

function defineCampaignId()
/*  Test for existence of cookie with qs= string already embedded.
    If does not already exist, then set cookie. Then
    use the getCookie function to unpick the cookie and define
    campaign id as identical to either the docid or source */
{   if (document.cookie.search(/^qs=.*/) < 0)
    { storeCampaignCode(5); }
    var campaignStr = "", formURL = "";
    var cookieArray = new Array();
    cookieArray = getCookie();
    if (cookieArray["docid"] != undefined)
    {   campaignStr = "&campaignid=" + cookieArray["docid"]; }
    else if (cookieArray["source"] != undefined)
    {   campaignStr = "&campaignid=" + cookieArray["source"]; }
    else
    {   campaignStr = ""; }
    return campaignStr
}

function testSetCookie()
/*  Test for existence of cookie with qs= string already embedded.
    If does not already exist, then set cookie*/
{   if (document.cookie.search(/^qs=.*/) < 0)
    { storeCampaignCode(5); }
}

