var browser;
var caution=false;
var vers;
if(navigator.appName == "Netscape"){
	browser = "NS";
}else{
	vers = navigator.appVersion; 
	vers = parseFloat(vers.substring(vers.lastIndexOf(".")-1,vers.length));
	browser = "IE";
}
///////////////////////////////////////////////////////////////////////////////////////
///  Form Element Highlighting - It operates itself
function setFormType(formtype)
{
    var allfields = document.getElementsByTagName(formtype);
    // loop through all input tags and add events
    for (var i=0; i<allfields.length; i++){
        var field = allfields[i];
	if(formtype == "input")
	{
		if ((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password") ) {
		   field.onmouseover = function () {this.className = 'highlightActiveField';}
		    field.onmouseout = function () {this.className = 'highlightInactiveField';}
		    field.className = 'highlightInactiveField';
		}
	}
	else
	{
		field.onmouseover = function () {this.className = 'highlightActiveField';}
		field.onmouseout = function () {this.className = 'highlightInactiveField';}
		field.className = 'highlightInactiveField';
	}
    }
}
function setElementError(field,showremove)
{
	var field, count=0;
	if(showremove == null) showremove = false; // default to leave the color
	if(showremove){ field.style.border = "1px solid"; field.className = "highlightErrorField"; }
	else field.style.border = "1px solid #FF5050";
}
function setError(showremove)
{
	var field, count=0;
	if(showremove == null) showremove = false; // default to leave the color
	var allfields = document.getElementsByTagName("input");
	for (var i=0; i<allfields.length; i++){
		var field = allfields[i]; 
		if (((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password")) && field.getAttribute("valid") == "true" && field.value=="" ) {
			if(showremove){ field.style.border = "1px solid"; field.className = "highlightErrorField"; }
			else field.style.border = "1px solid #FF5050";
			count++;
		}
	}
	allfields = document.getElementsByTagName("select");
	for (var i=0; i<allfields.length; i++){
		var field = allfields[i]; 
		if ( field.getAttribute("valid") == "true" && field.selectedIndex==0 ) {
			if(showremove){ field.style.border = "1px solid"; field.className = "highlightErrorField"; }
			else field.style.border = "1px solid #FF5050";
			count++;
		}
	}
	allfields = document.getElementsByTagName("textarea");
	for (var i=0; i<allfields.length; i++){
		var field = allfields[i]; 
		if ( field.getAttribute("valid") == "true" && field.innerText=="" ) {
			if(showremove){ field.style.border = "1px solid"; field.className = "highlightErrorField"; }
			else field.style.border = "1px solid #FF5050";
			count++;
		}
	}
	return count;
}
function setClassHighlight(hclass)
{
    var allfields = document.getElementsByTagName("div"); 
    // loop through all input tags and add events
    for (var i=0; i<allfields.length; i++){
        var field = allfields[i]; 
	if ( field.className == hclass ) { 
		var oldbgcolor = field.style.backgroundColor;
	   field.onmouseover = function () {this.style.backgroundColor = this.getAttribute("hlcolor");}
	    field.onmouseout = function () {this.style.backgroundColor = oldbgcolor;}
	}
    }
}
function initHighlight() {
    if (!document.getElementsByTagName){ return; }
    setFormType("input");
    setFormType("textarea");
    setFormType("select");
    setClassHighlight("highlighttext");
}
// Simon Willison http://simon.incutio.com/
function addLoadEvent(func) {   
	if(browser != "IE")
	{
		if (document.addEventListener) 
		{    
			document.addEventListener("DOMContentLoaded", func, false);
		}		
		return;
	}
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }
}
addLoadEvent(initHighlight);
// Standard page initialzation
try{addLoadEvent(PageInit);}catch(err){}
///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
///	AJAX Methods(Async)
	function ShowWait() // only valid if MagicAjax is turned on
	{
		try
		{
			if (waitElement == null) return;
			if (waitElement)
			{
				waitElement.style.zIndex = '9000'; 
				waitElement.style.visibility = 'visible';
				MoveWaitElement();
			}
		}
		catch(err){}
	}
	function HideWait()
	{
		try
		{
			if (waitElement == null) return;
			if (waitElement) waitElement.style.visibility = 'hidden'; 
		}
		catch(err){}
	}
	function getArgXml(inArgs, startloc)
	{
		var args="<d>";
		for(i=startloc; i < inArgs.length; i++)
		{
			if(i == startloc) args += "<m>"+inArgs[i]+"</m>"; // should be the method
			else args += "<p>"+inArgs[i]+"</p>"; // the rest of the arguments
		} 
		return args += "</d>";
	}
	// for executing IVC Ajax Functions in a HTTP Module
	function ivcExecFunctionSync(url)
	{
		return ExecutePost( url, "IvcPagePostBack=@@ivcSoapXml|"+getArgXml(arguments,1));
	}
	function ivcExecAjaxMethodSync()
	{
		var url = location.pathname;
		if(url.charAt(url.length-1) == '/') url += "default.aspx";
		return ExecutePost( url, "IvcPagePostBack=@@ivcSoapXml|"+getArgXml(arguments,0));
	}
	function ivcExecAjaxMethod(ThisCallBack)
	{
		var url = location.pathname;
		if(url.charAt(url.length-1) == '/') url += "default.aspx";
		ivcCallAjaxAsync( ThisCallBack, url, "IvcPagePostBack=@@ivcSoapXml|"+getArgXml(arguments,1)); 
	}
	function ivcMainCallback(cb,ret)  // sample callback function
	{
		cb(ret);
		HideWait();
	}
	function ivcCallAjaxAsync( CallBackFn, rscript, params, fid )
	{
		try
		{
			ShowWait();
			var httpObj = GetHttpObject();
			httpObj.open("POST", rscript, true, "", "");
			httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			httpObj.send(params); // if sending variables, omit the "?", i.e. if the get was url?name=max&day=now, then send only "name=max&day=now"
			httpObj.onreadystatechange = function () 
			{
				if (httpObj.readyState == 4) ivcMainCallback(CallBackFn,httpObj.responseText); 
			}
		}
		catch(err)
		{
			HideWait();
		}
	}
/// End AJAX Methods(Async)	/////////////////////////////////////////////////////////////////
	function URLEncode( inStr )
	{
		if(inStr == null) return "";
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
	
		var plaintext = inStr; 
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
		    if (ch == " ") {
			    encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
			    encoded += ch;
			} else {
			    var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
				    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
						"(URL encoding only supports 8-bit characters.)\n" +
							"A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
		return encoded;
	};
	
	function URLDecode( inStr )
	{
	   // Replace + with ' '
	   // Replace %xx with equivalent character
	   // Put [ERROR] in output if %xx is invalid.
	   var HEXCHARS = "0123456789ABCDEFabcdef"; 
	   var encoded = inStr;
	   var plaintext = "";
	   var i = 0;
	   while (i < encoded.length) {
	       var ch = encoded.charAt(i);
		   if (ch == "+") {
		       plaintext += " ";
			   i++;
		   } else if (ch == "%") {
				if (i < (encoded.length-2) 
						&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
						&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
					plaintext += unescape( encoded.substr(i,3) );
					i += 3;
				} else {
					alert( 'Bad escape combination near ...' + encoded.substr(i) );
					plaintext += "%[ERROR]";
					i++;
				}
			} else {
			   plaintext += ch;
			   i++;
			}
		} // while
	   return plaintext;
	}
// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
	function StringBuilder(value)
	{
		this.strings = new Array("");
		this.append(value);
	}
	
	// Appends the given value to the end of this instance.
	StringBuilder.prototype.append = function (value)
	{
		if (value)
		{
			this.strings[this.strings.length] = value;
	//		this.strings.push(value);
		}
	}
	
	// Clears the string buffer
	StringBuilder.prototype.clear = function ()
	{
		this.strings.length = 1;
	}
	
	// Converts this instance to a String.
	StringBuilder.prototype.toString = function ()
	{
		return this.strings.join("");
	}
/////////////////////////////////////////////////////////////////////////////////////
/////		Cross Browser XML Document Loading
/////////////////////////////////////////////////////////////////////////////////////
	function DynamicPopup(html)
	{
		var generator=window.open('','name');
		generator.document.write(html);
		generator.document.close();
	}
	function DynamicPopupW(html,w,h)
	{
		var generator=window.open('','name','height='+h+',width='+w);
		generator.document.write(html);
		generator.document.close();
	}
	function remove(s, t) 
	{
		/*
		**  Remove all occurrences of a token in a string
		**    s  string to be processed
		**    t  token to be removed
		**  returns new string
		*/
		i = s.indexOf(t);
		r = "";
		if (i == -1) return s;
		r += s.substring(0,i) + remove(s.substring(i + t.length), t);
		return r;
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	///	Emulate IE's xpath methods
	var MozFox = false;
	if(document.implementation && document.implementation.createDocument)
	{
		MozFox = true;
		// Extend the Array to behave as a NodeList	
		Array.prototype.item = function(i)
		{
			return this[i];
		};
		// add IE's expr property
		Array.prototype.expr = "";
	    // dummy, used to accept IE's stuff without throwing errors
		XMLDocument.prototype.setProperty  = function(x,y){};
		// Emulate IE's selectNodes
		XMLDocument.prototype.selectNodes = function(sExpr, contextNode)
		{
			var oResult = this.evaluate(sExpr, (contextNode?contextNode:this), 
								this.createNSResolver(this.documentElement),
								XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			var nodeList = new Array(oResult.snapshotLength);
			nodeList.expr = sExpr;
			for(i=0;i<nodeList.length;i++)
				nodeList[i] = oResult.snapshotItem(i);
			return nodeList;
		};
		Element.prototype.selectNodes = function(sExpr)
		{
			var doc = this.ownerDocument;
			if(doc.selectNodes)
				return doc.selectNodes(sExpr, this);
			else
				throw "SarissaXPathOperationException: Method selectNodes is only supported by XML Nodes";
		};
		XMLDocument.prototype.selectSingleNode = function(sExpr, contextNode){
			var ctx = contextNode?contextNode:null;
			sExpr = "("+sExpr+")[1]";
			var nodeList = this.selectNodes(sExpr, ctx);
			if(nodeList.length > 0)
			    return nodeList.item(0);
			else
			    return null;
		};
		/**
		* <p>Extends the Element to emulate IE's selectNodes.</p>
		* @argument sExpr the XPath expression to use
		* @returns the result of the XPath search as an (Sarissa)NodeList
		* @throws An error if invoked on an HTML Element as this is only be
		*             available to XML Elements.
		*/
		Element.prototype.selectSingleNode = function(sExpr){
			var doc = this.ownerDocument;
			if(doc.selectSingleNode)
			    return doc.selectSingleNode(sExpr, this);
			else
			    throw "Method selectNodes is only supported by XML Elements";
		};
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function GetXmlString(szXmlString)
	{
		var xmlDoc;
		if (window.ActiveXObject){
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.loadXML(szXmlString); //Enforce download of XML file first. IE only.
		}
		else if (document.implementation && document.implementation.createDocument)
		{
			var parser = new DOMParser();
			xmlDoc = parser.parseFromString(szXmlString,"text/xml");
		}
		return xmlDoc;
	}
	function GetXmlDoc(szXmlFile)
	{
		var xmlDoc;
		if (window.ActiveXObject){
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false; //Enforce download of XML file first. IE only.
		}
		else if (document.implementation && document.implementation.createDocument)
		{
			xmlDoc= document.implementation.createDocument("","doc",null);
		}
		if (typeof xmlDoc != "undefined") xmlDoc.load(szXmlFile);
		return xmlDoc;
	}
/////////////////////////////////////////////////////////////////////////////////////
	/*
		Useage:
		ChangeCursor("wait");  // hourglass
		ChangeCursor("default");  // restore
	*/
	function isEmail(str) 
	{
		var s = str.split('@');	//alert(s[1]);
		if(s[1] == null) return false;
		else if(s[1].indexOf(".") < 3) return false;
	   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}
	function SetFocus(grp,name)
	{
		setFocus(grp,name);
	}
	
	function setFocus(grp,name)
	{
		var itemObj = getObject(grp,name);
		itemObj.focus();
	}
	function ChangeCursor(style) {
		document.body.style.cursor = style;     
	}
	function doPostBack(serverMethod,paramValue)
	{
		__doPostBack(serverMethod,"@@ivc|"+paramValue);
	}
	///////////////////////////////////////////////////////////////////
	///		Cookie Stuff
	////////////////////////////////////////////////////////////////////
	var today = new Date();   
	var cexpire = new Date();   
	cexpire.setTime(today.getTime() + 1000*60*60*24*5); // 5 days   
	function setCookie(name, value, expires, path, domain, secure) 
	{
		var curCookie = name + "=" + escape(value) +((expires) ? "; expires=" + expires.toGMTString() : "") +((path) ? "; path=" + path : "") +((domain) ? "; domain=" + domain : "") +((secure) ? "; secure" : "");
		if (!caution || (name + "=" + escape(value)).length <= 4000) document.cookie = curCookie;
		else{
			if (confirm("Cookie exceeds 4KB and will be cut!")) document.cookie = curCookie;
		}
	}

	function GetClipboard()
	{
		window.clipboardData.getData("Text");
	}
	
	function SetClipboard(text)
	{
		window.clipboardData.setData("Text", text); 
	}
	// name - name of the desired cookie
	// * return string containing value of specified cookie or null if cookie does not exist
	function getCookie(name) 
	{
		var prefix = name + "=";
		var cookieStartIndex = document.cookie.indexOf(prefix);
		if (cookieStartIndex == -1) return null;
		var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
		if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
		return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	}

	// name - name of the cookie
	// [path] - path of the cookie (must be same as path used to create cookie)
	// [domain] - domain of the cookie (must be same as domain used to create cookie)
	// * path and domain default if assigned null or omitted if no explicit argument proceeds
	function deleteCookie(name, path, domain) 
	{
		if (getCookie(name)) {
			document.cookie = name + "=" +((path) ? "; path=" + path : "") +((domain) ? "; domain=" + domain : "") +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}
	
//	from:  http://www.surfmind.com/musings/2003/09/15/
function alternateRowColors(color) 
{
	var className = 'classes';
	var rowcolor = '#bbbbbb';
	if(color != null) rowcolor = color;
	var rows, arow;
	var tables = document.getElementsByTagName("table");
	var rowCount = 0;
	for(var i=0;i<tables.length;i++) {
		//dump(tables.item(i).className + " " + tables.item(i).nodeName + "\n");
		if(tables.item(i).className == className) {
			atable = tables.item(i);
			rows = atable.getElementsByTagName("tr");
			for(var j=0;j<rows.length;j++) {
				arow = rows.item(j);
				if(arow.nodeName == "TR") {
					if(rowCount % 2) {
						arow.style.backgroundColor = rowcolor;
					} else {
						// default case
					}
					rowCount++;
				}
			}
			rowCount = 0;
		}
	}
}

function ivcPostBack(method)
{
	__doPostBack("", "@@ivc|"+method);
}
function setIframeSource(divname, src)
{
	var iframe = document.getElementById(divname+"Style_frame")
	iframe.setAttribute("src",src)
}
function OpenModalWindow(url,W,H)
{
	modeless = showModalDialog(url,"", "help:No;status:no;font-family:Verdana;font-size:12;dialogWidth:"+W+"px;dialogHeight:"+H+"px");
}
function OpenModlessWindow(url,W,H)
{
	modeless = showModelessDialog(url,"", "help:No;status:no;font-family:Verdana;font-size:12;dialogWidth:"+W+"px;dialogHeight:"+H+"px");
}
function OpenModalWindowIFrame(url,W,H,title)
{
	if(title == null) title="Alantus Modal Window";
	var u2="DialogIFrame.aspx?src="+escape(url)+"&w="+W+"&h="+H+"&title="+title;  // escape the url to allow the parameters to pass through
	modeless = showModalDialog(u2,"", "help:No;status:no;font-family:Verdana;font-size:12;dialogWidth:"+W+"px;dialogHeight:"+H+"px");
}
function OpenModlessWindowIFrame(url,W,H,title)
{
	if(title == null) title="Alantus Modless Window";
	var u2="DialogIFrame.aspx?src="+escape(url)+"&w="+W+"&h="+H+"&title="+title;  // escape the url to allow the parameters to pass through
	modeless = showModelessDialog(u2,"", "help:No;status:no;font-family:Verdana;font-size:12;dialogWidth:"+W+"px;dialogHeight:"+H+"px");
}
function ivcReplaceStr(orgString, findString, replString)
{
	pos = orgString.lastIndexOf(findString);
	return orgString.substr(0, pos) + replString + orgString.substr(pos + findString.length);
}
function GetParentElementByTagName(element, tagName)
{
	var element=element;
	while(element.tagName != tagName)
		element = element.parentNode;
	return element;
}
function openWin(locUrl,W,H,name)
{
	if(name == null) name = "";
	var options = "scrollbars=no,resizable=no,width=" + W +",height=" + H
	obj = window.open( locUrl,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,'+options);
}
function GetHttpObject() 
{
	if (typeof window.ActiveXObject != 'undefined' ) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		return new XMLHttpRequest();
	}
}
function ExecutePost( url, params )
{
	var httpObj = GetHttpObject();
	httpObj.open("POST", url, false, "", "");
	httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	httpObj.send(params); // if sending variables, omit the "?", i.e. if the get was url?name=max&day=now, then send only "name=max&day=now"
    	return httpObj.responseText;	
}
function runRemoteScript( rscript )
{
	var httpObj = GetHttpObject();
	httpObj.open("GET", rscript, false, "", "");
	httpObj.setRequestHeader("Content-Type","text/xml");
	httpObj.send(null);
    	return httpObj.responseText;	
}
function AsyncResponse(ret)
{
	alert(ret);
}
function runRemoteScriptAsync( rscript )
{
	var httpObj = GetHttpObject();
	httpObj.open("GET", rscript, true, "", "");
	httpObj.setRequestHeader("Content-Type","text/xml");
	httpObj.onreadystatechange = function () {
		if (httpObj.readyState == 4) AsyncResponse(httpObj.responseText); 
	}
	httpObj.send(null);
}
function ExecuteSoapPost( url, params )
{
	var httpObj = GetHttpObject();
	if(httpObj == null){alert("null object"); return; }
	httpObj.open("POST", url, false, "", "");
	httpObj.setRequestHeader("Content-Type","text/xml");
	httpObj.setRequestHeader("SOAPAction","http://tempuri.org/add");
	httpObj.send(params); // if sending variables, omit the "?", i.e. if the get was url?name=max&day=now, then send only "name=max&day=now"
    	return httpObj.responseText;	
}
function GetStyleObj(name)
{
	return getStyleObj(name);
}

function getId(name)
{
	var temp = new String(name);
	temp = temp.replace(/_|\./g,"");
	temp+="Style";
	return temp;
}

function getStyleObj(name)
{
	var temp = new String(name);
	temp = temp.replace(/_|\./g,"");
	temp+="Style";
	if(browser == "NS"){
		return document.layers[temp];
	}else{
		return eval(temp).style;
	}	
}

function GetObject(styleName,name)
{
	return getObject(styleName,name);
}
function getElement(id)
{
	return document.getElementById(id);
}
function getObject(styleName,name)
{
	var pre = window;
	var obj;
	if(browser == "NS"){
		obj = document.getElementById( name +"Style" ); // assumes AVB tag
		if(null != obj) return obj;
		else return document.getElementById( name); // assumes user tag
	}
	else{
		var lobj = document.all[name];
		if(lobj == null) 
		{
			lobj = document.getElementById( name +"Style" ); // assumes AVB tag
			if(null != lobj) return lobj;
			else return document.getElementById( name); // assumes user tag
		}
		else return lobj;
	}
}
function GetObjectVal(styleName,name)
{
	var obj = getObject(styleName,name);
	if(obj.type == "select-one"){
		if(obj.selectedIndex < 0)
			return null;
		return obj.options[obj.selectedIndex].value;
	}else{
		return obj.value;
	}
}

function WriteText(name,value)
{
	writeText(name,value);
}

function writeText(name,value)
{
	var obj = getObject(null,name);
	if(obj == null)
		return;
	if(obj.type != null)
		return;
	obj.innerHTML = value;
}

function addListItem2(rSel,display,value,defSel,selected)
{
	// send in an object reference - rSel
	if(browser == "IE"){
		if(vers < 5.0)
		{
			rSel.options[rSel.length] = new Option(display,value,defSel,selected);
		}
		else
		{
  			var newOpt = document.createElement("OPTION");
 			 newOpt.text=display;
  			newOpt.value=value;
			rSel.options[rSel.length] = newOpt;
		}
	}
	else
	{
		var elOptNew = document.createElement('option');
		elOptNew.text = display;
		elOptNew.value = value;
		rSel.add(elOptNew, null); // standards compliant; doesn't work in IE
	}
}
function addListItem(rSel,display,value,defSel,selected)
{
	// send in an object reference - rSel
	if(typeof(rSel) == "string");  // being sent from an event app
	{
		addListItem2(getElement(display),value,defSel);
		return;
	}
	if(browser == "IE"){
		if(vers < 5.0)
		{
			rSel.options[rSel.length] = new Option(display,value,defSel,selected);
		}
		else
		{
  			var newOpt = document.createElement("OPTION");
 			 newOpt.text=display;
  			newOpt.value=value;
			rSel.options[rSel.length] = newOpt;
		}
	}
}

function removeListItem(name,idx)
{
	if(browser == "IE"){
   	document.all[name].options[idx] = null;
	}
}

function replaceListItem(name,display,value,defSel,selected,idx)
{
	if(browser == "IE"){
		document.all[name].options[idx] = new Option(display,value,defSel,selected);
	}            
}

function getListItem(name,idx)
{
	if(browser == "IE"){
   	return document.all[name].options[idx].value;
	}            
}

function isLetter (c)
{ 
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c)
{   
	return (isLetter(c) || isDigit(c))
}

function isAlphaNum(s,u)
{   var i;
    if(u == 1) s.toLowerCase( );
    if(u == 2) s.toUpperCase( );
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);
        if (!isLetterOrDigit(c))
        return false;

    }
    return true;
}

function isAlphabetic (s,u)
{   var i;
    if(u == 1) s.toLowerCase( );
    if(u == 2) s.toUpperCase( );
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);
        if (!isLetter(c))
        return false;

    }
    return true;
}

function isInteger (s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }
    return true;
}

function mask (InString, Mask)  {
	LenStr = InString.length;
	LenMsk = Mask.length;
	if ((LenStr==0) || (LenMsk==0))
		return(0);
	if (LenStr!=LenMsk)
		return(0);
	TempString=""
	for (Count=0; Count<=InString.length; Count++)  {
		StrChar = InString.substring(Count, Count+1);
		MskChar = Mask.substring(Count, Count+1);
		if (MskChar=='#') {
			if(!isNumberChar(StrChar))
				return(0);
		}
		else if (MskChar=='?') {
			if(!isAlphabeticChar(StrChar))
				return(0);
		}
		else if (MskChar=='!') {
			if(!isNumOrChar(StrChar))
				return(0);
		}
		else if (MskChar=='*') {
		}
		else {
			if (MskChar!=StrChar) 
				return(0);
		}
	}
	return (1);
}

function isAlphabeticChar (InString)  {
	if(InString.length!=1) 
		return (false);
	InString=InString.toLowerCase();
	RefString="abcdefghijklmnopqrstuvwxyz";
	if (RefString.indexOf (InString.toLowerCase(), 0)==-1) 
		return (false);
	return (true);
}

function isNumberChar (InString)  {
	if(InString.length!=1) 
		return (false);
	RefString="1234567890";
	if (RefString.indexOf (InString, 0)==-1) 
		return (false);
	return (true);
}

function isNumOrChar (InString)  {
	if(InString.length!=1) 
		return (false);
	InString=InString.toLowerCase();
	RefString="1234567890abcdefghijklmnopqrstuvwxyz";
	if (RefString.indexOf (InString, 0)==-1)  
		return (false);
	return (true);
}

///////////////////////////////////////////////////////////////////////////
/////		IVC ASP.NET Supporting Javascript (c) Information Vortex Corporation 1991-2003
//////////////////////////////////////////////////////////////////////////
function getQueryExtras(){ return "&tabindex=99&tabid=0"; }
///////////////////////////////////////////////////////////////////////////
/////		copy the below between mvscript & Alantusscript
//////////////////////////////////////////////////////////////////////////
// Note:  These functions even work when the table is of the form "table1,table2".  Just pass in the comma delimited name.
function GetRowElementText(rowNum,col,table)
{
	var row = document.getElementById(table+"_row"+rowNum);
	if(row == null) return "";
	for(var i=0; i < row.childNodes.length; i++)
	{
		if(col == i)
		{
			return row.childNodes[i].innerText;
		}
	}
	return "";
}
function GetRowElementHtml(rowNum,col,table)
{
	var row = document.getElementById(table+"_row"+rowNum);
	if(row == null) return "";
	for(var i=0; i < row.childNodes.length; i++)
	{
		if(col == i)
		{
			return row.childNodes[i].innerHTML;
		}
	}
	return "";
}
function SetRowElementText(rowNum,col,table,text)
{
	var row = document.getElementById(table+"_row"+rowNum);
	if(row == null) return false;
	for(var i=0; i < row.childNodes.length; i++)
	{
		if(col == i)
		{
			row.childNodes[i].innerText = text;
			return true;
		}
	}
	return false;
}
function SetRowElementHtml(rowNum,col,table,html)
{
	var row = document.getElementById(table+"_row"+rowNum);
	if(row == null) return false;
	for(var i=0; i < row.childNodes.length; i++)
	{
		if(col == i)
		{
			row.childNodes[i].innerHTML = html;
			return true;
		}
	}
	return false;
}
function dbValConvert(s)
{
	var flag=true;
	if(s == null) return s;
	s = escapeSingleQuotes(s);
	for (var i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))){ flag=false; break; }
	}
	if(!flag) 
	{
		s = "'"+s+"'";
		return s;
	} else return s;
}
function pageRefresh( )
{
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	location=sPage;
}
function doPageGet(querystring)
{
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	location=sPage+querystring;
}
function MoveGridToForm(rowNum,table)
{
	var head=null;
	var headCol = document.getElementsByName("head");
	for(i=0; i < headCol.length; i++)
	{
		head = headCol(i);
		if(head.getAttribute("name") == table) break;
	}
	if(head == null){ alert("error:  table"); return; }
	var fields = head.getAttribute("fields");
	var arrayfields = fields.split(",");
	var row = document.getElementById(table+"_row"+rowNum);
	var len = row.childNodes.length;
	var cnt=0;
	for(var i=0; i < len; i++)
	{
		if(i == 0) continue;
		var rstr = row.childNodes[i].innerHTML;
		var rtxt = row.childNodes[i].innerText;
		if(rtxt == "activate" || rtxt == "doEdit")
		{
			var p1 = rstr.indexOf("'");
			var p2 = rstr.indexOf("'",p1+1); // search for the first double quoted value
			document.getElementById(arrayfields[cnt++]).value = rstr.substring(p1+1,p2);
		}
		else 
		{
			document.getElementById(arrayfields[cnt++]).value = rstr;
		}
	}
}
function ButtonClick(mode)
{
	document.getElementById("ivcmode").value = mode;
}
function details(row,column,fkvalue)
{
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	location=sPage+"?command=details&fkvalue="+fkvalue+getQueryExtras();
}
function InsertRow(table)
{
	if(null != document.getElementById("ivcaspx"))
	{ // in an Alantus generated page
		return;
	}
	else
	{
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		location=sPage+"?command=doInsert&table="+table+getQueryExtras();
	}
}
function doEdit(row,column,pkvalue,table)
{
	if(null != document.getElementById("ivcaspx"))
	{ // in an Alantus generated page
		MoveGridToForm(row,table);
	}
	else
	{
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		location=sPage+"?command=doEdit&pkvalue="+pkvalue+"&table="+table+getQueryExtras();
	}
}
function escapeSingleQuotes(s)
{   var i,out="";
    if(-1 == s.indexOf("'")) return s;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (c == '\'') out += "''";
	else out += c;
    }
    return out;
}
var rowVals;
var currentRowNum;
function dosave( rowdelete, table )
{
	if(rowVals == null) alert("rows null");
	if(currentRowNum == null)  alert("cur rows null");
	if(rowVals == null || currentRowNum == null) return;
	var i=0;
	var head=null;
	var headCol = document.getElementsByName("head");
	for(i=0; i < headCol.length; i++)
	{
		head = headCol(i);
		if(head.getAttribute("name") == table) break;
	}
	if(head == null){ alert("error:  table"); return; }
	var atts = head.attributes;
	var fields=head.getAttribute("fields");
	var newfields="";
	var arrayfields = fields.split(",");
	var pk=head.getAttribute("pk").toLowerCase();
	var pk2=table+"."+head.getAttribute("pk").toLowerCase();
	var len = rowVals.length;
	var update;
	var valarray ="",pkval="";
	var val;  var first=true; var cnt=0;
	// note:  right now, it is not possible to update the primary key
	for(var i=0; i < len; i++)
	{
		if(i > 0) val = document.getElementById("r"+currentRowNum+"_"+i).value;
		if(i == 0) continue;
		else if(first) 
		{
			if(pk == arrayfields[i-1].toLowerCase() || pk2 == arrayfields[i-1].toLowerCase()) pkval = dbValConvert(rowVals[i]);
			else if(rowVals[i] != val)
			{
				valarray += arrayfields[i-1]+"="+dbValConvert(val);
				first=false;
				cnt++;
			}
		}
		else 
		{
			if(pk == arrayfields[i-1].toLowerCase() || pk2 == arrayfields[i-1].toLowerCase()) pkval = dbValConvert(rowVals[i]);
			else if(rowVals[i] != val)
			{
				valarray += ","+arrayfields[i-1]+"="+dbValConvert(val);
				cnt++
			}
		}
	}
	if(cnt > 0 || rowdelete == 1)
	{
		if(rowdelete == 1) update = "delete from "+table+" where "+pk+"="+pkval;
		else update = "update "+table+" set "+valarray+" where "+pk+"="+pkval;
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		location=sPage+"?command=inPlaceUpdate&updateString="+update+getQueryExtras();
	}
}
var restoreArray=null,crowNum="",ctable="";
function InPlaceEdit(rowNum,table)
{
	if(rowVals != null)
	{
		if(rowVals.length > 0) return;
		rowVals.length = 0;
	}
	var row = document.getElementById(table+"_row"+rowNum);
	var len = row.childNodes.length;
	rowVals = new Array(len);
	restoreArray = new Array(len); crowNum = rowNum;  ctable=table;
	for(var i=0; i < len; i++)
	{
		var rstr = row.childNodes[i].innerHTML;
		var rtxt = row.childNodes[i].innerText;
		restoreArray[i] = rstr;
		if(rtxt == "edit")
		{
			// form of function('pkfield','pkvalue')
//					var p2 = rstr.lastIndexOf("'");
//					var p1 = rstr.lastIndexOf("'",p2-1);
//					row.childNodes[i].innerHTML = "<input id='r"+rowNum+"_"+i+"' type='text' value='"+rstr.substring(p1+1,p2)+"'></input>";
			// instead of getting the value, place save/cancel in the row
			rowVals[i] = i;
			row.childNodes[i].innerHTML = "<a href='javascript:InPlaceRestore()'>esc</a> <a href=\"javascript:dosave(0,'"+table+"')\">save</a> <a href=\"javascript:dosave(1,'"+table+"')\" onclick= \"return confirm('Are you sure you want to Delete?')\">del</a>";
		}
		else if(rstr.indexOf("javascript:") > -1)
		{
			// form of function(row,col,'value','table')
			var p1 = rstr.indexOf("'");
			var p2 = rstr.indexOf("'",p1+1); // search for the first double quoted value
//			var p2 = rstr.lastIndexOf("'");
			rowVals[i] = rstr.substring(p1+1,p2);
			if(rowVals[i].length > 100) row.childNodes[i].innerHTML = "<textarea cols='30' rows='8'  id='r"+rowNum+"_"+i+"'>"+rowVals[i]+"</textarea>"
			else row.childNodes[i].innerHTML = "<input id='r"+rowNum+"_"+i+"' type='text' value='"+rowVals[i]+"'></input>";
		}
		else 
		{
			rowVals[i] = rstr;
			if(rstr.length > 100) row.childNodes[i].innerHTML = "<textarea cols='30' rows='8'  id='r"+rowNum+"_"+i+"'>"+rstr+"</textarea>"
			else row.childNodes[i].innerHTML = "<input id='r"+rowNum+"_"+i+"' type='text' value=\""+rstr+"\"></input>";
		}
	}
	currentRowNum = rowNum;
}
function InPlaceRestore()
{
	if(restoreArray == null) return;
	var len = restoreArray.length;
	var row = document.getElementById(ctable+"_row"+crowNum);
	if(row == null) alert("null");
	for(var i=0; i < len; i++)
	{
		row.childNodes[i].innerHTML = restoreArray[i];
	}
	rowVals = null;
}

