function confirmAction(text) {
    return confirm(text)
}

function hideContent(d) {
    if(d.length < 1) { return; }
    if( document.getElementById(d) == null ) { return; }
    document.getElementById(d).style.display = "none";
}
function showContent(d) {
    if(d.length < 1) { return; }
    document.getElementById(d).style.display = "block";
}
function reverseContentDisplay(d) {
    if(d.length < 1) { return; }
    if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
    else { document.getElementById(d).style.display = "none"; }
}

function reverseContentDisplayWithSlide(d) {
    if(d.length < 1) { return; }
    if(document.getElementById(d).style.display == "none") {  Effect.SlideDown(d, {duration: 0.5 });/*document.getElementById(d).style.display = "block";*/ }
    else { new Effect.SlideUp(d, {duration: 0.5 });/*document.getElementById(d).style.display = "none";*/ }
}

function showProvinceRegionsForm() {

    provinceIndex = 1;
    while(provinceIndex < 12){
        //hideContent("provinceDiv_" + provinceIndex);
        provinceIndex++;
    }

    provinceId = document.getElementById("provincesFilter").value;
    showContent("provinceDiv_" + provinceId);
}

function openCandidateFile(url, name) {
    window.open(url, name, "menubar=no,width=800,height=600,toolbar=no,resizable=yes,scrollbars=yes")
}

function openCandidateEdit(url, name) {
    window.open(url, name, "menubar=no,width=800,height=600,toolbar=no,resizable=yes,scrollbars=yes")
}

function openCalendar(url) {
    window.open(url, 'calendar', "menubar=no,width=250,height=250,toolbar=no,resizable=sno,scrollbars=no")
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
  return false;
}


function submitenter(myfield,e)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13)
       {
       myfield.form.submit();
       return false;
       }
    else
       return true;
}

function validateFormElement(element){
    var url = window.location;
    var myAjax = new Ajax.Request
     (
         url,
         {
             method: 'post',
             parameters: $(element.id).serialize(true),
             onSuccess: function(transport){

                 var elementValue = $(element.id).getValue()
                 var errorBox = transport.responseText.evalJSON();

                 //Find the error div associated to the form element
                 var errorDiv = document.getElementById( element.id + '_errorBox' );

                 //Remove the div if it is found
                 if( errorDiv )
                    $(errorDiv.id).parentNode.removeChild($(errorDiv.id));

                 for( var i = 0; i< $(element.id).parentNode.childNodes.length; i++)
                 {

                     child = $(element.id).parentNode.childNodes[i];
                     if( child.className == 'errors' )
                     {
                        while (child.childNodes.length >= 1) {
                              child.removeChild(child.firstChild);
                        }
                        child.parentNode.removeChild(child);
                     }

                 }


                 if( errorBox )
                 {
                    $(element.id).parentNode.innerHTML += '<div id="' + element.id + '_errorBox">' + errorBox + '</div>';
                    var errorDiv = document.getElementById( element.id + '_errorBox' );
                 }

                 //Restore the value of the element
                 Form.Element.setValue( element.id, elementValue );

             },
             encoding: 'UTF-8'
         }
     );
}
