
/*tinyMCE.init({
			mode : "exact",
			elements : "ajaxfilemanager",
			theme : "advanced",
			plugins : "table,advhr,advimage,advlink,paste,fullscreen,noneditable,contextmenu,insertdatetime,emotions,print,preview,xhtmlxtras,layer,visualchars",

			theme_advanced_buttons1_add_before : "newdocument,separator,insertdate,inserttime,separator",
			theme_advanced_buttons1_add : "",
			theme_advanced_buttons2_add : "separator,fullscreen,preview",
			theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator",
			theme_advanced_buttons3_add : "advhr,separator,tablecontrols",
			theme_advanced_buttons4 : "fontsizeselect,separator,forecolor,backcolor,separator,cite,abbr,acronym,attribs,emotions,separator,visualchars",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			content_css : "http://192.168.0.3/piacentini/include/css/tinymce.css",
			extended_valid_elements : "hr[class|width|size|noshade]",
		    plugin_insertdate_dateFormat : "%d-%m-%Y",
	        plugin_insertdate_timeFormat : "%H:%M:%S",
	        plugin_preview_width : "500",
			plugin_preview_height : "600",
			file_browser_callback : "ajaxfilemanager",
			paste_use_dialog : false,
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : true,
			theme_advanced_statusbar_location : "bottom",
			apply_source_formatting : true,
			force_br_newlines : true,
			force_p_newlines : false,	
			relative_urls : true
		});*/
		
		tinyMCE.init({
	mode : "exact",
	plugins : "table, preview,contextmenu",
	elements : "ajaxfilemanager",
	theme : "advanced",
	theme_advanced_buttons1 : "bold,italic,underline,separator,forecolor,fontsizeselect,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink,separator,image",
	theme_advanced_buttons2 : "tablecontrols,separator,preview",
	theme_advanced_buttons3 : "",
	file_browser_callback : "ajaxfilemanager",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
});

		function ajaxfilemanager(field_name, url, type, win) {
			var ajaxfilemanagerurl = "../../plugins/ajaxfilemanager/ajaxfilemanager.php";
			switch (type) {
				case "image":
					break;
				case "media":
					break;
				case "flash": 
					break;
				case "file":
					break;
				default:
					return false;
			}
			var fileBrowserWindow = new Array();
			fileBrowserWindow["file"] = ajaxfilemanagerurl;
			fileBrowserWindow["title"] = "Piacentini Quad File Manager";
			fileBrowserWindow["width"] = "782";
			fileBrowserWindow["height"] = "440";
			fileBrowserWindow["close_previous"] = "no";
			tinyMCE.openWindow(fileBrowserWindow, {
			  window : win,
			  input : field_name,
			  resizable : "yes",
			  inline : "yes",
			  editor_id : tinyMCE.getWindowArg("editor_id")
			});
			
			return false;
		};

function selezionatutti(){	
	tot=document.forms.select_user.elements.length;
	for(cont=0;cont<tot;cont++){
		if(document.forms.select_user.elements[cont].type == 'checkbox'){
			ogg_box=document.forms.select_user.elements[cont];
			ogg_box.checked = true;
		}
	}
}

function setWidth()
{
		var screenW = 640, screenH = 480;
		var contentW=820;
		if (document.all)
		{
			screenW=document.body.clientWidth;
			screenH=document.body.clientHeight;
		}
		else
		{
			screenW=window.innerWidth;
			screenH=window.innerHeight;
		}
		screenH=screenH-200;
		document.getElementById("out_left").style.height=screenH;
		document.getElementById("out_right").style.height=screenH;
		
		var width=(screenW-contentW)/2;
		if(screenW<1200)
			{
			document.getElementById("out_left").style.display="none";
			document.getElementById("out_right").style.display="none";
			}
		else
		{
			document.getElementById("out_left").style.display="block";
			document.getElementById("out_right").style.display="block";
			document.getElementById("out_left").style.width=width;
			document.getElementById("out_right").style.width=width;
		}
	
	   if (navigator.userAgent.indexOf("Linux") != -1) {
	      document.getElementById("search_field").style.width="70px";
	   }

}

function deselezionatutti(){	
	tot=document.forms.select_user.elements.length;
	for(cont=0;cont<tot;cont++){
		if(document.forms.select_user.elements[cont].type == 'checkbox'){
			ogg_box=document.forms.select_user.elements[cont];
			ogg_box.checked = false;
		}
	}
}

function controlwrite_newsletter(){

		var htmlText = tinyMCE.getContent('ajaxfilemanager')
		var htmlobj = document.forms.formwrite.elements.object.value;
   		if ((htmlText == null || htmlText == "")||(htmlobj == null || htmlobj == ""))
     	{
     	alert("I campi Oggetto e Testo sono obbligatori!");
     	}
     	else {
     	document.forms.formwrite.submit();
     	}
}

