//<!--Script som kan vara med alla sidor-->
var AgntUsr=navigator.userAgent.toLowerCase();
var DomYes=document.getElementById?1:0;
var NavYes=AgntUsr.indexOf('mozilla')!=-1&&AgntUsr.indexOf('compatible')==-1?1:0;
var ExpYes=AgntUsr.indexOf('msie')!=-1?1:0;
var Opr=AgntUsr.indexOf('opera')!=-1?1:0;
var DomNav=DomYes&&NavYes?1:0;
var DomExp=DomYes&&ExpYes?1:0;
var Nav4=NavYes&&!DomYes&&document.layers?1:0;
var Exp4=ExpYes&&!DomYes&&document.all?1:0;
var isN4=false;
var isN6=false
var isIE=false;
var adm=null;
var admcont=null;

var startLevel='';
var submitme=true;
var lastSelectedSize = 2;
var sizeOne = 80;
var sizeTwo = 100;
var sizeThree = 120;
var defSize=new Array();
var buttons = new Array('sizeButton80', 'sizeButton100', 'sizeButton120');


window.onload=WCMinit;
//window.addEventListener('load',WCMinit,false);
//Funktion för att kolla om enter är tryckt
function checkMe(e){
	action=false;

	if(isIE){
		if(e.keyCode==13 || e.which==13){
			if(e.srcElement.name=="searchString"){
				action=true;
				window.event.returnValue=false;
				submitSearchForm();
			}else{
				if(e.srcElement.name=="username" || e.srcElement.name=="password"){
					action=true;
					window.event.returnValue=false;
					document.forms['logon'].submit();
				}
			}
		}
	}else{
		if(e.which==13){
			if(e.target.name=="searchString"){
				action=true;
				submitSearchForm();
			}else{
				if(e.target.name=="username" || e.target.name=="password"){
					action=true;
					document.forms['logon'].submit();
				}
			}
		}
	}
	if(action==true){
		submitme=false;
	}else{
		submitme=true;
	}
}

function submitSearchForm() {
	var v = document.forms['searchForm'].searchString;
	while(''+v.value.charAt(v.value.length-1)==' '){
		v.value=v.value.substring(0,v.value.length-1);
	}
	if(v.value.length<3){
		alert(lngArr['SEARCHMSG']);
		v.focus();
	}else{
		document.forms.searchForm.submit();
	}
}


function showAdmin(){
	document.location=mainpage+'?LVLC='+sidId+'&admin=true';
}
function hideAdmin(){
	document.location=mainpage+'?LVLC='+sidId+'&admin=false';
}

function listArt(sPARC,sLVLC, mallID){
	top.location=mainpage+'?LVLC='+sLVLC;
}
function checkdate(objName, checktime) {
	var datefield = objName;
	if (chkdate(objName, checktime) == false) {
		datefield.select();
		alert(lngArr['INVALIDDATE']);
		datefield.focus();
		return false;
	}
	else {
		return true;
	}
}
function showMessage(messageid){
	var msgw=window.open(root+'message.php?messageid='+messageid, 'Message', 'navigation=no,resize=yes,scrolling=yes');
}
function changeSize(intSize, buttonObj){
	if(intSize == lastSelectedSize) {
		return;
	}
	//alert(intSize);
	intSize = parseInt(intSize);
	//alert(document.getElementById(buttonObj).id);
	selectMe(document.getElementById(buttonObj));
	if(intSize==NaN){
		intSize=100;
		alert();
	}
	setFontSize(".mainPageBody", intSize);
	setFontSize(".mainTxtHead1", intSize);
	setFontSize(".mainTxtHead2", intSize);
	//mainTxtHead1
	setCookie("fontsize", intSize);
	setCookie("buttonID", buttonObj);
	lastSelectedSize = intSize;
}


