function fastsearch_selects(selname)
{
	var entry_level 	= document.getElementById('entry_level').value;
	var location 		= document.getElementById('location').value;
	var activity_level 	= document.getElementById('activity_level').value;
	
	if( selname == 'entry_level' )
	{
		if( location == '' )
		{
			$.post("inc/fastsearch_ajax.php", {selname:selname,selvalue:entry_level,getsel:'location' }, function(data){	
				$('#location').html(data);

			});
		}
		if( activity_level == '' )
		{	
			$.post("inc/fastsearch_ajax.php", {selname:selname,selvalue:entry_level,getsel:'activity_level' }, function(data){
				$('#activity_level').html(data);
			});
		}
	}
	
	if( selname == 'location' )
	{
		if( entry_level == '' )
		{
			$.post("inc/fastsearch_ajax.php", {selname:selname,selvalue:location,getsel:'entry_level' }, function(data){	
				$('#entry_level').html(data);
			});
		}
		if( activity_level == '' )
		{	
			$.post("inc/fastsearch_ajax.php", {selname:selname,selvalue:location,getsel:'activity_level' }, function(data){
				$('#activity_level').html(data);
			});
		}
	}
	
	if( selname == 'activity_level' )
	{
		if( entry_level == '' )
		{
			$.post("inc/fastsearch_ajax.php", {selname:selname,selvalue:activity_level,getsel:'entry_level' }, function(data){	
				$('#entry_level').html(data);
			});
		}
		if( location == '' )
		{	
			$.post("inc/fastsearch_ajax.php", {selname:selname,selvalue:activity_level,getsel:'location' }, function(data){
				$('#location').html(data);
			});
		}	
	} 	
}
function create_selects(originalRequest)
{
	var divselects = originalRequest.responseText.split("&");	
	for(var i=0; i < divselects.length; i++)
	{
		
		my_select=divselects[i].split(':|:|:|:');		
		document.getElementById(my_select[0]).innerHTML = my_select[1];
		
	}	
}
function displayJobAboConfirm()
{
	$('#checkboxConfirm').css("display","block");
}

function jobAboConfirm(yes)
{
	if(yes=='yes')
	{
		$('#jobAboForm').submit();
	}
	else
	{
		$('#checkboxConfirm').css("display","none");
		return true;
	}
	
}
function markJobad(jobad_id)
{
	var url = 'inc/jobmerker.php';	
  	var pars = "jobad_id="+jobad_id;	
  	var myAjax = new Ajax.Request( 
  		url, { 
  			method: 'post', 
  			parameters: pars,
  			onComplete: function(originalRequest)
			{
				var tmp = 'merker_icon_'+jobad_id;
				document.getElementById(tmp).innerHTML='<img src="'+originalRequest.responseText+'icon_jobmerker_off.gif" width="19" height="11" alt="Diese Stelle ist schon im JobMerker" title="Diese Stelle ist schon im JobMerker" border="0" />';
				return true;
			}
  		}
  	);	
}


function delete_merkerjobad(yes)
{
	var del_count = document.getElementById('del_count').value;
	if(del_count && del_count>0)
	{
		if(yes==null || yes=='')
		{
			$('#checkboxConfirm').css("display","block");
			return true;
		}
		else if(yes!=null && yes=='no')
		{
			$('#checkboxConfirm').css("display","none");
			return true;
		}
	
		var par='';

		for( var i=1; i <= del_count ;++i)
		{
			var temp_name = 'del_jobad_id_'+i;
			if( document.getElementById(temp_name).checked )
			{
				par += '&del_jobad_id[]='+ document.getElementById(temp_name).value;	
			}	
		}
		var url = 'inc/jobmerker.php';	
  		var pars = "jobad_delete=yes&"+par;	
  		var myAjax = new Ajax.Request( 
  			url, { 
  				method: 'post', 
  				parameters: pars,
  				onComplete: function(originalRequest)
				{
					location.href="index.php?ac=statuspage";
				}
  			}
  		);
	}		
}