/***********************************************
* Cool DHTML tooltip script II- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" style="display:none" src="arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

/*******************************************************************************************
 * Object: Hashtable
 * Description: Implementation of hashtable
 * Author: Uzi Refaeli
 *******************************************************************************************/

//======================================= Properties ========================================
Hashtable.prototype.hash	 	= null;
Hashtable.prototype.keys		= null;
Hashtable.prototype.location	= null;

/**
 * Hashtable - Constructor
 * Create a new Hashtable object.
 */
function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();

	this.location = 0;
}

/**
 * put
 * Add new key
 * param: key - String, key name
 * param: value - Object, the object to insert
 */
Hashtable.prototype.put = function (key, value){
	if (value == null)
		return;

	if (this.hash[key] == null)
		this.keys[this.keys.length] = key;

	this.hash[key] = value;
}

/**
 * get
 * Return an element
 * param: key - String, key name
 * Return: object - The requested object
 */
Hashtable.prototype.get = function (key){
		return this.hash[key];
}

/**
 * remove
 * Remove an element
 * param: key - String, key name
 */
Hashtable.prototype.remove = function (key){
	for (var i = 0; i < this.keys.length; i++){
		//did we found our key?
		if (key == this.keys[i]){
			//remove it from the hash
			this.hash[this.keys[i]] = null;
			//and throw away the key...
			this.keys.splice(i ,1);
			return;
		}
	}
}

