//----- PRELOADING -----
/*
These give 404's
waitBlack = new Image();
waitBlack.src = '../img/widgets/wait_black.gif';
waitWhite = new Image();
waitWhite.src = '../img/widgets/wait_white.gif';
waitWhite = new Image();
waitWhite.src = '../img/widgets/wait_333333.gif';
waitWhite = new Image();
waitWhite.src = '../img/widgets/wait_444444.gif';
*/

deferFormSubmit=false;

//----- FUNCTIONS -----
function focusInputBox(textbox)
{
	//textbox.style.backgroundImage = 'url("../img/repeaters/inputBox_focus_repeater.png")';
}
function unfocusInputBox(textbox)
{
	//textbox.style.backgroundImage = 'url("../img/repeaters/inputBox_repeater.png")';
}
function changeInnerHtml(elementId, text)
{
	document.getElementById(elementId).innerHTML = text;
}
function fadeAfterTimeout(id, opacStart, opacEnd, millisec, timeout)
{
	window.setTimeout("fade('"+id+"', "+opacStart+", "+opacEnd+", "+millisec+")", timeout);
}
function fade(id, opacStart, opacEnd, millisec)
{
	fade(id, opacStart, opacEnd, millisec, false);
}
function fade(id, opacStart, opacEnd, millisec, hideToo)
{
	//speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "', "+(hideToo?'true':'false')+")",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "', "+(hideToo?'true':'false')+")",(timer * speed));
            timer++;
        }
    } 
}
//change the opacity for different browsers
function changeOpac(opacity, id, hideToo) {
    var object = document.getElementById(id);
    
    if (!object) return;
    
    var objectStyle = object.style;
    objectStyle.opacity = (opacity / 100);
    objectStyle.MozOpacity = (opacity / 100);
    objectStyle.KhtmlOpacity = (opacity / 100);
    objectStyle.filter = "alpha(opacity=" + opacity + ")";
    
    if (opacity==0 && hideToo) {
    	object.style.display = 'none';
    	changeOpac(100, id, false);
    }
}
function redirectAfterTimeout(url, timeout)
{
	window.setTimeout("redirect('"+url+"')", timeout);
}
function redirect(url)
{ 
	window.location = url;
}
function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
	}
  
  return new Array(myWidth, myHeight);
}
function getBackgroundImage(element)
{
	if(element.currentStyle) {
		return element.currentStyle.backgroundimage;
	} 
	else {
		return getComputedStyle(element,'').getPropertyValue('background-image');
	}
}
function getBackgroundPosition(element)
{
	if(element.currentStyle) {
		return element.currentStyle.backgroundPosition;
	} 
	else {
		return getComputedStyle(element,'').getPropertyValue('background-position');
	}
}
function changeBackgroundImage(element, image)
{
	element.style.backgroundImage = 'url("'+image+'")';
}
function toggleAllCheckboxes(formId, checkboxElementId, toggleVariableName)
{
	var toggleVariable = !window[toggleVariableName];
	window[toggleVariableName] = toggleVariable;
	
	var i;
	for (i=0; i < document.forms[formId].elements.length; i++) {
		if ((document.forms[formId].elements[i].type == 'checkbox') &&
			(!checkboxElementId || document.forms[formId].elements[i].name.indexOf(checkboxElementId) > -1)
			)
		{
			document.forms[formId].elements[i].checked = toggleVariable;
		}
	}
}
function countToggledCheckboxes(formId, checkboxElementId)
{
	var retVal = 0;
	
	var i;
	for (i=0; i < document.forms[formId].elements.length; i++) {
		if ((document.forms[formId].elements[i].type == 'checkbox') &&
			(document.forms[formId].elements[i].name.indexOf(checkboxElementId) > -1) &&
			document.forms[formId].elements[i].checked)
		{
			retVal++;
		}
	}
	
	return retVal;
}
String.prototype.count=function(s1) { 
	return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
};
String.prototype.trim = function () {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
};
function detectLeftButton(evt)
{
    evt = evt || window.event;
    var button = evt.which || evt.button;
    return button == 1;
}
function showAutoModalWait(link, event)
{
	var showModal = false;
	
	try {
		if (link && detectLeftButton(event)) {
			var href = null;
			try {
				href = event.currentTarget.attributes['href'].nodeValue;
			} catch (e) {
				href="";
			}
			
			var target = null;
			try {
				target = event.currentTarget.attributes['target'].nodeValue;
			} catch (e) {
				target = "";
			}
			
			var onclick = null;
			try {
				onclick = event.currentTarget.attributes['onclick'].nodeValue;
			} catch (e) {
				onclick = "";
			}
			
			if (   !target &&
					href.indexOf('javascript')<0 &&
					href.indexOf('mailto:')<0 &&
					onclick.indexOf("Modal")<0 &&
					href.indexOf("#")<0)
			{
				showModal = true;
			}
		}
	}
	catch (e) {
		showModal = false;
	}
	
	if (showModal) {
		showAjaxModalWait();
	}
	
	return true;
}
function clearFileInputField(containerTag)
{
	containerTag.innerHTML = containerTag.innerHTML;
}

 
