// JavaScript Document
var msg = "Jobbsökande... Anställning omgående..."; // message to view in statusbar
var txt = ""; // leave this blank
var speed = 100; // how fast you want the text to appear, smaller means faster

function WriteInStatus(pos) {
  if(pos < msg.length) { // if the position is less than the message length then write one letter at the time
    txt += msg.charAt(pos);
    status = txt;
    pos++;
  }
  else { // else write the message
    status = msg;
  }
  setTimeout("WriteInStatus("+pos+")", speed); // set update time
}

function popUp(url, sc, dw, dh) {
  pl = parseInt((screen.width/2)-(dw/2));
  pt = parseInt((screen.height/2)-(dh/2));
  var win = window.open(url,"","scrollbars="+sc+",width="+dw+",height="+dh+",left="+pl+",top="+pt+"");
  win.creator = self;
}

function viewImg(src, alt) {
  pl = parseInt((screen.width/2)-75);
  pt = parseInt((screen.height/2)-75);
  window.open("image.aspx?src="+src+"&alt="+alt+"","img","resizable=1,width=150,height=150,left="+pl+",top="+pt+"");
}

function createBlankImg(src, alt, dw, dh) {
  pl = parseInt((screen.width/2)-(dw/2));
  pt = parseInt((screen.height/2)-(dh/2));
  img = window.open("","img","width="+dw+",height="+dh+",left="+pl+",top="+pt+"");
  img.document.open();
  img.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n');
  img.document.write('<html>\n<head>\n<title>'+alt+'</title>\n</head>\n');
  img.document.write('<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onblur="self.close();">\n');
  img.document.write('<img src="images/'+src+' width="'+dw+'" height="'+dh+'" border="0" alt="'+alt+'">\n');
  img.document.write('</body>\n</html>');
  img.document.close();
  img.focus()
}

function layerAct(id, iState) { // 1 visible, 0 hidden
  if(document.layers)	
    document.layers[id].visibility = iState ? "show" : "hide";   
  else if(document.getElementById) {
    var obj = document.getElementById(id);
    obj.style.visibility = iState ? "visible" : "hidden";
  }
  else if(document.all)
    document.all[id].style.visibility = iState ? "visible" : "hidden";
  else
    alert("Your browser doesn't support layers!");
}

function myMail(field) {
  var strEmail = field.value;
  while(strEmail.charAt(0) == ' ')
    strEmail = strEmail.substring(1);
  while(strEmail.charAt(strEmail.length-1) == ' ')
    strEmail = strEmail.substring(0, strEmail.length-1);
	 
  var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_@.";
  var ok = "yes";
  var temp;
  for(i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if(valid.indexOf(temp) == "-1") ok = "no";
  }
  if(ok == "no") {
    alert("0-9 a-z A-Z - _ . @");
	field.select(); field.focus();
  }
  
  // do some basic checking that the reg ex returns as true
  if(strEmail.indexOf("..") != -1) { alert(".. = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf(".@") != -1) { alert(".@ = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("@.") != -1) { alert("@. = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("--") != -1) { alert("-- = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("-.") != -1) { alert("-. = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf(".-") != -1) { alert(".- = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("__") != -1) { alert("__ = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("_.") != -1) { alert("_. = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("._") != -1) { alert("._ = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("-_") != -1) { alert("-_ = Wrong!"); field.select(); field.focus(); }
  if(strEmail.indexOf("_-") != -1) { alert("_- = Wrong!"); field.select(); field.focus(); }
  
  // check to see if regular expressions is supported by browser
  if(window.RegExp){
    // supported, use regular expression to validate email
    var objRegExp = new RegExp("^\w+[\.\-\w+]+@\w+[\.\-\w+]+(\.\w+)+$");
    return objRegExp.test(strEmail);
  }
  else {
    // not supported, use classic string parsing to find a valid pattern
    return((strEmail.indexOf("@") == -1) && (strEmail.indexOf(".") == -1) && (strEmail.indexOf(" ") != -1)); 
  }
}

function myField(field, valid, len) {
//  var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_:/.~";
  var ok = "yes";
  var temp;
  for(i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if(valid.indexOf(temp) == "-1") ok = "no";
  }
  if(ok == "no") {
    alert("Chars: " +valid+ " !");
    field.focus();
    field.select();
  }
  if(field.value.length < len) {
	alert("Atleast " + len + " chars!");
	field.focus();
	field.select();
  }
}

function doHtml(begin, end) { 
  text = (document.all) ? document.selection.createRange().text : document.getSelection();
  if(text != "") {
    klar = begin + text + end;
    repl = document.formen.innehall.value.replace(text, klar);
    document.formen.innehall.value = repl;
  }
  else {
	klar = begin + " " + end;
	document.formen.innehall.value = document.formen.innehall.value +" "+ klar;
  }
}

/*
function insertImg(src) {
  text = (document.all) ? document.selection.createRange().text : document.getSelection();
  if(text != "") {
	if(src != null) {
	  klar = '<img src="' +src+ '" border="0" alt="' +text+ '" title="' +text+ '">';
	  repl = document.formen.innehall.value.replace(text, klar);
	  document.formen.innehall.value = repl;
	}
  }
  else {
	alt = prompt("Alternativtext","");
	klar = '<img src="' +src+ '" border="0" alt="' +alt+ '" title="' +alt+ '">';
	document.formen.innehall.value = document.formen.innehall.value + " " + klar;
  }
}
*/
/*
See http://www.howtocreate.co.uk/perfectPopups.html and
http://www.howtocreate.co.uk/jslibs/termsOfUse.html
for details and terms of use.
To call this script, use something like (the number is a delay before
it closes or 0 for no timed closing -
the true/false says if the window should close when they switch to
another window):
<script type="text/javascript"><!--
//you can style this, but don't try to text-align it to the right, it
will break the resizing effect
//keep it narrow, if it is wider than the image, the window will wrap
to this width
//the makeright class tells the script to automatically align it to the right

//--></script>
<a href="me.jpg" onclick="return popImageExtra(this.href,'Site
author',true,3000,extraHTML);">link</a>
*/
/*
//really not important (the first two should be small for Opera's sake)
PositionX = 10;
PositionY = 10;
defaultWidth  = 600;
defaultHeight = 400;

//kinda important
var AutoClose = true;

//don't touch
function popImage(imageURL,imageTitle){
	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() {\n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		'<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	//return false; <br /><a href="javascript:self.close()" style="color:#003366;font-family:sans-serif;font-size:11px;">St&auml;ng f&ouml;nstret</a>
}
*/