// JavaScript Document


function login(form) {
	form.action =  '../login.php';
	form.submit();
}
function login_home(form) {
	form.action =  'login.php';
	form.submit();
}
function IsEnter(){
	if (window.event.keyCode == 13){
		login(document.login);
	}
}

function cerca(form) {
	form.action =  'ricerca/get_search.php';
	form.submit();
}
function EditForm(form) {
	form.action =  '../include/include_modifica_profilo.php';
	form.submit();
}
function CambiaPassword(form) {
	form.action =  '../include/include_cambia_password.php';
	form.submit();
}
function CambiaEmail(form) {
	form.action =  '../include/include_cambia_email.php';
	form.submit();
}

function AggiungiNera(url) {
	var x = confirm('Sei sicuro di volerlo aggiungere in lista nera?\nIl email non potra pił contattarti ne sapere quando sei on line');
	if (x == true){
		window.location =  url;
	}
}
function CancellaUtente(url) {
	var x = confirm('Sicuro di volerti cancellare?');
	if (x == true){
		window.location =  url;
	}
}
function Menu(links) {
     location.href = links[links.selectedIndex].value;
}

function ApriUrl(url) {
	window.open( url ,'','width=350,height=500 ,toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}
function goToURL(url) { 
	window.location = url; 
}

function get_tag(stringa, tag) { 

	inizio = stringa.search("<"+tag+">") + tag.length + 2;
	fine = stringa.search("</"+tag+">");
	lunghezza = fine-inizio;
	return stringa.substr(inizio, lunghezza);
}
function isTime(stringa) {
	var val_ritorno = true;
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	var matchArray = stringa.match(timePat);
	if (matchArray == null) {
		val_ritorno =  false; 
	}else{
		hour = matchArray[1];
		minute = matchArray[2];
		second = matchArray[4];
		ampm = matchArray[6];
		if (second=="") { second = null; }
		if (ampm=="") { ampm = null }
		if (hour < 0 || hour > 23) {
			val_ritorno =  false;
		}
		if (minute<0 || minute > 59) {
			val_ritorno =  false;
		}
		if (second != null && (second < 0 || second > 59)) {
			val_ritorno =  false;
		}
	}
	return val_ritorno;
}
function hideById(id) {
	document.getElementById(id).style.display="none";
}
function showById(id) {
	document.getElementById(id).style.display="block";
}
function show_hide_ById(id) {
	if (document.getElementById(id).style.display=="block") {
			document.getElementById(id).style.display="none";;
		}else{
			document.getElementById(id).style.display="block";
		}
}
function number_format (number, decimals, dec_point, thousands_sep) {
    number = (number + '').replace(',', '').replace(' ', '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }    return s.join(dec);
}

function ajax_live_search(obj, input_element, output_element, stringa_sessionid, return_funcion){
	//alert(return_funcion);
	
	var text_search = document.getElementById(input_element).value;
	var params = "obj="+obj;
	var params = params+"&text_search="+text_search;
	var params = params+"&return_funcion="+return_funcion;
	var params = params+stringa_sessionid;
	
	
	if(text_search==""){
		document.getElementById(output_element).style.display="none";
		return;
	}
		var ajax = assegnaXMLHttpRequest();

 		if(ajax){
		ajax.onreadystatechange=function(){
  			if(ajax.readyState==4){
				document.getElementById(output_element).style.display="block";
				document.getElementById(output_element).innerHTML = ajax.responseText;
			}
		}
		
		ajax.open("POST","../include/include_live_search.php",true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);
		ajax.setRequestHeader("Connection", "close");
		ajax.send(params);
		

//Send the proper header information along with the request

	}
}

function center_element(element){
	w=document.getElementById(element).clientWidth;
	h=document.getElementById(element).clientHeight;
	
	var margin_left=(document.body.clientWidth/2)+document.body.scrollLeft;
	document.getElementById(element).style.left = (margin_left-(w/2))+"px";

	var margin_top=(document.body.clientHeight/2)+document.body.scrollTop;
	document.getElementById(element).style.top= margin_top-(h/2)+"px";
}


//inizio gestione Popup
function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
		alert(windowname);
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}
//fine gestione popup

function GetRadioButtonValue(name){

     var radio = document.getElementsByName(name);
      for (var ii = 0; ii < radio.length; ii++){
                if (radio[ii].checked){
					return radio[ii].value;
            	}
	  }
	  return false;
}


