
addEvent(window,"load",init);
function addEvent(o,e,f){if(o.addEventListener){o.addEventListener(e,f,true);return true;}else if(o.attachEvent){return o.attachEvent("on"+e,f);}else{return false;}}
function setDefault(name,val){if(typeof(window[name])=="undefined" || window[name]==null){window[name]=val;}}
function expandTree(treeId){var ul = document.getElementById(treeId);if(ul == null){return false;}expandCollapseList(ul,nodeOpenClass);}
function collapseTree(treeId){var ul = document.getElementById(treeId);if(ul == null){return false;}expandCollapseList(ul,nodeClosedClass);}
function expandToItem(treeId,itemId){var ul = document.getElementById(treeId);if(ul == null){return false;}var ret = expandCollapseList(ul,nodeOpenClass,itemId);if(ret){var o = document.getElementById(itemId);if(o.scrollIntoView){o.scrollIntoView(false);}};setActiveLink(treeId, itemId);}
function expandCollapseList(ul,cName,itemId){if(!ul.childNodes || ul.childNodes.length==0){return false;}for(var itemi=0;itemi<ul.childNodes.length;itemi++){var item = ul.childNodes[itemi];if(itemId!=null && item.id==itemId){return true;}if(item.nodeName == "LI"){var subLists = false;for(var sitemi=0;sitemi<item.childNodes.length;sitemi++){var sitem = item.childNodes[sitemi];if(sitem.nodeName=="UL"){subLists = true;var ret = expandCollapseList(sitem,cName,itemId);if(itemId!=null && ret){item.className=cName;return true;}}}if(subLists && itemId==null){item.className = cName;}}}}
function convertTrees(){setDefault("treeClass","mktree");setDefault("nodeClosedClass","liClosed");setDefault("nodeOpenClass","liOpen");setDefault("nodeBulletClass","liBullet");setDefault("nodeLinkClass","bullet");setDefault("preProcessTrees",true);if(preProcessTrees){if(!document.createElement){return;}uls = document.getElementsByTagName("ul");for(var uli=0;uli<uls.length;uli++){var ul=uls[uli];if(ul.nodeName=="UL" && ul.className==treeClass){processList(ul);}}}init();}
function processList(ul){if(!ul.childNodes || ul.childNodes.length==0){return;}for(var itemi=0;itemi<ul.childNodes.length;itemi++){var item = ul.childNodes[itemi];if(item.nodeName == "LI"){var subLists = false;for(var sitemi=0;sitemi<item.childNodes.length;sitemi++){var sitem = item.childNodes[sitemi];if(sitem.nodeName=="UL"){subLists = true;processList(sitem);}}var s= document.createElement("SPAN");var t= '\u00A0';s.className = nodeLinkClass;if(subLists){if(item.className==null || item.className==""){item.className = nodeClosedClass;}if(item.firstChild.nodeName=="#text"){t = t+item.firstChild.nodeValue;item.removeChild(item.firstChild);}s.onclick = function(){this.parentNode.className =(this.parentNode.className==nodeOpenClass) ? nodeClosedClass : nodeOpenClass;return false;}}else{item.className = nodeBulletClass;s.onclick = function(){return false;}}s.appendChild(document.createTextNode(t));item.insertBefore(s,item.firstChild);}}}
function expandToItem2(treeId,itemId){var ul = document.getElementById(treeId);if(ul == null){return false;}var ret = expandCollapseList(ul,nodeOpenClass,itemId);if(ret){var o = document.getElementById(itemId);if(o.scrollIntoView){o.scrollIntoView(false);}};}
function setActiveLink(treeId,itemId) {
	document.getElementById('menu' + itemId.replace(/node/g, '')).className = "activeMenu"
	try {
		expandToItem2(treeId, document.getElementById(itemId).childNodes[1].nextSibling.childNodes[0].id)
	} catch(e) {

	}
}

function initPage() {
	// Cascade on relevant pages. Have it empty here.
}

function init() {
//	convertTrees()
}
function goToUrl(id) {
//	tree.saveOpenStates()
//	tree.saveState('rnit_menu')
	document.location.href = (tree.getUserData(id, 'url'))
}

