// Global variables
var flashContainerCount = 0;
var initDescription = "";
var textInjectForbiden = false;

function OpenWindow(url, winWidth, winHeight, resizable, scrollable, winName)
{
	if (winWidth == null) winWidth = 100;
	if (winHeight == null) winHeight = 100;
	if (resizable == null) resizable = "yes";
	if (scrollable == null) scrollable = "yes";
	try
	{
		var newWindow = this.open(url, winName, "resizable=" + resizable + ", scrollbars=" + scrollable + ", status=no, width=" + winWidth + ", height=" + winHeight);
		if (newWindow) newWindow.focus();
	}
	catch(e)
	{}
}
function Bookmark(bookmarkUrl, bookmarkTitle)
{
	if (document.all) window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
}

function FlashMovie(movieName)
{
	//if(navigator && navigator.appName)
	{
		if (navigator.appName.indexOf("Microsoft") != -1)
		{
			return window[movieName];
		}
		else
		{
			return document[movieName];
		}
	}
}

var loading = false;
function LoadData(contentId, loadingContentId, loadUrl, loadingContentData)
{
	var contentObj = document.getElementById(contentId);
	var loadingObj = document.getElementById(loadingContentId);
	if (contentObj && loading == false && lastLoadedPage != loadUrl) 
	if (contentObj && loading == false) 
	{
		loading = true;
		AjaxRequest.get
		(
			{
				'url': loadUrl
				,'timeout':20000
				,'onLoading':function(req)
				{
					if (loadingObj) loadingObj.style.visibility = 'visible';
				}
   				,'onTimeout':function(req)
				{
					if (loadingObj) loadingObj.style.visibility = 'hidden';
					ShowContent(contentObj, req.responseText);
					loading = false;
				}
    			,'onError':function(req)
				{
					if (loadingObj) loadingObj.style.visibility = 'hidden';
					ShowContent(contentObj, req.responseText);
					loading = false;
				}
				,'onSuccess':function(req)
				{
					if (loadingObj) loadingObj.style.visibility = 'hidden';
					ShowContent(contentObj, req.responseText);
					loading = false;
				}
			}
		);
	}
}

function ShowContent(contentObj, contentData)
{
	try
	{
		if (contentObj)
		{
			if (contentData)
			{
				if (contentData.toString().length > 0)
				{
					if (contentObj.innerHTML.toLowerCase() != contentData.toString().toLowerCase())
					{
						contentObj.innerHTML = contentData;
					}
				}
			}
		}
	}
	catch(e)
	{}
}

function InsertDiv(targetId, htmlContent, holderId, initDisplayState, bgColorValue, classIdValue, preserve)
{
	var divObj;
	var holderObj;
	if (holderId.length > 0) holderObj = document.getElementById(holderId);
	if (targetId.length > 0)
	{
		var formatedColor;
		if (bgColorValue.length > 0) formatedColor = " bgcolor='" + bgColorValue + "'";
		var formatedClass;
		if (classIdValue.length > 0) formatedClass = " class='" + classIdValue + "'";
		var divContent = "<table width='100%' height='100%' cellspacing='0' cellpadding='0'" + formatedColor + "><tr valign='middle'><td align='center'>" + htmlContent + "</td></tr></table>";
		if (initDisplayState.length == 0) initDisplayState = "none";
		var div = "<div id='" + targetId + "' style='overflow: hidden; display: " + initDisplayState + "; position: absolute; z-Index: 100; height: 100%; width: 100%;'" + formatedClass + ">" + divContent + "</div>";
		if (holderObj)
		{
			if (preserve == true)
			{
				holderObj.innerHTML = div + holderObj.innerHTML;
				
			}
			else
			{
				holderObj.innerHTML = div;
			}
			divObj = holderObj.getElementsByTagName(targetId);
		}
		else
		{
			document.write(div);
			divObj = document.getElementById(targetId);
		}
	}
	return divObj;
}
function SubmitFormByIndex(formsIndex)
{
	if (formsIndex != null && formsIndex >= 0)
	{
		if (document.forms[formsIndex]) document.forms[formsIndex].submit();
	}
}

