/*
* The programming and software materials herein are copyright Cyberhomes LLC (CH).
* The programming and software materials are owned, held, or licensed by CH. Personal, educational,
* non-commercial, commercial or any other use of these materials, without the written permission of the
* CH, is strictly prohibited.
*/

// ########## Start Browser Compatibility ######### //
if (document.all && !document.getElementById) {
	document.getElementById = function(id) {
		return document.all[id];
	}
}

// Sets a global css class so that browser-specific css
// can be used via css selectors.  
// ex:
//   .txt { width: 110px; } /* Will be 110 pixels by default */
//   .ie .txt { width: 100px; } /* Will be 100 pixels in IE */
(function() {
    var browser = jQuery.browser;
    var version = jQuery.browser.version.substring(0, 3);
    var browserclass = '';
    if (browser.msie) {
        browserclass = 'ie';
        if (version == '8.0') {
            browserclass += ' ie8';
        } else if (version == '7.0') {
            browserclass += ' ie7';
        } else if (version == '6.0') {
            browserclass += ' ie6';
        }
    } else if (browser.mozilla) {
        browserclass = 'mozilla';
    } else if (browser.safari) {
        browserclass = 'safari';
    } else if (browser.opera) {
        browserclass = 'opera';
    }
    jQuery('html').addClass(browserclass);
})();

// On document load fixes all of the pngs for IE5.5 and IE6
jQuery(function() { setTimeout(function() { jQuery(document).pngFix(); }); });

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = function() {
		var A_p = 0;
		for (A_p = 0; A_p < arguments.length; A_p++) {
			this[this.length] = arguments[A_p];
		}
		return this.length;
	}
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.isNullOrEmpty = function(s) {
    return !(s && typeof(s) == 'string' && s.trim().length > 0);
}

// From prototype.js
function $A(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) return iterable.toArray();
  var length = iterable.length || 0, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}

Function.prototype.bind = function() {
    if (arguments.length < 2 && typeof arguments[0] == "undefined")
        return this;
    var __method = this, args = $A(arguments), object = args.shift();
    return function() {
      return __method.apply(object, args.concat($A(arguments)));
    }
}

Function.prototype.bindAsEventListener = function() {
    var __method = this, args = $A(arguments), object = args.shift();
    return function(event) {
        return __method.apply(object, [event || window.event].concat(args));
    }
}

// ########## END Browser Compatibility ######### //
function IsNumeric(sText)
{
    var ValidChars = "0123456789.,";
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
         }
     }
    return IsNumber;
}

function IsMoney(sText) {
    return /^\$?[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{2})?$/.test(sText.trim());
}

function display(divName)
{
    if ( document.getElementById(divName))
        document.getElementById(divName).style.display = '';
}

function hide(divName)
{
    if ( document.getElementById(divName))
        document.getElementById(divName).style.display = 'none';
}

function sortSelect(selectToSort) {
	var myOptions = new Array(selectToSort.options.length);
	for (var i=0; i<selectToSort.options.length; i++) {
		myOptions[i] = selectToSort.options[i];
	}
	myOptions.sort(sortOptionsByName);
	selectToSort.options.length = 0;
	for (var i=0; i<myOptions.length; i++) {
		selectToSort.options[selectToSort.length] = myOptions[i];
	}
	selectToSort.options[0].selected=true;
}

function sortOptionsByName(record1, record2) {
	var value1 = record1.text.toLowerCase();
	var value2 = record2.text.toLowerCase();
	// Special handling for the default case
	if (value1.indexOf('-all-') > 0 || value1 > value2) return(1);
	if (value2.indexOf('-all-') > 0 || value1 < value2) return(-1);
	return(0);
}

function setElementDisplay(elName, display) {
	var el = document.getElementById(elName);
	if (el && el.style)
		el.style.display=display;
}


// ########## Popup Functions ################### //

