﻿

/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}
Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}

/// Other stuff

function ClearInput(n){
	document.forms[0][n].value='';
}



function showEventType2() {

    // This function accepts an event type id and finds all events that use this id.
    // Note: To find the events, the events must be wrappered in a div tag that begins
    //		with the name "evtype", and must have appended to that name each event type id 
    //		to which it is associated. 
    //		For example:
    //			name = evtype_1_2 means that the event has event type ids 1 and 2
    //			name = evtype_3_64 means that the event has event type ids 3 and 64
    //			name = evtype_2 means that the event has event type id 2
    //
    // ** Note: This function does not hide all of the other event types. It only shows them.
    //			See "hideAllEventTypes()" for hiding the events.
    hideAllEvents();
    etid1 = document.getElementById("TypeDropDownList").value;
    if (!etid1) {
        etid1 = 0;
    }



    var divArr = document.getElementsByTagName("div")



    // Matches all event types
    var rq = /^evtype/

    	

    // Passing etid=0 shows all event types, so if it's 0 then set rp to rq
    if (etid1 == 0) {
        if (etid2 != 0) {
            eval('var rp = /^evtype(.)*_' + etid2 + '(.)*/');
        } else {
            var rp = rq ;
        }
    } else if (etid2 == 0) {
        if (etid1 != 0) {
            eval('var rp = /^evtype(.)*_' + etid1 + '(.)*/');
        } else {
            var rp = rq ;
        }
    } else {
        eval('var rp = /^evtype(.)*_' + etid1 + '(.)*/');
        eval('var rt = /^evtype(.)*_' + etid2 + '(.)*/');
    }




    if(divArr) {

	    for(var x=0;x<divArr.length;x++) {

		    if(rq.test(divArr[x].id)) {

			    // Only check those divs whose ids begin with 'evtype' (RegEx rq)
                if ((etid1 == 0) || (etid2 == 0)) {
                    if (rp.test(divArr[x].id)) {
                        divArr[x].style.display = 'block' ;
                    }
                }
			    else if ((rp.test(divArr[x].id)) && (rt.test(divArr[x].id))){
                    divArr[x].style.display = 'block' ;
                }
            }

	    }

    }

}


function showEventType3() {

    // This function accepts an event type id and finds all events that use this id.
    // Note: To find the events, the events must be wrappered in a div tag that begins
    //		with the name "evtype", and must have appended to that name each event type id 
    //		to which it is associated. 
    //		For example:
    //			name = evtype_1_2 means that the event has event type ids 1 and 2
    //			name = evtype_3_64 means that the event has event type ids 3 and 64
    //			name = evtype_2 means that the event has event type id 2
    //
    // ** Note: This function does not hide all of the other event types. It only shows them.
    //			See "hideAllEventTypes()" for hiding the events.
    hideAllEvents();
    etid1 = document.getElementById("TypeDropDownList").value;
    if (!etid1) {
        etid1 = 0;
    }
    etid2 = document.getElementById("RegionDropDownList").value;
    if (!etid2) {
        etid2 = 0;
    }

    var divArr = document.getElementsByTagName("div")



    // Matches all event types
    var rq = /^evtype/

    	

    // Passing etid=0 shows all event types, so if it's 0 then set rp to rq
    if (etid1 == 0) {
        if (etid2 != 0) {
            eval('var rp = /^evtype(.)*_' + etid2 + '(.)*/');
        } else {
            var rp = rq ;
        }
    } else if (etid2 == 0) {
        if (etid1 != 0) {
            eval('var rp = /^evtype(.)*_' + etid1 + '(.)*/');
        } else {
            var rp = rq ;
        }
    } else {
        eval('var rp = /^evtype(.)*_' + etid1 + '(.)*/');
        eval('var rt = /^evtype(.)*_' + etid2 + '(.)*/');
    }




    if(divArr) {

	    for(var x=0;x<divArr.length;x++) {

		    if(rq.test(divArr[x].id)) {

			    // Only check those divs whose ids begin with 'evtype' (RegEx rq)
                if ((etid1 == 0) || (etid2 == 0)) {
                    if (rp.test(divArr[x].id)) {
                        divArr[x].style.display = 'block' ;
                    }
                }
			    else if ((rp.test(divArr[x].id)) && (rt.test(divArr[x].id))){
                    divArr[x].style.display = 'block' ;
                }
            }

	    }

    }

}


/*
	Quick search

*/
function RunQuickSearch(q)
{
	if (event.keyCode == 13)
	{
		window.location = "AdvancedSearch.aspx?searchtext=" + q;
	}
}

function openPortRoyalModule()

{

	myPortRoyal=window.open("/PortRoyal.htm","PortRoyal","toolbar=0,Location=0,Directories=0,Status=0,menubar=0,Scrollbars=0,Resizable=0,width=765,height=508");

}



/*
            function ShowCookie() only used for demo puposes
        
        */
        function ShowCookie(){
            document.getElementById('Results').innerHTML = 
                GetCookie('GuestQuickLinks');
        }
        
        /*
            function SaveCookie(sTitle, sAddress) should be called by
            the Flash Obejct to add Quick Link Cookie for a guest user
        
        */
        function SaveCookie(sTitle, sAddress){ 
            if(sTitle.length>0 && sAddress.length>0){
                var CookieId=CreateRandomNumber(1000000,9999999);            
		        var expDate = new Date();
		        expDate.setTime( expDate.getTime() + (365 * 24 * 60 * 60 * 1000) );  
    		    
		        var MyCookieVal = CookieId + '=' + escape(sTitle + '^' + sAddress);
                    
                var NewCookieVal='';
                if (null == GetCookie('GuestQuickLinks') || 1>GetCookie('GuestQuickLinks').length)
                    NewCookieVal = MyCookieVal;
                else
                    NewCookieVal = GetCookie('GuestQuickLinks') + '&' + MyCookieVal;
                SetCookie ( 'GuestQuickLinks', NewCookieVal, expDate, '/' );
            }
        }
        
        function CreateRandomNumber(Min, Max) 
        { var range = Max-Min+1;
          return (Math.floor(Math.random() * 
                  Math.pow(10,("" + range).length)) % range) + parseInt(Min);
        }
       
    function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
        endstr = document.cookie.length;
      return document.cookie.substring(offset, endstr);
    }

    function GetCookie (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
      }
      return null;
    }

    function SetCookie (name, value) {
      var argv = SetCookie.arguments;
      var argc = SetCookie.arguments.length;
      var expires = (argc > 2) ? argv[2] : null;
      var path = (argc > 3) ? argv[3] : null;
      var domain = (argc > 4) ? argv[4] : null;
      var secure = (argc > 5) ? argv[5] : false;
      document.cookie = name + "=" + value +        
        ((expires == null) ? "" : ("; expires=" + expires.toString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    }