function InsertFlash(flashContainer, targetId)
{
	if(document.all)
	{
		if (document.all[targetId]) document.all[targetId].innerHTML = flashContainer;
	}
	else
	{
		if (document.getElementById && document.getElementById(targetId))document.getElementById(targetId).innerHTML = flashContainer;
	}
}
function FlashObjectBuilder(flashVersion, wValue, hValue, srcValue, transparent, bgColorValue, nameId, noScale, useFullscreen)
{
	if (bgColorValue == undefined) bgColorValue = "000000";
	if (transparent == undefined) transparent = true;
	if (flashVersion == undefined) flashVersion = "8";
	if (useFullscreen == undefined) useFullscreen = false;
	if (flashVersion < 9 && useFullscreen == true) flashVersion = 9;
	var flashCode = '<object ';
	flashCode += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	flashCode += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + flashVersion + ',0,0,0" ';
	flashCode += 'width="' + wValue + '" ';
	flashCode += 'height="' + hValue + '" ';
	flashCode += 'id="' + nameId + '" ';
	flashCode += 'align="middle">';
	flashCode += '<param name="allowScriptAccess" value="always" />';
	flashCode += '<param name="movie" value="' + srcValue + '" />';
	flashCode += '<param name="menu" value="false" />';
	flashCode += '<param name="quality" value="best" />';
	if (noScale == true) flashCode += '<param name="scale" value="noscale" />';
	flashCode += '<param name="salign" value="lt" />';
	if (transparent == true) flashCode += '<param name="wmode" value="transparent" />';
	if (useFullscreen == true) flashCode += '<param name="allowFullScreen" value="true" />';
	flashCode += '<param name="bgcolor" value="#' + bgColorValue + '" />';
	flashCode += '<embed ';
	flashCode += 'src="' + srcValue + '"';
	flashCode += 'menu="false" ';
	flashCode += 'quality="best" ';
	if (noScale == true) flashCode += 'scale="noscale" ';
	flashCode += 'salign="lt" ';
	if (transparent == true) flashCode += 'wmode="transparent" ';
	if (useFullscreen == true) flashCode += 'allowfullscreen="true" ';
	flashCode += 'bgcolor="#' + bgColorValue + '" ';
	flashCode += 'width="' + wValue + '" ';
	flashCode += 'height="' + hValue + '" ';
	flashCode += 'name="' + nameId + '" ';
	flashCode += 'align="middle" ';
	flashCode += 'allowScriptAccess="always" ';
	flashCode += 'type="application/x-shockwave-flash" ';
	flashCode += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	flashCode += '</object>';
	
	return flashCode;
}

function GetUrl(urlValue)
{
	if (urlValue.length > 0)
	{
		document.location = urlValue;
	}
}

function RestoreDiv(targetId)
{
	if (initDescription && initDescription.length > 0 && !textInjectForbiden)
	{
		if(document.all)
		{
			document.all[targetId].innerHTML = initDescription;
		}
		else
		{
			document.getElementById(targetId).innerHTML = initDescription;
		}
	}
}

function TextInDiv(textValue, targetId, ignoreInit)
{
	if (ignoreInit == null) ignoreInit = false;
	if (!textInjectForbiden)
	{
		if(document.all)
		{
			if (!ignoreInit && initDescription.length == 0) initDescription = document.all[targetId].innerHTML;
			document.all[targetId].innerHTML = textValue;
		}
		else
		{
			if (!ignoreInit && initDescription.length == 0) initDescription = document.getElementById(targetId).innerHTML;
			document.getElementById(targetId).innerHTML = textValue;
		}
	}
}

function Highlight(colorValue, targetId, isImage)
{
	var tagetObj;
	if(document.all)
	{
		tagetObj = document.all[targetId];
	}
	else
	{
		tagetObj = document.getElementById(targetId);
	}
	
	if (tagetObj)
	{
		if (isImage)
		{
			tagetObj.style.backgroundImage = "url(" + colorValue + ")";
		}
		else
		{
			tagetObj.style.background = colorValue;
		}
	}
}

function SubmitOnKey(keyCodeIndex, formTarget, e)
{
	var keynum = 0;
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	if (formTarget && keynum == keyCodeIndex)
	{
		formTarget.submit();
	}
}

function FocusFieldOnKey(keyCodeIndex, targetField, e)
{
	var keynum = 0;
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	
	if (targetField && keynum == keyCodeIndex)
	{
		targetField.focus();
	}
}

