/*** DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */

// Declaring required variables
var digits = "0123456789";
var phoneNumberDelimiters = "()-. "; // non-digit characters which are allowed in phone numbers
var validWorldPhoneChars = phoneNumberDelimiters + "+"; // characters which are allowed in international phone numbers  // (a leading + is OK)
var minDigitsInIPhoneNumber = 10; // Minimum no of digits in an international phone no.

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    { // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true; // All characters are numbers.
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    { // Check that current character isn't whitespace.
        var c = s.charAt(i);  if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {// Check that current character isn't whitespace.
        var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

 


function verificare_fizica(_f){
         var eroare="";
         eroare=validareCNP(_f.txt_cnp.value)
         
         inputs = document.getElementsByTagName('input'); 
         for(var i=0; i < inputs.length; i++) { 
            //check if the input is a checkbox 
            if(inputs[i].getAttribute('type') == 'checkbox') {
			    if(_f.ch_accept_conditii.checked==false){ eroare="Trebuie sa fiti de acord cu Termeni si Conditii !"}
            }
         }
         
         if(_f.txt_cnp.value==""){
          eroare="ATENTIE: Campul CNP nu a fost completat !"
          _f.txt_cnp.focus();
         }
         
		 if (checkInternationalPhone(_f.area_telefon.value)==false){
			eroare="ATENTIE: Campul TELEFON nu a fost completat corect!" 
			_f.area_telefon=""
			_f.area_telefon.focus();
		 }
         if( (_f.area_telefon.value=="") || (_f.area_telefon.value==null) ){
          eroare="ATENTIE: Campul TELEFON nu a fost completat !"
          _f.area_telefon.focus();
         }

         if(_f.area_nume.value==""){
          eroare="ATENTIE: Campul NUME nu a fost completat !"
          _f.area_nume.focus();
         }

         if(eroare=="") return true
         else{
              alert(eroare);
              return false
         }
}

function verificare_juridica(_f){
         var eroare="";

         inputs = document.getElementsByTagName('input'); 
         for(var i=0; i < inputs.length; i++) { 
            //check if the input is a checkbox 
            if(inputs[i].getAttribute('type') == 'checkbox') {
			    if(_f.ch_accept_conditii.checked==false){ eroare="Trebuie sa fiti de acord cu Termeni si Conditii !"}
            }
         }
         
         if(_f.area_nume_pers_contact.value==""){
          eroare="ATENTIE: Campul NUME persoana de contact  nu a fost completat !"
          _f.area_nume_pers_contact.focus();
         }
         if(_f.txt_CUI.value==""){
          eroare="ATENTIE: Campul Cod Fiscal nu a fost completat !"
          _f.txt_CUI.focus();
         }
         
         var x=_f.area_telefon.value
         if(x==0) eroare="Campul TELEFON  nu poate fi 0 (zero) !"
         var anum=/(^\d+$)|(^\d+\.\d+$)/
         if (anum.test(x))  testresult=true
         else {
               eroare="Campul TELEFON nu a fost completat corect (trebuie sa fie numeric, fara puncte sau spatii) !"
               _f.area_telefon.focus();
         }
         
         if(_f.area_telefon.value==""){
          eroare="ATENTIE: Campul TELEFON nu a fost completat !"
          _f.area_telefon.focus();
         }
         
         if(_f.area_nume.value==""){
          eroare="ATENTIE: Campul NUME FIRMA nu a fost completat !"
          _f.area_nume.focus();
         }
         if(eroare=="") return true
         else{
              alert(eroare);
              return false
         }
}

function verificare_inscriere_concurs(_f){
         var eroare="";
         if(_f.ch_accept_regulament.checked==false){ eroare="Trebuie sa fiti de acord cu 'Regulamentul concursului' !"}
         
         radio_selectat=false;raspuns=0;
		 for (var i=0; i < document.frm_concurs.radio_raspuns_concurs.length; i++){
			 if(_f.radio_raspuns_concurs[i].checked == true) {radio_selectat=true; raspuns=_f.radio_raspuns_concurs[i].value;break;}
		 }
         if(radio_selectat==false)  eroare="Trebuie selectat un raspuns";
         
         if(_f.area_telefon.value==""){
          eroare="ATENTIE: Campul TELEFON nu a fost completat !"
          _f.area_telefon.focus();
         }
         
         err= echeck(_f.area_mail.value);
         if(err==false) {eroare="ATENTIE: Campul EMAIL nu a fost completat corect!";_f.area_mail.focus();}
         
          if(_f.area_mail.value==""){
          eroare="ATENTIE: Campul EMAIL nu a fost completat !"
          _f.area_mail.focus();
         }

         if(_f.area_nume.value==""){
          eroare="ATENTIE: Campul NUME nu a fost completat !"
          _f.area_nume.focus();
         }
         
         if(eroare=="") return true
         else{
              alert(eroare);
              return false
         }
}


function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var bun=true; 
		
		if (str.indexOf(at)==-1){
		   bun=false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   bun=false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    bun=false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    bun=false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    bun=false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    bun=false
		 }
		 if (str.indexOf(" ")!=-1){
		    bun=false
		 }
 		 return bun	;}


function validareCNP(s){
var suma=0;
var mesaj="";
    if(s.length==13)
    {
       suma=parseInt(s.charAt(0))*2+parseInt(s.charAt(1))*7+parseInt(s.charAt(2))*9+parseInt(s.charAt(3))*1+parseInt(s.charAt(4))*4+parseInt(s.charAt(5))*6+parseInt(s.charAt(6))*3+parseInt(s.charAt(7))*5+parseInt(s.charAt(8))*8+parseInt(s.charAt(9))*2+parseInt(s.charAt(10))*7+parseInt(s.charAt(11))*9;
       suma=suma%11;
       if(suma==10) suma=1;
       if(suma==parseInt(s.charAt(12)))  {
          mesaj="";
          return mesaj;
       }
       else{
          mesaj="CNP nu este valid !!!";
          return mesaj;
       }

    }
    else{
         mesaj="CNP-ul nu are lungimea corespunzatoare !!! ";
         return  mesaj;
    }
}

function open_fereastra(cale,x,y){
        eval("window.open('"+cale+"','','height='+y+',width='+x+',type=fullWindow,alwaysLowered=0,alwaysRaised=1,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=0,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0, z-lock=1,screenX=0,screeny=0,left=10,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,fullscreen=no')");
}



function open_fereastra_fixa(cale){
eval("window.open('"+cale+"','',' toolbar=no, menubar=no,scrollbars=yes,resizable=no,height=500,width=500,top=10,left=10')");
}



function verificare_date_livrare(_f){
         var eroare="";
         if(_f.area_codpostal_livrare.value==""){
          eroare="ATENTIE: Campul COD POSTAL nu a fost completat !"
          _f.area_codpostal_livrare.focus();
         }
         
         if(_f.area_adresa_livrare.value==""){
          eroare="ATENTIE: Campul ADRESA nu a fost completat !"
          _f.area_adresa_livrare.focus();
         }


         if(_f.area_nume_livrare.value==""){
          eroare="ATENTIE: Campul NUME nu a fost completat !"
          _f.area_nume_livrare.focus();
         }

         if(eroare=="") return true
         else{
              alert(eroare);
              return false
         }
}


function verificare_date_facturare_livrare_fizic(_f){
         var eroare="";
         
         if(_f.area_adresa_livrare.value==""){
          eroare="ATENTIE: Campul 'Detalii Livrare - ADRESA' nu a fost completat !"
          _f.area_adresa_livrare.focus();
         }
         if(_f.area_oras_livrare.value==""){
          eroare="ATENTIE: Campul 'Detalii Livrare - ORAS' nu a fost completat !"
          _f.area_oras_livrare.focus();
         }
         if(_f.area_nume_livrare.value==""){
          eroare="ATENTIE: Campul 'Detalii Livrare - NUME' nu a fost completat !"
          _f.area_nume_livrare.focus();
         }
         
         
         if(_f.area_cnp_facturare.value==""){
          eroare="ATENTIE: 'Detalii Facturare - Campul CNP' nu a fost completat !"
          _f.area_cnp_facturare.focus();
         }
         if(_f.area_nr_bi_ci_facturare.value=="" || _f.area_serie_bi_ci_facturare.value==""){
          eroare="ATENTIE: 'Detalii Facturare - Campul SERIE,NR BI/CI' nu a fost completat !"
          if(_f.area_nr_bi_ci_facturare.value==""  ) _f.area_nr_bi_ci_facturare.focus();
          if(_f.area_serie_bi_ci_facturare.value==""  ) _f.area_serie_bi_ci_facturare.focus();
         }
         if(_f.area_telefon_facturare.value==""){
          eroare="ATENTIE: 'Detalii Facturare - Campul TELEFON' nu a fost completat !"
          _f.area_telefon_facturare.focus();
         }
         if(_f.area_email_facturare.value==""){
          eroare="ATENTIE: 'Detalii Facturare - Campul EMAIL' nu a fost completat !"
          _f.area_email_facturare.focus();
         }
         if(_f.area_adresa_facturare.value==""){
          eroare="ATENTIE: 'Detalii Facturare - Campul ADRESA' nu a fost completat !"
          _f.area_adresa_facturare.focus();
         }
         if(_f.area_oras_facturare.value==""){
          eroare="ATENTIE: Campul 'Detalii Facturare - ORAS' nu a fost completat !"
          _f.area_oras_facturare.focus();
         }
		 if(_f.area_nume_facturare.value==""){
          eroare="ATENTIE: Campul 'Detalii Facturare - NUME' nu a fost completat !"
          _f.area_nume_facturare.focus();
         }
         

         if(eroare=="") return true
         else{
              alert(eroare);
              return false
         }
}

 
function verificare_date_facturare_livrare_juridic (_f){
         var eroare="";
         
         if(_f.area_adresa_livrare.value==""){
          eroare="ATENTIE: Campul 'Detalii Livrare - ADRESA' nu a fost completat !"
          _f.area_adresa_livrare.focus();
         }
         if(_f.area_oras_livrare.value==""){
          eroare="ATENTIE: Campul 'Detalii Livrare - ORAS' nu a fost completat !"
          _f.area_oras_livrare.focus();
         }
         if(_f.area_nume_livrare.value==""){
          eroare="ATENTIE: Campul 'Detalii Livrare - NUME' nu a fost completat !"
          _f.area_nume_livrare.focus();
         }
         
         
         if(_f.area_nume_pers_contact_facturare.value==""){
          eroare="ATENTIE: Campul 'Detalii Facturare - NUME persoana de contact'  nu a fost completat !"
          _f.area_nume_pers_contact_facturare.focus();
         }
         if(_f.txt_CUI_facturare.value==""){
          eroare="ATENTIE: Campul 'Detalii Facturare - Cod Fiscal' nu a fost completat !"
          _f.txt_CUI_facturare.focus();
         }
         if(_f.area_telefon_facturare.value==""){
          eroare="ATENTIE: Campul 'Detalii Facturare - TELEFON' nu a fost completat !"
          _f.area_telefon_facturare.focus();
         }
         
         if(_f.area_nume_facturare.value==""){
          eroare="ATENTIE: Campul 'Detalii Facturare - NUME FIRMA' nu a fost completat !"
          _f.area_nume_facturare.focus();
         }
         
         
		 if(eroare=="") return true
         else{
              alert(eroare);
              return false
         }
}



//functii necesare in pagina de tremeni si conditii

/***********************************************
* Contractible Headers script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Mar 23rd, 2004.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}
}

function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(cid){
if (typeof ccollect!="undefined"){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
}


if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate


