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;
    }
    // All characters are numbers.
    return true;
}
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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr,strMessage,dtCh,minYear,maxYear,strLanguage)
{
	var arrMessages=new Array();
	if(strLanguage=="en")
	{
		arrMessages[0]=" The date format should be: mm"+dtCh+"dd"+dtCh+"yyyy";
		arrMessages[1]=" Please enter a 2 digit month"
		arrMessages[2]=" Please enter a valid month";
		arrMessages[3]=" Please enter a 2 digit day";
		arrMessages[4]=" Please enter a valid day";
		arrMessages[5]=" Please enter a valid 4 digit year between "+minYear+" and "+maxYear;
		arrMessages[6]=" Please enter a valid date. Example: 31-01-2005";
	}
	if(strLanguage=="ro")
	{
		arrMessages[0]=" Formatul corect este: zz"+dtCh+"ll"+dtCh+"aaaa";
		arrMessages[1]=" Va rugam sa introduceti o luna formata din 2 cifre"
		arrMessages[2]=" Va rugam sa introduceti o luna valida";
		arrMessages[3]=" Va rugam sa introduceti o zi formata din 2 cifre";
		arrMessages[4]=" Va rugam sa introduceti o zi valida";
		arrMessages[5]=" Va rugam sa introduceti un an valid format din patru cifre ";
		arrMessages[6]=" Va rugam sa introduceti o data calendaristica valida.\nExemplu: 31-01-2005";

	}	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	for (var i = 1; i <= 3; i++) 
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1)
	{
		alert(strMessage+arrMessages[0])
		return false;			
	}					
	if (strMonth.length<2 || month<1 || month>12){
		if(strMonth.length<2)
		{
			alert(strMessage+arrMessages[1])
		}
		else
		{
			alert(strMessage+arrMessages[2])
		}	
		return false
	}
	if (strDay.length<2 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		if(strDay.length<2)
		{
			alert(strMessage+arrMessages[3])
		}
		else
		{
			alert(strMessage+arrMessages[4])
		}	
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(strMessage+arrMessages[5])
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert(strMessage+arrMessages[6])
		return false
	}
return true
}
function checkTextDate(frmForm,errWrongDate,arrFieldNumbers,dtCh,minYear,maxYear,strLanguage)
{
	var el = frmForm.elements;	
	// loop through the elements...
	var iTextFieldIndex=-1;	
	for(i=0;i<arrFieldNumbers.length;i++) 	
	{								
		//alert(el[arrFieldNumbers[i]].value);
		if(el[arrFieldNumbers[i]].type == "text")
		{				
			iTextFieldIndex++;	
			boolOk=isDate(el[arrFieldNumbers[i]].value,errWrongDate[iTextFieldIndex],dtCh,minYear,maxYear,strLanguage)						
			if(boolOk==false)
			{				
				el[arrFieldNumbers[i]].focus();
				return (false)
			}
		}
	}
	return (true);
}
function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char; 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;
}
function LoadPopup(doc, w, h) {
	if (!w) w=580; 
	if (!h) h=600; 
	win = window.open(doc, "BC", 'status=no,toolbar=0,scrollbars=1,menubar=0,titlebar=0,resizable=0,width='+w+',height='+h);
	win.moveTo(screen.width/2-w/2, screen.height/2-h/2);
	win.focus();
}
function ClosePopup() {
	if(win)	win.close();
	document.location="index.php";
}

function checkEmailAddress(field) {
var good;
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail){
   return true;
} 
return false;   
}

function checkEmail(sir){

    if (checkEmailAddress(sir)==0){
      	alert ("Atentie! Adresa de email nu este valida. Va rugam incercati din nou.");
   		return false;
   	}
	return true;
}

function focusElem(obj, str)
{
 if (obj.value == str) obj.value = "";
 return true;
}