function FocusField(targetField)
{
	if (targetField)
	{
		targetField.focus();
	}
}

function ShowHide(elementId)
{
	var srcElement = GetObjById(elementId);
	if(srcElement != null && srcElement.style != null)
	{
		if(srcElement.style.display == "block")
		{
			srcElement.style.display= 'none';
		}
		else
		{
			srcElement.style.display='block';
		}
	}
	return false;
}


function Hide(elementId)
{
	var srcElement = GetObjById(elementId);
	if(srcElement != null)
	{
		if(srcElement.style.display == "block")
		{
			srcElement.style.display= 'none';
		}
	}
	return false;
}

function Show(elementId)
{
	var srcElement = GetObjById(elementId);
	if(srcElement != null)
	{
		if(srcElement.style.display == "none")
		{
			srcElement.style.display= 'block';
		}
	}
	return false;
}

function DisableSelect(target)
{
	if (typeof target.onselectstart != "undefined") //IE route
		target.onselectstart=function(){return false}
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
		target.style.MozUserSelect="none"
	else //All other route (ie: Opera)
		target.onmousedown=function(){return false}
	//target.style.cursor = "default"
}

function ChangeCss(obj, borderColorLeft, borderColorTop, borderColorRight, borderColorBottom, borderSize)
{
	if (!borderSize || borderSize.length == 0 || borderSize <= 0) borderSize = 1;
	if (obj && borderColorLeft && borderColorLeft.length > 0)
	{
		if ((!borderColorTop || borderColorTop.length == 0) && (!borderColorRight || borderColorRight.length == 0) && (!borderColorBottom || borderColorBottom.length == 0))
		{
			obj.style.borderColor = "#" + borderColorLeft;
		}
		else
		{
			obj.style.borderLeft = borderSize + "px #" + borderColorLeft + " solid";
			obj.style.borderTop = borderSize + "px #" + borderColorTop + " solid";
			obj.style.borderRight = borderSize + "px #" + borderColorRight + " solid";
			obj.style.borderBottom = borderSize + "px #" + borderColorBottom + " solid";
		}
	}
}

function Bookmark(url, title)
{
	if (url && url.length > 0 && title && title.length > 0)
	{
		if(window && window.sidebar)
		{
			// Firefox
			//window.sidebar.addPanel(title, url,'');
			//Handle it from the link
		}
		else if(window && window.opera && window.print)
		{
			// Opera
			/*
			var elem = document.createElement('a');
			elem.setAttribute("title", title);
			elem.setAttribute("rel","sidebar");
			elem.setAttribute("href", "#");
			elem.click();
			*/
			// Handle it from the link
		}
		else if(document && document.all && window && window.external)
		{
			//IE
			window.external.AddFavorite(url, title);
		}
	}
}
function CheckCharCount(maxChars, fieldObj, labelId)
{
	if (fieldObj && maxChars > 0)
	{
		var label = document.getElementById(labelId);
		var currentLength = fieldObj.value.length;
		if (currentLength >= maxChars - 1)
		{
			fieldObj.value = String(fieldObj.value).substring(0, maxChars);
		}
		var remaining = maxChars - currentLength;
		if (remaining < 0) remaining = 0;
		if (remaining > maxChars) remaining = maxChars;
		label.innerHTML = remaining;
	}
}

function SubmitForm(formId)
{
	if (formId && formId.length > 0)
	{
		var objForm = document.getElementById(formId);
		if (objForm != undefined)
		{
			objForm.submit();
		}
	}
}

function GetObjById(targetId)
{
	var targetObj;
	if (targetId && targetId.length > 0)
	{
		if(document.all)
		{
			if (document.all[targetId]) targetObj = document.all[targetId];
		}
		else
		{
			if (document.getElementById && document.getElementById(targetId)) targetObj = document.getElementById(targetId);
		}
	}
	return targetObj;
}


function InsertText(targetId, textToInsert)
{
	if (textToInsert)
	{
		var targetObj = GetObjById(targetId);
		if (targetObj)
		{
			targetObj.innerHTML = textToInsert;
		}
	}
}
function GetFlashMovieObject(movieName)
{
	if (window.document[movieName]) 
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName]; 
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	} 
}