// Master popup function
function popup(URL, name, properties) {
	var myWindow = window.open(URL, name, properties);
	if (myWindow) {
		myWindow.focus();
	} else {
		if (confirm('Your web browser appears to be configured to block popup windows.\nFor more information, please click OK.')) {
			location.href='/Public/Popup_Info.aspx';
		}
	}
}

function goTo(URL)
{
    location.href = URL;
}

function email_property(URL) {
	popup(URL, "EmailProperty", "height=600,width=475,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");
}

function open_tour(URL) {
	popup(URL, "VirtualTour", "height=360,width=512,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");
}

function open_browserUpgrade(URL) {
    // Display browser upgrade popup once per session
    var cookieName = 'browserUpgradePopup';
    if (readCookie(cookieName) == 'true')
    {
        // Do nothing
    }
    else
    {
        popup(URL, "BrowserUpgrade",  "height=360,width=512,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");
        createCookie(cookieName, 'true');
    }
}

function open_financialcalculator(URL) {
	popup(URL, "FinancialCalculator",  "height=400,width=485,scrollbars=no,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_financialcalculator_scrollbars(URL) {
	popup(URL, "FinancialCalculator", "height=400,width=485,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_financialcalculators(URL) {
	popup(URL, "FinancialCalculator", "height=600,width=620,scrollbars=no,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_RatePlug(URL) {
	popup(URL, "RatePlug", "height=650,width=795,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_bannerAd(URL) {
	popup(URL, "BannerAd", "height=450,width=650,scrollbars=auto,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_mortgageApp(URL) {
	popup(URL, "MortgageApplication", "height=450,width=650,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_mortgageApplication() {
	var URL = "/Public/FrameSet.aspx?redirectto=/Public/Content/Forms/MortgageApplication.aspx";
	popup(URL, "MortgageApplication", "height=450,width=650,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_oldMortgageCalc() {
	popup('http://www.homeservices.com/TRIOtools/MortgageCalculator/MortgageCalculator.asp', "oldMortgageCalculator", "height=438,width=500,scrollbars=no,menubar=no,toolbar=no,status=no,resizable=no");
}

function Popup_Window(URL) {
	popup(URL, "WindowPreview", "resizable=1,toolbar=1,scrollbars=1,status=1,location=1,menubar=1,height=550,width=800");
}

function PopupMortgage_Window(URL) {
	popup(URL, "WindowPreview", "toolbar=1,resizable=1,scrollbars=1,height=590,width=695");
	SourceWindow.focus(); 
}

function open_ListingSearchHelp(URL) {
	popup(URL,"ListingSearchHelp","resizable=1,scrollbars=1,status=1,height=350,width=300");
}

function open_IntranetLink(URL) {
	popup(URL,"Intranet","resizable=1,toolbar=1,menubar=1,scrollbars=1,status=1,height=550,width=600");
}

function openContactMe(URL) {
	popup(URL, "ContactMe", "height=" + getWindowHeight(730) + ",width=600,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_ScheduleViewing(URL) {
	popup(URL, "ScheduleViewing", "height=" + getWindowHeight(730) + ",width=600,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function openTheFixUp(URL) {
	// NOTE: this function is currently only being used by CBSHOME, see Left Nav "Home Improvement" - 9/12/02, BKF
	popup(URL, "TheFixUp", "height=" + getWindowHeight(750) + ",width=630,scrollbars=no,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function Popup_Article(nContentID) {
	popup('/Irp/Content/ArticlePopup.asp?ContentID=' + nContentID);
}

function open_map(URL) {
	popup(URL, "ListingMap", "height=600,width=850,scrollbars=yes,menubar=no,toolbar=no,resizable=yes");
}

function open_OpenHouseInfo(URL) {
	popup(URL, "OpenHouseInfo", "height=600,width=1100,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_printableBrochure(URL) {
	popup(URL, "PrintableBrochure", "height=600,width=735,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_preferredParters(URL) {
	popup(URL, "PreferredParters", "height=" + getWindowHeight(800) + ",width=615,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_showingtime(URL) {
	popup(URL, "ShowingTime", "height=" + getWindowHeight(730) + ",width=665,scrollbars=yes,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_neighborhood(URL) {
	popup(URL, "Neighborhood", "height=400,width=640,scrollbars=no,menubar=no,toolbar=no,status=yes,resizable=yes");
}
					
function open_homedocs() {
	popup("https://www.homedocs.com/index.htm", "HomeDocs", "height=440,width=600,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_referencelibrary(URL) {
	popup(URL, "ReferenceLibrary", "height=" + getWindowHeight(680) + ",width=640,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_ExternalSearch(URL) {
	popup(URL, "TRIOExternalSearch", "height=440,width=600,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function openValuation(URL) {
	popup(URL, "ValueSure", "height=700,width=900,scrollbars=yes,menubar=yes,toolbar=no,status=yes,resizable=yes");
}

function open_AgentWebsite(URL) {
	popup(URL,"AgentWebsite" , "height=700,width=900,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
}

function open_TextProperty(URL) {
	popup(URL,"TextProperty" , "height=220,width=460,scrollbars=no,menubar=no,toolbar=no,status=yes,resizable=yes");
}

function open_detail(url, listingid, height, width, resizable) // listing detail window
{
    // if the parameters aren't passed in then set them to default values.
    if (listingid == null || listingid == 'undefined' || listingid.length == 0)
        listingid = 'ListingDetail';
    if (height == null || height == 'undefined' || height.length == 0)
        height = 600;
    if (width == null || width == 'undefined' || width.length == 0)
        width = 620;
    if (resizable == null || resizable == 'undefined' || resizable.length == 0)
        resizable = 'yes';

    // Use the ListingID as the name of the window so that when a user opens the same property more than once, only 1 window is shown
    popup(url, listingid, 'width=' + width + ',height=' + height + ',toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=' + resizable);
}


// ########## END Popup Functions ############### //

function emailobfuscator(username,domain,ext) {
	location.href = "mail" + "to:" + username + "@" + domain + "." + ext;
}

function rollover(whichimg,overimg) {
	eval('document.images["' + whichimg + '"].src = ' + overimg + '.src');
}

function getWindowHeight(maxHeight) {
	var bufferHeight = 90;
	if (screen.height >= (maxHeight + bufferHeight)) {
		return maxHeight;
	} else {
		return (screen.height - bufferHeight);
	}
}

function fieldLengthLimit(field, maxlimit) {
    maxlimit = maxlimit - 1;
    if (field.value.length > maxlimit) {    // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    }
}

function validateEmailAddress(address) {
	if (address != '' && address.search) {
      if (address.search(/^\w+((-\w+)|(\.\w+)|(\'\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
      else return false;
	}
   // allow empty strings to return true - screen these with either a 'required' test or a 'length' test
   else return true;
}

function IsDate(objVal) {
    /**--------------------------
    //* Validate Date Field script- By JavaScriptKit.com
    //* For this script and 100s more, visit http://www.javascriptkit.com
    //* This notice must stay intact for usage
    ---------------------------**/
    var validformat = /^\d{2}\/\d{2}\/\d{4}$/;
    var isValid = false;

    if (validformat.test(objVal)) {// This RegEx is a basic check for format validity { // Begin detailed check for valid date ranges
        var monthfield = objVal.split("/")[0];
        var dayfield = objVal.split("/")[1];
        var yearfield = objVal.split("/")[2];
        var dayobj = new Date(yearfield, monthfield - 1, dayfield);
        if ((dayobj.getMonth() + 1 == monthfield) && (dayobj.getDate() == dayfield) && (dayobj.getFullYear() == yearfield))
            isValid = true;
    }
    return isValid;
}

// Validates to MM/DD/YYYY and by default will show an error message and clear the field.
function validateDate(obj, justValidate)
{
    var objVal = null;
    if (obj)
        objVal = obj.value;

    if(typeof(justValidate) == 'undefined')
        justValidate = false;

    var isValid = IsDate(objVal);
    if(!isValid && !justValidate) {
        alert('Please enter a date in the format MM/DD/YYYY.');
        obj.value = "";
        obj.focus();
    }
    
    return isValid;
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function currentlySearchingMenu(target) {
	if (target != "separator") {
		if (target.indexOf("popup") > 0) {
			var myWindow = window.open(target, "TRIOExternalSearch", "height=440,width=600,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
			myWindow.focus();
		} else {
			location.href = target;
		}
	}
}

function showHelp(menuName, containerName, show)
{
	if (document.getElementById(menuName) && document.getElementById(containerName)) {
		if (show == 1) {
			//alert('will display menu: ' + menuName)
			document.getElementById(menuName).style.top = document.getElementById(containerName).style.top; 
			document.getElementById(menuName).style.left = document.getElementById(containerName).style.left; 
			document.getElementById(menuName).style.visibility = 'visible';
		}
		else {
			document.getElementById(menuName).style.visibility="hidden";
		}
	}
}

function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripCharsNotInBag (s, bag){
  var i;
  var returnString = "";
  for (i = 0; i < s.length; i++){   
    // caracterul nu este spatiu
    var c = s.charAt(i);
    if (bag.indexOf(c) != -1) 
    {
		// remove everything after decimal point
		if( c == "." )
		{
			break;
		}
		else
		{
			returnString += c;
		}
	}
  }
  return returnString;
}

function checkInt (val)
{
    return (!isNaN(val));
}

function checkIntMaxValue (val)
{
	val = stripCharsNotInBag(val, '1234567890.');
	if (val > 2147483647)
	{
		return 2147483647;
	}
	return val;
}

function checkZip (val)
{
	if(val.length > 0) {
		var strippedVal = stripCharsInBag(val, ' ');
		return (strippedVal.length == 5 && checkInt(strippedVal));
	} else {
		return true;
	}
}

function delayPageRefresh(milliSecondWait)
{
	setTimeout("location.reload()", milliSecondWait);
}

function getRandom(num) 
{
	return Math.floor(Math.random() * num) + 1;
}
function getRandomImage(path,imagename,num,ext,background)
{
	if (background == 1)
	{
		return '<td width="100%" background="' + path + imagename + getRandom(num) + '.'+ ext + '"></' + 'td>';
	}
	else
	{
		return '<img src="' + path + imagename + getRandom(num) + '.' + ext + '" border="0"/>';
	}
}

// ########## Cookie Functions ############### //
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 eraseCookie(name)
{
	createCookie(name,"",-1);
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
// ########## END Cookie Functions ############### //

function toggleOpenHouseRange()
{
	if(
	       (document.getElementById('OpenHouses') != null && document.getElementById('OpenHouses').checked)
	    || (document.getElementById('Criteria/349') != null && document.getElementById('Criteria/349').checked)
	    || (document.getElementById('Criteria/575') != null && document.getElementById('Criteria/575').checked)
	  )
	{
        document.getElementById('OpenHouseStartDtm').disabled = false;
	    document.getElementById('OpenHouseStopDtm').disabled = false;
    }
    else
    {
	    document.getElementById('OpenHouseStartDtm').disabled = true;
	    document.getElementById('OpenHouseStopDtm').disabled = true;
    }
}
function OpenDrivingDirections(qs)
{
    var url = Utils.PublicAppName + '/Listing/PrintDrivingDirections.aspx';
    if (qs != '' && qs != undefined)
        url += '?' + qs;
        
    popup(url, 'PrintDirections', 
        'width=650,height=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function resizeIFrame(iframe) 
{ 
    if (iframe)
    {
        if ( iframe.contentDocument ) // firefox 
        { 
            iframe.height = iframe.contentDocument.height; 
        } 
        else // IE 
        { 
            iframe.style.height = iframe.contentWindow.document.body.scrollHeight; 
        }
          
    } 
}

function FieldHelpText(field, changeClass)
{
	if(changeClass == undefined)
		changeClass = true;

    if (field.defaultValue == field.value) 
    {
        field.value = '';
        if(changeClass)
            field.className = "txt_blk";
    }
    else if (field.value == '') 
    {
        field.value = field.defaultValue;
        if(changeClass)
            field.className = "txt_gray";
    }
}


/* 4/28/09 [Vince]: This section has been moved to \Include\Js\widgets\common.js

                var chartDivID;
                var chartStreet = "";
                var chartCityStateZip = "";
                var chartType = 3;
                var chartWidth = 250;
                var chartHeight = 200;
                var chartTitle = "";
                // Cyberhomes Chart Widget
                function GetChart()
                {
                    if (chartDivID != null && chartDivID != "undefined" && document.getElementById(chartDivID))
                    {
	                if (chartTitle == "undefined" || chartTitle == null)
	                       chartTitle = "";
                        var url = "/Public/Tools/GetValuationData.aspx?streetaddress=" + chartStreet + "&citystatezip=" + chartCityStateZip + "&charttype=" + chartType + "&width=" + chartWidth + "&height=" + chartHeight + "&chartonly=1&from=cyberhomes";
                        XMLRequestGET(url, chartDivID, chartTitle);   
                    }
                }

                var xmlrequests = new Array();
                function MyXMLReq(xmlhttp) 
                {
	                this.xmlhttp = xmlhttp;
                }
                function XMLRequestGET(url, divID, title) 
                {
	                var xmlhttp=false;
	                if (window.XMLHttpRequest) 
	                { // Mozilla, etc.
		                xmlhttp=new XMLHttpRequest();
		                xmlhttp.onreadystatechange = function() {XMLHttpChange(divID, title);};
		                xmlhttp.open("GET",url,true);
		                xmlhttp.send(null);
	                } 
	                else if (window.ActiveXObject) 
	                { // IE
		                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		                if (xmlhttp) 
		                {
			                xmlhttp.onreadystatechange = function() {XMLHttpChange(divID, title);};
			                xmlhttp.open("GET",url,true);
			                xmlhttp.send();
		                }
	                }
	                var xmlreq = new MyXMLReq(xmlhttp);
	                xmlrequests.push(xmlreq);
                }
                function XMLHttpChange(divID, title) 
                {
	                if (typeof(window['xmlrequests']) == "undefined") return;

	                for (var i=0; i < xmlrequests.length; i++) 
	                {
		                if (xmlrequests[i].xmlhttp.readyState == 4) 
		                {
			                if (xmlrequests[i].xmlhttp.status == 200 || xmlrequests[i].xmlhttp.status == 304) 
			                {
			                    if (xmlrequests[i].xmlhttp.responseText != "undefined" && xmlrequests[i].xmlhttp.responseText != "" && xmlrequests[i].xmlhttp.responseText.length > 10)
			                    {
				                    if (title == "" || title == "undefined")
				                        document.getElementById(divID).innerHTML = xmlrequests[i].xmlhttp.responseText;				
				                    else
				                        document.getElementById(divID).innerHTML = "<span class='chartHeader'>" + title + "</span><br/>" + xmlrequests[i].xmlhttp.responseText;				
				                }
				                else
				                    document.getElementById(divID).innerHTML = "";
			                } 
                            xmlrequests.splice(i,1); i--;		
		                }
	                }
                } 
*/


function addOption(obj, opt)
{
    try 
    {
        obj.add(opt, null); // standards compliant; doesn't work in IE
    }
    catch(ex) 
    {
        obj.add(opt); // IE only
    }
}

function DisplayFullDate() {
    var d = new Date()
    var weekday = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
    var monthname = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    var date = '';
    date += weekday[d.getDay()] + ", ";
    date += monthname[d.getMonth()] + " ";
    date += d.getDate() + ", ";
    date += d.getFullYear();
    document.write(date);
}
/* 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];
    default_ = default_ || "";
    return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
    var value = this.params[key];
    return (value != null);
}
