
////////Moved from scriptfunc.js
function CancelBubble(e) {
	if (typeof(tsMemo) != 'undefined')
	{
		if (tsPMA) tsPMA.hideAllMenus();
	}
	if (!e) { e=window.event; }
	if (e) {
		if (e.stopPropagation) {
			e.stopPropagation();
		}
		e.cancelBubble=true;
	}
}

var TSCaptureObj, TSContainerCapture, TSCaptureNonIE, TSCapturePrevKeyHandler=null;
function TSSetCapture(obj, bContainerCapture, e) {
	// it is important to pass event as parameter "e" - otherwise you must manually call CancelBubble
	// to avoid TSCaptureOncontextmenuHandler being called immediately in FireFox etc. 
	if (obj) {
		TSCaptureObj=obj;
		TSContainerCapture=bContainerCapture ? true : false;
		if (obj.setCapture) {
			obj.setCapture(TSContainerCapture);
		} else {
			// Mozilla etc.
			TSCaptureNonIE=true;
			document.body.onclick=TSCaptureOnclickHandler;
			document.body.oncontextmenu=TSCaptureOncontextmenuHandler;
			if (e) {
				CancelBubble(e);
			}
		}
		if (document.body.onkeydown && document.body.onkeydown!=TSCaptureKeyHandler) {
			TSCapturePrevKeyHandler=document.body.onkeydown;
		}
		document.body.onkeydown=TSCaptureKeyHandler;
		window.onfocus=TSSetCaptureOnFocus;
	}
}
 
function TSReleaseCapture() {
	if (document.releaseCapture) {
		document.releaseCapture();
	}
	if (TSCaptureNonIE) {
		document.body.onclick=null;
		document.body.oncontextmenu=null;
	}
	document.body.onkeydown=TSCapturePrevKeyHandler;
	
	TSCaptureObj=null;
	TSContainerCapture=null;
	window.onfocus=null;
}

function TSSetCaptureOnFocus() {
	if (TSCaptureObj && TSCaptureObj.setCapture) { 
		TSCaptureObj.setCapture(TSContainerCapture); 
	}
}

function TSCaptureOnclickHandler() { 
	if (TSCaptureObj && TSCaptureObj.onclick) { 
		TSCaptureObj.onclick() 
	} 
}

function TSCaptureOncontextmenuHandler() { 
	if (TSCaptureObj && TSCaptureObj.oncontextmenu) { 
		return TSCaptureObj.oncontextmenu() 
	} 
}

function TSCaptureKeyHandler(e) { 
	if (!e) { e=window.event; }
	if (TSCaptureObj && e && e.keyCode && e.keyCode==27) { 
		// mimick a click (which typically hides the iframe)
		TSCaptureOnclickHandler();
	} 
	if (TSCapturePrevKeyHandler) {
		TSCapturePrevKeyHandler();
	}
}

/// set event handler that traps 'save' key combination ///
/// func = string with name of function to call on save ///
/// elm = element to attach event to - default: window.document ///    
/// example: <body onload="addSaveKeyHandler('doSave')"> ///
function addSaveKeyHandler(func, elm)
{
	if (typeof(elm) == 'undefined') elm = document;
	tsCompat.addEvent(elm, 'onkeydown', function(event){saveKeyHandler(event, func)}, true);
}

function saveKeyHandler(e, func)
{
	if (!e && window.event) e = window.event;
	// Ctrl + S
	if (e.keyCode == 83 && e.ctrlKey)
	{
		if (e.cancelBubble) e.cancelBubble = true;
		if (e.returnValue) e.returnValue = false;
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
		eval(func + '()');
		return false;
	}
}

function MiniCalendar (formname,fieldname,value,settingsid,ownerid,windowwidth,windowheight,windowcolor,containstime) {
    if (!containstime) {
        containstime=0;
    }
    value=eval ("document."+formname+"."+fieldname).value;
	window.open ('/lib/minicalendar.aspx?formname='+formname+'&fieldname='+fieldname+'&value='+value+'&settingsid='+settingsid+'&ownerid='+ownerid+'&windowcolor='+windowcolor+'&firsttime=1&containstime='+containstime,'','width='+windowwidth+',height='+windowheight+',dependent=yes');
}

