function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName, features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
//Validera anmälningsformulär till kevenemang
function event_form(type)
{
	var boo = true;
	var i = 0;
	valErr = new Array();
	//Om typen är företag
	if(type == "f")
	{
		if(document.validering.Foretagsnamn.value == 0)
		{
			valErr[i] = " företagsnamn";
			i++;
			boo = false;
		}
		if(document.validering.Kontaktperson.value == 0)
		{
			valErr[i] = " kontaktperson";
			i++;
			boo = false;
		}
	}
	//Om typen är privatperson
	else
	{
		if(document.validering.Namn.value == 0)
		{
			valErr[i] = " namn";
			i++;
			boo = false;
		}	
	}
	//Rader som är generella
		if(document.validering.Telnr.value == 0)
		{
			valErr[i] = " telefonnummer";
			i++;
			boo = false;
		}
		if(document.validering.Leveransadress.value == 0)
		{
			valErr[i] = " postadress";
			i++;
			boo = false;
		}
		if(document.validering.Postnr.value == 0)
		{
			valErr[i] = " postnummer";
			i++;
			boo = false;
		}
		if(document.validering.ort.value == 0)
		{
			valErr[i] = " ort";
			i++;
			boo = false;
		}
		if(document.validering.Epost.value == 0)
		{
			valErr[i] = " e-post";
			i++;
			boo = false;
		}
        if(boo == false)
		{
			alert("Du har missat att fylla i" + valErr +  ". Vänligen kompletera formuläret med" + valErr + ".");
			return false;
		}
}
function validate_form()
{
		var boo = true;
		var i = 0;
		valErr = new Array();
		if(document.validering.Namn.value == 0)
		{
			valErr[i] = " namn";
			i++;
			boo = false;
		}
		if(document.validering.Epost.value == 0)
		{
			valErr[i] = " epost";
			i++;
			boo = false;
		}
		if(document.validering.Adress.value == 0)
		{
			valErr[i] = " adress";
			i++;			
			boo = false;
		}
		if(document.validering.Postnr.value == 0)
		{
			valErr[i] = " postnr";
			i++;			
			boo = false;
		}
		if(document.validering.Ort.value == 0)
		{
			valErr[i] = " ort";
			i++;			
			boo = false;
		}
		if(document.validering.Telnr.value == 0)
		{
			valErr[i] = " telefonnummer";
			i++;			
			boo = false;
		}
		if(document.validering.Mobilnr.value == 0)
		{
			valErr[i] = " mobiltelefonnummer";
			i++;			
			boo = false;
		}						
        if(boo == false)
		{
			alert("Du har missat att fylla i" + valErr +  ". Vänligen kompletera formuläret med" + valErr + ".");
			return false;
		}
		else
		{
				if(isEmail(document.validering.Epost.value))
				{
					return true;
				}
				else
				{
					alert('Epost-adressen är inte korrekt.');
					return false;
				}
		}
}

function isEmail(str)
{
   return /^[\w\-%~\.]+@[\w\-\.]+\.[\w]{2,4}$/.test(str);
}

function isTitel(str)
{
	if (str == "") 
	{
		document.forms[0].elements[0].focus();
		return false;
	}
}

function isName(str){
if (str == "") {
document.forms[0].elements[0].focus();
return false;
}
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i + 1);
if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ')
{
document.forms[0].elements[0].select();
document.forms[0].elements[0].focus();
return false;
   }
}
return true;
}

function isArvode(pengar)
{

	if(/^[0-9]/.test(pengar))
	return true;
	else
	alert('sjöjn grejj');
	

}

function doExpandContract(theTarget)
{
	// Tar emot objektet och lägger till ett 'd' för att nå underliggande objekt
	theId = theTarget + "d";
	// Hämtar objektet med ovanstående id från sidan
	var targetElement = document.all(theId);
	// Om objektet är osynligt visas det och bilden sätts till ett minus, annars tvärt om.
	if (targetElement.style.display == "none")
	{
		targetElement.style.display = "" ;
		document.all(theTarget).src = "../images/minus.gif" ;
	}
	else
	{
		targetElement.style.display = "none" ;
		document.all(theTarget).src = "../images/plus.gif" ;
	}
}

