// -------------------------------------------------------------------
// --- FUNZIONI X Controllo FORM SEARCH ---
// -------------------------------------------------------------------

function toolSearchSubmit(theForm) {   
	
	if (theForm.search.value.length < 3) { 
		alert('The KEYWORDS should have at least 3 characters.');
		theForm.search.focus();
		return (false); 
	} else { 
		theForm.submit();
	}
}

// -------------------------------------------------------------------


// -------------------------------------------------------------------
// --- FUNZIONI COPIATE DA HEADER STANDARD DI JAHIA
// -------------------------------------------------------------------

function quickOff(element) {
    element.style.color ="#323232";
    element.style.backgroundColor ="#ffffff";
}
function quickOn(element) {
    element.style.color="#ffffff";
    element.style.backgroundColor ="<%=color1%>";
}
function leftOff(element) {
    element.style.backgroundColor ="#F0F0F0";
}
function leftOn(element) {
    element.style.backgroundColor ="#C5C5C5";
}
function goTo(url) {
    document.location=url;
}
function topOff(id) {
    var element = jahiaGetObject(id);
    element.style.backgroundImage = "url(<%=theURL%>/images/top_menu_left_off.gif)";
}
function swithToEditMode(){
     var theUrl = window.location.href;

     var pos = theUrl.indexOf("/op/edit");
     if (pos == -1) {
        pos = theUrl.indexOf("/op/");
        if ( pos == -1 ){
            pos = theUrl.indexOf("/pid/");
            if ( pos != -1 ){
                theUrl = theUrl.substring( 0, pos ) + "/op/edit" + theUrl.substring( pos );
            }
         } else {
            theUrl = theUrl.substring( 0, pos ) + "/op/edit/oldop/" + theUrl.substring( pos + 4 );
         }
         //alert(theUrl);
         window.location.href = theUrl;
    }
}

function resizeme(i) {
  if (i.width > 500) i.width=500;
}

function checkMaxPageItems(){
	if ( document.searchpager && document.searchpager.maxPageItems
		&& document.searchpager.maxPageItems.selectedIndex != -1 ){
		document.searchForm.maxPageItems.value = document.searchpager.maxPageItems.options[document.searchpager.maxPageItems.selectedIndex].value;
	}
}
		
function setForm(formName,fieldName,value,booleanSubmit,actionValue){
	var objForm;
	var objField;
	objForm = eval('window.document.'+formName);
	if (objForm){
		objField = eval(objForm.name+'.'+fieldName);
		if (objField){
			objField.value = value;
		}
		if (actionValue && actionValue!='') objForm.action=actionValue;
		if (booleanSubmit) objForm.submit();
	}
}

function leftTrim(stringa) 
{
	while (stringa.substring(0,1) == ' ')
	{stringa = stringa.substring(1, stringa.length);}
	return stringa;
}

function rightTrim(stringa) 
{
	while (stringa.substring(stringa.length-1, stringa.length) == ' ')
	{stringa = stringa.substring(0,stringa.length-1);}
	return stringa;
}


function trim(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 setTextCounter(objTextArea,idCounter,maxSize){
	//window.document.getElementById('function').value='setTextCounter';
	try {
		var text = objTextArea.value;
		//window.document.getElementById('output').value=text.length;
		if (text.length > maxSize) {
			text = text.substring(0,maxSize);
			objTextArea.value=text;
		}
		var objCounter = window.document.getElementById(idCounter);
		objCounter.innerHTML = text.length;
	} catch (e) {
		//window.document.getElementById('error').value=e;
	}
	return;
}

function cleanTextArea(objTextArea,idCounter,maxSize){
	//window.document.getElementById('function').value='cleanTextArea';
	try {
		var text = trim(objTextArea.value);
		objTextArea.value = text;
		//window.document.getElementById('output').value='step';
		if (text.length > maxSize) {
			//window.document.getElementById('output').value='attenzione';
			text = text.substring(0,maxSize);
			objTextArea.value = trim(text);
		}
	} catch (e) {
		//window.document.getElementById('error').value=e;
	}
	return;
}
