<!--

var error_emptyfield = "This field is required and can't be empty";
var error_invalidemailmsg = "Email is invalid";

function string_exist (stringa) {
    if (stringa == "") {
        return false;
    }
    return true;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function check_tel (numerotel) {
    if (numerotel.length < 8) { return false; }
    for (i=0; i<numerotel.length; i++) {
        charact = numerotel.charCodeAt(i);
        if ( (charact < 48) || (charact > 57) ) {
            return false;
        }
    }
    return true;
}

function chekdate(day,month,year) {
        dd = day.parseint;
        mm = month.parseint;
        yy = year.parseint;

        if ( yy < 1910 ) {
            //alert('!')
            return false;
        }
        if ((mm < 1) || (mm > 12)) {
            return false;
        }
        if ((dd < 1) || (dd > 31)) {
            return false;
        }
        if ( ((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd == 31) ) {
            return false;
        }
        if ( (mm == 2) && (dd > 29) ) {
            return false;
        }
        bisestile = yy % 4;
        if ((bisestile != 0) && (dd > 28) && (mm == 2)) {
            return false;
        }
        return true;
}

function generico(stringa) {
    stringa = trim(stringa);
    if (!string_exist(stringa)) {
        return false;
    }
    for (i=0; i < stringa.length; i++) {
        if (stringa.charCodeAt(i) > 127) { 
            return false;
        }
    }
    return true;
}

///////////////////////////////
/*
function invalidEmailMsg(itsname)
{
    if (itsname && itsname.length != 0) { alert("Необходимо ввести нормальный email в поле: " + itsname); }
    return false;
}

function invalidSelectMsg(itsname)
{
    if (itsname && itsname.length != 0) { alert("Необходимо выбрать что-нибудь в поле: " + itsname); }
    return false;
}

function invalidRadioMsg(itsname)
{
    if (itsname && itsname.length != 0) { alert("Необходимо выбрать что-нибудь в поле: " + itsname); }
    return false;
}

function invalidNumberMsg(itsname)
{
    if (itsname && itsname.length != 0) { alert("Необходимо ввести число в поле: " + itsname); }
    return false;
}

function invalidEmptyMsg(itsname)
{
    if (itsname && itsname.length != 0) { alert("Необходимо заполнить поле: " + itsname); }
    return false;
}

function invalidFilename(itsname)
{
    if (itsname && itsname.length != 0) { alert("Некорректное имя файла в поле : " + itsname); }
    return false;
}

function invalidNotEqualStrings(itsname1, itsname2)
{
    if (itsname1 && itsname1.length != 0 && itsname2 && itsname2.length != 0 ) 
    { 
        alert("Поля " + itsname1 + " и " + itsname2 + " не совпадают "); 
    }
    return false;
}



////////////////////////////////


function validEmail(email, itsname) {
    if (typeof email != "string") { return invalidEmailMsg(itsname); }
    var retValue = trim(email);
    invalidChars = " /:,;";
    if (retValue == "") {
        return invalidEmailMsg(itsname);
    }
    for (i=0; i < invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (retValue.indexOf(badChar,0) > -1) {
            return invalidEmailMsg(itsname);
        }
    }
    atPos = retValue.indexOf("@",1);
    if (atPos == -1) {
        return invalidEmailMsg(itsname);
    }
    if (retValue.indexOf("@",atPos+1) > -1) {
        return invalidEmailMsg(itsname);
    }
    periodPos = retValue.indexOf(".",atPos)
    if (periodPos == -1) {
        return invalidEmailMsg(itsname);
    }
    if (periodPos+3 > retValue.length) {
        return invalidEmailMsg(itsname);
    }
    return true;
}

function isChosen(select, itsname) {
    if (select.selectedIndex == 0) {
        return invalidSelectMsg(itsname);
    } else {
        return true;
    }
}

function isValidRadio(radio, itsname) {
    var valid = false;
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            return true;
        }
    }
    return invalidRadioMsg(itsname);
}

function isNumber(elem, itsname) {
    var str = elem.value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString( );
    if (!str.match(re)) {
        return invalidNumberMsg(itsname);
    }
    return true;
}

function isNotEmpty(elem, itsname) {
    var str = elem.value;
    if(str == null || str.length == 0) {
        return invalidEmptyMsg(itsname);
    } else {
        return true;
    }
}

function isValidFilename(elem, itsname)
{
//    alert(elem.indexOf(".."));
//    alert(elem.indexOf("\\"));
//    alert(elem.indexOf("/"));
    if (elem.indexOf("..") != -1 || elem.indexOf("\\") != -1 || elem.indexOf("/") != -1)
    {
//        alert("isValidFilename_bad");
        return invalidFilename(itsname);
//        alert("invalidFilename return " + a);
//        return false;
    } else {
//        alert("isValidFilename_good");
        return true;
    }

}

function isStringEqual(elem1, elem2, itsname1, itsname2) {
    var str1 = elem1.value;
    var str2 = elem2.value;

    if(str1 != str2) {
        return invalidNotEqualStrings(itsname1, itsname2);
    } else {
        return true;
    }
}
*/

////////////////////////////////

function line_setcolor(num,clss)
{
    if(clss=='') {document.getElementById(num).className='ln_tran';}
    else {document.getElementById(num).className=clss;}
}

////////////////////////////////

dragging = false;
not_close = false;
d_id = 0;
function GetDragDivObject(id)
{
    d_id=id;
    try { 
        var helpdivobject = document.getElementById('helpdiv'+d_id); 
        if (helpdivobject == undefined) { 
            helpdivobject = (document.all)? document.all['helpdiv'+d_id] : eval('document.helpdiv'+d_id); 
            if (helpdivobject == undefined) return undefined; 
        } 
    } 
    catch (e){} 
    return helpdivobject; 
} 

function StartDrag(id)
{ 
    d_id=id;
    var helpdivobject = GetDragDivObject(d_id); 
    if (helpdivobject == undefined) return; 

    dragstartX = helpdivobject.offsetLeft - MouseX;
    dragstartY = helpdivobject.offsetTop  - MouseY;
    dragging = true;
    return true; 
} 

function StopDrag(id)
{
    dragging = false; 
} 

function ShowHelpDiv(id, event)
{
    d_id=id;
    var helpdivobject = GetDragDivObject(d_id); 
    if (helpdivobject == undefined) return; 

    if (!document.all){ 
        MouseX = event.pageX; 
        MouseY = event.pageY; 
    } 
    else { 
        MouseX = event.x + document.body.scrollLeft;
        MouseY = event.y + document.body.scrollTop; 
    } 

    helpdivobject.style.visibility = 'visible'; 
    helpdivobject.style.left = MouseX + 15;
    helpdivobject.style.top  = MouseY + 15;
    if(MouseX + 15 + helpdivobject.clientWidth >= document.body.clientWidth)
    {
        helpdivobject.style.left = document.body.clientWidth - helpdivobject.clientWidth - 2;
    }
    if(MouseY + 15 + helpdivobject.clientHeight >= document.body.clientHeight+document.body.scrollTop)
    {
        helpdivobject.style.top = document.body.scrollTop + document.body.clientHeight - helpdivobject.clientHeight - 2;
    }
} 

function MouseMove(evt)
{
    if (!document.all){ 
        MouseX = Math.max(50, evt.pageX); 
        MouseY = evt.pageY; 
    } 
    else { 
        MouseX = Math.max(50,event.x); 
        MouseY = event.y; 
    } 
    if (!dragging) return; 

    var helpdivobject = GetDragDivObject(d_id); 
    if (helpdivobject == undefined)return; 
    helpdivobject.style.left = MouseX + dragstartX; 
    helpdivobject.style.top  = MouseY + dragstartY; 
    if(MouseX + dragstartX + helpdivobject.clientWidth >= document.body.clientWidth)
    {
        helpdivobject.style.left = document.body.clientWidth - helpdivobject.clientWidth - 2;
    }
    if(MouseY + dragstartY + helpdivobject.clientHeight >= document.body.clientHeight + document.body.scrollTop)
    {
        helpdivobject.style.top = document.body.scrollTop + document.body.clientHeight - helpdivobject.clientHeight - 2;
    }
    if(MouseX + dragstartX < 1)
    {
        helpdivobject.style.left = 1;
    }
    if(MouseY + dragstartY < 1)
    {
        helpdivobject.style.top = 1;
    }
    return true; 
} 

function MouseDown()
{
    var helpdivobject = GetDragDivObject(d_id);
    if (not_close || dragging || helpdivobject == undefined) return; 

    if (helpdivobject.style.visibility != 'hidden') helpdivobject.style.visibility = 'hidden'; 
} 

if (!document.all) { 
    captureEvents(Event.MOUSEMOVE); 
    captureEvents(Event.MOUSEDOWN); 
} 
document.onmousemove = MouseMove; 
document.onmousedown = MouseDown; 



function init_editor()
{
    tinyMCE.init({
        mode : "specific_textareas",
        theme : "advanced",
        language : "it",
        plugins : "table,advhr,advimage,advlink,emotions,insertdatetime,searchreplace,contextmenu,paste",
        theme_advanced_buttons1_add : "fontselect,fontsizeselect",
        theme_advanced_buttons2_add : "separator,insertdate,inserttime,separator,forecolor,backcolor",
        theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
        theme_advanced_buttons3_add_before : "tablecontrols,separator",
        theme_advanced_buttons3_add : "emotions,advhr",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_path_location : "bottom",
        content_css : "wysiwyg.css",
        plugin_insertdate_dateFormat : "%Y-%m-%d",
        plugin_insertdate_timeFormat : "%H:%M:%S",
        textarea_trigger : "wysiwigarea",
        external_link_list_url : "/wysiwyg_files_list.php",
        external_image_list_url : "/wysiwyg_image_list.php",
        external_link_list_page_url : "/wysiwyg_pages_list.php"
    });
}

function showoverdiv(event, obj, txt)
{
    ovdiv = document.getElementById('overDiv');
    if (ovdiv)
    {
        ovdiv.style.left = document.body.scrollLeft + event.clientX + 15;
        ovdiv.style.top  = document.body.scrollTop + event.clientY + 12;
        ovdiv.style.display = "block";
        ovdiv.innerHTML = "<nobr>"+txt+"</nobr>";
    }
    return true;
}

function hideoverdiv()
{
    ovdiv = document.getElementById('overDiv');
    if (ovdiv)
    {
        ovdiv.style.display = "none";
    }
    return true;
}

function just_show_div(id, show)
{
    ovdiv = document.getElementById(id);
    if (ovdiv)
    {
        if (show == true) { ovdiv.style.display = "block"; }
        else { ovdiv.style.display = "none"; }
    }
    return true;
}

function just_disble_input(id, show, txt)
{
    oinpt = document.getElementById(id);
    if (oinpt)
    {
        if (show == true)
        {
            oinpt.className = "forminput";
            oinpt.disabled = false;
            oinpt.readOnly = false;
            if(oinpt.getAttribute('oldvalue'))
            {
                oinpt.value = oinpt.getAttribute('oldvalue');
            }
            else oinpt.value="";
        }
        else
        {
            oinpt.className = "inputdisabled";
            oinpt.disabled = true;
            oinpt.readOnly = true;
            oinpt.setAttribute('oldvalue',oinpt.value);
            oinpt.value = txt;
        }
    }
    return true;
}

function validateForm( f, type )
{
    var elem, i = 0, attr = "alt";
    while ( elem = f.elements[i++] )
    {
        //  Skip fieldsets
        if ( elem.nodeName == "FIELDSET" ) continue;

        //  Does element have validator attribute? (short-circuit check)
        fvCode          = ( elem[attr] ) ? elem[attr] : elem.getAttribute( attr );
        if ( !( typeof fvCode == 'undefined' || fvCode == null || fvCode == "" ) )
        {
            //alert(fvCode);
            //  Set params, validation type, and validation state
            validcontrols = fvCode.split( "|" );

            vld = true;

            var spanobj = document.getElementById(elem.name + "_valid");

            var clsname = elem.className;

            var poserr = clsname.indexOf("_error");
            if (poserr != -1) // this is already error tag
            {
                clsname = clsname.substring(0, poserr);
            }
            elem.className = clsname;

            for (k=0; k<validcontrols.length; k++)
            {
                validcontrol = validcontrols[k];
                var params = validcontrol.split( "," );    
                switch( validcontrol )
                {
                    case "empty" :
                        try
                        {
                            var str = elem.value;
                            if(str == null || str.length == 0) 
                            {
                                vld = false;
                                if (type == 2)
                                {
                                    var globalspanobj = document.getElementById("form_error_span");
                                    if (globalspanobj) 
                                    {
                                        elem.className = clsname + "_error";
//                                      elem.style.border = "red 2px solid";
                                        globalspanobj.innerHTML = "&nbsp;<font color=red> " + error_emptyfield + " </font>";
                                    }
                                }
                                else
                                {
                                    if (spanobj) { spanobj.innerHTML = "&nbsp;<font color=red> " + error_emptyfield + " </font>";}
                                }

                                elem.focus();
                                return false;    
                            }
                        } 
                        catch(e) { }
                        break;

                    case "email" :
                        var bad = 0;
                        try
                        {

                            var str = elem.value;
                            var retValue = trim(str);
                            invalidChars = " /:,;";
                            if (retValue == "") {
                                bad = 1;
                            }
                            for (ii=0; ii < invalidChars.length; ii++) {
                                badChar = invalidChars.charAt(ii);
                                if (retValue.indexOf(badChar,0) > -1) {
                                    bad = 1;
                                }
                            }
                            atPos = retValue.indexOf("@",1);
                            if (atPos == -1) {
                                bad = 1;
                            }
                            if (retValue.indexOf("@",atPos+1) > -1) {
                                bad = 1;
                            }
                            periodPos = retValue.indexOf(".",atPos)
                            if (periodPos == -1) {
                                bad = 1;
                            }
                            if (periodPos+3 > retValue.length) {
                                bad = 1;
                            }

                        }
                        catch(e) {}

                        if (bad > 0 )
                        {                   
                            if (type == 2)
                            {
                                var globalspanobj = document.getElementById("form_error_span");
                                if (globalspanobj) 
                                {
                                    elem.style.border = "red 2px solid";
                                    globalspanobj.innerHTML = "&nbsp;<font color=red> " + error_invalidemailmsg + " </font>";
                                }
                            }
                            else
                            {
                                if (spanobj) { spanobj.innerHTML = "&nbsp;<font color=red> " + error_invalidemailmsg + " </font>"; }
                            }
                                
                            elem.focus();
                            return false;
                        }

                        break;
                        default: break;
                }
            }
        }
    } 
    return true;
}

var current_image_browser = null;

// -->
