function popUp(URL,width,height)
{
	day = new Date();
	id = "win" + day.getTime();
	window.open(URL,id,"toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1,width=" + width + ",height=" + height);
}

function disableTextArea (textAreaId, maxchr, counterId)
{
	//maxchr = maximum character length of input box
	if (document.getElementById)
	{
		var textArea = (document.getElementById(textAreaId)) ? document.getElementById(textAreaId) : false;
		var counter = (document.getElementById(counterId)) ? document.getElementById(counterId) : false;
		if(textArea)
		{
			if(textArea.value.length > maxchr)
			{
				textArea.disabled = true;
				alert("maximum input length reached");
				textArea.value = textArea.value.substring(0, maxchr);
				textArea.disabled = false;
			}
			if (counter)
			{
				counter.innerHTML = textArea.value.length.toString() + "/" + maxchr.toString();
			}
		}
	}
}

function changeLanguage(lang)
{
	self.location.href += (self.location.search) ? "&lang=" + lang : "?lang=" + lang;
}

// This is used for redirecting legacy  OS to the appropriate client (98 abnd NT).
function redirect98(url)
{
	var os=navigator.userAgent.toLowerCase();
	if((os.indexOf('win')!=-1)&&((os.indexOf('98')!=-1)||(os.indexOf('nt 4')!=-1))) window.location=url;
}

/**
 * +++++++++++ BEGIN DHTML Menu Code +++++++++++++
 */

/**
 * Define MenuItem Object
 */
function MenuItem(url, name)
{
	this.url = url;
	this.name = name;
}
MenuItem.prototype.itemTemplate = "<li><a href='__url__'>__name__<\/a><\/li>";
MenuItem.prototype.buildListItem = function() // output HTML
{
	var strListItem = this.itemTemplate.replace("__url__", this.url);
	return strListItem.replace("__name__", this.name);
}
/**
 * End MenuItem object
 */


/**
 * Define Menu Object
 */
function Menu(parent) //creates a child with id = id to existing parent element with id = parent
{
	this.key = Menu.arrMenus.length;
	if (document.getElementById)//For recent browsers only - Non DOM brwosers can use side nav
	{
		this.arrList = new Array();
		this.id = "m_" + parent;
		this.visible = false;
		this.menu = document.createElement( "div" );
		this.menu.style.display = "none";
		this.menu.className = "menu";
		this.menu.id  = "m_" + parent;
		this.menu.onmouseover =  Menu.cancelHide;
		this.menu.onmouseout = Menu.startHide;
		this.parent = (document.getElementById(parent)) ? document.getElementById(parent) : false;
		if (this.parent)
		{
			this.parent.appendChild( this.menu );
			this.exists = true;
		}
		else
		{
			this.exists = false;
		}
	}
	else
	{
		this.exists = false;
	}
	Menu.arrMenus[this.key] = this;		
}
Menu.prototype.containerTemplate = "<ul>__list__<\/ul>";
Menu.prototype.addListItem = function (url, name)
{
	var listItem = new MenuItem(url, name);
	this.arrList.push(listItem);
}
Menu.prototype.buildList = function () //output HTML based on the template property
{
	var strList = "";
	for (i = 0; i < this.arrList.length; i++) strList += this.arrList[i].buildListItem();
	return this.containerTemplate.replace("__list__", strList);
}
Menu.prototype.show = function ()
{
	if (this.exists)
	{
		this.hideAll();
		this.stopCountDown();
		this.menu.style.display = "block";
		this.parent.className = "menu_on";
		this.visible = true;
	}
}
Menu.prototype.hideAll = function()
{
	for (i = 0; i < Menu.arrMenus.length; i++)
	{
		var menu = Menu.arrMenus[i];
		if (menu.exists)
		{
			if (menu.visible) 
			{
				menu.hide(); 
				menu.visible = false; 
				menu.parent.className = "";
			}
		}
	}
}
Menu.prototype.hide = function ()
{
	if (this.exists)
	{
		this.stopCountDown;
		this.parent.className = "";
		this.menu.style.display = "none";
	}
}
Menu.prototype.add = function ()
{
	if (this.exists) this.menu.innerHTML += this.buildList();
}

