var xmlhttp = null;

function checkEmail(email) {
  var proto  = "(mailto:)?";
  var usr    = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
  var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
  var regex  = "^" + proto + "?" + usr + "\@" + domain + "$";

  var rgx    = new RegExp(regex);
  valid = rgx.exec(email) ? true : false;
  if (valid==false)
	alert("Geben Sie bitte eine gültige E-Mail-Adresse ein.");
  return valid;
}

function radioWert(rObj) {
    for (var i=0; i<rObj.length; i++) {
      if (rObj[i].checked)
        return rObj[i].value;
    }
    return false;
  }

function jumpToUrl(uri) {
  window.location.href=uri;
}

function resizeIFrame() {
  var y = getDocDim("jobframe","y");
  document.getElementById("jobframe").style.height = y;
  var x = getDocDim("jobframe","x");
  if (x < 50) {
    x = 800;
  }
  document.getElementById("jobframe").style.width = x+20;
  //alert (x+" * "+y);
  changeAnchorTargets();
}

// Hoehe und Breite der Stellenanzeige im IFrame ermitteln
// und IFrame daran anpassen
function getDocDim(iframe_id,xy) {

  var x,y;
  var iframe = document.getElementById(iframe_id);
  var iframe_doc = (iframe.contentWindow || iframe.contentDocument);
  if (iframe_doc.document) {
    iframe_doc = iframe_doc.document;
  }
  //alert(iframe_doc);
  var test1 = iframe_doc.body.scrollHeight;
  var test2 = iframe_doc.body.offsetHeight
  if (test1 > test2) // all but Explorer Mac
  {
  	x = iframe_doc.body.scrollWidth;
  	y = iframe_doc.body.scrollHeight;
  }
  else // Explorer Mac;
       //would also work in Explorer 6 Strict, Mozilla and Safari
  {
  	x = iframe_doc.body.offsetWidth;
  	y = iframe_doc.body.offsetHeight;
  }
  
  return xy=="x" ? x : y;
  
}

// Ziele der Anchor-Tags auf "_blank" setzen, sofern kein javascript-Link
function changeAnchorTargets() {
  var iframe = document.getElementById("jobframe");
  var iframe_doc = (iframe.contentWindow || iframe.contentDocument);
  if (iframe_doc.document) {
    iframe_doc = iframe_doc.document;
  }
  if (iframe_doc.getElementsByTagName("a").length > 0) {
    for (i=0; i<iframe_doc.getElementsByTagName("a").length; i++) {
      if (iframe_doc.getElementsByTagName("a")[i].href.indexOf("javascript")==-1) {
        iframe_doc.getElementsByTagName("a")[i].target = "_blank";
      }
    }
  }
}

function openJobDetail() {
  document.getElementById("jf_anchor").click();
}

function checkJobLinks(ut_nr) {
	if (ajax == true) {
    xmlhttp = new getXMLRequester();
    xmlhttp.open("POST", "cron.check_ext_stellen.php",true);
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send("ut_nr="+ut_nr);
    xmlhttp.onreadystatechange = linksChecked;
  }
}

function linksChecked() {
	if (xmlhttp.readyState == 4) { 
	    if (xmlhttp.status == 200) {
	      response = xmlhttp.responseText;
	      alert(response);
	    }
	}
}
