// Ogilvy JS Library
// function qsObject()
// returns name/value pairs of data passed in querystring
// use: var myQSobj = new qsObject();
//	 var idObj= myQSobj.item("SomeQSVariable");
//	 alert(idObj.value);		   
function qsObject(){
    this.objects = new Array();
    this.add = _add;
    this.remove =_remove;
    this.item = _item;
    this.populateCollection =_populateCollection;
    this.setRawString = _setRawString;
    this.rawString ="";
    
    this.setRawString();
    this.populateCollection();
    
    // to add items to the array
    function _add(obj){
        this.objects[this.objects.length] = obj;
    }
    //to remove items from the array
    function _remove(index){
        this.objects.splice(index, 1);
    }
    //gets a reference to an item object
    function _item(searchKey){
        searchKey = new String(searchKey);
        searchKey = searchKey.toLowerCase();
        for(i=0;i<this.objects.length;i++){
            //the current key in the coll
            var key = this.objects[i].key;
            key = new String(key);
            key = key.toLowerCase();
            
            if(key == searchKey){
                return this.objects[i];
            }
        }
    }
    
    function _setRawString(){
        //Create regular expression object to retrieve the qs part
        // Used regex 'cause the search property on the location object includes the bookmark stuff
        var qsReg = new RegExp("[?][^#]*","i");  
        hRef = unescape( window.location.href);
        var qsMatch = hRef.match(qsReg);  
        //removes the question mark from the url 
        qsMatch = new String(qsMatch);
        qsMatch = qsMatch.substr(1, qsMatch.length -1);        
        this.rawString = qsMatch;        
    }
    
    //takes a string and populates the array with the key/value pairs
    function _populateCollection(rawString){
        this.rawString = new String(this.rawString);
        var rootArr = this.rawString.split("&");
        for(i=0;i<rootArr.length;i++){
            var tempArr =  rootArr[i].split("=");
            if(tempArr.length ==2){
                tempArr[0] = unescape(tempArr[0]);
                tempArr[1] = unescape(tempArr[1]);
                
                this.add(new qsValue(tempArr[0], tempArr[1]));
            }
        }
    }
    
    function qsValue(key, value){
        this.key = key;
        this.value=value;    
    }     
}    

function newExitWin(WinURL, WinNewUrlParam, WinNewUrl, WinNAME, WinWIDTH, WinHEIGHT, WinRESIZE, WinSCROLL, WinTOOLBAR) 
	{       
	        /*      variables passed by the link calling the function       */ 
	        var newUrl = WinNewUrl; 
	        newUrl = newUrl.replace('?','%3F'); 
	        while (newUrl.indexOf('=') > -1){ 
	                newUrl = newUrl.replace('=','%3D'); 
	        } 
	        while (newUrl.indexOf('&') > -1){ 
	                newUrl = newUrl.replace('&','%26'); 
	        } 
	        
	        var URL = WinURL+'?'+WinNewUrlParam+'='+newUrl+''; 
			
			
	        var WINDOW_NAME = WinNAME; 
	        var POPUP_WIDTH = WinWIDTH; 
	        var POPUP_HEIGHT = WinHEIGHT; 
	        var POPUP_RESIZE = WinRESIZE; 
	        var POPUP_SCROLL = WinSCROLL; 
	        var POPUP_TOOLBAR = WinTOOLBAR; 

/*      window properties that determine the window attributes depending on what values are passed by the link calling the function     */
	        var window_toolbar = POPUP_TOOLBAR; 
	        var window_resize = POPUP_RESIZE; 
	        var window_scroll = POPUP_SCROLL; 
	        var window_width = POPUP_WIDTH; 
	        var window_height = POPUP_HEIGHT; 
	        var screen_balance_w = ((screen.width)-(window_width))/2; 
	        var screen_balance_h = ((screen.height)-(window_height))/2; 
			
	        //var set_top = screen_balance_h; 
	       // var set_left = screen_balance_w; 
			var set_top  = 50;  
	        var set_left = 50; 


	        win = window.open(URL,WINDOW_NAME,'resizable=' + window_resize + ',toolbar=' + 
window_toolbar + ',scrollbars=' + window_scroll + ',width=' + window_width + ',height=' + window_height + 
',top=' +  set_top + ',left=' + set_left + '');

	        win.focus(); 
	} 

function win_pop(theURL)
{
 window.open(theURL,"","height=400,width=550,scrollbars=yes,resizable=yes,screenX=100,left=100,screenY=100,top=100");
}

// exitRedirect takes the URl of an exit disclaimer and passes the URL of the exit destination;
// It acts as a wrapper for newExitWindow
function exitRedirect(disclaimerURL, exitURL)
{

// window.open(disclaimerURL,"","height=250,width=435,scrollbars=yes,resizable=yes,screenX=100,left=100,screenY=100,top=100");
newExitWin(disclaimerURL, "exitURL", exitURL, "Disclaimer", 435, 250, "yes", "yes", "no") ;
}

// exitSiteAlert is a basic redirection function 
// it takes the destinaltion URL and an op[tional disclaimer
//  if no disclaimer is desired, pass in the empty string, ''
function exitSiteAlert(theURL, sMssg)
{			
	if (sMssg.length >0){alert(sMssg);}
	window.location = theURL;	
}

// exitSiteConfirm is a basic redirection function which REQUIRES user intereaction
//before the redirect will occur
// it takes the destinaltion URL and an odisclaimer
function exitSiteConfirm(theURL, sMssg)
{			
	if(confirm(sMssg)){
		window.location = theURL;	
		}else{alert('Action cancelled.');}
}

function win_pop_flex(theURL,width,height)
{
 
 window.open(theURL,"","height="+height+",width="+width+",scrollbars=yes,resizable=yes,screenX=50,left=50, location=on,menubar=no,toolbar=no, screenY=50,top=50");
}
function exit_pop_flex(width,height)
{
 
 //get the querystring objects and pass them to the popup fn
 var qs= new qsObject(); 
 var idObj= qs.item("exitURL");

 window.open(idObj.value,"","height="+height+",width="+width+",scrollbars=yes,resizable=yes,screenX=50,left=50, location=yes,menubar=yes,toolbar=yes, screenY=50,top=50");
}

/*	function: closeWin - closes the child window	*/

function closeWin()
{
	top.window.close();
}

function submitCommentForm(sFormID){
	var oForm 		= xGetElementById(sFormID);
	oForm.submit();
}

//Pop up code added by client request from: Sandra Ely

