/**************************************************************************************************
* Copyright(c) 2009 Fabian Gerold, http://www.alumniserver.net
*
* This script is part of the AlumniServer project. It is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option) any later version.
*
* The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt
*
* This script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************************************************/

function loadAlumniServerJobs(){
	var djcn=document.createElement('div');
	djcn.id='jobcategories';
	djcn.className='jobselectbox';
	document.getElementById('alumniserverjobs').appendChild(djcn);
		
	var djfn=document.createElement('div');
	djfn.id='jobfields';
	djfn.className='jobselectbox';
	document.getElementById('alumniserverjobs').appendChild(djfn);

	var djn=document.createElement('div');
	djn.id='jobs';
	document.getElementById('alumniserverjobs').appendChild(djn);
	
	loadJobCategories();
}
function loadJobCategories(){
	var djc=document.getElementById('jobcategories');
	djc.innerHTML='loading...';
		
	document.getElementById('jobfields').innerHTML='';
	document.getElementById('jobs').innerHTML='';
	var rjc=createRequest();
	rjc.onreadystatechange=function(){
		if(rjc.readyState==4){
			djc.innerHTML=rjc.responseText;
			djc.style.background='#fff'
		}
	};
	var data='load=jobcategories&version='+version+'&lang='+lang;
	rjc.open('POST','getJobCategories.php',true);
	rjc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	rjc.send(data);
}
var highlightedCategory=null;
function loadJobFields(category){
	var djf=document.getElementById('jobfields');
	djf.innerHTML='loading...';
	
	document.getElementById('jobs').innerHTML='';
	
	if(highlightedCategory!=null)highlightedCategory.style.fontWeight='normal';
	var ac=document.getElementById('ac'+category);
	if(ac){
		ac.style.fontWeight='bold';
		highlightedCategory=ac;
	}
	
	var rjf=createRequest();
	rjf.onreadystatechange=function(){
		if(rjf.readyState==4){
			djf.innerHTML=rjf.responseText;
			djf.style.background='#fff'
		}
	};
	
	var data='load=jobfields&version='+version+'&lang='+lang+'&category='+category;
	rjf.open('POST','getJobFields.php',true);
	rjf.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	rjf.send(data);
}

var highlightedField=null;
function loadJobs(field,page){
	if(page==null)page=1
	var dj=document.getElementById('jobs');
	dj.innerHTML='loading...';

	if(highlightedField!=null)highlightedField.style.fontWeight='normal';
	var ac=document.getElementById('af'+field);
	if(ac){
		ac.style.fontWeight='bold';
		highlightedField=ac;
	}
	
	var rj=createRequest();
	rj.onreadystatechange=function(){
		if(rj.readyState==4){
			dj.innerHTML=rj.responseText;
		}
	};
	
	var data='load=jobs&version='+version+'&lang='+lang+'&field='+field+'&page='+page;
	rj.open('POST','getJobs.php',true);
	rj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	rj.send(data);
}

function validateJobEdit(){
	document.getElementById('warn_label').innerHTML='';
	document.getElementById('warn_jcategory').innerHTML='';
	document.getElementById('warn_jfield').innerHTML='';
	var success=true;
	if(document.jobedit.joblabel.value==''){document.getElementById('warn_label').innerHTML=strPleaseEnterJobLabel;success=false;}
	if(document.jobedit.category.selectedIndex==0){document.getElementById('warn_jcategory').innerHTML=strPleaseSelectJobCategory;success=false;}
	//if(document.jobedit.field==null){document.getElementById('warn_jfield').innerHTML='No job fields loaded. Please select a different category';success=false;}
	//if(document.jobedit.field.selectedIndex==0){document.getElementById('warn_jfield').innerHTML=strPleaseSelectJobField;return false;}
	return success;
}


//var highlightedCategory=null;
function companyLoadJobFields(){
	var djf=document.getElementById('jfield');
	djf.innerHTML='loading...';
	document.getElementById('warn_jfield').innerHTML='';
	document.getElementById('warn_jcategory').innerHTML='';
	
	//document.getElementById('jfield').innerHTML='';
	
	/*if(highlightedCategory!=null)highlightedCategory.style.fontWeight='normal';
	var ac=document.getElementById('ac'+category);
	if(ac){
		ac.style.fontWeight='bold';
		highlightedCategory=ac;
	}*/
	
	var rjf=createRequest();
	rjf.onreadystatechange=function(){
		if(rjf.readyState==4){
			djf.innerHTML=rjf.responseText;
			djf.style.background='#fff'
		}
	};
	
	var category;
	for(i=0; i<document.jobedit.category.options.length; ++i){if(document.jobedit.category.options[i].selected==true){category=document.jobedit.category.options[i].value;break;}}
	if(category==0){
		djf.innerHTML='';
		return;
	}
	var data='lang='+lang+'&category='+category;
	rjf.open('POST','src/a/loadJobFields.php',true);
	rjf.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	//rjf.setRequestHeader('Content-Type','text/plain');
	rjf.send(data);
}

function paymentFormChanged(){
	if(document.jobedit.payment.selectedIndex>3)
		document.getElementById('paymentcurrency').innerHTML='<input type="text" name="paymentvalue" class="inp" style="margin:0px 6px;width:50px;"><select name="currency" class="combo" style="width:50px;"><option value="euro">&euro;</option><option value="usdollar">US-$</option></select>';
	else
		document.getElementById('paymentcurrency').innerHTML='';

}
function showphoneChanged(checkbox){
	if(checkbox.checked==true){
		document.jobedit.phone.value=phone;
	}
	else{
		document.jobedit.phone.value='';
	}
}
function showemailChanged(){
	if(document.jobedit.showemail.checked==true){
		document.jobedit.email.value=email;
	}
	else{
		document.jobedit.email.value='';
	}
}


function validthruChanged(){
	if( document.jobedit.validthru.selectedIndex==7){
		document.getElementById('hint_validthru').innerHTML='';
	}
	else{
		document.getElementById('hint_validthru').innerHTML=hint_validthru;
	}
	
	
}




var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose;