function controlwrite_news(){

		var htmlText = tinyMCE.getContent('ajaxfilemanager')
		var htmlobj = document.forms.formwrite.elements.title.value;
   		if ((htmlText == null || htmlText == "")||(htmlobj == null || htmlobj == ""))
     	{
     	alert("I campi Titolo e Testo sono obbligatori!");
     	}
     	else {
     	document.forms.formwrite.submit();
     	}
}

function controlwrite(){

		var name = document.forms.contact_frm.elements.name.value;
		var email = document.forms.contact_frm.elements.email.value;
		var text = document.forms.contact_frm.elements.text.value;
   		if (name=="")
     	{
     	alert("Si prega di inserire il nome.");
     	}
     	else 
     	if (email=="")
     	{
     	alert("Si prega di inserire l'email.");
     	}
     	else
     	if (emailCheck(email)==false)
     	{
     	alert("Indirizzo email non valido.");
     	}
     	else 
     	if (text=="")
     	{
     	alert("Si prega di inserire il testo del messaggio.");
     	}
     	else
     	{
     	document.forms.contact_frm.submit();
     	}
}

function controluser(){
		counter=0;
		tot=document.forms.select_user.elements.length;
		for(cont=0;cont<tot;cont++){
		 if(document.forms.select_user.elements[cont].type == 'checkbox')
		 {
			if(document.forms.select_user.elements[cont].checked==true) 
				counter++;
		 }
		}
		if(counter==0)
		{
		 	alert("E' necessario selezionare almeno un utente!");
		}
		else
			document.forms.select_user.submit();
		
}

function validateedit(){
		username=document.forms.edituser_form.username.value;
		password=document.forms.edituser_form.password.value;
		passwordconf=document.forms.edituser_form.password_conf.value;
		email=document.forms.edituser_form.email.value;
		if(username=="")
		{
		 	alert("Lo username non puo' essere nullo.");
		}
		else if(password!=passwordconf)
		{
		 	alert("Le due password non coincidono.");
		}
		else if(password=="")
		{
		 	alert("La password non puo' essere nulla.");
		}
		else if(email=="")
		{
		 	alert("L'email non puo' essere nulla.");
		}
		else
			document.forms.edituser_form.submit();
		
}

	function validateadd(){
		username=document.forms.adduser_form.username.value;
		password=document.forms.adduser_form.password.value;
		passwordconf=document.forms.adduser_form.password_conf.value;
		email=document.forms.adduser_form.email.value;
		if(username=="")
		{
		 	alert("Lo username non puo' essere nullo.");
		}
		else if(password!=passwordconf)
		{
		 	alert("Le due password non coincidono.");
		}
		else if(password=="")
		{
		 	alert("La password non puo' essere nulla.");
		}
		else if(email=="")
		{
		 	alert("L'email non puo' essere nulla.");
		}
		else
			document.forms.adduser_form.submit();
		
}

function deletecategory(id_category)
{
		if(window.confirm("La categoria verra' cancellata. Continuare?")){
			page="admin_categories.php?action=delete&id_category=" + id_category;
			return location.href= page;
		}
}

		function DeletePicture(id_category){
			
			page='upload_image_categ.php?action=delete&id_category=' + id_category;
			window.open(page,'Piacentini Quad','width=320,height=170,left=400,top=300,resizable=no,menubar=no,toolbar=no,scrollbars=no,locations=no,status=no');
}

		function selectcolor(ncolor){
			
			page='../lib/DHTML_Color_Picker/select_color.php?ncolor=' + ncolor;
			window.open(page,'Piacentini Quad','width=215,height=200,left=400,top=300,resizable=no,menubar=no,toolbar=no,scrollbars=no,locations=no,status=no');
}

			function applycolor(ncolor,color)
{
		var cellname;
		cellname='color_'+ncolor;
		document.getElementById("cell_"+ncolor).style.background=color;
		eval("document.forms.add_product."+cellname+".value=color");
}

			function aggiorna()
{
		document.forms.form1.submit();

}

		function UploadImage(){
		
			id_category=document.forms.add_image.id_category.value;	
			window.open('upload_image_categ.php?id_category=' + id_category,'Piacentini Quad','width=320,height=170,left=400,top=300,resizable=no,menubar=no,toolbar=no,scrollbars=no,locations=no,status=no');
}


		function DatiTecniciDefault(){
		var editorInstance = tinyMCE.selectedInstance;
			document.forms.defaults.datitecnici.value=editorInstance.getHTML();
			document.forms.defaults.submit();
}

	function DisableEnableUsers(ncheck){
		pubblico=document.forms.add_category.pubblico.checked;
		
		if(ncheck==null)
			ncheck=document.forms.add_category.elements.length;
			
		for(cont=0;cont<ncheck;cont++){
			check = document.getElementById("read"+cont);
			if(check!=null)
			{
				if(pubblico==true)
				{
				 	check.disabled=true;
				}
				else 
					check.disabled=false;
			}
		}
		
}

	function validateadd_category(){

		name_category=document.forms.add_category.name_category.value;
		if(name_category=="")
		{
		 	alert("Il nome categoria puo' essere nullo.");
		}
		else
			document.forms.add_category.submit();
		
}

	function validateadd_product(){
		product_name=document.forms.add_product.product_name.value;
		if(product_name=="")
		{
		 	alert("Il nome prodotto puo' essere nullo.");
		}
		else
			document.forms.add_product.submit();
		
}

		function UploadImage_product(){
		
			id_product=document.forms.add_image.id_product.value;		
			window.open('upload_image.php?id_product=' + id_product,'Piacentini Quad','width=320,height=240,left=400,top=300,resizable=no,menubar=no,toolbar=no,scrollbars=no,locations=no,status=no');
}

		function DeletePicture_product(id_picture, id_product){
			
			page='upload_image.php?action=delete&id_picture=' + id_picture + '&id_product=' +id_product;
			window.open(page,'Piacentini Quad','width=320,height=170,left=400,top=300,resizable=no,menubar=no,toolbar=no,scrollbars=no,locations=no,status=no');
}

		function EditLabel_product(id_picture, id_product){
			
			page='upload_image.php?action=editlabel&id_picture=' + id_picture + '&id_product=' +id_product;
			window.open(page,'Piacentini Quad','width=320,height=170,left=400,top=300,resizable=no,menubar=no,toolbar=no,scrollbars=no,locations=no,status=no');
}

			function aggiorna()
{
		document.forms.form1.submit();

}