function MiniCalendar2 (formname,fieldname,value,containstime,FromAdmin,SettingsId,pageid,datefmt) {
    if (formname==null || formname=="") 
    {   
        formname = document.forms[0].id;        
    }
    value=eval ("document."+formname+"."+fieldname).value;
	var CalendarDiv=document.getElementById ('calendardiv_'+fieldname);
	var Calendar=document.getElementById ('calendar_'+fieldname);
	if (datefmt) {
	}
	else {
	  datefmt="-1";
	}
	if (Calendar.style.visibility=='visible') {
		Calendar.style.visibility='hidden';
	}
	else {
		if (!FromAdmin && typeof (FromAdmin)!="undefined") {
			Calendar.src='/lib/minicalendar.aspx?inline=1&thedate='+value+'&formname='+formname+'&fieldname='+fieldname+'&settingsid='+SettingsId+'&pageid='+pageid+'&dateformat='+datefmt;
	    }
	    else {
			if (containstime) {
				Calendar.src='module.aspx?modid=1&refpath=calendar&thedate='+value+'&formname='+formname+'&fieldname='+fieldname+'&containstime='+containstime;
			}
			else {
				Calendar.src='module.aspx?modid=1&refpath=calendar&thedate='+value+'&formname='+formname+'&fieldname='+fieldname;
			}
			if (!Tangora.Browser.IE) {
			    Calendar.style.width='150px';
			}
		}
		Calendar.style.visibility='visible';
		
		// -----
		// HDN 31.08.2009: Firefox/Safari needs this in news module or else WYSIWYG buttons shine through... 
		Calendar.style.zIndex = 1;
		// -----
		
		TSSetCapture(CalendarDiv);
	}
	//CalendarDiv.style.display='inline';
}

function CalendarHide(fieldname) {
	var CalendarDiv=document.getElementById ('calendardiv_'+fieldname);
	var Calendar=document.getElementById ('calendar_'+fieldname);
	
	Calendar.style.visibility='hidden';
	TSReleaseCapture();
}

function CalendarLoaded(CtrlName) {
	var MainTbl=document.getElementById('calendar');
	//alert (MainTbl.offsetLeft+'*'+MainTbl.offsetHeight);
	//alert (document.body.scrollWidth+'*'+document.body.scrollHeight+'   '+MainTbl.offsetWidth+'*'+MainTbl.offsetHeight);
	//alert (MainTbl.offsetHeight);
	var Width=MainTbl.offsetWidth;
	var Height=MainTbl.offsetHeight;
	//var Width=MainTbl.offsetWidth+MainTbl.offsetLeft;
	//var Height=MainTbl.offsetHeight+MainTbl.offsetTop;
	var Control=window.parent.document.getElementById ('calendar_'+CtrlName);
	Control.style.height = Math.max((Height-1), 0) + 'px';
	Control.style.width=Width + 'px';
}

///////////////////////////


function OpenWYSIWYGLink (s,width,height,screenx,screeny,canresizable,canscrollbars,canmenubar,cantoolbar,canlocation,candirectories,canstatus) {
	if (document.getElementById("maineditdiv") || document.getElementById("mainadminwindowtable")) {
		// ignore link when editing page
		if (window.event) {
			// this function is probably called from an onclick handler
			return false;
		} else {
			// this function is probably called from href
			return;
		}
	}
	var Specs=new String;
	if (width && (screenx || screenx==0)) {
		Specs="";
		if (width!=0) {
			Specs=Specs+"width="+width;
		} 
		if (height!=0) {
			if (Specs!="") {
				Specs=Specs+",";
			}
			Specs=Specs+"height="+height;
		}
		if (Specs!="") {
			Specs=Specs+",";
		}
		Specs=Specs+"left="+screenx;
		Specs=Specs+",top="+screeny;
		if (canresizable==1) {
			Specs=Specs+",resizable=yes";
		}
		if (canscrollbars==1) {
			Specs=Specs+",scrollbars=yes";
		}
		if (canmenubar==1) {
			Specs=Specs+",menubar=yes";
		}
		if (cantoolbar==1) {
			Specs=Specs+",toolbar=yes";
		}
		if (canlocation==1) {
			Specs=Specs+",location=yes";
		}
		if (candirectories==1) {
			Specs=Specs+",directories=yes";
		}
		if (canstatus==1) {
			Specs=Specs+",status=yes";
		}
		window.open (s,"",Specs);
	}
	else if (width) {
		if (width==0 || height==0) {
			window.open (s);
		}
		else {
			window.open (s,'','width='+width+',height='+height+',menubar=yes,scrollbars=yes,resizable=yes,status=yes');
		}
	}
	else {
		window.open (s);
	}
}

