function change_image(img_name, img_src) 
{
    document[img_name].src = img_src;
}


function GenNewCap() {
    NC = CyloCaptcha.genRan(6); //get a new random number
    document.getElementById("txt_holdCAP").value = NC;
    document.getElementById("SecurityCodeDiv").innerHTML = CyloCaptcha.display(NC);
}
function writeText(varText, varLabel) {
    var x = document.getElementById(varLabel);
    x.innerHTML = varText;
}
//valideaza forma rom
function validate() {
    var submitOK = true;
    var tempPhone = "";
    var tempObj = document.getElementById("txt_UserName");
    if (tempObj.value == "") {
        document.getElementById("lbl_UserName").setAttribute('style', 'color:red;');
        writeText("Va rugam completati numele si prenumele!", 'lbl_UserName');
        submitOK = false;
    }
    else if (tempObj.value.indexOf(' ') == -1) {
        document.getElementById("lbl_UserName").setAttribute('style', 'color:red;');
        writeText("Va rugam introduceti atat numele cat si prenumele!", 'lbl_UserName');
        submitOK = false;
    }
    else writeText("", 'lbl_UserName');

    tempObj = document.getElementById("txt_Email");
    if (tempObj.value == "") {
        document.getElementById("lbl_Email").setAttribute('style', 'color:red;');
        writeText("Va rugam completati adresa de email!", 'lbl_Email');
        submitOK = false;
    }
    else if (checkEmail(tempObj) == false) {
        writeText("Adresa de email introdusa nu este valida!", 'lbl_Email');
        submitOK = false;
    }
    else writeText("", 'lbl_Email');

    tempObj = document.getElementById("txt_Phone");
    tempPhone = tempObj.value
    if (tempPhone.value != "") {
        tempPhone = tempPhone.split(' ').join('');
        tempPhone = tempPhone.split('/').join('');
    }
    if (tempPhone == "") {
        document.getElementById("lbl_Phone").setAttribute('style', 'color:red;');
        writeText("Va rugam completati telefonul!", 'lbl_Phone');
        submitOK = false;
    }
    else if (isNaN(tempPhone)) {
        writeText("Nu ati introdus un numar de telefon!", 'lbl_Phone');
        submitOK = false;
    }
    else writeText("", 'lbl_Phone');

    tempObj = document.getElementById("txt_CompanyName");
    if (tempObj.value == "") {
        document.getElementById("lbl_CompanyName").setAttribute('style', 'color:red;');
        writeText("Va rugam completati numele firmei!", 'lbl_CompanyName');
        submitOK = false;
    }
    else writeText("", 'lbl_CompanyName');

    tempObj = document.getElementById("txt_CompanyID");
    if (tempObj.value == "") {
        document.getElementById("lbl_CompanyID").setAttribute('style', 'color:red;');
        writeText("Va rugam completati codul unic de inregistrare!", 'lbl_CompanyID');
        submitOK = false;
    }
    else if (isNaN(tempObj.value.split(' ').join(''))) {
        writeText("Nu ati introdus un numar! (nu folositi RO inaintea numarului)", 'lbl_CompanyID');
        submitOK = false;
    }
    else writeText("", 'lbl_CompanyID');

    tempObj = document.getElementById("txt_CompanyCity");
    if (tempObj.value == "") {
        document.getElementById("lbl_CompanyCity").setAttribute('style', 'color:red;');
        writeText("Va rugam completati orasul!", 'lbl_CompanyCity');
        submitOK = false;
    }
    else writeText("", 'lbl_CompanyCity');

    tempObj = document.getElementById("txt_CompanyEmail");
    if (tempObj.value != "") {
        //document.getElementById("lbl_CompanyEmail").setAttribute('style','color:red;'); 
        //writeText("Va rugam completati adresa de email!",'lbl_CompanyEmail');   
        //submitOK=false;
        if (checkEmail(tempObj) == false) {
            writeText("Adresa de email introdusa nu este valida!", 'lbl_CompanyEmail');
            submitOK = false;
        }
        else writeText("", 'lbl_CompanyEmail');
    }
    else writeText("", 'lbl_CompanyEmail');

    tempObj = document.getElementById("txt_CompanyPhone");
    tempPhone = tempObj.value
    if (tempPhone.value != "") {
        tempPhone = tempPhone.split(' ').join('');
        tempPhone = tempPhone.split('/').join('');
    }
    if (tempPhone == "") {
        document.getElementById("lbl_CompanyPhone").setAttribute('style', 'color:red;');
        writeText("Va rugam completati telefonul!", 'lbl_CompanyPhone');
        submitOK = false;
    }
    else if (isNaN(tempPhone)) {
        writeText("Nu ati introdus un numar de telefon!", 'lbl_CompanyPhone');
        submitOK = false;
    }
    else writeText("", 'lbl_CompanyPhone');

    //checkboxes
    tempObj = document.getElementById("ckFax");
    if (tempObj.checked == true) {
        tempPhone = document.getElementById("txt_CompanyFax").value;
        if (tempPhone.value != "") {
            tempPhone = tempPhone.split(' ').join('');
            tempPhone = tempPhone.split('/').join('');
        }
        if (tempPhone == "") {
            document.getElementById("lbl_CompanyFax").setAttribute('style', 'color:red;');
            writeText("Va rugam completati numarul de fax!", 'lbl_CompanyFax');
            submitOK = false;
        }
        else if (isNaN(tempPhone)) {
            writeText("Nu ati introdus un numar de telefon!", 'lbl_CompanyFax');
            submitOK = false;
        }
        else writeText("", 'lbl_CompanyFax');
    }
    else writeText("", 'lbl_CompanyFax');

    tempObj = document.getElementById("ckPost");
    if (tempObj.checked == true) {
        tempPhone = document.getElementById("txt_CompanyAddress").value;
        if (tempPhone == "") {
            document.getElementById("lbl_CompanyAddress").setAttribute('style', 'color:red;');
            writeText("Va rugam completati adresa!", 'lbl_CompanyAddress');
            submitOK = false;
        }
        else writeText("", 'lbl_CompanyAddress');
    }
    else writeText("", 'lbl_CompanyAddress');

    tempObj = document.getElementById("txt_Request");
    if (tempObj.value == "") {
        document.getElementById("lbl_Request").setAttribute('style', 'color:red;');
        writeText("Va rugam completati cererea!", 'lbl_Request');
        submitOK = false;
    }
    else writeText("", 'lbl_Request');

    tempObj = document.getElementsByName("rbtnAbout");
    if (getCheckedValue(tempObj) == 6) {
        if (document.getElementById("txt_alteModuri").value == "") {
            document.getElementById("lbl_alteModuri").setAttribute('style', 'color:red;');
            writeText("Va rugam completati modul!", 'lbl_alteModuri');
            submitOK = false;
        }
        else writeText("", 'lbl_alteModuri');
    }
    else writeText("", 'lbl_alteModuri');

    tempObj = document.getElementById("txt_SecurityCode");
    if (tempObj.value == "") {
        document.getElementById("lbl_SecurityCode").setAttribute('style', 'color:red;');
        writeText("Va rugam introduceti codul de securitate!", 'lbl_SecurityCode');
        submitOK = false;
    }
    else if (document.getElementById("txt_holdCAP").value.toLowerCase() != tempObj.value.toLowerCase()) {
        document.getElementById("lbl_SecurityCode").setAttribute('style', 'color:red;');
        writeText("Cod de securitate incorect!", 'lbl_SecurityCode');
        submitOK = false;
    }
    else writeText("", 'lbl_SecurityCode');

    if (submitOK == false)
        return false;
    else
        return true;
}

//valideaza forma engl
function validate_engl() {
    var submitOK = true;
    var tempPhone = "";
    var tempObj = document.getElementById("txt_UserName");
    if (tempObj.value == "") {
        document.getElementById("lbl_UserName").setAttribute('style', 'color:red;');
        writeText("First name & last name are required!", 'lbl_UserName');
        submitOK = false;
    }
    else if (tempObj.value.indexOf(' ') == -1) {
        document.getElementById("lbl_UserName").setAttribute('style', 'color:red;');
        writeText("Please fill out first and last name!", 'lbl_UserName');
        submitOK = false;
    }
    else writeText("", 'lbl_UserName');

    tempObj = document.getElementById("txt_Email");
    if (tempObj.value == "") {
        document.getElementById("lbl_Email").setAttribute('style', 'color:red;');
        writeText("E-mail address is required!", 'lbl_Email');
        submitOK = false;
    }
    else if (checkEmail(tempObj) == false) {
        writeText("Not a valid e-mail address!", 'lbl_Email');
        submitOK = false;
    }
    else writeText("", 'lbl_Email');

    tempObj = document.getElementById("txt_Phone");
    tempPhone = tempObj.value
    if (tempPhone.value != "") {
        tempPhone = tempPhone.split(' ').join('');
        tempPhone = tempPhone.split('/').join('');
    }
    if (tempPhone == "") {
        document.getElementById("lbl_Phone").setAttribute('style', 'color:red;');
        writeText("Phone no. is required!", 'lbl_Phone');
        submitOK = false;
    }
    else if (isNaN(tempPhone)) {
        writeText("Not a valid phone no.!", 'lbl_Phone');
        submitOK = false;
    }
    else writeText("", 'lbl_Phone');

    tempObj = document.getElementById("txt_CompanyName");
    if (tempObj.value == "") {
        document.getElementById("lbl_CompanyName").setAttribute('style', 'color:red;');
        writeText("Company name is required!", 'lbl_CompanyName');
        submitOK = false;
    }
    else writeText("", 'lbl_CompanyName');

    tempObj = document.getElementById("txt_CompanyID");
    if (tempObj.value == "") {
        document.getElementById("lbl_CompanyID").setAttribute('style', 'color:red;');
        writeText("Registration no. is required!", 'lbl_CompanyID');
        submitOK = false;
    }
    //else if (isNaN(tempObj.value.split(' ').join(''))) {
    //    writeText("Not a valid no.!", 'lbl_CompanyID');
    //    submitOK = false;
    //}
    else writeText("", 'lbl_CompanyID');

    tempObj = document.getElementById("txt_CompanyCity");
    if (tempObj.value == "") {
        document.getElementById("lbl_CompanyCity").setAttribute('style', 'color:red;');
        writeText("City is required!", 'lbl_CompanyCity');
        submitOK = false;
    }
    else writeText("", 'lbl_CompanyCity');

    tempObj = document.getElementById("txt_CompanyEmail");
    if (tempObj.value != "") {
        //document.getElementById("lbl_CompanyEmail").setAttribute('style','color:red;'); 
        //writeText("Va rugam completati adresa de email!",'lbl_CompanyEmail');   
        //submitOK=false;
        if (checkEmail(tempObj) == false) {
            writeText("Not a valid e-mail address!", 'lbl_CompanyEmail');
            submitOK = false;
        }
        else writeText("", 'lbl_CompanyEmail');
    }
    else writeText("", 'lbl_CompanyEmail');

    tempObj = document.getElementById("txt_CompanyPhone");
    tempPhone = tempObj.value
    if (tempPhone.value != "") {
        tempPhone = tempPhone.split(' ').join('');
        tempPhone = tempPhone.split('/').join('');
    }
    if (tempPhone == "") {
        document.getElementById("lbl_CompanyPhone").setAttribute('style', 'color:red;');
        writeText("Phone no. is required!", 'lbl_CompanyPhone');
        submitOK = false;
    }
    else if (isNaN(tempPhone)) {
        writeText("Not a valid phone no.!", 'lbl_CompanyPhone');
        submitOK = false;
    }
    else writeText("", 'lbl_CompanyPhone');

    //checkboxes
    tempObj = document.getElementById("ckFax");
    if (tempObj.checked == true) {
        tempPhone = document.getElementById("txt_CompanyFax").value;
        if (tempPhone.value != "") {
            tempPhone = tempPhone.split(' ').join('');
            tempPhone = tempPhone.split('/').join('');
        }
        if (tempPhone == "") {
            document.getElementById("lbl_CompanyFax").setAttribute('style', 'color:red;');
            writeText("Fax no. is required!", 'lbl_CompanyFax');
            submitOK = false;
        }
        else if (isNaN(tempPhone)) {
            writeText("Not a valid fax no.!", 'lbl_CompanyFax');
            submitOK = false;
        }
        else writeText("", 'lbl_CompanyFax');
    }
    else writeText("", 'lbl_CompanyFax');

    tempObj = document.getElementById("ckPost");
    if (tempObj.checked == true) {
        tempPhone = document.getElementById("txt_CompanyAddress").value;
        if (tempPhone == "") {
            document.getElementById("lbl_CompanyAddress").setAttribute('style', 'color:red;');
            writeText("Address is required!", 'lbl_CompanyAddress');
            submitOK = false;
        }
        else writeText("", 'lbl_CompanyAddress');
    }
    else writeText("", 'lbl_CompanyAddress');

    tempObj = document.getElementById("txt_Request");
    if (tempObj.value == "") {
        document.getElementById("lbl_Request").setAttribute('style', 'color:red;');
        writeText("Request information is required!", 'lbl_Request');
        submitOK = false;
    }
    else writeText("", 'lbl_Request');

    tempObj = document.getElementsByName("rbtnAbout");
    if (getCheckedValue(tempObj) == 6) {
        if (document.getElementById("txt_alteModuri").value == "") {
            document.getElementById("lbl_alteModuri").setAttribute('style', 'color:red;');
            writeText("Please fill out the way!", 'lbl_alteModuri');
            submitOK = false;
        }
        else writeText("", 'lbl_alteModuri');
    }
    else writeText("", 'lbl_alteModuri');

    tempObj = document.getElementById("txt_SecurityCode");
    if (tempObj.value == "") {
        document.getElementById("lbl_SecurityCode").setAttribute('style', 'color:red;');
        writeText("Security code is required!", 'lbl_SecurityCode');
        submitOK = false;
    }
    else if (document.getElementById("txt_holdCAP").value.toLowerCase() != tempObj.value.toLowerCase()) {
        document.getElementById("lbl_SecurityCode").setAttribute('style', 'color:red;');
        writeText("Wrong security code!", 'lbl_SecurityCode');
        submitOK = false;
    }
    else writeText("", 'lbl_SecurityCode');

    if (submitOK == false)
        return false;
    else
        return true;
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function checkEmail(emailObj) {
    //var email = document.getElementById("usr_email");
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(emailObj.value)) {
        //writeText("Not a valid e-mail!",'lbl_usr_email'); 
        return false;
    }
    return true;
}