function showObject(objid){
	installning="toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=510,height=500";
	var wn=window.open('/objectopener.php?objid='+objid, 'object', installning);
}
function viewPrintable(){
	var gry;
	if(location.search) {
		gry = location.search + '&LVLC='+sidId;
	}
	else {
		gry = '?LVLC=' + sidId;
	}
	var wn=window.open(root + 'justinfo.php' + gry, 'Printable', 'navigation=no,resize=yes,height=480,width=640');
	if(!wn){
		alert(lngArr['POPUPALERT']);
	}
}
function viewPDF(){
	var wn=window.open(root+'justinfopdf.php?LVLC='+sidId+'&cachecontrol=private', 'Printable', 'navigation=no');
	if(!wn){
		alert(lngArr['POPUPALERT']);
	}
}
function statImage(){
	document.write('<img src="'+objpath+'stat.php?screenw='+screen.width+'&screenh='+screen.height+'" border="0" alt="" />');
	//document.write('<iframe src="http://www.destinator.se/admin/nosession/sessionkeeper.php" height="0" width="0" frameborder="0"></iframe>');
}
function WCMinit(){
	//Vilken läsare:
	AgntUsr=navigator.userAgent.toLowerCase();
	DomYes=document.getElementById?1:0;
	NavYes=AgntUsr.indexOf('mozilla')!=-1&&AgntUsr.indexOf('compatible')==-1?1:0;
	ExpYes=AgntUsr.indexOf('msie')!=-1?1:0;
	Opr=AgntUsr.indexOf('opera')!=-1?1:0;
	DomNav=DomYes&&NavYes?1:0;
	DomExp=DomYes&&ExpYes?1:0;
	Nav4=NavYes&&!DomYes&&document.layers?1:0;
	Exp4=ExpYes&&!DomYes&&document.all?1:0;
	if(DomNav){
		adm=document.getElementById('adminbar');
		admcont=document.getElementById('admincontainer');
	}
	if(DomExp){
		adm=document.getElementById('adminbar');
		admcont=document.getElementById('admincontainer');
	}
	if(Nav4){
		//alert(window.innerWidth);
		adm=document.layers['adminbar'];
		admcont=document.layers['admincontainer'];
	}
	if(Exp4){
		adm=document.all['adminbar'];
		admcont=document.all['admincontainer'];
	}
	//	if(document.getElementById("admincontainer")!=null && document.getElementById('adminbar')!=null){
	//		document.getElementById("admincontainer").style.height=document.getElementById('adminbar').offsetHeight;
	//	}
	//alert(admcont.id);
	//Hämta cookien:
	var fontsize=readCookie('fontsize');
	var buttonID=readCookie('buttonID');
	if(fontsize==NaN){
		fontsize=100;
	}
	if(typeof(initDHTMLAPI)=="function"){
		initDHTMLAPI();
	}
	if(typeof(changeSize)=="function"){
		changeSize(fontsize, buttonID);
	}
	if(typeof(start)=="function"){
		start();
	}
	if(typeof(makeStatic)=="function"){
		makeStatic();
	}
	if(typeof(posMainMenu)=="function"){
		posMainMenu();
	}
	if(typeof(fnInit)=="function"){
		fnInit();
	}
	//if(typeof(initAjax)=="function"){
	//		initAjax();
	//	}
	if(typeof(initSessionKeeper)=="function"){
		initSessionKeeper();
	}

	if(typeof(statImageDOM)=="function"){
		statImageDOM();
	}
}
function selectMe(objdiv){
	//alert(objdiv.className + ' - ' + objdiv.id);
	if (objdiv == null){
		return;
	}
	if (objdiv.className == 'buttonActive'){
		return;
	}
	else{
		for (i = 0; i < buttons.length; i++){
			document.getElementById(buttons[i]).className = 'button';
			document.getElementById(buttons[i]).style.color='#d47800';
			//alert(document.getElementById(buttons[i]).className);
		}
		objdiv.className = 'buttonActive';
		objdiv.style.color='#999999';
	}
}
function setspecCSS(css){
	setCookie('specCSS',css);
	applyCSS(css);
}
function applyCSS(css){
	//Remove other specCSS
	var csstag=document.getElementById('specCSS');
	if(csstag != null){
		csstag.href=css;
	}
}