function Schimba_incadrarea(chkObject)
{	
	document.getElementById('persoana_fizica');
	if(chkObject.value=="0")
	{
		//alert("0");
		document.getElementById('persoana_fizica').style.display="inline";
		document.getElementById('persoana_juridica').style.display="none";		
	}	
	if(chkObject.value=="1")
	{		
		document.getElementById('persoana_fizica').style.display="none";
		document.getElementById('persoana_juridica').style.display="inline";
		//document.getElementById('persoana_juridica').style.visibility="visible";
	}
}
function  FCheck_Form(frmForm)
{
	if(trimAll(document.getElementById('txtNume').value)=="")
	{
		alert("Va rugam sa completati campul 'Nume'");
		document.getElementById('txtNume').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtPrenume').value)=="")
	{
		alert("Va rugam sa completati campul 'Prenume'");
		document.getElementById('txtPrenume').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtAdresa').value)=="")
	{
		alert("Va rugam sa completati campul 'Adresa'");
		document.getElementById('txtAdresa').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtLocalitatea').value)=="")
	{
		alert("Va rugam sa completati campul 'Localitatea'");
		document.getElementById('txtLocalitatea').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtJudet').value)=="")
	{
		alert("Va rugam sa completati campul 'Judet/Sector'");
		document.getElementById('txtJudet').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtCodPostal').value)=="")
	{
		alert("Va rugam sa completati campul 'Cod postal'");
		document.getElementById('txtCodPostal').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtTelefon').value)=="")
	{
		alert("Va rugam sa completati campul 'Telefon'");
		document.getElementById('txtTelefon').focus();
		return false;
	}
	if(!isNumeric(trimAll(document.getElementById('txtCodPostal').value)))
	{
		alert("Campul 'Cod postal' necesita o valoare numerica");
		document.getElementById('txtCodPostal').focus();
		return false;
	}
	if(!isNumeric(trimAll(document.getElementById('txtTelefon').value)))
	{
		alert("Campul 'Telefon' necesita o valoare numerica");
		document.getElementById('txtTelefon').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtEmail').value)!="" && !checkEmail(document.getElementById('txtEmail')))
	{		
		document.getElementById('txtEmail').focus();
		return false;
	}
	// require at least one radio button be selected
	var radioSelected = false;
	for (i = 0;  i < frmForm.f_price.length;  i++)
	{
		if (frmForm.f_price[i].checked)
		radioSelected = true;
	}
	if (!radioSelected)
	{
		alert("Va rugam sa selectati tipul de abonament dorit");
		return (false);
	}
	if(trimAll(document.getElementById('txtSuma').value)=="")
	{
		alert("Va rugam sa precizati suma expediata");
		document.getElementById('txtSuma').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtNumarAct').value)=="")
	{
		alert("Va rugam sa precizati numarul mandatului postal sau al ordinului de plata folosit");
		document.getElementById('txtNumarAct').focus();
		return false;
	}
	if(trimAll(document.getElementById('txtData').value)=="")
	{
		alert("Va rugam sa precizati data expedierii");
		//document.getElementById('txtData').focus();
		return false;
	}
	var arrDateFieldError=new Array();
	arrDateFieldError[0]="Eroare format data calendaristica";
	var minYear=1900;
	var maxYear=2100;
	errWrongDate=new Array();
	errWrongDate[0]="Eroare format data calendaristica";
	arrFieldNumbers=Array();
	arrFieldNumbers[0]=15;	
	boolOK=checkTextDate(frmForm,errWrongDate,arrFieldNumbers,"/",1900,2100,"ro");
	if(boolOK==false)
	{
		document.getElementById('txtData').focus();
		return boolOK;
	}
	return (true);
}
function  _FCheck_Form(frmForm)
{
	if(trimAll(document.getElementById('_txtCompania').value)=="")
	{
		alert("Va rugam sa completati campul 'Compania'");
		document.getElementById('_txtCompania').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtCodInregistrare').value)=="")
	{
		alert("Va rugam sa completati campul 'Cod unic de inregistrare'");
		document.getElementById('_txtCodInregistrare').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtNume').value)=="")
	{
		alert("Va rugam sa completati campul 'Nume'");
		document.getElementById('_txtNume').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtPrenume').value)=="")
	{
		alert("Va rugam sa completati campul 'Prenume'");
		document.getElementById('_txtPrenume').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtAdresa').value)=="")
	{
		alert("Va rugam sa completati campul 'Adresa'");
		document.getElementById('_txtAdresa').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtLocalitatea').value)=="")
	{
		alert("Va rugam sa completati campul 'Localitatea'");
		document.getElementById('_txtLocalitatea').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtJudet').value)=="")
	{
		alert("Va rugam sa completati campul 'Judet/Sector'");
		document.getElementById('_txtJudet').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtCodPostal').value)=="")
	{
		alert("Va rugam sa completati campul 'Cod postal'");
		document.getElementById('_txtCodPostal').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtTelefon').value)=="")
	{
		alert("Va rugam sa completati campul 'Telefon'");
		document.getElementById('_txtTelefon').focus();
		return false;
	}
	if(!isNumeric(trimAll(document.getElementById('_txtCodPostal').value)))
	{
		alert("Campul 'Cod postal' necesita o valoare numerica");
		document.getElementById('_txtCodPostal').focus();
		return false;
	}
	if(!isNumeric(trimAll(document.getElementById('_txtTelefon').value)))
	{
		alert("Campul 'Telefon' necesita o valoare numerica");
		document.getElementById('txtTelefon').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtEmail').value)!="" && !checkEmail(document.getElementById('_txtEmail')))
	{		
		document.getElementById('_txtEmail').focus();
		return false;
	}
	// require at least one radio button be selected
	var radioSelected = false;
	for (i = 0;  i < frmForm.j_price.length;  i++)
	{
		if (frmForm.j_price[i].checked)
		radioSelected = true;
	}
	if (!radioSelected)
	{
		alert("Va rugam sa selectati tipul de abonament dorit");
		return (false);
	}
	if(trimAll(document.getElementById('_txtSuma').value)=="")
	{
		alert("Va rugam sa precizati suma expediata");
		document.getElementById('_txtSuma').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtNumarAct').value)=="")
	{
		alert("Va rugam sa precizati numarul mandatului postal sau al ordinului de plata folosit");
		document.getElementById('_txtNumarAct').focus();
		return false;
	}
	if(trimAll(document.getElementById('_txtData').value)=="")
	{
		alert("Va rugam sa precizati data expedierii");
		//document.getElementById('_txtData').focus();
		return false;
	}
	errWrongDate=new Array();
	errWrongDate[0]="Eroare format data calendaristica";
	arrFieldNumbers=Array();
	arrFieldNumbers[0]=19;	
	boolOK=checkTextDate(frmForm,errWrongDate,arrFieldNumbers,"/",1900,2100,"ro");
	if(boolOK==false)
	{
		document.getElementById('_txtData').focus();
		return boolOK;
	}
		
	return (true);
}
function SetValues()
{
	var object=document.getElementById("chk_persoanafizica");         
	if(object)
	{		
		object.checked=true;
	}

}
function submitform()
{	
	if(trimAll(document.getElementById('timp').value)=="")
	{
		alert("Va rugam sa raspundeti la intrebarea nr 1");
		document.getElementById('timp').focus();
		return false;
	}
	if(document.getElementById("motiv1").checked==false && document.getElementById("motiv2").checked==false && document.getElementById("motiv3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 2")
		document.getElementById("motiv1").focus();
		return false;
	}
	if(document.getElementById("modalitate1").checked==false && document.getElementById("modalitate2").checked==false && document.getElementById("modalitate3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 3");
		document.getElementById("modalitate1").focus();
		return false;
	}
	if(document.getElementById("numere_citite1").checked==false && document.getElementById("numere_citite2").checked==false && document.getElementById("numere_citite3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 4");
		document.getElementById("numere_citite1").focus();
		return false;
	}
	if(trimAll(document.getElementById('top_rubrici').value)=="")
	{
		alert("Va rugam sa raspundeti la intrebarea nr 5");
		document.getElementById('top_rubrici').focus();
		return false;
	}
	if(trimAll(document.getElementById('rubrici_preferate').value)=="")
	{
		alert("Va rugam sa raspundeti la intrebarea nr 6");
		document.getElementById('rubrici_preferate').focus();
		return false;
	}
	if(trimAll(document.getElementById('rubrici_deficitare').value)=="")
	{
		alert("Va rugam sa raspundeti la intrebarea nr 7");
		document.getElementById('rubrici_deficitare').focus();
		return false;
	}
	if(trimAll(document.getElementById('noi_rubrici').value)=="")
	{
		alert("Va rugam sa raspundeti la intrebarea nr 8");
		document.getElementById('noi_rubrici').focus();
		return false;
	}
	
	if(document.getElementById("diversitate1").checked==false && document.getElementById("diversitate2").checked==false && document.getElementById("diversitate3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 9")
		document.getElementById("diversitate1").focus();
		return false;
	}
	if(document.getElementById("obiectivitate1").checked==false && document.getElementById("obiectivitate2").checked==false && document.getElementById("obiectivitate3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 10")
		document.getElementById("obiectivitate1").focus();
		return false;
	}
	if(document.getElementById("calificativ1").checked==false && document.getElementById("calificativ2").checked==false && document.getElementById("calificativ3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 11")
		document.getElementById("calificativ1").focus();
		return false;
	}
	if(document.getElementById("loc1").checked==false && document.getElementById("loc2").checked==false && document.getElementById("loc3").checked==false && document.getElementById("loc4").checked==false && document.getElementById("loc5").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 12")
		document.getElementById("loc1").focus();
		return false;
	}
	if(document.getElementById("recomandare1").checked==false && document.getElementById("recomandare2").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 13")
		document.getElementById("recomandare1").focus();
		return false;
	}
	if(document.getElementById("varsta1").checked==false && document.getElementById("varsta2").checked==false && document.getElementById("varsta3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 14")
		document.getElementById("varsta1").focus();
		return false;
	}
	if(document.getElementById("sex1").checked==false && document.getElementById("sex2").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 15")
		document.getElementById("sex1").focus();
		return false;
	}
	if(document.getElementById("studii1").checked==false && document.getElementById("studii2").checked==false && document.getElementById("studii3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 16")
		document.getElementById("studii1").focus();
		return false;
	}
	if(trimAll(document.getElementById('profesie').value)=="")
	{
		alert("Va rugam sa raspundeti la intrebarea nr 17");
		document.getElementById('profesie').focus();
		return false;
	}	
	if(document.getElementById("venit1").checked==false && document.getElementById("venit2").checked==false && document.getElementById("venit3").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 18")
		document.getElementById("venit1").focus();
		return false;
	}
	if(document.getElementById("domiciliu1").checked==false && document.getElementById("domiciliu2").checked==false)
	{
		alert("Va rugam sa raspundeti la intrebarea nr 19")
		document.getElementById("domiciliu1").focus();
		return false;
	}
	if(trimAll(document.getElementById('adresa').value)=="")
	{
		alert("Va rugam sa specificati adresa");
		document.getElementById('adresa').focus();
		return false;
	}	
	if(trimAll(document.getElementById('telefon').value)=="")
	{
		alert("Va rugam sa specificati numarul de telefon");
		document.getElementById('telefon').focus();
		return false;
	}	
	if(trimAll(document.getElementById('email').value)=="")
	{
		alert("Va rugam sa specificati adresa de mail");
		document.getElementById('email').focus();
		return false;
	}	
	document.Form1.submit();	
}