
var time=new Date();
var month=time.getMonth();
var date=time.getDate();
var year=time.getYear();
var cdate = date+'.'+month+'.'+year;

function checkEmail(emailStr) {
    /* The following pattern is used to check if the entered e-mail address
       fits the user@domain format.  It also is used to separate the username
       from the domain. */
    var emailPat=/^(.+)@(.+)$/
    /* The following string represents the pattern for matching all special
       characters.  We don't want to allow special characters in the address. 
       These characters include ( ) < > @ , ; : \ " . [ ]    */
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    /* The following string represents the range of characters allowed in a 
       username or domainname.  It really states which chars aren't allowed. */
    var validChars="\[^\\s" + specialChars + "\]"
    /* The following pattern applies if the "user" is a quoted string (in
       which case, there are no rules about which characters are allowed
       and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
       is a legal e-mail address. */
    var quotedUser="(\"[^\"]*\")"
    /* The following pattern applies for domains that are IP addresses,
       rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
       e-mail address. NOTE: The square brackets are required. */
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    /* The following string represents an atom (basically a series of
       non-special characters.) */
    var atom=validChars + '+'
    /* The following string represents one word in the typical username.
       For example, in john.doe@somewhere.com, john and doe are words.
       Basically, a word is either an atom or quoted string. */
    var word="(" + atom + "|" + quotedUser + ")"
    // The following pattern describes the structure of the user
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    /* The following pattern describes the structure of a normal symbolic
       domain, as opposed to ipDomainPat, shown above. */
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

    /* Finally, let's start trying to figure out if the supplied address is
       valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
       different pieces that are easy to analyze. */
    var matchArray=emailStr.match(emailPat)
    if (matchArray==null) {
        /* Too many/few @'s or something; basically, this address doesn't
           even fit the general mould of a valid e-mail address. */
        //alert("Email address seems incorrect (check @ and .'s)")
        return false
    }
    var user=matchArray[1]
    var domain=matchArray[2]

    // See if "user" is valid 
    if (user.match(userPat)==null) {
        // user is not valid
        //alert("The username doesn't seem to be valid.")
        return false
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
       host name) make sure the IP address is valid. */
    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null) {
        // this is an IP address
        for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
        //alert("Destination IP address is invalid!")
return false
    }
        }
        return true
    }

    // Domain is symbolic name
    var domainArray=domain.match(domainPat)
    if (domainArray==null) {
//alert("The domain name doesn't seem to be valid.")
        return false
    }

    /* domain name seems valid, but now make sure that it ends in a
       three-letter word (like com, edu, gov) or a two-letter word,
       representing country (uk, nl), and that there's a hostname preceding 
       the domain or country. */

    /* Now we need to break up the domain to get a count of how many atoms
       it consists of. */
    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {
       // the address must end in a two letter or three letter word.
       //alert("The address must end in a three- or four-letter domain, or two letter country.")
       return false
    }

    // Make sure there's a host name preceding the domain.
    if (len<2) {
       //alert("This address is missing a hostname!")
       return false
    }

    // If we've gotten this far, everything's valid!
    return true;
}

function validateTelefon(x)
{
	expr=/^(\d*)|(\-*)|(\,*)$/;
	ok = x.match(expr);
	if(ok)
		return true;
	else
		return false;
}


function checkPhoneNumber(phoneno)
{
rv=false;
 try
 {
txt=new String(phoneno);
rv=(txt.length==10);
if (rv)
for(i=0;(rv && i<txt.length);i++)
 rv=!isNaN(parseInt(txt.charAt(i),10));
 }catch(e)
 {
  rv=false;
 }
 return rv;
}


function isNumber(input)
{
	rv=true;
	try
	{
		txt=new String(input);
		if (txt.length==0) rv=false;
		for(i=0;(rv && i<txt.length);i++)
			rv=!isNaN(parseInt(txt.charAt(i),10));
	}
	catch(e)
	{
		rv=false;
	}
 return rv;
}

function checkInteger(x)
{
	//expr=/(\d+)/;
	expr=/(^-*\d+$)/;
	ok = x.match(expr);
	if(ok)
		return true;
	else
		return false;
}

function checkDecimal(x)
{
	//expr=/(\d+)/;
	expr=/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	ok = x.match(expr);
	if(ok)
		return true;
	else
		return false;
}


function popup(image, lang)
{
	window.open("popup.php?lang="+lang+"&img="+image+"_b.jpg","Imagine", "directories=0, locationbar=0, menubar=0, personalbar=0, statusbar=0, toolbar=0, scrollbars=0, width=454, height=350");
}

function validare(lang, f)
{
	err="";
	frm = document.getElementById(f);
	
	if (frm.email.value=="")
	{
		if (lang == "ro")
			err += "Va rugam completati adresa de e-mail.\n";
		else
			err += "Please fill the e-mail address.\n";	
		frm.email.value="";
		frm.email.focus();
	}
	else
		if (frm.email.value!="" && !checkEmail(frm.email.value))
		{
			if (lang == "ro")
				err += "Va rugam completati corect adresa de e-mail.\n";
			else
				err += "Please fill correctly the e-mail address.\n";	
			frm.email.value="";
			frm.email.focus();			
		}
	
	if (err!="")
		alert(err);
	else
		frm.submit();
}