function moveItemsInSelect(from,to) {
	var len
	oSBleft = document.getElementById(to)
	oSBright = document.getElementById(from)
	for ( i=0; i<oSBright.length ; i++) {
		if (oSBright.options[i].selected == true ) {
			oSBleft.options[oSBleft.length] = new Option(oSBright.options[i].text, oSBright.options[i].value)
		}
	}
	for ( i = (oSBright.length -1); i>=0; i--){
		if (oSBright.options[i].selected == true ) {
			oSBright.options[i] = null
		}
	}
}
function isAlphanum(string) {
	string = string.toString()
	var re = new RegExp(/^[0-9A-ÖøæÆØ\!:`´\., \+\-]+$/gi)
	return string.match(re)
}
function isAlphanumBlank(string) {
	var returnValue = true
	string = string.toString()
	if (string != '') {
		var re = new RegExp(/^[0-9A-ÖøæÆØ\!:´`\., \+\-]+$/gi)
		returnValue = string.match(re)
	}
	return returnValue
}
function isPostNo(string) {
	string = string.toString()
	var re = new RegExp(/^(s-|S-){0,1}[0-9]{3}\s?[0-9]{2}$/gi)
	return string.match(re)
}
function isMail(string) {
	string = string.toString()
	var re = new RegExp(/^(\w|[-])+(\.(\w|[-])+)*@((\[([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\])|((([a-zA-Z0-9])+(([-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([-])+([a-zA-Z0-9])+)*))$/gi)
	return string.match(re)
}
function isMailBlank(string) {
	var returnValue = true
	string = string.toString()
	if (string != '') {
		var re = new RegExp(/^(\w|[-])+(\.(\w|[-])+)*@((\[([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\])|((([a-zA-Z0-9])+(([-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([-])+([a-zA-Z0-9])+)*))$/gi)
		returnValue = string.match(re)
	}
	return returnValue
}

var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)

	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	var strYear=dtStr.substring(0,pos1)

	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
//		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
//		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
//		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
//		alert("Please enter a valid date")
		return false
	}
	return true
}

function filterStringByNumbers(string) {
	string = string.toString()
	string = string.replace(/[^\d]/gi, '')
	if (string == "") string = 1
	return string
}

function validateBy(el, validChars, string) {
	var bOk = false, charOk, sErrorValue

	string = string.toString()
	switch (validChars) {
		case 'alfanum_blank':
			re = /^[0-9A-Ö\., !\/\-\(\)]*/gi
			break
			
		case 'alfanum':
			re = /^[0-9A-Ö\., !\/\-\(\)]+$/gi
			break

		case 'number':
			string = string.replace(',','.')
			el.value = string
			re = /^[0-9\.\-]+$/gi
			break
		
		case 'number_blank':
			string = string.replace(',','.')
			el.value = string
			re = /^([0-9]\.]+)?$/g
			break
		
		case 'mail':
			if (isMail(string)) {
				bOk = true
			}
			break

		case 'mail_blank':
			if (isMailBlank(string)) {
				bOk = true
			}
			break
	}
	
	if (validChars == 'checked') {
		if (!el.checked) {
			bOk = false
			el.style.background='red'
//			el.focus()
//			window.status='Some fields contain non-valid characters'
		} else {
			bOk = true
			if (el.type == 'checkbox') {
				el.style.background=''
			} else {
				el.style.background='white'
			}
			window.status=''
		}
	}

	if (!bOk) {
		if (re.test(string)) {
			bOk = true
			if (el.type == 'checkbox') {
				el.style.background=''
			} else {
				el.style.background='white'
			}
			window.status=''
		} else {
			bOk = false
			el.style.background='red'
//			el.focus()
//			window.status='Some fields contain non-valid characters'
		}
	}
	return bOk
}

function getElementbyClass(classname) {
	ccollect = new Array()
	var inc = 0
	var alltags = document.all? document.all : document.getElementsByTagName("*")
	
	for (i=0; i < alltags.length; i++) {
		if (alltags[i].className==classname) {
			ccollect[inc++]=alltags[i]
			alltags[i].className=strActiveClassName //reset the old active item
		}
	}
}

function PopUpWindow(url, w,h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	window.open(url, 'popper', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=700,height=460,top='+wint+',left='+winl)
}

function validate(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Kolla epost-adressen (@ och .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
	    alert("Kolla epost-adressen!")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
		  if (IPArray[i]>255) {
	      alert("Kolla epost-adressen!")
				return false
		  }
	  }
	  return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Kolla epost-adressen!")
	  return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>4) {
		alert("Please check the e-mail again")
		return false
	}
	if (len<2) {
		var errStr="Kolla epost-adressen!"
		alert(errStr)
		return false
	}
}

function runSlideShow() {
	if (document.all) {
		document.images.SlideShow.style.filter="blendTrans(duration=6)";
		document.images.SlideShow.style.filter="blendTrans(duration=6)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[j].src;
	if (document.all) {
		document.images.SlideShow.filters.blendTrans.Play();
	}
	j = j + 1;
	if (j > (p - 1)) j = 0;
	t = setTimeout('runSlideShow()', slideShowSpeed);
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = '0';
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = '0' + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+currMilleSeparator+
	num.substring(num.length-(4*i+3));
	if (cents == '00') {
		if (currBehind) {
			return (((sign)?'':'-') + num + currSymbol);
		} else {
			return (currSymbol + ((sign)?'':'-') + num);
		}
		return (((sign)?'':'-') + num + currSymbol);
	} else {
		if (currBehind) {
			return (((sign)?'':'-') + num + currDecimalSeparator + cents + currSymbol);
		} else {
			return (currSymbol + ((sign)?'':'-') + num + currDecimalSeparator + cents);
		}
	}
}

// PHOTO ALBUM POPUP
// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.
PositionX = 50;
PositionY = 50;
defaultWidth  = 500;
defaultHeight = 500;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		writeln('<html><head><title>Laddar...</title><style>body{margin:0px; background-color: #fff;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width)+7;');
		writeln('height=100-(document.body.clientHeight-document.images[0].height)-0;');
		writeln('if (width > 1000) {width = 1000};');
		writeln('if (height > 600) {height = 600; width = width + 16};');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="RNIT CommerceWeb Pro";}');writeln('</sc'+'ript>');
	if (!AutoClose) writeln('</head><body bgcolor=fff scroll="auto" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body bgcolor=fff scroll="auto" onload="reSizeToImage();doTitle();self.focus()" onclick="self.close()" onblur="self.close()">');
		writeln('<center><img name="George" src='+imageURL+' style="display:block"></body></html>');
		close();		
	}
}

function popupZoom(src,w,h) {
	var opt='scrollbars=auto,width='+w+',height='+h+',left='+PositionX+',top='+PositionY;
	imgWin=window.open('/includes/imagezoom.asp?src='+src+'&w='+w+'&h='+h,'',opt)
}

	function genericPost(sPost, sUrl) {
		var xmlhttp
		var sOutput
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
		} catch (e) {
			try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
			} catch (E) {
				xmlhttp = false
			}
		}
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest()
		}
		xmlhttp.open("POST", '/admin/'+sUrl+'?'+Math.random(), true)
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded")
		xmlhttp.setRequestHeader("Content-length", sPost.length)
		xmlhttp.setRequestHeader("Connection","close")
		
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState!=4) {

			}
			if (xmlhttp.readyState==4) {

				if (xmlhttp.responseText == '') {

				} else {
					alert(xmlhttp.responseText)
				}
			}
		}
		xmlhttp.send(reverseXMLFormatting(sPost))
	}
	
	function splitToArray(str) {
		aCols = new Array(2)
		aRows = str.split('***')
		for (i=0; i<aRows.length; i++ ) {
			aCols[i] = aRows[i].split('|||')
		}
		return aCols
	}
	function reverseXMLFormatting(str) {
		str = str.replace('&#197;', 'Å')
		str = str.replace('&#229;', 'å')
		str = str.replace('&#196;', 'Ä')
		str = str.replace('&#228;', 'ä')
		str = str.replace('&#214;', 'Ö')
		str = str.replace('&#246;', 'ö')
		return str
	}


	function store_sql(el, table, column, datatype, value, where, validate_by) {
		var xmlhttp
		var aResult
		if(validateBy(validate_by, value)) {
			sPost = "tbl="+escape(table)+"&col="+escape(column)+"&val="+escape(value)+"&where="+escape(where)+"&datatype="+escape(datatype)
			/*@cc_on @*/
			/*@if (@_jscript_version >= 5)
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
			} catch (e) {
				try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
				} catch (E) {
					xmlhttp = false
				}
			}
			@end @*/
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
				xmlhttp = new XMLHttpRequest()
			}
			xmlhttp.open("POST", '/includes/store_sql.asp?'+Math.random(), true)
			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded")
			xmlhttp.setRequestHeader("Content-length", sPost.length)
			xmlhttp.setRequestHeader("Connection","close")

			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState!=4) {
					document.body.style.cursor="wait"
					window.status="Updating..."
					el.style.backgroundColor='red'
				}
				if (xmlhttp.readyState==4) {
					if (xmlhttp.responseText != 'OK') alert(xmlhttp.responseText)
					document.body.style.cursor="auto"
					window.status=""
					el.style.backgroundColor='white'
				}
			}
			xmlhttp.send(sPost)
		}
	}
	var sTempStore
	function tempStore() {
		sTempStore = this.value
	}
	function checkIfSaved() {
		if (sTempStore != this.value) {
			this.style.backgroundColor='#feffbd'
		}
	}

	function autoSave(el) {
		el.onfocus = tempStore
		el.onkeyup = checkIfSaved
	}


	function folder(id,idtext) {
		current = (document.getElementById(id).style.display == 'none') ? 'block' : 'none'
		document.getElementById(id).style.display = current
	}
