
function SetDropDown(triggerID,targetID){
    targetID.disabled = !triggerID.checked;
    }

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(InputName, CounterName, maxlimit) {
    var Input = document.getElementById(InputName);
    var Counter = document.getElementById(CounterName);
	if (Input.value.length > maxlimit) {
		Input.value = Input.value.substring(0, maxlimit);
	}
	else {
//		var obj = MM_findObj(countfield);
		Counter.innerHTML = maxlimit - Input.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;
}

// Switch stylesheet for large browser ------------------------------------------
if (clientWidth > 600) {
//	setActiveStyleSheet('Normal');
	// Insert IE-fix stylesheet -----------------------------------------
	if (browserDetect('browser')=='Internet Explorer') {
//		document.write('<link href="common/aanavigator-ie.css" rel="stylesheet" type="text/css" media="screen" />');
	}
}
else {
//	setActiveStyleSheet('Small screen');
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function applySection(section) {
	switch ( section ) {
		case 'products': {
//			document.getElementById("navProducts").className = "nav1active";
			return;
		}
		case 'shop': {
//			document.getElementById("navContact").className = "nav1active";
			return;
		}
		case 'support': {
//			document.getElementById("navServices").className = "nav1active";
			return;
		}
		default: {
//			document.getElementById("navHome").className = "nav1active";
			return;
		}
	}
}


function ShowOne(container,searchClass,showDiv) {
	var contentDiv = document.getElementById(container);
//alert(document.getElementById(container));
	for(var i=0;i < contentDiv.childNodes.length;i++) {
		if (hasClassName(contentDiv.childNodes[i], searchClass)) {
			contentDiv.childNodes[i].style.display = 'none';
		}
	}
	if (document.getElementById(showDiv)) document.getElementById(showDiv).style.display = 'block';
}
function ChangeDisplay(container,searchClass,strDisplay) {
	var contentDiv = document.getElementById(container);
//alert(document.getElementById(container));
	for(var i=0;i < contentDiv.childNodes.length;i++) {
		if (hasClassName(contentDiv.childNodes[i], searchClass)) {
			contentDiv.childNodes[i].style.display = strDisplay;
		}
	}
}
function hasClassName(el, name) {

  var i, list;

  if (el.className) {
		list = el.className.split(" ");
  	for (i = 0; i < list.length; i++)
  	  if (list[i] == name)
  	    return true;
	}
  return false;
}
function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

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;
}


// 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);
    }
}