function validezstire()
{
	err ="";
	frm = document.getElementById("frmnou");
	
	if (frm.title_ro.value=="")
		err += "Va rugam sa completati titlul in romana.\n";
	
	if (frm.continut_ro.value=="")
		err += "Va rugam sa completati continutul in romana.\n";

	if (frm.title_en.value=="")
		err += "Va rugam sa completati titlul in engleza.\n";
	
	if (frm.continut_en.value=="")
		err += "Va rugam sa completati continutul in engleza.\n";
		
	if (frm.datastire.value=="")
		err += "Va rugam sa completati data stirii.\n";
	else
	{
		if (validateDate(frm.datastire.value) == false)
			err += "Completati corect data stirii.";
		//else if (frm.datastire.value<cdate)
		//	err += "Data introdusa este anterioara datei curente.";
	}
	
	if (err!="")
	{
		//return false;
		alert(err);
		
	}
	else
		frm.submit();		
}


function valideznews()
{
	err ="";
	frm = document.getElementById("frmnew");
	/*
	if (frm.title_ro.value=="")
		err += "Va rugam sa completati titlul in romana.\n";
	
	if (frm.continut_ro.value=="")
		err += "Va rugam sa completati continutul in romana.\n";

	if (frm.title_en.value=="")
		err += "Va rugam sa completati titlul in engleza.\n";
	
	if (frm.continut_en.value=="")
		err += "Va rugam sa completati continutul in engleza.\n";
		
	if (frm.datanews.value=="")
		err += "Va rugam sa completati data newsletter.\n";
	else
	{
		if (validateDate(frm.datanews.value) == false)
			err += "Completati corect data newsletter.";
		//else if (frm.datastire.value<cdate)
		//	err += "Data introdusa este anterioara datei curente.";
	}
	
	if (err!="")
	{
		//return false;
		alert(err);
		
	}
	else*/
		frm.submit();		
}


function validezcv()
{
	err ="";
	frm = document.getElementById("frmcv");

	if (frm.nume.value=="")
		err += "Va rugam sa completati numele.\n";
	if (frm.prenume.value=="")
		err += "Va rugam sa completati prenumele.\n";
	if (frm.datan.value=="")
		err += "Va rugam sa completati data nasterii.\n";
	else
	{
		if (validateDate(frm.datan.value) == false)
			err += "Completati corect data nasterii.";
		//else if (frm.datastire.value<cdate)
		//	err += "Data introdusa este anterioara datei curente.";
	}
	if (frm.locn.value=="")
		err += "Va rugam sa completati locul nasterii.\n";
		
	if (frm.telefon.value=="")
		err += "Va rugam sa completati numarul de telefon.\n";
	
	if (frm.email.value=="")
		err += "Va rugam completati adresa de e-mail.\n";
	else
		if (frm.email.value!="" && !checkEmail(frm.email.value))
			err += "Va rugam completati corect adresa de e-mail.\n";

	
	if (frm.adresa.value=="")
		err += "Va rugam sa completati adresa.\n";	
	//cvu = document.getElementById("cvupload");
	//alert (cvu.value);
	//alert (frm.cvfile);
	/*if (frm.cvfile.value=="" && cvu.value=="")
	{	 
		err += "Va rugam sa adaugati cv.\n";
	}
	else
		if (frm.cvfile.value!="" && filterFiles(frm.cvfile.value) == false)
			err += "Puteti trimite doar fisiere de tip: "+tipFisiere+"\n";*/
	
	if (err!="")
		alert(err);	
	else
		frm.submit();			
}


function clearall()
{
	frm = document.getElementById("rezerv");
	frm.nume.value="";
	frm.prenume.value="";
	frm.tel.value="";
	frm.email.value="";
	frm.nrp.value="";
	frm.nrc.value="";
	frm.firma.value="";
	frm.obs.value="";
	frm.zs.selectedIndex=0;
	frm.ls.selectedIndex=0;
	frm.as.selectedIndex=0;
	frm.zp.selectedIndex=0;
	frm.lp.selectedIndex=0;
	frm.ap.selectedIndex=0;
}

function validateDate( strValue ) {
  var objRegExp = /^\d{1,2}\.\d{1,2}\.\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) 
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[0],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    
    //check for February (bugfix 20050322)
    //bugfix  for parseInt kevin
    //bugfix  biss year  O.Jp Voutat
    var intMonth = parseInt(arrayDate[1],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}

//filter tipul de fisiere acceptat
var fileType = new Array(".pdf", ".doc");
var tipFisiere="";
for (i=0;i<fileType.length;i++)
  { tipFisiere+=fileType[i]+" "; }

function filterFiles(thefile) 
{
  if (thefile)
  {
	 while (thefile.indexOf("\\") != -1)
		thefile = thefile.slice(thefile.indexOf("\\") + 1);
	
	ftype = thefile.slice(thefile.indexOf(".")).toLowerCase();
	for (i=0;i<fileType.length;i++) 
		if (fileType[i]==ftype)
		   return true;
  }
  return false;
}
//  End -->