/**
 * size
 * Return: Number of elements in the hashtable
 */
Hashtable.prototype.size = function (){
    return this.keys.length;
}

/**
 * populateItems
 * Deprecated
 */
Hashtable.prototype.populateItems = function (){}

/**
 * next
 * Return: true if theres more items
 */
Hashtable.prototype.next = function (){
	if (++this.location < this.keys.length)
		return true;
	else
		return false;
}

/**
 * moveFirst
 * Move to the first item.
 */
Hashtable.prototype.moveFirst = function (){
	try {
		this.location = -1;
	} catch(e) {/*//do nothing here :-)*/}
}

/**
 * moveLast
 * Move to the last item.
 */
Hashtable.prototype.moveLast = function (){
	try {
		this.location = this.keys.length - 1;
	} catch(e) {/*//do nothing here :-)*/}
}

/**
 * getKey
 * Return: The value of item in the hash
 */
Hashtable.prototype.getKey = function (){
	try {
		return this.keys[this.location];
	} catch(e) {
		return null;
	}
}

/**
 * getValue
 * Return: The value of item in the hash
 */
Hashtable.prototype.getValue = function (){
	try {
		return this.hash[this.keys[this.location]];
	} catch(e) {
		return null;
	}
}

/**
 * getKey
 * Return: The first key contains the given value, or null if not found
 */