function delete_application(yes)
{
	var del_count = document.getElementById('del_count').value;
	if(del_count && del_count>0)
	{
		if(yes==null || yes=='')
		{
			$('#checkboxConfirm').css("display","block");
			return true;
		}
		else if(yes!=null && yes=='no')
		{
			$('#checkboxConfirm').css("display","none");
			return true;
		}
		var par='';

		for( var i=1; i <= del_count ;++i)
		{
		
			var temp_name = 'del_candidate_id_'+i;
			if( document.getElementById(temp_name).checked )
			{
				par += '&del_candidate_id[]='+ document.getElementById(temp_name).value;	
			}	
		}
		var ac=document.getElementById('ac').value;
		var url = 'index.php?ac=applicationstate';	
  		var pars = "application_delete=yes&"+par;	
  		var myAjax = new Ajax.Request( 
  			url, { 
  				method: 'post', 
  				parameters: pars,
  				onComplete: function(originalRequest)
				{
					location.href="index.php?ac="+ac;
				}
  			}
  		);
	}		
}


function delete_account(yes, candidate_id)
{
	if(yes==null || yes=='')
	{
		$('#checkboxConfirm').css("display","block");
		return true;
	}
	else if(yes!=null && yes=='no')
	{
		$('#checkboxConfirm').css("display","none");
		return true;
	}

	var url = 'inc/delete_account.php';	
	var pars = "account_delete=yes&candidate_id='"+candidate_id+"'";	
	var myAjax = new Ajax.Request( 
		url, { 
			method: 'post', 
			parameters: pars,
			onComplete: function(originalRequest)
			{
				location.href="index.php?ac=logout";
			}
		}
	);
}

