/**
* EuroCv
* Copyright 2000 - 2009
* http://www.eurocv.eu .it
* http://bugs.eurocv.eu
*
* @version 2.0
* @date Mon Oct 02 08:56:38 CEST 2006
* @copyright EuroCv Italia
*/

contacts_counter = 1;
references_counter = 1;
addresses_counter = 1;

window.onload = function () { setTimeout("START()", 2000);}

function START(){

}

function go(selectidobj) {
	if($(selectidobj).value != ""){
		window.location=$(selectidobj).value;
	}
}

function loadxml(section, id){
	if(section != ""){
		var url = 'batch/getxml.php';
		var target = 'xml';
		var loader = 'loader';
		$(loader).style.display = '';
		var myAjax = new Ajax.Updater(target, url, {
			method: 'post',
			parameters: 'action=getxml&id='+id+'&section=' + section,
			onComplete: function(req){
				$(loader).style.display = 'none';
			}
		});
	}
}

function addreference(){
	while ( document.getElementById("reference_"+references_counter) ) ++references_counter;

	if(references_counter <= 7){
		var url = 'batch/edit_options.php';
		var target = 'referencelist';

		var myAjax = new Ajax.Updater(target, url, {
			method: 'post',
			parameters: 'action=newreference&id=' + references_counter,
			insertion: Insertion.Bottom,
			onComplete: function(req){
				references_counter++;
			}
		});
	}
}


function SaveJobcategory(){
	var url = 'batch/edit_options.php';
	var target = 'jobcategory';

	var myAjax = new Ajax.Updater(target, url, {
		method: 'post',
		parameters: 'action=save_jobcat&id=' + $('idcategory').value,
		onComplete: function(req){}
	});
}


function checkpwd(){
	if($('password_1').value == $('password_2').value){
		$('password_1').setStyle({backgroundColor : 'white'});
		$('password_2').setStyle({backgroundColor : 'white'});
		$('save').disabled = false;
		$('saveclose').disabled = false;
		return true;
	}else{
		$('password_1').setStyle({backgroundColor : 'red'});
		$('password_2').setStyle({backgroundColor : 'red'});
		$('save').disabled = true;
		$('saveclose').disabled = true;
		return false;
	}
}

function clearbox(id){
	$('address_' + id).value = "";
	$('code_' + id).value = "";
	$('city_' + id).value = "";
	$('nation_' + id).options[0].selected = true;
	$('visible_' + id).checked = false;

}

function clearreferencebox(id, Msg){

	if(!isNumber(id)){
		return null;
	}
	var url = 'batch/edit_options.php';
	var pars = 'action=delreference&id=' + $('ref_idreference_' + id).value;
	var target = 'referencelist';

	var submitOK = confirm(Msg)
	if (submitOK == true){
		$('ref_name_' + id).value = "";
		$('ref_surname_' + id).value = "";
		$('ref_email_' + id).value = "";

		var opt = {
			// Use POST
			method: 'post',
			// Send this lovely data
			postBody: pars,
			// Handle successful response
			onSuccess: function(t) {
				Element.remove('reference_' + id);
			},
			// Handle 404
			on404: function(t) {
				alert('Error 404: location "' + t.statusText + '" was not found.');
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}

		var myAjax = new Ajax.Request(url, opt);
	}

}

function CreateMark(iditem, address, city, code, country, title, text){
	mylat = 'lat_'+iditem;
	mylon = 'lon_'+iditem;
	var opt = {

		// Use POST
		method: 'post',

		// Send this lovely data
		postBody: 'address='+address+'&city='+city+'&code='+code+'&country='+country,

		// Handle successful response
		onSuccess: function(t) {
			Geocoords = t.responseText;

			if(String(Geocoords) != 'notfound'){
				coords = Geocoords.split(',');
				$(mylat).value = coords[0];
				$(mylon).value = coords[1];
				var point = new GLatLng(coords[0], coords[1]);
				text = iditem + '. ' + address + '<br>' + city;
				var marker = createMarker(point, '', text, 0,"");
				map.setCenter(new GLatLng(coords[0], coords[1]), 15);
				map.addOverlay(marker);
			}else{
				$(mylat).value = "";
				$(mylon).value = "";
			}
		},

		// Handle 404
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.');
		},

		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}
	}
	map.clearOverlays()

	new Ajax.Request('batch/geocoords.php', opt);
}

function addcontacts(){
	while ( document.getElementById("contactbox_"+contacts_counter) ) ++contacts_counter;

	if(contacts_counter <= 7){
		var url = 'batch/edit_options.php';
		var target = 'contactlist';

		var myAjax = new Ajax.Updater(target, url, {
			method: 'post',
			parameters: 'action=newcontact&id=' + contacts_counter,
			insertion: Insertion.Bottom,
			onComplete: function(req){
				contacts_counter++;
			}
		});
	}
}