Hashtable.prototype.getKeyOfValue = function (value){
	for (var i = 0; i < this.keys.length; i++)
		if (this.hash[this.keys[i]] == value)
			return this.keys[i]
	return null;
}


/**
 * toString
 * Returns a string representation of this Hashtable object in the form of a set of entries,
 * enclosed in braces and separated by the ASCII characters ", " (comma and space).
 * Each entry is rendered as the key, an equals sign =, and the associated element,
 * where the toString method is used to convert the key and element to strings.
 * Return: a string representation of this hashtable.
 */
Hashtable.prototype.toString = function (){

	try {
		var s = new Array(this.keys.length);
		s[s.length] = "{";

		for (var i = 0; i < this.keys.length; i++){
			s[s.length] = this.keys[i];
			s[s.length] = "=";
			var v = this.hash[this.keys[i]];
			if (v)
				s[s.length] = v.toString();
			else
				s[s.length] = "null";

			if (i != this.keys.length-1)
				s[s.length] = ", ";
		}
	} catch(e) {
		//do nothing here :-)
	}finally{
		s[s.length] = "}";
	}

	return s.join("");
}

/**
 * add
 * Concatanates hashtable to another hashtable.
 */
Hashtable.prototype.add = function(ht){
	try {
		ht.moveFirst();
		while(ht.next()){
			var key = ht.getKey();
			//put the new value in both cases (exists or not).
			this.hash[key] = ht.getValue();
			//but if it is a new key also increase the key set
			if (this.get(key) != null){
				this.keys[this.keys.length] = key;
			}
		}
	} catch(e) {
		//do nothing here :-)
	} finally {
		return this;
	}
};
////////////		ANIMATION	/////////////////////////////
/*	sample
function start() {
  anim1 = new animation("ball1");
  if (!anim1.element) return;
  anim2 = new animation("ball2");

  anim2.slideBy(200, 0, 256, 10, "anim1.circle(100, 0, -360, 150, 10)");
  // anim2.slideBy(200, -300, 256, 30, "anim1.slideBy(320, -150, 99, 50, 'anim1.circle(230, 0, -180, 100, 30)')");
  //anim1.circle(100, 0, -360, 150, 50);
}
*/
var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;
function animation(id) 
{
	this.element = (NS4) ? document[id] : document.all[id].style;
	this.active = 0;
	this.timer = null;
	this.path = null;
	this.num = null;
	
	this.name = id + "Var";
	eval(this.name + " = this");
	
	this.animate = animate;
	this.step = step;
	this.show = show;
	this.hide = hide;
	this.left = left;
	this.top = top;
	this.moveTo = moveTo;
	this.slideBy = slideBy;
	this.slideTo = slideTo;
	this.circle = circle;
}
function pos(x, y) {
	this.x = Math.round(x);
	this.y = Math.round(y);
}
function show() {
	this.element.visibility = (NS4) ? "show" : "visible";
}
function hide() {
	this.element.visibility = (NS4) ? "hide" : "hidden";
}
function left() {
	return parseInt(this.element.left);
}
function top() {
	return parseInt(this.element.top);
}
function moveTo(x, y) {
	this.element.left = x;
	this.element.top = y;
}
function step() {
	this.moveTo(this.path[this.num].x, this.path[this.num].y);
	if (this.num >= this.path.length - 1) {
		clearInterval(this.timer);
		this.active = 0;
		if (this.statement)
		eval(this.statement);
	} else {
		this.num++;
	}
}
function animate(interval) {
	if (this.active) return;
	this.num = 0;
	this.active = 1;
	this.timer = setInterval(this.name + ".step()", interval);
}
function slideBy(dx, dy, steps, interval, statement) {
	var fx = this.left();
	var fy = this.top();
	var tx = fx + dx;
	var ty = fy + dy;
	this.slideTo(tx, ty, steps, interval, statement);
}
function slideTo(tx, ty, steps, interval, statement) {
	var fx = this.left();
	var fy = this.top();
	var dx = tx - fx;
	var dy = ty - fy;
	var sx = dx / steps;
	var sy = dy / steps;
	
	var ar = new Array();
	for (var i = 0; i < steps; i++) {
		fx += sx;
		fy += sy;
		ar[i] = new pos(fx, fy);
	}
	this.path = ar;
	
	this.statement = (statement) ? statement : null;
	this.animate(interval);
}
function circle(radius, angle0, angle1, steps, interval, statement) 
{
	var dangle = angle1 - angle0;
	var sangle = dangle / steps;
	var x = this.left();
	var y = this.top();
	var cx = x - radius * Math.cos(angle0 * Math.PI / 180);
	var cy = y + radius * Math.sin(angle0 * Math.PI / 180);
	
	var ar = new Array();
	for (var i = 0; i < steps; i++) {
		angle0 += sangle;
		x = cx + radius * Math.cos(angle0 * Math.PI / 180);
		y = cy - radius * Math.sin(angle0 * Math.PI / 180);
		ar[i] = new pos(x, y);
	}
	this.path = ar;
	
	this.statement = (statement) ? statement : null;
	this.animate(interval);
}
////////////////////////////////////////////////////////////////////
// Opacity(Cross Browser) Fading
function opacity(id, opacStart, opacEnd, millisec) {
	//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 + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
var ale=1;
//change the opacity for different browsers
function changeOpac(opacity, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