function ShowStatus(text) {
    window.status = text;
    return true;
}

function createMail(id, name) {
    var str1 = "mailto";
    var strDom = "gerotools";
    var str2 = "ro";
    document.getElementById(id).setAttribute('href', str1 + ':' + name + '@' + strDom + '.' + str2);
}

function openFile(object, url) {
    var path = getAppPath(url);
    var windowwidth = screen.width / 2;
    var windowheight = screen.height;
    var myTempWindow = window.open(path, "SaveMe", "left=" + windowwidth / 2 + ",resizable=1,height=" + windowheight + ",width=" + windowwidth);
    myTempWindow.document.execCommand("SaveAs", true, path);
    myTempWindow.close();
}

function roundNumber(number, decimals) {
    var newString; // The new rounded number
    decimals = Number(decimals);
    if (decimals < 1) {
        newString = (Math.round(number)).toString();
    } else {
        var numString = number.toString();
        if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
            numString += "."; // give it one at the end
        }
        var cutoff = numString.lastIndexOf(".") + decimals; // The point at which to truncate the number
        var d1 = Number(numString.substring(cutoff, cutoff + 1)); // The value of the last decimal place that we'll end up with
        var d2 = Number(numString.substring(cutoff + 1, cutoff + 2)); // The next decimal, after the last one we want
        if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
            if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
                while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
                    if (d1 != ".") {
                        cutoff -= 1;
                        d1 = Number(numString.substring(cutoff, cutoff + 1));
                    } else {
                        cutoff -= 1;
                    }
                }
            }
            d1 += 1;
        }
        if (d1 == 10) {
            numString = numString.substring(0, numString.lastIndexOf("."));
            var roundedNum = Number(numString) + 1;
            newString = roundedNum.toString() + '.';
        } else {
            newString = numString.substring(0, cutoff) + d1.toString();
        }
    }
    if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
        newString += ".";
    }
    var decs = (newString.substring(newString.lastIndexOf(".") + 1)).length;
    for (var i = 0; i < decimals - decs; i++) newString += "0";
        var newNumber = Number(newString);// make it a number if you like
 
    return newNumber;
}