function isValidRadio(radio){
	var valid=false;
	alert(radio.value+' ' + radio.name);
	for(var i=0;i < radio.length;i++){
		if(radio[i].checked){
			return true;
		}
	}
	alert('Du måste välja en');
	radio.focus();
	return false;
}
function isNotEmpty(field, markdivid){
	var str=field.value;
	var re=/.+/;
	if(!str.match(re)){
		alert('Fältet får inte vara tomt');
		field.focus();
		if($(markdivid)){
			$(markdivid).addClassName('error');
		}
		return false;
	}else{
		return true;
	}
}
function isNumber(field){
	if(isNotEmpty(field)){
		var str=field.value;
		var re=/^[-]?\d*\.?\d*$/;
		str=str.toString();
		if(!str.match(re)){
			alert('Endast nummer får skrivas här');
			field.focus();
			return false;
		}else{
			return true;
		}
	}else{
		return false;
	}
}
function isEmailAddress(field){
	var str=field.value;
	var re=/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if(!str.match(re)){
		alert('Kontrollera epostadressen');
		field.focus();
		return false;
	}else{
		return true;
	}
}
function numeralsOnly(evt){
	evt=(evt)?evt:event;
	var charCode=(evt.charCode)?evt.charCode:((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
	if(charCode>31 && (charCode <48 || charCode>57) && charCode!=46){
		alert("Endast nummer");
		return false;
	}
	return true;
}
function toggleVisibility(elemid){
	Effect.toggle(elemid, 'blind',{duration:0.2});
	//alert($(elemid).style.display);

	setCookie(elemid,$(elemid).style.display=='none','/');
}
function getRSSNews(feed, target){
	new Ajax.Updater(target, '/admin/RSSreader.php?feed='+escape(feed), {asynchronous:true});
}
function getContentHTML(content, target){
	new Ajax.Updater(target, content, {asynchronous:true});
}
function rand(n){
	return(Math.floor(Math.random() * n + 1 ));
}
var num1 = rand(10);
var num2 = rand(10);
function valMe(input, button){
	if($(input).value==(num1 + num2)){
		$(button).disabled=false;
	}
	else{
		$(button).disabled=true;
	}
}

function showDatePicker(dateBoxId, evt) {
	if (oDatePicker.visible){
		oDatePicker.hide();
		return true;
	}
	//evt=(evt)?evt:event;
	//var elem = (evt.target)?evt.target:evt.srcElement;

	var elem=Event.element(evt);
	var oTxt=$(dateBoxId);
	var dat=oTxt.value;
	var aDt = Array();
	aDt[0]=dat.substr(0,4);
	aDt[1]=dat.substr(4,2);
	aDt[2]=dat.substr(6);
	var dt = null;
	if ( aDt && (aDt.length == 3) ) {
		dt = new Date(parseInt(aDt[0]),parseInt(aDt[1])-1,parseInt(aDt[2]));
	}
	// store the textbox for use in the client
	oDatePicker.client = oTxt;
	var position = getElementPosition(elem.id);
	//position = {left:oTxt.offsetLeft,top:oTxt.offsetTop};
	//alert(position.top + ' - ' + position.left);
	oDatePicker.show(dt, position.left, position.top+12, callback);
}
function callback(dt){
	var yr=dt.getFullYear();
	var mth=dt.getMonth()+1;
	var dy=dt.getDate();
	if(mth<10){
		mth='0' + mth + '';
	}
	if(dy<10){
		dy='0' + dy + '';
	}
	oDatePicker.client.value =yr + '' + mth + '' + dy;
}
function initSessionKeeper(){
	if(loggedon){
		setTimeout("initSessionKeeper()",600000);
		new Ajax.Request(root+'/admin/nosession/sessionkeeper.php', null);
	}
}