﻿
/**
  * Danieli-Corus
  * javascript functions for www.danieli-corus.com by quince
  */

function getAllHQ() {
	var x = $("footer").childElements();
	if (x[0].className == "footcont") {
		var d = x[0].childElements(); // footcont inserted to be able to center footer!
	} else {
		var d = x;
	}
	var r = new Array();
	for (var i = 0; i < d.length; i++) {
		var eid = "";
		if (eid = d[i].getAttribute("id")) {
			if (eid.indexOf("hq_") == 0) {
				r.push(d[i]);
			}
		}
	}
	return r;
}

function getAllHref() {
	var d = $("links").childElements();
	var r = new Array();
	for (var i = 0; i < d.length; i++) {
		var eid = "";
		if (eid = d[i].getAttribute("id")) {
			if (eid.indexOf("link") == 0) {
				r.push(d[i]);
			}
		}
	}
	return r;
}


function hideAllHQ() {
	var w = getAllHQ();
	var l = getAllHref();
	
	for (var i = 0; i < w.length; i++) {
		w[i].style.display = "none";
	}
	
	for (var i = 0; i < l.length; i++) {
		l[i].style.color = "#7c8c9b";
	}
	
}

function showHide(eid, a) {
	a.blur();
	if ($(eid).style.display == "none") {
		hideAllHQ();
		$(eid).style.display = "block";
		$("footer").style.height = "81px";
		$(a).style.color = "#193049";
		//location.hash = "footer";
	} else {
		$(a).style.color = "#7c8c9b";
		$(eid).style.display = "none";
		$("footer").style.height = "25px";
	}
	moveFooter();
}

function jobOver(event) {
	var ptr = Event.findElement(event, "tr");
	if (ptr.className.indexOf("job_hover") == -1) {
		ptr.oClass = ptr.className;
		ptr.className = " job_hover";
	}
}
function jobOut(event) {
	var ptr = Event.findElement(event, "tr");
	if (ptr.oClass) {
		ptr.className = ptr.oClass;
	}
}
function jobClick(event) {
	var ptr = Event.findElement(event, "tr");
	var wla = window.location.href.split("?");
	var chunk = wla[0];
	window.location.href = chunk + "?view=" + ptr.getAttribute("id");
}

function initJobList() {
	var j = $("job_list");
	var tbody = j.childElements().pop();
	var trs = tbody.childElements();
	for (var i = 0; i < trs.length; i++) {
		if (trs[i].className.indexOf("job_record") != -1) {
			Event.observe(trs[i], 'mouseover', jobOver);
			Event.observe(trs[i], 'mouseout', jobOut);
			Event.observe(trs[i], 'click', jobClick);
			var tds = trs[i].childElements();
			for (var a = 0; a < tds.length; a++) {
			}
		}
	}
	if ($("job_region_select")) {
		Event.observe("job_region_select", 'change', jobRegionChange)
	}
}

function jobRegionChange(event) {
	if (event.target.options[event.target.selectedIndex].value == "netherlands") {
		$("job_lang_select").disabled = false;
	} else {
		$("job_lang_select").disabled = true;
	}
}

function jobApplyAttach() {
	if ($("job_attachment_list")) {
		var ul = $("job_attachment_list");
		var newli = document.createElement("li");
		ul.count = Number(ul.count) + 1;
		var inname = "attach_" + String(ul.count);
		newli.innerHTML = '<input type="file" name="' + inname + '" />';
		ul.appendChild(newli);
	}
}

function submitJob() {
	if ($("job_input_name").value.length > 0) {
		$("fapplyjob").submit();
	} else {
		$("form_error").style.display = "inline";
	}
}

function submitMailJob() {
	if ($("destmail").value.length > 0 && $("srcmail").value.length > 0) {
		$("fmailjob").submit();
	} else {
		$("form_error").style.display = "inline";
	}
}

function p(w) {
	var p = "";
	p = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=622';
	window.open(w, '', p);
}

function pup(w) {
	window.open(w, '', 'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
}

/**
  * event handlers
  */

Event.observe(window, 'load', function() {
	//Event.observe('signinForm', 'submit', checkForm);
	if ($("footer")) {
		hideAllHQ();
	}
	if ($("job_list")) {
		initJobList();
	}
	if ($("job_attachment_list")) {
		$("job_attachment_list").count = 1;
	}
});


