/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetElementById(e)
{
    if(typeof(e)=='string') {
        if(document.getElementById) e=document.getElementById(e);
        else if(document.all) e=document.all[e];
        else e=null;
    }
    return e;
}


function onLoad()
{
    document.contact.department.focus();
}

function CallMeValidation(call_me)
{
    var validation = new Array();
    if(document.call_me.time.value == 0)
    {
        document.getElementById("time_validation").style["display"] = "block";
        validation.push(0);
    }
    if(document.call_me.your_name.value == "")
    {
        document.getElementById("your_name_validation").style["display"] = "block";
        validation.push(1);
    }

    if(document.call_me.telephone.value == "")
    {
        document.getElementById("telephone_validation").style["display"] = "block";
        validation.push(2);
    }

    if(setFocus(validation))
        return true;
    else
        return false;

}

function ContactValidation(contact)
{
    var validation = new Array();
    if(document.contact.department.value == 0)
    {
        document.getElementById("department_validation").style["display"] = "block";
        validation.push(0);
    }

    if(document.contact.your_name.value == "")
    {
        document.getElementById("your_name_validation").style["display"] = "block";
        validation.push(1);
    }

    if(document.contact.email.value == "")
    {
        document.getElementById("email_validation").style["display"] = "block";
        validation.push(2);
    }

    if(document.contact.enquiry.value == "")
    {
        document.getElementById("enquiry_validation").style["display"] = "block";
        validation.push(3);
    }

    if(setFocus(validation))
        return true;
    else
        return false;

}


function SellToUsValidation(sell_to_us)
{
    var validation = new Array();
    if(document.sell_to_us.department.value == 0)
    {
        document.getElementById("department_validation").style["display"] = "block";
        validation.push(0);
    }
    if(document.sell_to_us.time_frame.value == "")
    {
        document.getElementById("time_frame_validation").style["display"] = "block";
        validation.push(1);
    }
    if(document.sell_to_us.company.value == "")
    {
        document.getElementById("company_validation").style["display"] = "block";
        validation.push(1);
    }
    if(document.sell_to_us.address.value == "")
    {
        document.getElementById("address_validation").style["display"] = "block";
        validation.push(2);
    }
    if(document.sell_to_us.telephone.value == "")
    {
        document.getElementById("telephone_validation").style["display"] = "block";
        validation.push(3);
    }
    if(document.sell_to_us.your_name.value == "")
    {
        document.getElementById("your_name_validation").style["display"] = "block";
        validation.push(4);
    }
    if(document.sell_to_us.email.value == "")
    {
        document.getElementById("email_validation").style["display"] = "block";
        validation.push(5);
    }
    if(document.sell_to_us.equipment.value == "")
    {
        document.getElementById("equipment_validation").style["display"] = "block";
        validation.push(6);
    }
    if(document.sell_to_us.enquiry.value == "")
    {
        document.getElementById("enquiry_validation").style["display"] = "block";
        validation.push(7);
    }

    if(setFocus(validation))
        return true;
    else
        return false;

}

function QuoteUsValidation(quote_us)
{
    var validation = new Array();
    if(document.quote_us.department.value == 0)
    {
        document.getElementById("department_validation").style["display"] = "block";
        validation.push(0);
    }
    if(document.quote_us.time_frame.value == "")
    {
        document.getElementById("time_frame_validation").style["display"] = "block";
        validation.push(1);
    }
    if(document.quote_us.company.value == "")
    {
        document.getElementById("company_validation").style["display"] = "block";
        validation.push(1);
    }
    if(document.quote_us.address.value == "")
    {
        document.getElementById("address_validation").style["display"] = "block";
        validation.push(2);
    }
    if(document.quote_us.telephone.value == "")
    {
        document.getElementById("telephone_validation").style["display"] = "block";
        validation.push(3);
    }
    if(document.quote_us.your_name.value == "")
    {
        document.getElementById("your_name_validation").style["display"] = "block";
        validation.push(4);
    }
    if(document.quote_us.email.value == "")
    {
        document.getElementById("email_validation").style["display"] = "block";
        validation.push(5);
    }
    if(document.quote_us.equipment.value == "")
    {
        document.getElementById("equipment_validation").style["display"] = "block";
        validation.push(6);
    }
    if(document.quote_us.enquiry.value == "")
    {
        document.getElementById("enquiry_validation").style["display"] = "block";
        validation.push(7);
    }

    if(setFocus(validation))
        return true;
    else
        return false;

}


function AssetRecoveryValidation(asset_recovery)
{
    var validation = new Array();
    if(document.asset_recovery.department.value == 0)
    {
        document.getElementById("department_validation").style["display"] = "block";
        validation.push(0);
    }
    if(document.asset_recovery.time_frame.value == "")
    {
        document.getElementById("time_frame_validation").style["display"] = "block";
        validation.push(1);
    }
    if(document.asset_recovery.company.value == "")
    {
        document.getElementById("company_validation").style["display"] = "block";
        validation.push(1);
    }
    if(document.asset_recovery.address.value == "")
    {
        document.getElementById("address_validation").style["display"] = "block";
        validation.push(2);
    }
    if(document.asset_recovery.telephone.value == "")
    {
        document.getElementById("telephone_validation").style["display"] = "block";
        validation.push(3);
    }
    if(document.asset_recovery.your_name.value == "")
    {
        document.getElementById("your_name_validation").style["display"] = "block";
        validation.push(4);
    }
    if(document.asset_recovery.email.value == "")
    {
        document.getElementById("email_validation").style["display"] = "block";
        validation.push(5);
    }
    if(document.asset_recovery.equipment.value == "")
    {
        document.getElementById("equipment_validation").style["display"] = "block";
        validation.push(6);
    }
    if(document.asset_recovery.enquiry.value == "")
    {
        document.getElementById("enquiry_validation").style["display"] = "block";
        validation.push(7);
    }

    if(setFocus(validation))
        return true;
    else
        return false;

}



//ESTA FUNCION OCULTA LOS MENSAJES QUE HAN SIDO ENVIADOS POR EL SERVIDOR
function displayMessage()
{
    document.getElementById("server1").style["display"] = "none";
    document.getElementById("server2").style["display"] = "none";
}


//ESTA FUNCION NOS VALE PARA ASIGNAR EL FOCO AL FORMULARIO
//DEPENDIENDO DEL VALOR DEL ARRAY QUE LE VIENE DE LA FUNCION
//QUE LA LLAMA, PONE EL FOCO EN EL PRIMER ELEMENTO DEL ARRAY

function setFocus(validation)
{

    var position = -1;

    if( validation.length > 0)
    {

        for (i=0;i<validation.length;i++)
        {
            document.getElementById(validation[i]).focus();
            return false;
            position++;
        }
        return false;
    }
    else
        return true;
}


function hideMessage(id_element)
{
    var numItems = document.forms[0].elements.length;

    for(i=0; i<numItems; i++)
    {
        //Esto nos vale para comprobar el tipo de un elemento en el formulario
        //los input son de tipo text y habria que comprobar los demas elementos
        //sacando un mensaje de alert!!!LA LINEA ESTA AKI DEBAJO
        //document.forms[i].elements[i].type;
        document.getElementById(id_element).style["display"] = "none";

    /*
    *PARA RECORRER LOS ELEMENTOS HARIAMOS LO SIGUIENTE
    if(document.forms[i].elements[i].value != "" )
     {
         if(document.getElementById(id_element).style["display"] == "block")
            document.getElementById(id_element).style["display"] = "none";
     } */
    }
}