Menu.prototype.timeout = null;
Menu.prototype.startCountDown = function()
{
	if (this.exists)
	{
		this.stopCountDown();
		this.timeout = setTimeout( "Menu.arrMenus[" + this.key + "].hide()", 500 );
	}
}
Menu.prototype.longCountDown = function()
{
	if (this.exists)
	{
		this.stopCountDown();
		this.timeout = setTimeout( "Menu.arrMenus[" + this.key + "].hide()", 8000 );
	}
}
Menu.prototype.stopCountDown = function()
{
	if (this.timeout) clearTimeout(this.timeout);
}
// Static Menu methods/properties
Menu.cancelHide = function (e)
{
	for (i = 0; i < Menu.arrMenus.length; i++)
	{
		if (Menu.arrMenus[i].exists)
		{
			if (Menu.arrMenus[i].visible) Menu.arrMenus[i].stopCountDown();
		}
	}
}
Menu.startHide = function (e)
{
	if (!e) var e = window.event;
	var to = (e.relatedTarget) ? e.relatedTarget : e.toElement; // the element that the mouse out event has moved to
	for (i = 0; i < Menu.arrMenus.length; i++)
	{
		var menu = Menu.arrMenus[i];
		if (menu.exists)
		{
			if (menu.visible)
			{  
				while (to.nodeName != 'BODY') // bubble up from event either hitting the body or the last changed 
				{
					if (to == menu.menu) { return; }
					to = to.parentNode;
				}
				menu.startCountDown();
			}
		}
	}
}
Menu.arrMenus = new Array();
/**
 * End Menu object
 *
 * +++++++++++ END DHTML Menu Code +++++++++++++
 */

/* 
 * Begin Validation code
 */


function fillForm()
{
	for (var i = 0; i < postData.length; i++)
	{
		var arrKeyValue = postData[i].split('%%');
		var key = arrKeyValue[0];
		var value = (arrKeyValue.length > 0) ? arrKeyValue[1] : "";
		var element = document.getElementById(key);
		if (element && element.value == "") element.value = value;
		if (element && ((element.type == "radio") || (element.type == "checkbox"))) element.checked = true;
	}
}

function validate(form)
{
	if (!document.getElementById) return true; // Browser not DOM compliant so let the server do the validation work
	buildControlArray(form);
	var isValid = true;
	var errorHead = document.getElementById("errorHead");
	var errorMessage = new Array();
	for (var i = 0; i < Control.arrControls.length; i++)
	{
		var ctrl = Control.arrControls[i];
		if (!ctrl.validateControl())
		{
			errorMessage[ctrl.element.name] = ctrl.errorMessage;
			isValid = false;
			ctrl.element.style.borderColor = "#F00";
			ctrl.element.style.backgroundColor = "#ffdada";
			if (document.getElementById('errorMessage_' + ctrl.element.name))
			{
				Control.multipleErrorMsgs = true;
				var em = document.getElementById('errorMessage_' + ctrl.element.name);
				em.innerHTML = ctrl.errorMessage;
				em.style.display = "block";
			}
		}
		else
		{
			ctrl.element.style.borderColor = "";
			ctrl.element.style.backgroundColor = "";
			if (document.getElementById('errorMessage_' + ctrl.element.name))
			{
				document.getElementById('errorMessage_' + ctrl.element.name).innerHTML = "";
				document.getElementById('errorMessage_' + ctrl.element.name).style.display = "none";
			}
		}
	}
	if (isValid)
	{
		return true;
	}
	else
	{
		if (document.getElementById('errorMessage') && !Control.multipleErrorMsgs)
		{
			document.getElementById('errorMessage').innerHTML = "";
			for (var msg in errorMessage)
			{
				document.getElementById('errorMessage').innerHTML += "<p>" + errorMessage[msg] + "<\/p>";
			}
		} 
		else if (!Control.multipleErrorMsgs)
		{
			eMessage = window.open('','eMessage','width=200,height=200,resizable,scrollbars=1');
			eMessage.document.write('<head><title>Form Error<\/title>')
			eMessage.document.write('<link rel="stylesheet" type="text/css" media="all" href="/css/default.css?20050705" \/><\/head>');
			eMessage.document.write('<body onLoad="self.focus();"><div id="errorMessage">')
			for (var msg in errorMessage)
			{
				eMessage.document.write("<p>" + errorMessage[msg] + "<\/p>");
			}
			eMessage.document.write(errorMessage);
			eMessage.document.write('<\/div><\/body>')
			eMessage.document.close();
		}
		return false;
	}
}