function StrReplace (Str,Find,Replace) {
	srs=Str;
	while (srs.indexOf (Find)!=-1) {
		srs=srs.replace (Find,Replace);
	}
	return srs;
}

function URLEncode (s) {
	s = unescape(s);	
	s = escape (s);
	return s;
}

function URLEncode2 (s) {
	s = StrReplace (StrReplace (StrReplace (StrReplace (StrReplace (StrReplace(s,unescape("%C6"), "%C3%86"),unescape("%D8"), "%C3%98"),unescape("%C5"), "%C3%85"),unescape("%E6"), "%C3%A6"),unescape("%F8"), "%C3%B8"),unescape("%E5"), "%C3%A5");
	s=StrReplace (s,"%","OPERCENTO");
	s=URLEncode (s);
	s=StrReplace (s,"OPERCENTO","%");
	return s;
}

function openMiniCal (formname,fieldname,value,settingsid,ownerid,windowwidth,windowheight,pageid,dateformat) {
	value=eval ("document."+formname+"."+fieldname).value;
	window.open ('/lib/minicalendar.aspx?pageid='+pageid+'&formname='+formname+'&fieldname='+fieldname+'&value='+value+'&settingsid='+settingsid+'&ownerid='+ownerid+'&dateformat='+URLEncode (dateformat)+'&firsttime=1','','width='+windowwidth+',height='+windowheight+',dependent=yes');
}

function getWindowHeight(minheight, usedheight) {	
	isIEMac = false;
	var browser = navigator.appName;
	var version = navigator.appVersion;
	if (browser == 'Microsoft Internet Explorer'){
		if (version.indexOf('MSIE 5') != -1 && version.indexOf('Mac') != -1) {
			isIEMac = true
		}
	}
	
	var h;
	if (document.all) {
		var a = new String (document.body.style.marginTop);
		a = a.replace ("px","");
		var b = new Number (a);		
		h = document.body.clientHeight - (b*2);
	}
	else {
		h = window.innerHeight;	
	}
	h = h - usedheight;
	if (h < minheight) {
			h=minheight;
	}
	if (isIEMac) {h -= 16} else {h -= 1}
	return h;		
}

function getWindowWidth(minwidth, usedwidth) {		
	isIEMac = false;
	var browser = navigator.appName;
	var version = navigator.appVersion;
	if (browser == 'Microsoft Internet Explorer'){
		if (version.indexOf('MSIE 5') != -1 && version.indexOf('Mac') != -1) {
			isIEMac = true
		}
	}
	var w;
	if (document.all) {
		w = document.body.clientWidth;
	}
	else {
		w = window.innerWidth;	
	}		
	w = w - usedwidth;
	if (w < minwidth) {
			w=minwidth;
	}	
	if (isIEMac) {w -= 16}
	w = w - 25;
	return w;
}