function randomImage(imgArr)
{
  var imgSrc, imgW, imgH, r;
  r = randomNumber(imgArr.length / 3);

 if (r==0)
	  {
  		text="<br><b>CV-Boken</b><br> Köp CV-boken - en handbok för att skriva professionella ansökningshandlingar och bli en framgångsrik jobbsökare. Sveriges mest köpta jobbsökarbok!";
	  }
  if(r==1)
	{
		text = "<br><b>Bli din egen coach</b><br>Läs boken som hjälper dig att hitta rätt i yrkeslivet! Charlotte Hågårds nya bok hjälper dig att göra din livs - och karriär-planering på egen hand. Mängder av fakta, inspiration, tips, exempel och övningar.";
	}

  
  imgSrc = imgArr[r * 3];
  imgW = imgArr[(r * 3)+1];
  imgH = imgArr[(r * 3)+2];
  document.write('<IMG SRC='+imgSrc+' WIDTH='+imgW+' HEIGHT='+imgH+'>');
  document.write(text);
}

function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}

function printpage() 
{
window.print();  
}
function placeFocus() 
{
if (document.forms.length > 0) 
{
var field = document.forms[0];
for (i = 0; i < field.length; i++) 
{
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
         }
      }
   }
}
//********************
//Antal tecken
//*******************
function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

//Contador de caracteres.
function Contar(entrada,salida,texto,caracteres) {
  var entradaObj=getObject(entrada);
  var salidaObj=getObject(salida);
  var longitud=caracteres - entradaObj.value.length;
  if(longitud <= 0) {
    longitud=0;
    texto='<span class="disable"> '+texto+' </span>';
    entradaObj.value=entradaObj.value.substr(0,caracteres);
  }
  salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

function previewPic(sel,kat) 
{
document.previewpic.src = "../../../images/"+kat+"/" + sel;
}
function previewPic2(sel) 
{
document.previewpic2.src = "../../../images/"+kat+"/" + sel;
}
//Formhantering
//*********************
bbtags = new Array('<b></b>','<i></i>','<u></u>','<br>','<span class="kursub"></span>');

function bbstyle(bbnumber,formName) {
var objForm = formName;
var txtarea = formName.ntext;
nr = bbtags[bbnumber];
a = txtarea.value+nr;
formName.ntext.value = a;
}

function goTo (page) {


	if (page != "" ) {
		if (page == "--" ) {
			//resetMenu();
		} else {
			document.location.href = page;
		}
	}
	return false;
}
function validate_Bocker()
{
		var boo = true;
		var i = 0;
		valErr = new Array();
		if(document.Bocker.Titel.value == 0)
		{
			valErr[i] = " Titel";
			i++;
			boo = false;
		}
        
		if(document.Bocker.fnamn.value == 0 || document.Bocker.enamn.value == 0)
		{
			if(document.Bocker.forf.value == 0)
			{
			valErr[i] = " Författare";
			i++;
			boo = false;
			}
			else if(document.Bocker.fnamn.value == 0 && document.Bocker.enamn.value == 0)
			{
				if(document.Bocker.forf.value == 0)
				{
				valErr[i] = " Författare";
				i++;
				boo = false;
				}
			}
		}
		
		if(document.Bocker.utg.value == 0)
		{
			if(document.Bocker.utgivare.value == 0)
			{
				valErr[i] = " Utgivare";
				i++;
				boo = false;
			}
		}
		
		if(document.Bocker.ar.value == 0)
		{
			if(document.Bocker.Artal.value == 0)
			{
				valErr[i] = " År";
				i++;
				boo = false;
			}
		}
		
		if(document.Bocker.lnd.value == 0)
		{
			if(document.Bocker.land.value == 0)
			{
				valErr[i] = " Språk";
				i++;
				boo = false;
			}
		}
		
		
		if(document.Bocker.bandt.value == 0)
		{
			if(document.Bocker.band.value == 0)
			{
				valErr[i] = " Bandtyp";
				i++;
				boo = false;
			}
		}
		
		if(document.Bocker.pris.value == 0)
		{
			if(document.Bocker.Kpris.value == 0)
			{
				valErr[i] = " Pris eller Kampanjpris";
				i++;
				boo = false;
			}
		}
		
		if(document.Bocker.supp.value == 0)
		{
			valErr[i] = " Leverantör";
			i++;
			boo = false;
		}			
		
		if(boo == false)
		{
			alert("Du har missat att fylla i" + valErr +  ". Vänligen kompletera formuläret med" + valErr + ".");
			return false;
		}

}
	//-------------------------------------
	function ChangeBgColor(ID,mOver,tName)
	{	
		if (document.getElementById(ID).tagName != tName)
		{
			document.getElementById(ID).style.backgroundColor = (mOver)?"#fdf8d6":"#ffffff";						
		}		
	}
	function rowCh(tableName,row,mOver)
	{
	  tableName.rows(row).bgColor = (mOver)?"#fdf8d6":"#999966";
	}