function deleteproduct(id_product)
{
		if(window.confirm("Il prodotto verra' cancellato. Continuare?")){
			page="admin_products.php?action=delete&id_product=" + id_product;
			return location.href= page;
		}
}

function ShowUnshowSelect(pubblico,id)
{
		if(pubblico==1){
			document.getElementById(id).style.display = "none";
		}
		else
			document.getElementById(id).style.display = "";
}

function ShowUnshowDescription(show,id)
{
		if(show==0){
			document.getElementById(id).style.display = "none";
		}
		else
			document.getElementById(id).style.display = "";
}

function emailCheck (emailStr) {
		var emailPat=/^(.+)@(.+)$/
		/* The following string represents the pattern for matching all special
		   characters.  We don't want to allow special characters in the address. 
		   These characters include ( ) < > @ , ; : \ " . [ ]    */
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		/* The following string represents the range of characters allowed in a 
		   username or domainname.  It really states which chars aren't allowed. */
		var validChars="\[^\\s" + specialChars + "\]"
		/* The following pattern applies if the "user" is a quoted string (in
		   which case, there are no rules about which characters are allowed
		   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		   is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")"
		/* The following pattern applies for domains that are IP addresses,
		   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		   e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		/* The following string represents an atom (basically a series of
		   non-special characters.) */
		var atom=validChars + '+'
		/* The following string represents one word in the typical username.
		   For example, in john.doe@somewhere.com, john and doe are words.
		   Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")"
		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		/* The following pattern describes the structure of a normal symbolic
		   domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		
		
		/* Finally, let's start trying to figure out if the supplied address is
		   valid. */
		
		/* Begin with the coarse pattern to simply break up user@domain into
		   different pieces that are easy to analyze. */
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
		  /* Too many/few @'s or something; basically, this address doesn't
		     even fit the general mould of a valid e-mail address. */
			//alert("Email address seems incorrect (check @ and .'s)")
			return false
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		
		// See if "user" is valid 
		if (user.match(userPat)==null) {
		    // user is not valid
		    //alert("The username doesn't seem to be valid.")
		    return false
		}
		
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		   host name) make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
		    // this is an IP address
			  for (var i=1;i<=4;i++) {
			    if (IPArray[i]>255) {
			        //alert("Destination IP address is invalid!")
				return false
			    }
		    }
		    return true
		}
		
		// Domain is symbolic name
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			//alert("The domain name doesn't seem to be valid.")
		    return false
		}
		
		/* domain name seems valid, but now make sure that it ends in a
		   three-letter word (like com, edu, gov) or a two-letter word,
		   representing country (uk, nl), and that there's a hostname preceding 
		   the domain or country. */
		
		/* Now we need to break up the domain to get a count of how many atoms
		   it consists of. */
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
		    domArr[domArr.length-1].length>3) {
		   // the address must end in a two letter or three letter word.
		   //alert("The address must end in a three-letter domain, or two letter country.")
		   return false
		}
		
		// Make sure there's a host name preceding the domain.
		if (len<2) {
		   var errStr="This address is missing a hostname!"
		   //alert(errStr)
		   return false
		}
		
		// If we've gotten this far, everything's valid!
		return true;
}