function addaddress(){
	while ( document.getElementById("addressbox_"+addresses_counter) ) ++addresses_counter;

	if(addresses_counter <= 3){
		var url = 'batch/edit_options.php';
		var target = 'addresslist';

		var myAjax = new Ajax.Updater(target, url, {
			method: 'post',
			parameters: 'action=newaddress&id=' + addresses_counter,
			insertion: Insertion.Bottom,
			onComplete: function(req){
				addresses_counter++;
			}
		});
	}
}

function switchtab(idtab){
	if(idtab==1){
		$('tab1').setStyle({backgroundColor : '#eee', 'color' : '#000'});
		$('tab2').setStyle({backgroundColor : 'transparent', 'color' : '#fff'});
		$('_tab1').show();
		$('_tab2').hide();
		return true;
	}else{
		$('tab1').setStyle({backgroundColor : 'transparent', 'color' : '#fff'});
		$('tab2').setStyle({backgroundColor : '#eee', 'color' : '#000'});
		$('_tab1').hide();
		$('_tab2').show();
		return true;
	}
}

function setStats(value){
	var url = 'statistics.php';
	var pars = 'setEmailStat=' + value;
	var target = 'chkstat';
	var loader = 'loader';
	$(loader).style.display = '';
	var myAjax = new Ajax.Updater(target, url, {method: 'post',
	parameters: pars,
	onComplete: function(req){
		$(loader).style.display = 'none';
	}
	});
}

function trapEnter(e, enterFunction){
	if (!e) e = window.event;
	if (e.keyCode == 13){
		e.cancelBubble = true;
		if (e.returnValue) e.returnValue = false;
		if (e.stopPropagation) e.stopPropagation();
		if (enterFunction) eval(enterFunction);
		return false;
	} else {
		return true;
	}
}

// Inizio Gestione autenticazione
function parseForm(){
	var u = document.getElementById('email'), p = document.getElementById('password');
	if(u.value == ''){
		u.focus();
		return false;
	}
	if(p.value == ''){
		p.focus();
		return false;
	}
	p.value = hex_hmac_md5($('key').value, hex_md5(p.value));
	$('js').value = 1;
	return true;
}
// Fine Gestione autenticazione


function GetFocus(){
	document.frmhome.pac.focus();
}

function submitPD(){
	document.modulo.submit();
}

function Delete(Msg, URL){
	var submitOK = confirm(Msg)
	if (submitOK == true){
		open(URL,"_self");
	}
}

function Question(Msg, URL){
	var submitOK = confirm(Msg)
	if (submitOK == true){
		open(URL,"_self");
	}
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}



/***********************************************
* Disable "Enter" key in Form script
* This notice must stay intact for use
***********************************************/

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
		break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	}
	else
	return true;
}



//////////////////////////// CHANGE FONT SIZE FUNCTION /////////////////////////////////////
var min=8;
var max=18;
function increaseFontSize() {
	var p = document.getElementsByTagName('td');
	for(i=0;i<p.length;i++) {
		if(p[i].style.fontSize) {
			var s = parseInt(p[i].style.fontSize.replace("px",""));
		} else {
			var s = 12;
		}
		if(s!=max) {
			s += 1;
		}
		p[i].style.fontSize = s+"px"
	}
}
function decreaseFontSize() {
	var p = document.getElementsByTagName('td');
	for(i=0;i<p.length;i++) {
		if(p[i].style.fontSize) {
			var s = parseInt(p[i].style.fontSize.replace("px",""));
		} else {
			var s = 12;
		}
		if(s!=min) {
			s -= 1;
		}
		p[i].style.fontSize = s+"px"
	}
}

function revertStyles() {
	var p = document.getElementsByTagName('td');
	for(i=0;i<p.length;i++) {
		var s = 11;
		p[i].style.fontSize = s+"px"
	}
}
//////////////////////////// END CHANGE FONT SIZE FUNCTION /////////////////////////////////////


function verifynotify(field1, field2, result_id, match_html, nomatch_html) {
	this.field1 = field1;
	this.field2 = field2;
	this.result_id = result_id;
	this.match_html = match_html;
	this.nomatch_html = nomatch_html;

	this.check = function() {

		// Make sure we don't cause an error
		// for browsers that do not support getElementById
		if (!this.result_id) { return false; }
		if (!document.getElementById){ return false; }
		r = document.getElementById(this.result_id);
		if (!r){ return false; }

		if (this.field1.value != "" && this.field1.value == this.field2.value) {
			document.getElementById("submit").style.display = "";
			r.innerHTML = this.match_html;
		} else {
			document.getElementById("submit").style.display = "none";
			r.innerHTML = this.nomatch_html;
		}
	}
}

function fullscreen(theURL) {
	if (navigator.appName == "Microsoft Internet Explorer"){ // better be ie6 at least
		window.open(theURL, '', 'fullscreen=yes, scrollbars=auto, resizable=yes').focus();
	}
	else { // i.e. if Firefox
		window.open(theURL, '', 'width=' + (screen.width-5) + ',height=' + (screen.height-30) + ', scrollbars=auto, resizable=yes, ').focus();
	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}