function explode( delimiter, string, limit ) {
    // http://kevin.vanzonneveld.net
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function updateJobCount(response) {
	var theid;
	var jobcount;
	
	$('#industry .orange').html('');
	$('#entrylvl .orange').html('');
	
	var responsestring = explode('&',response);
	var industry = explode('=',responsestring[0]);
	industry = explode(',',industry[1]);	

	var entry = explode('=',responsestring[1]);
	entry = explode(',',entry[1]);	
	
	$.each(industry, function(i,fach) {
		jobcount = explode(':',fach);
		theid = jobcount[0];
		jobcount = jobcount[1];
		
		if (jobcount > 0)
			$('#industry'+theid).html('('+jobcount+')');	
	});
	
	$.each(entry, function(i,entryl) {
		jobcount = explode(':',entryl);
		theid = jobcount[0];
		jobcount = jobcount[1];
		
		if (jobcount > 0)
			$('#entrylevel'+theid).html('('+jobcount+')');	
	});	
}

function getSearchCheckbox(region_ids)
{	
	var url = 'inc/search_checkbox.php';
	var pars = "region_ids="+region_ids;	
  	var myAjax = new Ajax.Request( 
  		url, { 
  			method: 'post', 
  			parameters: pars,
  			onComplete: function(originalRequest)
			{
				updateJobCount(originalRequest.responseText);
			}
  		}
  	);		
}
function getCandidateForm(candidate_id)
{

}
function setJobnews(form, language)
{
	if(form.elements['getJobnews'][0].checked == true)
	{
		var checkedRadio = 'JobnewsEmail';
        if ( ! checkEmail( form.abomail.value, true ) ) {
			if (language == 1)
				alert ("Ihre E-Mail-Adresse ist syntaktisch falsch!\n");
			else if (language == 3)
				alert("La syntaxe de votre adresse e-mail n'est pas correcte!\n");
			else if (language == 4)
				alert("Su dirección e-mail tiene errores sintácticos!\n");
			else if (language == 5)
				alert("Errore di sintassi nell’indirizzo di e-mail!\n");
			else if (language == 6)
				alert("Uw e-mail is syntactisch fout!\n");		
			return false; 
        }
	}
	else
	{
		var checkedRadio = 'JobnewsRss';
	}	
	var entry_level_js = [];
   $('#entry_level_jobabo :selected').each(function(i, selected){
   entry_level_js[i] = $(selected).val();
   });
   var entry_level_js_str = entry_level_js.join(",");
   
   var location_js = [];
   $('#location_jobabo :selected').each(function(i, selected){
   location_js[i] = $(selected).val();
   });
   var location_js_str = location_js.join(",");
   
   var activity_level_js = [];
   $('#activity_level_jobabo :selected').each(function(i, selected){
   activity_level_js[i] = $(selected).val();
   });
   var activity_level_js_str = activity_level_js.join(",");
   
	$.post("inc/jobnews_abo.php", {email:form.abomail.value,checkedRadio:checkedRadio,entry_level_jobabo:entry_level_js_str, location_jobabo:location_js_str,activity_level_jobabo:activity_level_js_str  }, function(data){
		if(data)
		{		
			if( checkedRadio == 'JobnewsRss' )
			{
				window.open('jobabo_rss.php?jobabo_code='+data, 'Zweitfenster', 'width=800, height=600, scrollbars=yes, status=yes ,toolbar=no, menubar=no, resizable=yes');
			}
			else
			{
				$('p#jobabo_response').html($('#abo_succ_lang').val());
			}
		}	
		else
		{
			if (language == 1)
				$('p#jobabo_response').html('Das Abonnieren war leider nicht erfolgreich!');
			else if (language == 3)
				$('p#jobabo_response').html('L’abonnement n’a pas été effectué correctement!');
			else if (language == 4)
				$('p#jobabo_response').html('Desgraciadamente, la suscripción no ha tenido éxito!');
			else if (language == 5)
				$('p#jobabo_response').html('L´abbonamento purtroppo non è riuscito!');
			else if (language == 6)
				$('p#jobabo_response').html('Het abonneren is helaas niet gelukt!');	
		}		
 	});
}


function isDigit( ch )
{
if ( (ch >= '0') && (ch <= '9') )
  return true;
else
  return false;
}


function isAlpha( ch )
{
if ( ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) )
  return true;
else
  return false;
}


function isAlnum( ch )
{
if ( isAlpha( ch ) || isDigit( ch ) )
  return true;
else
  return false;
}


function notIn( str1, str2 )
{
var i = 0;
var j = str2.length;
for( ; i<j; i++ )
{
  var str3 =  str2.charAt(i);
  if( str1.indexOf( str3 ) != -1 )
    return false;
}
return true;
}


function checkUsername( username, mustBeQuoted )
{
var i = 0;
var j = username.length;
if ( username.charAt(0) != '"' )
{
  if ( (username.charAt(0) <  ' ') || (username.charAt(0) >  '~')
        || !notIn( mustBeQuoted, username.charAt(0) ) )
    return false;
  for( i=1; i<j; i++ )
  {
    if ( ( (username.charAt(i) < ' ') || (username.charAt(i) >  '~')
          || !notIn ( mustBeQuoted, username.charAt(i) ) )
         && ( username.charAt(i-1) != '\\' ) )
      return false;
  }
}
else
{
  if ( username.charAt( j-1 ) != '"' )
    return false;
  for( i=1; i<j-1; i++ )
  {
    if ( ( (username.charAt(i) == '\n') || (username.charAt(i) == '\r')
          || (username.charAt(i) == '\"') )
        && (username.charAt(i-1) != '\\') )
      return false;
  }

}
return true;
}


function checkNr ( nr )
{
var i=0;
var j=nr.length;

if( j < 1 )
  return false;

for( ; i<j; i++ )
  if( ( nr.charAt(i) < '0' ) || ( nr.charAt(i) > '9' ) )
    return false;

return true;
}