function buildControlArray(form)
{
	if (!Control.bFlag) //only build the controls on the first call;
	{
		for (var i = 0; i < form.length; i++)
		{
			if ((form[i].type == 'hidden') && (form[i].name.indexOf("valid__")==0)) 
			{
				// form[i].name structure = valid__validationType__fieldToValidate__matchField(optional)
				var arrObj = form[i].name.split('__');
				if (arrObj.length < 3) { continue; } //not enough arguments
				var validationType = arrObj[1]
				var element = (document.getElementById(arrObj[2])) ? document.getElementById(arrObj[2]) : false;
				if (!element) { continue; } //Object not found
				var matchElement = element;
				if (arrObj.length > 3) {
					 matchElement = (document.getElementById(arrObj[3])) ? document.getElementById(arrObj[3]) : element;
				}
				new Control(form, validationType, element, matchElement, form[i].value);
			}
		}
		Control.bFlag = true;
	}
}
// ---- Global variable for holding controls to validate ----
Control.arrControls = new Array();
Control.bFlag = false;
Control.multipleErrorMsgs = false;
// ----------------------------------------------------------

function Control(form, validationType, element, matchElement, errorMessage)
{
	this.form = form;
	this.validationType = validationType;
	this.element = element;
	this.matchElement = matchElement
	this.errorMessage = errorMessage;
	this.key = Control.arrControls.length;
	Control.arrControls[this.key] = this;
}

Control.prototype.validateControl = function()
{
	switch (this.validationType)
	{
		case "empty":		return this.checkEmptyTextBox();	break;
		case "email":		return this.checkEmail();			break;
		case "number":		return this.checkIsNumeric();		break;
		case "checkgroup":	return this.checkGroup();			break;
		case "selected":	return this.checkSelectBox();		break;
		case "match":		return this.checkMatch();			break;
		default:		return true;	break;
	}
}

Control.prototype.checkEmail = function ()
{
	var RE = /\S+@\S+\.\S+/;
	return (RE.test(this.element.value)) ?  true : false;
}

Control.prototype.checkEmptyTextBox = function()

{
	var RE = /\S+/;
	return (RE.test(this.element.value)) ? true : false;
}

Control.prototype.checkIsNumeric = function()
{
	var RE = /\d{1,}/;
	return (RE.test(this.element.value)) ?	true : false;
}

Control.prototype.checkSelectBox = function()
{
	return (this.element.selectedIndex > 0) ? true : false;
}

Control.prototype.checkMatch = function()
{
	return (this.element.value == this.matchElement.value) ? true : false;
}

Control.prototype.checkGroup = function()
{
	for (var i = 0; i < this.form.length; i++)
	{
		//is it a checkbox or radio begining with the group name
		if ( ((this.form[i].type == 'checkbox') || (this.form[i].type == 'radio')) && (this.form[i].name.indexOf(this.element.value)==0) ) 
		{
			if (this.form[i].checked) return true;
		}
	}
	return false;
}
/*
 *  End validation code
 */

// animation javascript

function ArrayAndPreLoadImages()
{
	var args = ArrayAndPreLoadImages.arguments;
	var i, d = document;
	var arr = new Array();
	for (i = 1; i < args.length; i++) 
	{
		var x = new Image();
		x.src = args[i];
		d.images[d.images.length] = x;
 		arr[arr.length] = x;
	}
	eval("d." + args[0] + " = new Object;");
	eval("d." + args[0] + " = arr;");
}

function createLayer(div, img, name)
{
	img.name = name;
	//var html = "<img id='" + img.name + "' src='" + img.src + "' height='" + img.height +"' width='" + img.width + "' class='hidden' >";
	var html = "<img id='" + img.name + "' src='" + img.src + "' class='hidden' >";
	var divRef;
	if(document.all)
	{
		divRef = document.all[div];
		divRef.innerHTML += html;
	} 
	else if(document.getElementById(div))
	{
		divRef = document.getElementById(div);
		divRef.innerHTML += html;
	} 
	else if(document.layers)
	{
		divRef = document.layers[div].document;
		with (divRef)
		{
			open();
			write(html);
			close();
		}
	}
}

