var ajax = new GLM.AJAX();
var pageroot = '/';
var nav4 = window.Event ? true : false;

function countyCallback(content){
try{
    results = content.split('---');
	addNewOptionsToSelect('varos_id0', results);
} catch (e){}
}

function cityCallback(content){
try{
	if (oselect = document.getElementById('megye_id0')) {
		results = content.split('---');
		prevselectedIndex = oselect.selectedIndex;
		oselect.selectedIndex = results[0];
		if (prevselectedIndex!=oselect.selectedIndex){
			ajax.callPage(pageroot+"includes/ajax/hiteligenylo.ajax.php?county_id="+results[1]+(prevselectedIndex!=oselect.selectedIndex ? "&diff=1": "&diff=0")+"&selectedidx="+document.getElementById('varos_id0').selectedIndex, countyCallback);
		}
	}
} catch (e){}
}

function countyCallback2(content){
try{
    results = content.split('---');
	addNewOptionsToSelect('varos_id1', results);
} catch (e){}
}

function cityCallback2(content){
try{
	if (oselect = document.getElementById('megye_id1')) {
		results = content.split('---');
		prevselectedIndex = oselect.selectedIndex;
		oselect.selectedIndex = results[0];
		if (prevselectedIndex!=oselect.selectedIndex){
			ajax.callPage(pageroot+"includes/ajax/hiteligenylo.ajax.php?county_id="+results[1]+(prevselectedIndex!=oselect.selectedIndex ? "&diff=1": "&diff=0")+"&selectedidx="+document.getElementById('varos_id0').selectedIndex, countyCallback);
		}
	}
} catch (e){}
}

function addNewOptionsToSelect(selectid, results){
	var sel = document.getElementById(selectid);
	var opt = "";
	var opt_txt = "";
	sel.innerHTML = "";

	for(var i=0;i < (results.length-1);i=i+3) {
			opt = document.createElement("option");
			opt_txt = document.createTextNode(results[i+1]);
			opt.appendChild(opt_txt);
			opt.setAttribute("value", results[i+0]);
			sel.appendChild(opt);
	}

    sel.selectedIndex = results[i-1];
}

function switchCounty(id) {
try{
	ajax.callPage(pageroot+"includes/ajax/hiteligenylo.ajax.php?county_id="+id, countyCallback);
} catch (e){}
}

function switchCity(id) {
try{
	ajax.callPage(pageroot+"includes/ajax/hiteligenylo.ajax.php?city_id="+id, cityCallback);
} catch (e){}
}

function switchCounty2(id) {
try{
	ajax.callPage(pageroot+"includes/ajax/hiteligenylo.ajax.php?county_id="+id, countyCallback2);
} catch (e){}
}

function switchCity2(id) {
try{
	ajax.callPage(pageroot+"includes/ajax/hiteligenylo.ajax.php?city_id="+id, cityCallback2);
} catch (e){}
}

function calculateOwnResourceByPercenage(id, priceid, target){
try{
	var objprice = document.getElementById(priceid);
	var obj = document.getElementById(target);
	obj.value=Math.round(document.getElementById(id).value/100*objprice.value);
	document.getElementById('igenyelthitelosszege_id0').value = objprice.value-obj.value;
} catch (e){}
}

function calculateOwnResourceByHUF(id, priceid, target){
try{
	var objprice = document.getElementById(priceid);
	var obj = document.getElementById(target);
	obj.value=Math.round(document.getElementById(id).value/objprice.value*100*10)/10;
	document.getElementById('igenyelthitelosszege_id0').value = objprice.value-document.getElementById(id).value;
} catch (e){}
}

function calculateOwnResourceByPrice(id, percentage, huf){
try{
	var objprice = document.getElementById(id);
	var obj1 = document.getElementById(percentage);
	var obj2 = document.getElementById(huf);
	if (obj2.value != ''){
		obj1.value=Math.round(obj2.value/objprice.value*100*10)/10;
	}else if (obj1.value != ''){
		obj2.value=Math.round(document.getElementById(id).value/100*objprice.value);
	}
	document.getElementById('igenyelthitelosszege_id0').value = objprice.value-obj2.value;
} catch (e){}
}

function switchOHIAim(value, cf) {
try{
	if (value == 'Érdeklődés'){
		window.location = '?af=1'+'&cf='+cf;
	}
	else if (value == 'Hitelkérelem rögzítés'){
		window.location = '?af=2'+'&cf='+cf;
	}
} catch (e){}
}

function switchOHIForm(value, af) {
try{
	if (value == 'Magánszemély'){
		window.location = '?cf=1'+'&af='+af;
	}
	else if (value == 'Egyéni vállalkozó'){
		window.location = '?cf=2'+'&af='+af;
	}
	else if (value == 'Cég'){
		window.location = '?cf=3'+'&af='+af;
	}
} catch (e){}
}

function showOnlyIf(compValue, value, objName){
try{
	if (document.getElementById)
	{
		var obj = document.getElementById(objName);

		if (value == compValue){
			eval("obj.style.display = 'block'");
		}
		else{
			eval("obj.style.display = 'none'");
		}
	}
} catch (e){}
}

function showObj(objName){
try{
	if (document.getElementById)
	{
		var obj = document.getElementById(objName);
		eval("obj.style.display = 'block'");
	}
} catch (e){}
}

function hideObj(objName){
try{
	if (document.getElementById)
	{
		var obj = document.getElementById(objName);
		eval("obj.style.display = 'none'");
	}
} catch (e){}
}

function showhidePreviousJob(){
try{
	if (document.getElementById)
	{
		var year = document.getElementById('munkaviszonyanakkezdete_year_id0').value;
		var month = document.getElementById('munkaviszonyanakkezdete_month_id0').value;
		var day = document.getElementById('munkaviszonyanakkezdete_day_id0').value;
		var myDate = new Date;
		var halfayearago = new Date;
		halfayearago.setMonth(halfayearago.getMonth()-6);
		myDate.setFullYear(year);
		myDate.setMonth(month);
		myDate.setDate(day);
		if (myDate > halfayearago){
			showObj('jobblock_id0');
			showObj('jobblock_id1');
			showObj('jobblock_id2');
			showObj('jobblock_id3');
			//placeFocus('jobblock_id0');
		}
		else {
			hideObj('jobblock_id0');
			hideObj('jobblock_id1');
			hideObj('jobblock_id2');
			hideObj('jobblock_id3');
			placeFocus('munkaltatojanakcegformaja_id0');
		}

	}
} catch (e){}
}

function showhideBarList(value){
try{
	if (document.getElementById)
	{
		var obj = document.getElementById('hiddenRow_id0');
		if (value == 'Vállalkozó' || value == 'Cég'){
			eval("obj.style.display = 'block'");
		}
		else{
			eval("obj.style.display = 'none'");
		}
	}
} catch (e){}
}

function checkLen(e,x,y,nextID) {
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if (code != 9 && code != 8 && y.length>=x.maxLength) document.getElementById(nextID).focus();
}