function checkIpnr( ipnr )
{
var iL=0;
var iC=0;
var i=0;
var sNr = "";

for( ; i< ipnr.length; i++ )
{
  if ( ipnr.charAt(i) == '.' )
  {
    if ( !iL || (iL> 3) || parseInt( sNr,10 ) > 255 )
      return false;
    iC++;
    iL = 0;
    sNr = "";
    continue;
  }
  if ( isDigit ( ipnr.charAt(i) ) )
  {
    iL++;
    sNr = sNr + ipnr.charAt(i);
    continue;
  }
  return false;
}

if ( parseInt( sNr,10 ) > 255 )
  return false;
if ( ( (iC==3) && (iL>=1) && (iL<=3) ) || ( (iC==4) && (!iL) )  )
  return true;
else
  return false;
}


function checkFqdn( fqdn )
{
var iL=0;
var iC=0;
var i=fqdn.length-1;

if ( (fqdn.charAt(0) == '.') || (fqdn.charAt(0) == '-') )
  return false;
if ( fqdn.charAt(i) == '.' )
  i=i-1;

for( ; i>=0; i-- )
{
  if ( fqdn.charAt(i) == '.' )
  {
    if ( iL < 2 && iC < 2 )
      return false;
    if ( fqdn.charAt(i-1) == '-' )
      return false;
    iC++;
    iL = 0;
    continue;
  }
  if ( isAlnum ( fqdn.charAt(i) ) )
  {
    iL++;
    continue;
  }
  if ( fqdn.charAt(i) == '-' )
  {
    if ( !iL )
      return false;
    iL++;
    continue;
  }
  return false;
}

if ( !iC || ( iL == 1 && iC < 2 ) || ( !iL && iC==1 ) ) {
  return false;
}

return true;

}


function checkHostname( hostname )
{
if ( hostname.charAt(0) == '[' )
{
  if ( hostname.charAt(hostname.length-1) != ']' )
    return false;
  var ipnr = hostname.substring( 1, hostname.length -1 );
    return checkIpnr( ipnr );
}

if ( hostname.charAt(0) == '#' )
{
  var nr = hostname.substring( 1, hostname.length );
    return checkNr( nr );
}

return checkFqdn( hostname );
}


function checkEmailAdr( address )
{
var status = true;
var username = "";
var hostname = "";

if ( address.length < 8 )
  return false;

var seperate = address.lastIndexOf("@");
if ( seperate == -1 )
  return false;

username = address.substring(0, seperate );
if ( ! checkUsername( username, "<>()[],;:@\" " ) )
  return false;

hostname = address.substring(seperate+1, address.length );
if ( ! checkHostname( hostname ) )
  return false;

return true;
}


function checkEmail( email, allowFullname )
{
var existFullname = false;
var status = true;
var fullname = "";
var adress = "";
if ( email.length < 8 )
  return false;
var emailBegin = email.indexOf("<");
var emailEnd = email.lastIndexOf(">");

if ( (emailBegin == -1) && (emailEnd == -1) )
  return checkEmailAdr( email );

if ( ( (emailBegin == -1) && (emailEnd != -1) )
    || ( (emailBegin != -1) && (emailEnd == -1) ) )
  return false;

adress = email.substring( emailBegin+1, emailEnd );

if ( ! checkEmailAdr( adress ) )
  return false;

if ( email.length == adress.length + 2 )
  return true;
else
  if ( ! allowFullname )
    return false;

if ( emailEnd == email.length - 1 )
{
  if ( emailBegin == 0 )
    return true;
  if ( email.charAt( emailBegin -1 ) != ' ' )
    return false;
  fullname = email.substring( 0, emailBegin-1 );
  return checkUsername ( fullname, "<>()[],;:@\"" );
}

return false ;

}
function getLocationSelect(region_id)
{
	$.post("inc/getLocationSelect.php", {region_id: region_id}, function(data){
 		$('#location').html(data);
 	});	
}
