//validates an email address
function check_mail(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)
	   return false
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   return false
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false
	 if (str.indexOf(at,(lat+1))!=-1)
		return false
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false
	 if (str.indexOf(dot,(lat+2))==-1)
		return false
	 if (str.indexOf(" ")!=-1)
		return false
	 return true					
}

//validate a date
function check_date(input)
{
	ok = 1;
   	if(input.value != "")
	{
		var testString = input.value.split("/");
  		var dayfield=input.value.split("/")[0];
		var monthfield= input.value.split("/")[1];   
	 	var yearfield= input.value.split("/")[2];
		if(testString.length > 1)
		{
			if (monthfield.length <1 || monthfield.length >2 || dayfield.length < 1 || dayfield.length >2 || yearfield.length > 4  || yearfield.length < 2)
			{
			   ok = 2;
			   input.select();
			}
			else
			{ 
			 	//Detailed check for valid date ranges
				var dayobj = new Date(yearfield, monthfield-1, dayfield)
				if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getYear()!=yearfield && dayobj.getFullYear() !=yearfield))
				{
				   ok = 2;
				   input.select();
				}
			}
		}
		else
		   ok = 2;
   }
	if (ok ==2) 
		validation=false;
	else
		validation = true;
	return validation;
}

//checks if file extention is valid as photo
function check_photoExtension(con)
{
    if(con.length >0)
    {
        var fileExtension = con.substring(con.lastIndexOf('.')+1,con.length);
        extensionValid =true;
        fileExtension = fileExtension.toUpperCase();
        if( fileExtension != "PNG" && fileExtension != "GIF" && fileExtension != "JPEG" && fileExtension != "JPG" )
            return false;	         				
   	}
	return true;
}

//checks if file extention is valid as file:doc,docx,xls,xlsx,ppt,pptx,txt,jpg,jpeg,pdf
function check_fileExtension(con)
{
    if(con.length >0)
    {
        var fileExtension = con.substring(con.lastIndexOf('.')+1,con.length);
        extensionValid =true;
        fileExtension = fileExtension.toUpperCase();
        if( fileExtension != "DOC" && fileExtension != "DOCX" && fileExtension != "PDF" )
            return false;	         				
   	}
	return true;
}

//checks if URL is valid
function check_url(s) 
{
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

//checks if phone number is valid
function check_phoneNo(str)
{
	str=str.replace("/","");
	str=str.replace("+","");
	str=str.replace(".","");
	if (!IsNumeric(str))
		return false;
	else
		if(str=="")
			return false;
		else
			if(str.length<3)
				return false;
			else
				return true;
}

//checks if string is number
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;
}

//submit form for admin adding
function submitAddForm()
{
	if(validate_form()==true)
		document.getElementById('add_form').submit();
}

function conf(strAlert)
{
	return confirm(strAlert);
}
	
function validate_contact()
	{
	document.getElementById('input_nume').value=trim(document.getElementById('input_nume').value);
	document.getElementById('input_prenume').value=trim(document.getElementById('input_prenume').value);
	document.getElementById('input_email').value=trim(document.getElementById('input_email').value);
	document.getElementById('input_message').value=trim(document.getElementById('input_message').value);
	//REQUIRED FIELDS
		if((document.getElementById('input_nume').value=="")||(document.getElementById('input_prenume').value=="")||(document.getElementById('input_email').value=="")||(document.getElementById('input_message').value==""))
		{
			document.getElementById('div_error').style.display = "";
			document.getElementById('div_error1').style.display = "";
			document.getElementById('div_error').innerHTML = "<table cellpadding='0' cellspacing='0'><tr><td><img src='images/exclamation.gif' alt=''/>&nbsp;</td><td>V&#259; rug&#259;m completa&#355;i toate c&acirc;mpurile marcate cu * !</td></tr></table>";
			return false;
		}
	//VALID FIELDS	
		if(check_mail(document.getElementById('input_email').value)==false)
		{
			document.getElementById('div_error').style.display = "";
			document.getElementById('div_error1').style.display = "";
			document.getElementById('div_error').innerHTML = "<table cellpadding='0' cellspacing='0'><tr><td><img src='images/exclamation.gif' alt=''/>&nbsp;</td><td>E-mail nu con&#355;ine un text valid !</td></tr></table>";
			document.getElementById('input_email').focus();
			return false;
		}
	return true;
	}

function display_error(div_id, imag, post_error)
{
document.getElementById(div_id).innerHTML = "<table cellpadding='0' cellspacing='0'><tr><td><img src='images/"+imag+"' alt=''/>&nbsp;</td><td>"+post_error+"</td></tr></table>";
}


function cautareRapida(val)
{
if (val!="")
	{
	document.location="?pg=search&input="+val;
	}
}

function displayFlash(parentDiv,flashFile,imgFile,width,height)
{
var so = new SWFObject(flashFile, "", width, height, "8", "#FFFFFF");
so.addParam("wmode","transparent");

so.write(parentDiv);
if(document.getElementById(parentDiv).innerHTML=="")
document.getElementById(parentDiv).innerHTML = "<img src='"+imgFile+"' alt=''/>";
}

function window_open(caract1,caract2,caract3)
{
//caract="'imageviewer.php?img_name="+caract1+"','"+caract2+"','"+caract3+"'";
testwindow= window.open(caract1,'mywindow','location=0,status=0,scrollbars=0,width=360,height=500,scrollbars=1');
testwindow.moveTo(0,0);
}

function view_player(echipa, player_id){
	window_open("jucatori.php?jucator=" + player_id);
}

var c=0;
var t;
var timer_is_on=0;
special=new Array("01.jpg","02.jpg","03.jpg","04.jpg","05.jpg","06.jpg","07.jpg","08.jpg","09.jpg","10.jpg");

 
function timedCount()
{

x=c;
c=c+1;
document.getElementById('img_header').src='images/galerie/' + special[x]; 

t=setTimeout("timedCount()",4000);
if (c == 10) c=0;
}

function doTimer()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  timedCount();
  }
}