//Custom select functions
function findPos(obj,ddl)
{
	var initialObj = obj;
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	var t = curtop + 20;
	var l = curleft;
	ddl.style.top = t +"px";
	ddl.style.left = l +"px";
}

function expandDDL(itemPrefix)
{
	if(document.getElementById('div_'+itemPrefix+'_list').style.visibility=="visible")
	{
		document.getElementById('div_'+itemPrefix+'_list').style.visibility="hidden";
		document.getElementById('div_'+itemPrefix+'_list').style.display="none";
	}
	else
	{
		document.getElementById('div_'+itemPrefix+'_list').style.visibility="visible";
		document.getElementById('div_'+itemPrefix+'_list').style.display="block";
	}
}

function ascundeDDL(itemPrefix)
{
	if(document.getElementById('div_'+itemPrefix+'_list').style.visibility=="visible")
	{
		document.getElementById('div_'+itemPrefix+'_list').style.visibility="hidden";
		document.getElementById('div_'+itemPrefix+'_list').style.display="none";
	}
	
}

function selectDDL(opt,opt_text,itemPrefix)
{
	document.getElementById('div_'+itemPrefix+'_first_text').innerHTML = opt_text;
	document.getElementById('div_'+itemPrefix+'_list').style.visibility="hidden";
	document.getElementById('div_'+itemPrefix+'_list').style.display="none";
	document.getElementById('hidden_select_'+itemPrefix).value = opt;
	document.getElementById('hidden_select_'+itemPrefix+'_opt').value = opt_text;
}
function updatePos(itemPrefix)
{
	findPos(document.getElementById('div_'+itemPrefix+'_first'),document.getElementById('div_'+itemPrefix+'_list'));
}

function updatePositions_flights()
{
	updatePos('tara');
	updatePos('conv_din');
	updatePos('conv_in');
	updatePos('transport');
	updatePos('camera');
	updatePos('categorie');
	updatePos('tip');
	updatePos('regiune');
	updatePos('statiune');
	
	
	
}

//eliminates white spaces from a string
function trim(str)
{  
	while(str.charAt(0) == (" ") )
		str = str.substring(1);
  	while(str.charAt(str.length-1) == " " )
		str = str.substring(0,str.length-1);
  return str;
}

//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);
}
//Create js date object from date,time string
function formatDateJS(strInput)
{
	var myDate = new Date;
	myDate = Date.UTC(strInput.split("/")[2]*1,strInput.split("/")[1]*1,strInput.split("/")[0]*1,0,0,0);
	return myDate;
}

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_tel').value=trim(document.getElementById('input_tel').value);		
	document.getElementById('input_message').value=trim(document.getElementById('input_message').value);
	document.getElementById('input_code').value=trim(document.getElementById('input_code').value);
	//REQUIRED FIELDS
		if((document.getElementById('input_nume').value=="")||(document.getElementById('input_prenume').value=="")||(document.getElementById('input_tel').value=="")||(document.getElementById('input_email').value=="")||(document.getElementById('input_message').value=="")||(document.getElementById('input_code').value==""))
		{
			
			document.getElementById('div_error').innerHTML = lg_err_required;
			return false;
		}
	//VALID FIELDS	
		if(check_mail(document.getElementById('input_email').value)==false)
		{
			
			document.getElementById('div_error').innerHTML = lg_err_invalid_mail;
			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 menu_display(page)
{
	if(document.getElementById(page).style.display=="none")
		document.getElementById(page).style.display = "";
	else
		document.getElementById(page).style.display = "none";
}
function changeMovie(tdOb,index,title,photoN,linkFilm)
{
	a=index;
	tdOb.style.cursor='pointer'; 
	tdOb.style.backgroundImage='url(images/bt_link_sel.gif)';
	tdOb.style.color='#FFFFFF';
	
	for(i=1; i<4;i++)
	{
		if(i!=index)
		{
			document.getElementById('film'+i).style.backgroundImage='url(images/bt_link.gif)'; 
			document.getElementById('film'+i).style.color='#6E6E6E'; 
		}
	}
	
	document.getElementById('link_film').innerHTML=title;
	document.getElementById('link_film').title=title;
	document.getElementById('link_film').href = "http://www.retim.ro/FLV/"+linkFilm;
	document.getElementById("photo_mare").src= "upload/photos/"+photoN;
	
}
var flag =0;
var lastDv =null;
var i=0;

function getShadow(divId,mouseEvent)
{
	var dv =document.getElementById(divId);
	
	if(mouseEvent == 1 ) //mouse over
	{
		
			dv.style.display="block";
	}
	else //mouseout
	{
		dv.style.display="none";
	}
	
	
}
function changeDate(type)
{
	document.getElementById("t_date").value = document.getElementById("h_date"+type).value;
}