﻿
        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
        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; 
        }
        
// 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;
}


var preloadFlag = false;
function preloadImages() {
	if (document.images && preloadFlag==false) {
		banner = newImage("images/banner.jpg");
		search = newImage("images/search.gif");
		title = newImage("images/menu/title.gif");
		toptitle = newImage("images/menu/toptitle.gif");
		toptitle_1 = newImage("images/menu/toptitle_1.gif");
		toptitle_2 = newImage("images/menu/toptitle_2.gif");
		bottom = newImage("images/menu/bottom.gif");
		collapsed = newImage("images/menu/collapsed.gif");
		expanded = newImage("images/menu/expanded.gif");
		linkarrow = newImage("images/menu/linkarrow.gif");
		preloadFlag = true;
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

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 clearMenu(Menu) {
    Menu.collapseAll();
}

function change_image(img_name, img_src) {
    document[img_name].src = img_src;
}