function tsinit() {	
    if (location.href.indexOf("/admin")!=-1) {return;}
	var browser = navigator.appName;var version = navigator.appVersion;
	if (browser == 'Microsoft Internet Explorer'){
		if (version.indexOf('MSIE 5') != -1 && version.indexOf('Mac') != -1) {
			var loc = window.location.href;
			var coll = document.all.tags('div');
			for (i=0;i<coll.length;i++) {
				if (coll(i).className == 'scrollable') {
					if((loc.indexOf('#') != -1 || loc.indexOf('localref')!=-1) && (loc.indexOf('#top')==-1)){
						coll(i).style.height = '100%';
						coll(i).style.overflow = 'visible';
					} else{coll(i).style.paddingRight='16px';
						coll(i).style.marginRight='-16px';
					}
				}
			}
			var obj = null;
			coll = document.all.tags('td');
			for (i=0;i<coll.length;i++) {
				if (coll(i).className == 'maincell') {
					obj = coll(i);
				}
			}			
			if (obj) {
				var srcData = obj.innerHTML;				
				var mask = String.fromCharCode(173)
				var newData = "";
				var tmp = srcData;
				while (tmp!=newData) {						
					newData = tmp;
					tmp = newData.replace(mask,"");
				}		
				
				if (newData!=srcData) {			
					obj.innerHTML=newData;
				}
			}
		} 
	}	
	highlightSearchwords();
}

function get_url (layoutnumber) {
	var l = new String (location);
	var p = l.indexOf ("&layout=");
	var s = "";
	s = l;
	if (p!=-1) {		
		var p2 = l.indexOf ("&", p+8);
		if (p2!=-1) {
			s = l.substring (0, p);
			s += l.substring (p2, l.length - p2);
		} else {
			s = l.substring (0, p);
		}
		s = l.substring (0, p);
	}	
	s = s.replace ("#","");
	if (l.indexOf("?")>0) {
		s += "&layout=" + layoutnumber;
	} else {
		s += "?layout=" + layoutnumber;
	}	
	return s
}
	
function TSCA_LoadContentArea (o, rightID, thisID, lp, rp, suffix) {
	o.onload="";
	if (!suffix) {suffix=''}
	if (rightID==thisID) {
		o.src='/setup/'+lp + 'act' + suffix + rp;
	} else {
		o.src='/setup/'+lp + 'inact' + suffix + rp;
	}
}

function TSCA_Hover(o, rightID, thisID, lp, rp, show) {
	if (rightID==thisID) {
		o.src='/setup/'+lp + 'act' + (show?"on":"off")+ rp;
		window.status=o.alt;
	} else {
		o.src='/setup/'+lp + 'inact' + (show?"on":"off") + rp;
		window.status="";
	}
}

function ToLegalNumberString(n,ch) {
  if (ch==",") {ch2="."} else {ch2=","}
  if (n.indexOf(ch)>-1 && n.indexOf(ch2)>-1)
  {		
		n = n.replace(ch2, "");
		return n.replace(ch,".");
  }
  else return n.replace(",",".");    
}

function GetIframeDocument(framename) {
	if (window.frames[framename] && window.frames[framename].document) {
		return window.frames[framename].document;
	}
	var obj=document.getElementById(framename);
	if (obj && obj.contentDocument) {
		return obj.contentDocument;
	}
	return null;
}

function MiniBasketLoaded() {
	//var obj=document.getElementById ('MiniBasketFrame');
	var obj=GetIframeDocument ('MiniBasketFrame');
	var obj2=document.getElementById ('MiniBasketDiv');
	
	if (obj && obj.body && obj.body.innerHTML!='' && obj2) {
		obj2.innerHTML=obj.body.innerHTML;
	}
}

function RandomNumber (From,To) {
	return (Math.floor ((To - From + 1) * Math.random() + From));
}

function RandomName (Length) {
	var ValidChars="abcdefghijklmnopqrstuvwxyz";
	var s="";
	for (i=0;i<Length;i++) {
		var j=RandomNumber (0,25);
		s=s+ValidChars.substring (j,j+1);
	}
	return s;
}

