
function SetAllDay(checkboxId,starttime,endtime) {
    //var starttime = $find(starttimeId.id);
    //var endtime = $find(endtimeId.id);
    if (checkboxId.checked) {
        starttime.style.display = "none";
        //starttime.get_textBox().style.display = "none";
        endtime.style.display = "none";
    }
    else {
        starttime.style.display = "inline";
        //starttime.get_textBox().style.display = "inline";
        endtime.style.display = "inline";
    }
}
function ToggleDatePopup(element) {
    $find(element.id).togglePopup();
}
function ToggleTimePopup(element) {
    $find(element.id).toggleTimePopup();
}


// Character counter for text area fields -----------------------------------
// onKeyDown="textCounter(this.form.message,this.form.remLen,1000)"
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		var obj = MM_findObj(countfield);
		obj.innerHTML = maxlimit - field.value.length;
	}
}


// Browser detect script -------------------------------------------------
var detect = navigator.userAgent.toLowerCase();
var thestring;
function browserDetect(attribute) {
	var OS,browser,version,total;
	
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";
	
	if (!version) version = detect.charAt(place + thestring.length);
	
	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
	switch ( attribute ) {
		case 'OS': return OS;
		case 'version':  return version;
		default:  return browser;
	}
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


// Find window width --------------------------------------------------------
var clientWidth, clientHeight;
if (self.innerHeight) // all except Explorer
{
	clientWidth = self.innerWidth;
	clientHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
{
	clientWidth = document.documentElement.clientWidth;
	clientHeight = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
	clientWidth = document.body.clientWidth;
	clientHeight = document.body.clientHeight;
}


function getLeftOffset(el) {
// Return the x coordinate of an element relative to the page.
  var x;
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getLeftOffset(el.offsetParent);
  return x;
}

function getTopOffset(el) {
// Return the x coordinate of an element relative to the page.
	var y;
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getTopOffset(el.offsetParent);
  return y;
}



// A set of Page Query functions ************************************
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
		this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
	return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key){
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}

function displayItem(key){
	if(queryString(key)=='false') {
		document.write("you didn't enter a ?name=value querystring item.");
	}
	else {
		document.write(queryString(key));
	}
}


// Use this function to retrieve a cookie. ************************************
function getCookie(name){
var cname = name + "=";               
var dc = document.cookie;             
    if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
        if (begin != -1) {           
        begin += cname.length;       
        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
return null;
}

// Use this function to save a cookie.
function setCookie(name, value, expires) {
	document.cookie = name + "=" + escape(value) + "; path=/" +
	((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

// Use this function to delete a cookie.
function delCookie(name) {
	document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

//var exp = null;
var exp = new Date();
exp.setTime (exp.getTime() + (24 * 60 * 60 * 1000 * 31));

function setChip(cookie, name, value) {
	var dc = getCookie(cookie);              
	var cv = getChip(cookie, name); 
	var cn = name + '=';
    if (cv != null) {                        
    var start = dc.indexOf(cn);              
        if (start != -1) {
        var end = dc.indexOf('|', start);           
        setCookie(cookie, dc.substring(0, start) + cn + value + '|' + dc.substring(end + 1, dc.length), exp);
        }        
    }
    else {
       if (dc != null) dc += cn + value + '|';
       else dc = cn + value + '|';                              
    setCookie(cookie, dc, exp);
    }
}

function getChip(cookie, name){
	var cn = name + '=';
	var dc = getCookie(cookie);
    if (dc != null) {
    var start = dc.indexOf(cn);
       if (start != -1) {                       
       start += cn.length;
       var end = dc.indexOf('|', start);  
           if (end != -1) return unescape(dc.substring(start, end));
       }
   }
	return null;
}

function delChip(cookie, name) {
	var dc = getCookie(cookie);
	var cv = getChip(name); 
	var cn = name + '=';                     
    if (cv != null) {                         
    var start = dc.indexOf(cn); 
    var end = dc.indexOf('|', start);           
    setCookie(cookie, dc.substring(0, start) + dc.substring(end + 1, dc.length), exp);
    }
}