function init()
{
	var args = init.arguments;
	var div = args[0];
	document.div = div;
	for (var i = 1; i < args.length; i++)
	{
		var arr = eval("document." + args[i]);
		for (var j = 0; j < arr.length; j++)
		{
			createLayer(div, arr[j], args[i] + j);
		}
	}
}

function animate(name, current)
{
	var cmd, img, arr = eval("document." + name);
	var d = document;
	if(d.tout!=null) clearTimeout(d.tout);
	if(current=="")
	{
		current = 0;
	}
	if(d.lastChanged!=null)
	{
		img = d.lastChanged;
		d.images[img].className= 'hidden';
	}
	img = arr[current].name;
	d.lastChanged = img;
	div = d.div;
	//Apply sexy image fade in to IE browsers only
	if(d.all)
	{
		d.images[img].filters[0].Apply();
		d.images[img].filters[0].Play();
	}
	
	d.images[img].className = '';
	if(current < arr.length-1)
	{
		cmd = "animate('" + name + "'," + parseInt(current+1) + ");";
		d.tout = setTimeout(cmd, 3000);
	}
	else
	{
		cmd = "animate('" + name + "',0);";
		d.tout = setTimeout(cmd, 3000);
	}
}

function toggleTab(id)
{
    for (var i = 0; i < tabList.length; i++)
    {
        document.getElementById(tabList[i] + "_tab").className = 'off';
        document.getElementById(tabList[i] + "_content").style.display = 'none';
    }
    document.getElementById(id + "_tab").className = 'on';
    document.getElementById(id + "_tab").blur();
    document.getElementById(id + "_content").style.display = 'block';
}

// Clear Search box on focus
function search_focus()
{
    if (!document.getElementById) return;
    var o = document.getElementById('q');
    if (!o) return;
    o.onfocus = function()
    {
        if (o.value == 'Search') o.value = '';
    }
    if (o.captureEvents) o.captureEvents(Event.FOCUS);

}

// Popups for Knowledgebase screenshots
init_anchors = function() {
    var al = document.links;
    var alsize = al.length;
    // onclick event with "image_pop" class
    for (var i = 0; i < alsize; i++) {
        if (al[i].className == 'image_pop') {
            al[i].onclick = image_pop;
        }
        if (al[i].className == 'popup') {
            al[i].onclick = popup;
        }
    }
}
window.onload = function()
{
    search_focus();
    init_anchors();
}

image_pop = function(e) {
    // Event object for IE
    e = (e) ? e : (event) ? event : null;
    // Prevent original event propagation
    if (e.preventDefault) e.preventDefault()
    else e.returnValue = false;

    var element = (e.target) ? e.target : (e.srcElement) ? e.srcElement: null;
    // bubble up to the anchor tag to read the href
    while (element) {
        if (element.className && element.className == 'image_pop') break;
        if (element.parentNode) element = element.parentNode;
        else element = false;
    }
    if (!element) return false;
    var href = element.href;
    window.open(href);
}

popup = function(e) {
    // Event object for IE
    e = (e) ? e : (event) ? event : null;
    // Prevent original event propagation
    if (e.preventDefault) e.preventDefault()
    else e.returnValue = false;

    var element = (e.target) ? e.target : (e.srcElement) ? e.srcElement: null;
    // bubble up to the anchor tag to read the href
    while (element) {
        if (element.className && element.className == 'popup') break;
        if (element.parentNode) element = element.parentNode;
        else element = false;
    }
    if (!element) return false;
    var href = element.href;
    var q = decodeURIComponent(href);
    if (q.indexOf('?') > -1) q = q.substr(q.indexOf('?')+1);
    var qs = q.split('&');
    var args = new Array();
    for (var i in qs) {
        var arg = qs[i];
        var s = arg.split('=');
        args[s[0]] = s[1];
    }
    var width = (args['width']) ? args['width'] : '';
    var height = (args['height']) ? args['height'] : '';
    var attributes = "scrollbars=1,statusbar=1,menubar=1,resizable=1,width=" + width + ",height=" + height;
    window.open(href, 'popup', attributes);
}

