// JavaScript Document
//var previouscolor='';
//function focusElement()
//{
//previouscolor=this.style.borderColor; this.style.borderColor='#FF0000';
//}
//function blurElement() { this.style.borderColor=previouscolor; }
//Selecting the first input box available

var j=0; var flag=true;
var buttonSubmit=true;
while((j<document.forms.length))
	{
	var i=0;
	while ((i<document.forms[j].length))
		{		
		obj=document.forms[j].elements[i];
		if (obj.getAttribute('noFocus')!='yes')
			{
			if(obj.tagName!='SELECT') obj.onfocus=showTooltip;
			else obj.onmousedown=showTooltip;
			obj.onblur=hideTooltip;
			if (obj.type!='hidden')
				if (obj.id!='ignore')
					if(flag)
						if(obj.tagName=='INPUT')
							if(obj.type!='submit')
								if(obj.type!='button')
									if (obj.disabled==false)
										if (obj.style.visibility!='hidden')
											if (obj.style.display!='none')
												if(obj.focus)
													{
													obj.select();
													obj.focus();
													flag=false;
													}
			if (obj.type=='file')
				obj.onchange=onChangeCheckAllowed;
			}
		i++;
		}
	document.forms[j].onsubmit=processSubmit;
	j++;	
	}

function processSubmit()
	{
	if (checkFields(this)===false)
		return false;
	}

function deactivateSubmit(element)
	{
	if (element.parentNode!=undefined)
		{
		var working=document.createElement('div');
		working.setAttribute('style','font-weight:bold;');
		working.innerHTML="<blink>SUBMITTING...</blink>";
		element.parentNode.insertBefore(working,element);
		element.style.display='none';
		}
	}

function onChangeCheckAllowed()
	{
	var notAllowed=checkAllowed(this)
	if (notAllowed)
		alert(notAllowed);
	}

function checkAllowed(element)
	{
	var allowed=element.getAttribute('allow');
	if (allowed)
		{	
		if (element.value!='')
			{
			file=element.value;
			if (file.indexOf('.')!=-1)
				{
				var extension=file.substr(file.lastIndexOf('.')+1);
				var is_array=false;
				if (allowed.indexOf(',')!=-1)
					{
					is_array=true;
					allowed_array=allowed.split(',');
					}
				if (!is_array)
					{
					if (allowed.toUpperCase()!=extension.toUpperCase())
						return "You have uploaded a "+extension.toUpperCase()+" file but you are only allowed to upload "+allowed.toUpperCase()+" files!";
					}
				else
					{
					var is_valid=false;
					for (var i in allowed_array)
						if (allowed_array[i].toUpperCase()==extension.toUpperCase())
							is_valid=true;
					if (!is_valid)
						return "You have uploaded a "+extension.toUpperCase()+" file but you are only allowed to upload "+allowed.toUpperCase()+" files!";
					}
				}
			else
				return "We could not determine the type of your file. Please choose another one!";
			}
		}
	return false;
	}
	
function checkFields(element)
{
var flag=true;
var i=0;
var submiters=Array();
while ((i<element.length))
	{	
	obj=element.elements[i];
	if (obj.getAttribute('isRequired')=='yes')
		if(obj.value=='')
			{
			requiredName=obj.getAttribute('requiredName').toLowerCase();
			requiredName=requiredName.charAt(0).toUpperCase()+requiredName.substr(1);
			alert(requiredName+' is missing !');
			return false;
			}
	if (obj.type=='file')
		{
		var notAllowed=checkAllowed(obj);
		if (notAllowed)
			{
			alert(notAllowed);
			return false;
			}
		}
	if (obj.type=='submit')
		if (obj.getAttribute('noFocus')!='yes')
			submiters[i]=obj;
	i++;
	}
for (var j in submiters)
	deactivateSubmit(submiters[j]);
}

function showTooltip()
{
this.style.backgroundColor = '#FFE6F6';
this.style.color ='#000000';
if(this.name) if(typeof(tooltips)!='undefined')
	{
	var flag=true, i=0;
	while((i<tooltips.length)&&(flag))
		if(this.name==tooltips[i]) flag=false;
		else i+=2;
	if(!flag)
		{
		var coors = findPos(this);
		var x = document.getElementById('Tooltip');
		var elemWidth=parseInt(this.offsetWidth);
		var additional=parseInt(this.getAttribute('additional'));
		if (!isNaN(additional))
			elemWidth=elemWidth+additional;
		x.style.top = coors[1] + 'px';
		x.style.left = coors[0] +elemWidth+10+'px';
		x.innerHTML=tooltips[i+1];x.style.visibility='visible';
		}
	}

}

function showTips(Obj,text)
{
var coors = findPos(Obj);
var x = document.getElementById('Tooltip');
var elemWidth=parseInt(Obj.offsetWidth);
var additional=parseInt(Obj.getAttribute('additional'));
if (!isNaN(additional))	elemWidth=elemWidth+additional;
x.style.top = coors[1] + 'px';
x.style.left = coors[0] +elemWidth+10+'px';
x.innerHTML=text;
x.style.visibility='visible';
}

function hideTips() 
	{
	var x = document.getElementById('Tooltip');
	x.style.visibility='hidden';
	}

function hideTooltip() 
	{
	var x = document.getElementById('Tooltip');
	x.style.visibility='hidden';
	this.style.backgroundColor = '';	
	this.style.color='';
	}

function findPos(InputTag)
	{
	var curleft = curtop = 0;
		curleft = InputTag.offsetLeft
		curtop = InputTag.offsetTop
		while (InputTag = InputTag.offsetParent) {
			curleft += InputTag.offsetLeft
			curtop += InputTag.offsetTop
		}
	return [curleft,curtop];
	}


	
function doBlink()
{
var blink = document.all.tags('BLINK')
for (var i=0; i < blink.length; i++)
  blink[i].style.visibility = blink[i].style.visibility == '' ? 'hidden' : '' 
}
if (document.all) setInterval('doBlink()',1000);

function q(name){return confirm('Are you sure you want to delete ' + name + ' ?');}

function p(name){return confirm('Are you sure you want to ' + name + ' ?');}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function capsDetect(Obj,e) 
{
 if(!e) e = window.event;
 if(!e) return; 
 var theKey = 0;
 if( e.which ) { theKey = e.which; } 
 else if( e.keyCode ) { theKey = e.keyCode; } 
 else if( e.charCode ) { theKey = e.charCode } 
 var theShift = false;
 if( e.shiftKey ) theShift = e.shiftKey;
 else if( e.modifiers ) 
 	{ 
    if( e.modifiers & 4 ) theShift = true;
	}
 
 if( theKey > 64 && theKey < 91 && !theShift ) showTips(Obj,'Caps Lock is ON');
 else if( theKey > 96 && theKey < 123 && theShift ) showTips(Obj,'Caps Lock is ON');
 else hideTips();
}
function preventMoreClicks(e)
{
    if (!e)
      e = window.event;

    if (e.cancelBubble)
      e.cancelBubble = true;
    else
      e.stopPropagation();
}