function hlWord(node,word) {	
	if (node.hasChildNodes) {
		var iterator;
		for (iterator=0;iterator<node.childNodes.length;iterator++) {			
			hlWord(node.childNodes[iterator],word);
		}
	}
		
	if (node.nodeType == 3) {
		tempNodeValue = node.nodeValue.toLowerCase();
		tempWordValue = word.toLowerCase();
		if (tempNodeValue.indexOf(tempWordValue) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {				
				nv = node.nodeValue;
				ni = tempNodeValue.indexOf(tempWordValue);				
				before = document.createTextNode(nv.substr(0,ni));
				docWordValue = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordValue);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function doHighlight(ref) {
	if (ref.indexOf('?') == -1) return;
		var refElement = document.getElementById("maincell");
		if (!refElement) {refElement = document.getElementById("scrollable");}
		if (!refElement) {refElement = document.getElementsByTagName("body")[0];}		
		var paramStr = ref.substr(ref.indexOf('?')+1);
		var paramList = paramStr.split('&');
		for (i=0;i<paramList.length;i++) {
			var valueList = paramList[i].split('=');			
			if (valueList.length == 1) continue;
        	if (valueList[0] == 'q') { 
				var words = decodeURI(valueList[1].replace(/\+/g,' ')).split(/\s+/);
				for (w=0;w<words.length;w++) {						
					hlWord(refElement,words[w]);
                }
			}
		}	
}

function highlightSearchwords() {
	if (!document.createElement) return;		
	var ref = document.location.href;
	doHighlight(ref); // Highlight our local searchwords		
	var ref = document.referrer;
	doHighlight(ref); // Highlight words based on referer (google)
}

function getHTTPObject() {	
  var xmlhttp;    
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

//var GlobalHTTPReq;

function setCaretToStart (control) {
  if (control.createTextRange) {
    var range = control.createTextRange();
    range.collapse(true);
    range.select();
  }
  else if (control.setSelectionRange) {
    control.focus();
    control.setSelectionRange(0, 0);
  }
}

function setCaretToEnd (control) {
  if (control.createTextRange) {
    var range = control.createTextRange();
    range.collapse(false);
    range.select();
  }
  else if (control.setSelectionRange) {
    control.focus();
    var length = control.value.length;
    control.setSelectionRange(length, length);
  }
}

// --------------------------------------

if (typeof(attachEvent)!="undefined") attachEvent('onload',resetObjects);
var fixObjects = false;

function resetObjects()
{
	if (!fixObjects) return;
	var coll = document.getElementsByTagName('object');
	for (var i=0; i<coll.length; i++) 
	{
		var nonia = coll[i].className;
		if (!nonia || nonia.toLowerCase().indexOf('noninteractive') == -1) coll[i].outerHTML = coll[i].outerHTML;
	}
}

// --------------------------------------

function nameSpace()
{
	this.GetType = function() {return 'nameSpace'};
}

function evalExpr(pattern, str) {
	var re = new RegExp (pattern);
	var retVal = '';
	retVal = re.exec (str);
	return (retVal ? retVal[1] : '')
}

var TErrorHandler = function()
{
	this.GetType = function() {return 'TErrorHandler'};

	this.Silent = true;
	
	this.ThrowError = function(title, error)
	{
		if (!this.Silent) throw new Error(title + '\nDetaljer: ' + error);
	}
}

var TDOM = function()
{
	this.GetType = function() {return 'TDOM'};

	this.EnsureElement = function(identifier)
	{
		if (typeof(identifier) == 'string') return document.getElementById(identifier);
		else if (typeof(identifier) == 'object') return identifier;
		else return null;
	}
	
	this.CheckElements = function(srcElm, destElm, errorTitle)
	{
		if (!srcElm)
		{
			Tangora.ErrorHandler.ThrowError(errorTitle, 'Kunne ikke finde kildeelementet.\nVærdi: ' + srcElm);
			return false;
		}
		if (!destElm)
		{
			Tangora.ErrorHandler.ThrowError(errorTitle, 'Kunne ikke finde destinationselementet.\nVærdi: ' + destElm);
			return false;		
		}
		if (srcElm == destElm) 
		{
			Tangora.ErrorHandler.ThrowError(errorTitle, 'Kilde- og destinationselementet er det samme.\nVærdi: ' + destElm);
			return false;
		}
		return true;
	}

	this.MoveElement = function(elementToMove, elementToMoveInto)
	{
		var elm = this.EnsureElement(elementToMove);
		var pelm = this.EnsureElement(elementToMoveInto);
		if (!this.CheckElements(elm, pelm, 'Tangora.DOM.MoveElement')) return;
		pelm.insertBefore(elm, null);
	}
	
	this.CloneElement = function(elementToClone, elementToCloneInto)
	{
		var elm = this.EnsureElement(elementToClone);
		var pelm = this.EnsureElement(elementToCloneInto);
		if (!this.CheckElements(elm, pelm, 'Tangora.DOM.CloneElement')) return;
		var newelm = elm.cloneNode(true);
		if (newelm.id)
		{
			var id = newelm.id;
			var postFix = 1;
			while (document.getElementById(id + '_' + postFix))
			{
				postFix++;
			}
			newelm.id = id + '_' + postFix;
		}
		this.MoveElement(newelm, pelm);
	}

	this.GetCollection = function(ElementToSearch, tagNameOfCollection)
	{
		var parent = document;
		if (ElementToSearch)
		{
			pelm = this.EnsureElement(ElementToSearch);
			if (pelm) parent = pelm;
			else
			{
				Tangora.ErrorHandler.ThrowError('Tangora.DOM.GetCollection', 'Kunne ikke finde elementet, der skal gennemsøges.\nVærdi: ' + ElementToSearch);
				return null;
			}
		}
		return parent.getElementsByTagName(tagNameOfCollection);
	}
	
	this.GetCollectionByClassName = function(ElementToSearch, tagNameOfCollection, classNameToMatch)
	{
		var coll = this.GetCollection(ElementToSearch, tagNameOfCollection);
		var result = [];
		if (coll != null)
		{
		    for (var i=0; i<coll.length; i++)
		    {
			    if (coll[i].className.indexOf(classNameToMatch) != -1) result.push(coll[i]);			
		    }
		}
		return result;
	}

	this.GetFirstCollectionMember = function(ElementToSearch, tagNameOfCollection)
	{
		var coll = this.GetCollection(ElementToSearch, tagNameOfCollection);
		if (coll && coll.length > 0) return coll[0];
		else return null;
	}
	
	this.GetFirstCollectionMemberByClassName = function(ElementToSearch, tagNameOfCollection, classNameToMatch)
	{
		var coll = this.GetCollection(ElementToSearch, tagNameOfCollection);
		if (!coll || coll.length == 0) return null;
		for (var i=0; i<coll.length; i++)
		{
			if (coll[i].className.indexOf(classNameToMatch) != -1)
			{
				return coll[i];
			}
		}
		return null;
	}
	
	this.MoveFirstCollectionMember = function(ElementToSearch, tagNameOfCollection, ElementToMoveInto)
	{
		this.MoveElement(this.GetFirstCollectionMember(ElementToSearch, tagNameOfCollection), ElementToMoveInto);
	}
	
	this.MoveFirstCollectionMemberByClassName = function(ElementToSearch, tagNameOfCollection, classNameToMatch, ElementToMoveInto)
	{
		this.MoveElement(this.GetFirstCollectionMemberByClassName(ElementToSearch, tagNameOfCollection, classNameToMatch), ElementToMoveInto);
	}

	this.CloneFirstCollectionMember = function(ElementToSearch, tagNameOfCollection, ElementToCloneInto)
	{
		this.CloneElement(this.GetFirstCollectionMember(ElementToSearch, tagNameOfCollection), ElementToCloneInto);
	}

	this.CloneFirstCollectionMemberByClassName = function(ElementToSearch, tagNameOfCollection, classNameToMatch, ElementToCloneInto)
	{
		this.CloneElement(this.GetFirstCollectionMemberByClassName(ElementToSearch, tagNameOfCollection, classNameToMatch), ElementToCloneInto);
	}
}

function TBrowser()
{
	this.GetType = function() {return 'TBrowser'};
	
	var ua = navigator.userAgent.toLowerCase();
	this.Name = 'Unknown';
	this.Version = 'Unknown';
	this.Safari = (ua.indexOf('safari') > -1);
	this.Gecko = (ua.indexOf('gecko') > -1 && !this.Safari);
	this.Firefox = (this.Gecko && ua.indexOf('firefox') > -1);
	this.Opera = (ua.indexOf('opera') > -1);
	this.IE = (ua.indexOf('msie') > -1 && !this.Opera);
	if (this.IE)
	{
		this.Name = 'Internet Explorer';
		var ver = /msie ([\d\.]+)/m.test(ua);
		if (ver) this.Version = RegExp.lastMatch.replace(/msie/,'').replace(/\s/,'');
	}
	else if (this.Opera)
	{
		this.Name = 'Opera';
		var ver = ua.match(/opera\/([\d\.]+)/);
		if (ver.length && ver.length > 0) this.Version = ver[0].replace(/opera\//,'').replace(/\s/,'');
	}
	else if (this.Firefox)
	{
		this.Name = 'Firefox';
		var ver = ua.match(/firefox\/([\d\.]+)/);
		if (ver.length && ver.length > 0) this.Version = ver[0].replace(/firefox\//,'').replace(/\s/,'');
	}
	else if (this.Safari)
	{
		this.Name = 'Safari';
		var ver = ua.match(/safari\/([\d\.]+)/);
		if (ver.length && ver.length > 0) this.Version = ver[0].replace(/safari\//,'').replace(/\s/,'');
	}
}

var TCommon = function()
{
	this.GetType = function() {return 'TCommon'};
	this.DoUnEscape = function (fldID)
	{
		var o = document.getElementById(fldID);
		var c = new String(o.innerHTML);		
		c = c.replace(/&lt;/gi,'<');
		c = c.replace(/&gt;/gi,'>');
		c = c.replace(/&amp;/gi,'&');
		o.innerHTML = c;
	}
}

var TCookies = function()
{
	this.SetCookieValue = function(name, key, value) 
	{
		var	argv = arguments;	 
		var	argc = arguments.length;	
		var	expires	= (argc	> 3) ? argv[3] : null;  
		var	path = (argc > 4) ?	argv[4]	: null;	 
		var	domain = (argc > 5)	? argv[5] :	null;  
		var	secure=(argc > 6) ?	argv[6]	: false;  
		
		// read previous state
		var state = this.GetCookie(name);

		// no cookie?
		if (!state) 
		{
			state = '';
		} 
		// remove identifier if already set
		var pos = state.indexOf('&' + key + '=');
		if (pos >= 0) 
		{
			var pos2 = state.indexOf('&', pos + 1);
			if (pos2 == -1) 
			{
				pos2 = state.length;
			}
			state = state.substr(0, pos) + state.substr(pos2);
		}
		
		// add new value
		if (typeof(value)!= 'undefined') 
		{
			state += '&' + key + '=' + escape(value);
		}

		// set cookie
		document.cookie	= name + '=' + state +	
			((expires == null) ? ''	: ('; expires='	+ expires.toGMTString())) +	
			((path == null)	? '' : ('; path=' +	path)) +  
			((domain ==	null) ?	'' : ('; domain=' +	domain)) +	  
			((secure ==	true) ?	'; secure' : '');
	}

	this.SetCookie = function(name, value) 
	{	
		var	argv = arguments;	 
		var	argc = arguments.length;	
		var	expires	= (argc	> 2) ? argv[2] : null;  
		var	path = (argc > 3) ?	argv[3]	: null;	 
		var	domain = (argc > 4)	? argv[4] :	null;  
		var	secure=(argc > 5) ?	argv[5]	: false;  
		document.cookie	= name + '=' + escape (value) +	
			((expires == null) ? ''	: ('; expires='	+ expires.toGMTString())) +	
			((path == null)	? '' : ('; path=' +	path)) +  
			((domain ==	null) ?	'' : ('; domain=' +	domain)) +	  
			((secure ==	true) ?	'; secure' : '');
	}

	this.GetCookie = function(name) 
	{
		var	arg	= name + '=';  
		var	alen = arg.length;	
		var	clen = document.cookie.length;
		var i = 0;  
		while (i < clen) 
		{
			var	j =	i +	alen;	 
			if (document.cookie.substring(i, j)	== arg) return this._getCookieVal(j);
			i =	document.cookie.indexOf(' ', i)	+ 1;	
			if (i == 0) break;
		}  
		return null;
	}

	this.GetCookieValue = function(name, key) 
	{
		var state = this.GetCookie(name);
		if (state) 
		{
			var str = '&' + key + '=';
			var pos = state.indexOf(str);
			if (pos >= 0) 
			{
				var pos2 = state.indexOf('&', pos + 1);
				if (pos2 == -1) 
				{
					pos2 = state.length;
				}
				// remove prefix (key)
				pos += str.length;
				return state.substr(pos, pos2-pos);
			}
		}
		return null;
	}

	this.DeleteCookie = function(name) 
	{	
		var	exp	= new Date();  
		exp.setTime(exp.getTime() - 1); 
		var	cval = this.GetCookie(name);  
		document.cookie	= name + '=' + cval	+ '; expires=' + exp.toGMTString();
	}

	this._getCookieVal = function(offset) // private!
	{
		var	endstr = document.cookie.indexOf (';', offset);
		if (endstr == -1) 
		{
			endstr = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset, endstr));
	}

}

function TSGetSelectValues (elemname,formname) {
	var i;
	var s='';
	var obj=document.forms[formname][elemname];
	if (obj) {
		for (i=0;i<obj.options.length;i++) {
			if (obj.options [i].selected) {
				if (s!='') {
					s=s+',';
				}
				s=s+obj.options [i].value;
			}
		}
	}
	return s;
}

function setWindowStatus (str) {
}

function PostFormUsingHTTPReq (HTTPReq,PostURL,FormName,BGSaveButtons,ReturnResponseText) {
	var i,j,item,poststring;
	var form=eval ("document."+FormName);
	poststring='';
	if (!HTTPReq) {
		HTTPReq=getHTTPObject();
	}
	HTTPReq.open ("POST",PostURL,false);
	HTTPReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	for (i=0;i<form.elements.length;i++) {
		item=form.elements[i];
		if (i>0) {
			poststring=poststring+'&';
		}
		if ((item.type=='checkbox' || item.type=='radio') && !item.checked) {
		}
		else if (item.type=='select-multiple') {
			var s='';
			for (j=0;j<item.options.length;j++) {
				if (item.options[j].selected) {
					if (s!='') {
						s=s+',';
					}
					s=s+item.options[j].value;
				}
			}
			poststring=poststring+item.name+'='+s;
		}
		else {
			poststring=poststring+item.name+'='+encodeURIComponent(item.value);
		}
	}
	HTTPReq.send (poststring);
	if (BGSaveButtons) {
		var s=HTTPReq.responseText;
		if (s.indexOf ("top.location.href='/admin/logon.aspx'")!=-1) {
			ShowLoginBox("bgsave=1");
		}
		else if (s.indexOf ("&refpath=errorwindow&text=")!=-1) {
			if (s.indexOf("HandledError")==-1) {
				i=s.indexOf ("&refpath=errorwindow&text=");
				j=s.indexOf ("'",i+30);
				window.open('module.aspx?modid=1&refpath=errorwindow&text='+s.substring (i+26,j),'','width=300,height=200');
			}
		}
		else {
			i=s.indexOf ('<script>window.parent.location.href=');
			if (i!=-1) {
				j=s.indexOf ("'",i+40);
				location.replace (s.substring (i+37,j));
			}
		}
	}
	if (ReturnResponseText) {
		return (HTTPReq.responseText);
	}
}
 
 
if (typeof(Tangora) == 'undefined') var Tangora = new Object();
Tangora.Browser = new TBrowser();
Tangora.Common = new TCommon();
Tangora.Cookies = new TCookies();
Tangora.DOM = new TDOM();
Tangora.ErrorHandler = new TErrorHandler();
Tangora.Events = new nameSpace();
// methods are added to Tangora.Events in compatibility.js //
Tangora.ServerVariables = new nameSpace();
var tmp = Tangora.Cookies.GetCookieValue('ServerVars', 'AcceptLanguage');
Tangora.ServerVariables.AcceptLanguage = (tmp!=null)?tmp.replace(/\|/g, ';'):"";