function validMail(email, required) {
	
		function allValidChars(email) {
		  var parsed = true;
		  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
		  for (var i=0; i < email.length; i++) {
			var letter = email.charAt(i).toLowerCase();
			if (validchars.indexOf(letter) != -1)
			  continue;
			parsed = false;
			break;
		  }
		  return parsed;
		}
		
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function showdiv(dv){
    if (document.getElementById(dv)) {
  divv=document.getElementById(dv);
    divv.style.display="";
}
  }
function hidediv(dv){
    if (document.getElementById(dv)) {
      divv=document.getElementById(dv); 
divv.style.display="none";
  }
    }  
    
    
function markError(divid,textul){
         
        obj=document.getElementById(divid);
        if (obj){ 
          
         if (obj.innerHTML.indexOf('error')>0){
          }
          else {
        obj.innerHTML='<span class="error">'+textul+'</span><br />'+obj.innerHTML;
        
          }
}
}
 
function BoxBifat(radiog){
var bifat=false;
 
for (counter = 0; counter < radiog.length; counter++){

  if (radiog[counter].checked) {
    bifat=true;
    }
  }
return bifat;
}

function EmptyText(caseta){
    var reg=new RegExp("[\._a-zA-Z0-9-]+");
    //invers
    if (caseta.match(reg)) return false; else return true;
} 
function ValidMail(mail){
  
  var reg=new RegExp("(^[\._a-zA-Z0-9-]+@[a-zA-Z0-9][\._a-zA-Z0-9-]+\.[a-zA-Z]{2,4}$)");
  return (mail.match(reg));
}
function printmail(username,domain){

		t='<a href="mailto:'+
			username+String.fromCharCode(64)+domain+'" target="_blank">'+username+String.fromCharCode(64)+domain+'</a>';
      
      document.write(t);		
	}
function saveCookie(name,value,seconds) {
	if (seconds) {
		var date = new Date();
		date.setTime(date.getTime()+(seconds*1000))
		var expires = "; expires="+date.toGMTString()
	}
	else expires = ""
	document.cookie = name+"="+value+expires+"; path=/"
}
function readCookie(name) {
	var nameEQ = name + "="
	var ca = document.cookie.split(';')
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length)
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
	}
	return null
}
function deleteCookie(name) {
	saveCookie(name,"",-1)
}


function popUp(URL,w,h) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+w+",height="+h+"');");
}
  function voteaza(arg1, arg2) {
	  window.open("voteaza.php?what=" + arg1 + "&lid="+arg2, "_blank", "width=280,height=190,status=yes,toolbar=no,scrollbars=yes,resizable=yes");
  }

  function comentarii(action, for_what, item_id) {
	  if (action == 'sterge') {
		   if (confirm("Esti sigur ca vrei sa stergi comentariul?")) {
			   window.open("comentarii.php?for_what=" + for_what + "&item_id=" + item_id + "&action=sterge", "_blank", "width=380,height=290,status=yes,toolbar=no,scrollbars=no");
		   }
	  }else{
		  window.open("comentarii.php?for_what=" + for_what + "&item_id=" + item_id, "_blank", "width=380,height=290,status=yes,toolbar=no,scrollbars=no");
	  }
  }

  function actionWindow(page, action, id) {
 
		window.open("_include/administrare/" + page + ".php?action=" + action + "&pid="+id, "adminwindow", 	"width=680,height=520,status=yes,toolbar=yes,scrollbars=yes,resizable=yes");
    
    if (document.getElementById('div'+id)){
        hidediv('div'+id);
    }
	}
