function isValidEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
	else
	return false;
}

function provaJs(){
	alert("funziona lo script js?");
}

function PopupCentrata(linki) {
   var w = 400;
   var h = 250;
   var l = Math.floor((screen.width-w)-50);
   var t = Math.floor(30);
  window.open("./visImg.php?fold="+linki,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
 }
 
 function PopupWindow(linki) {
  window.open("./visImg.php?fold="+linki);
 }
 
 function Ttrim(stringa)  
{
	while (stringa.substring(0,1) == ' ')
	{
	stringa = stringa.substring(1, stringa.length);
	}
	while (stringa.substring(stringa.length-1, stringa.length) == ' ')
	{
	stringa = stringa.substring(0,stringa.length-1);
	}
return stringa;
}


function checkAndGo(){
	document.getElementById("descrizione").value = document.getElementById("descrizione_vis").value;
	yoForm = document.getElementById("formA");
	yoForm.submit();
}


function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.left =  Math.floor(700)+"px";
	obj.style.top =  Math.floor(60)+"px";
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
} 

function linkizza(hoover){
	//alert(hoover);
	tr_hid = document.getElementById("descrizione");
	tr = document.getElementById("descrizione_vis");	
	contTextTr = tr;
	textTr = tr.value;
	//alert("area sotto parsing: "+textTr);
	toMod = takeText(contTextTr);
	//alert("ecco cosa torna la takeText:"+ toMod);
	textTr = tr.value;
	//alert("area sotto parsing 2: "+textTr);
	
	if(toMod=='') 
	{
		alert("Evidenzia una parola da linkare");
		return;
	}
	
	//alert(toMod);
	if(hoover.indexOf("@")==-1){  
	mod = "<a href='#' onclick=\" javascript:PopupWindow('"+hoover+"'); \">"+toMod+" </a>";
	alert("Linking all'immagine "+hoover+" effettuato");
	}else{
	//linkiamo alla pagina php che fa tutto
	linki = "./visImg.php?hoover="+hoover+"";
	 mod = "<a href='#' onclick=\" javascript:PopupWindow('"+hoover+"'); \">"+toMod+" </a>";
	alert("Linking alla cartella "+hoover+" effettuato");
	}
	//mod = "<a href="+hoover+">"+toMod+"</a>";
	//alert("mod "+mod);
	//alert("toMod "+mod);
	caio = textTr.replace(toMod,mod);
	//alert(caio);
	tr_hid.value = caio;
	tr.value = tr_hid.value;
	
	
}

function takeText(myArea) {
  //var selezione = window.getSelection(); 
   //window.alert(selezione);
   //var range = selezione.getRangeAt(0);
   // fai qualcosa con il range
   	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
 	var ttt='';
	if(browser=="Microsoft Internet Explorer") //ie
	{  
		ttt = (document.all) ? document.selection.createRange().text : document.getSelection();	
	}
	else { //mozilla
		if (typeof(myArea.selectionStart) != "undefined") { 
		 var begin = myArea.value.substr(0, myArea.selectionStart); 
		 var selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart); 
		 var end = myArea.value.substr(myArea.selectionEnd);  
		}
		ttt = selection;
	}	
	new_ttt = ttt;
	if(ttt.indexOf('<a')!=-1){ //trappo l'href
		start_a = ttt.indexOf('>');
		new_sub_a = ttt.substr(start_a+1);
		end_a = new_sub_a.indexOf('<');
		new_ttt = new_sub_a.substr(0,end_a);
	}
	// alert("new_ttt: " +new_ttt);
	// alert ("ttt: "+ttt);
	 myArea.value = myArea.value.replace(ttt,new_ttt);
	// alert ("eccome come viene modificata la area: "+myArea.value);
	 return new_ttt;
}

function addtext() 
{
	var newtext = document.getElementById("descrizione_vis").value;
	document.getElementById("descrizione").value = newtext;
}

function carrello(id_prop, kind_prop) {
   var w = 700;
   var h = 400;
   var l = Math.floor((screen.width-w)-50);
   var t = Math.floor(30);
  // window.open("./php/carrello/carrello_1.php?id_p="+ id_prop +"&kind_item="+ kind_prop,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
 window.open("./?op=14&step=55&popup=1&id_p="+ id_prop +"&kind_item="+ kind_prop,"Carrello","scrollbars=1, width=" + w + ",height=" + h + ",top=" + t + ",left=" +l);
 }




