/*
Ajax.Form = Class.create();

Object.extend(Object.extend(Ajax.Form.prototype, Ajax.Request.prototype), {
	initialize: function (form, options)
	{
		var form = $(form);
		if(!form) return false;
		if(form.tagName.toLowerCase() != 'form') return false; // Only <FORM> elements can be used
		this.form = form;
		this.transport = Ajax.getTransport();
		this.setOptions(options);
		this.options.method = this.form.method || 'post';
		this.setParameters();
		this.request(this.form.action);
	},
	setParameters: function()
	{
		this.options.parameters = Form.serialize(this.form);
	}
});
*/

/* izveido flash banerus bez "click here...", kas rādās uz IE
	Edmunds: šitajam izmantosim gatavu kodu - swfobject.js
*/
function CreateControl(PARAM, DIV_ID)
{
  var d = document.getElementById(DIV_ID);
  document.write(PARAM);
}

/* Nodrošina sadaļu pārslēgšanu pirmajā lapā (zem logo) */
function changeFrontpageIntro(current_id, all_ids)
{

	document.getElementById('infotext').innerHTML = document.getElementById('frontpageintro_'+current_id).innerHTML;

	s = all_ids.split(',');

	for (i=0; i<s.length; i++)
	{
		e = document.getElementById('intro_link_'+s[i]);
		e.className = ( s[i] == current_id ? 'active' : '' );
	}
}

/* Ievieto padotos datus elementā ar id = dst_id */
function insertContents(data, dst_id)
{
	e = document.getElementById(dst_id);
	e.innerHTML = data;
}

/**
 * Dropdown menu
 */

var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf('opera') != -1);

var dropdownMenu = {
	timer: null,
	activeMenuID: null,

	show: function(menuId)
	{
		if (is_opera){ return; }
		var menu = document.getElementById? document.getElementById(menuId): null;
		if (!menu) return;
		if (menu.style.display != 'none') return;
		this.activeMenuID = menuId;
		if ( menu.onmouseout == null ) { menu.onmouseout = this.mouseoutCheck; }
		if ( menu.onmouseover == null ) { menu.onmouseover = this.clearTimer; }
		this.activate();
	},

	hide: function()
	{
		if (is_opera){ return; }
		this.clearTimer();
		if (this.activeMenuID && document.getElementById)
		this.timer = setTimeout("document.getElementById('"+dropdownMenu.activeMenuID+"').style.display = 'none'", 50);
		// this.timer = setTimeout("Effect.BlindUp('"+dropdownMenu.activeMenuID+"',{duration:0.3})", 300);
	},

	activate: function()
	{
		if (is_opera){ return; }
		this.timer = setTimeout("document.getElementById('"+dropdownMenu.activeMenuID+"').style.display='block'", 50);
	// this.timer = setTimeout("Effect.myBlindDown('"+dropdownMenu.activeMenuID+"',{duration:0.2})", 200);
	},

	mouseoutCheck: function(e)
	{
		if (is_opera){ return; }
		e = e? e: window.event;
		// is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
		var menu = document.getElementById(dropdownMenu.activeMenuID);
		var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
		if (toEl){
		if ( menu != toEl && !dropdownMenu.contained(toEl, menu) && (menu.parentNode!=toEl.parentNode)) { dropdownMenu.hide(); }
		}
	},

	// returns true of oNode is contained by oCont (container)
	contained: function(oNode, oCont)
	{
		if (is_opera){ return; }
		if (!oNode) return; // in case alt-tab away while hovering (prevent error)
		while ( oNode = oNode.parentNode )
			if ( oNode == oCont ) return true;
		return false;
	},

	clearTimer: function()
	{
		if (is_opera){ return; }
		if (dropdownMenu.timer) clearTimeout(dropdownMenu.timer);
	}
}




/**
 * Changes elemets class to "sending"
 * Used in AJAX forms
 */
function setSending(id) {
	var element = document.getElementById? document.getElementById(id): null;
    if (!element) return;
	element.className = "sending";
}


/**
 * Changes elenets class to nothing
 * Used in AJAX forms
 */
function unsetSending(id) {
	var element = document.getElementById? document.getElementById(id): null;
    if (!element) return;
	if (element.className == "sending") {
		element.className = "";
	}
}

/**
 * Opens workingday vacancy window
 */
function View(id,cpart) {
	var vw;
	vw = window.open('http://www.workingday.lv/vakances/'+cpart+'/item.php?id='+id,'view','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
	vw.focus();
}


function confirmAction()
{
	return confirm('Vai tiešām vēlaties veikt šo darbību?')
}



/* PTESTS */

/**
 * Load next Ptest question
 *
 *
 */
function loadPtestQuestion()
{
	if (question > 1 && answer_id == 0)
	{
		alert("Lūdzu atzīmējiet atbilžu variantu");
	}
	else
	{
		var questionDIV = $("ptest-question");

		if (question > 1)
		{
			questionDIV.addClassName("disabled");
		}

		var url = webroot+lang+"/ptests/question/"+test_id+"/"+question+"/"+answer_id;

		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				questionDIV.update(transport.responseText);
				questionDIV.removeClassName("disabled");
				answer_id = 0;
			}
		});

		question++;
	}
}
