function setLangCookie(value)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+30);
document.cookie= "cinelang=" +escape(value)+";expires="+exdate.toGMTString();
}

function doQueueAction(idUser,idMovie,action)
{
	doGet(null,'addRemQ', 'php/actions/movie.action.php', {action:action,idMovie:idMovie,idUser:idUser,method:'addRemQ'},'<img src=web/img/other/loading_wheel.gif >');
}

function rateMovie(idMovie,rate,lang)
{
	doGet(null,'rateDiv', 'php/actions/movie.action.php', {idMovie:idMovie,rate:rate,lang:lang,method:'rateMovie'},'<img src=web/img/other/loading_wheel.gif >');
}

function fillStar(num)
{
	for(i=1;i<=num;i++)
	{
		var tempImg=document.getElementById('star'+i);
		tempImg.src='web/img/movies/starlight.gif';
	}
	
}

function emptyStar(num)
{
    for(i=1;i<=num;i++)
    {
        var tempImg=document.getElementById('star'+i);
        tempImg.src='web/img/movies/star.gif';
    }
    
}


/**
 * Shows the div containing the detaled info a movie in the most popular section
 */
function showMovieInfo(idDiv)
{
	var div=document.getElementById(idDiv);
	var childs=div.childNodes;
    for(i=0;i<childs.length; i++)
    {
    	if(childs[i].id=="sub1")
    	{
    		childs[i].style.display='none';
    	}
    	else if(childs[i].id=="sub2")
        {
            childs[i].style.display='block';
        }
    }	
}

/**
 * Hides the div containing the detaled info a movie in the most popular section
 */
function hideMovieInfo(idDiv)
{
    var div=document.getElementById(idDiv);
    var childs=div.childNodes;

    for(i=0;i<childs.length; i++)
    {
        if(childs[i].id=="sub1")
        {
            childs[i].style.display='block';
        }
        else if(childs[i].id=="sub2")
        {
            childs[i].style.display='none';
        }
    }
}

/**
 * Changes the tab style in the most popular section
 */
function selectedTab(divName,id,total)
{
	var temp;
	for(i=1 ; i<=total ; i++)
	{
		temp=document.getElementById(divName+i);
		if(i==id)
		{
			temp.className='tabMenu2';
		}
		else
		{
		    temp.className='tabMenu';	
		}
	}
}

/**
 * changes the displayed role of the users in the admin settings
 */
function changeRole(id,user,admin)
{
	var link=document.getElementById('link'+id);
	var actual=document.getElementById('role'+id);
	if(link.innerHTML==user)
	{
	   doGet(null,'dummy', '../actions/admin.user.action.php', {id:id,role:2,method:'changeRole'},'searching...');
	   link.innerHTML=admin;
	   actual.innerHTML=user;
	}   
    else
    {
    	doGet(null,'dummy', '../actions/admin.user.action.php', {id:id,role:1,method:'changeRole'},'searching...');
    	link.innerHTML=user;
    	actual.innerHTML=admin;
    }
}

/**
 * changes the shown information in the account section
 */
function showHideAccount(id,msg1,msg2,msg3,msg4)
{
    hidediv('basicInfoDiv');
    hidediv('personalInfoDiv');
    hidediv('interestDiv');
    
    showSimpleDiv(id);
    
    var button=document.getElementById('submitLink');
    if(id=='basicInfoDiv')
    {
        button.onclick=function(){validateBasicInfoForm(document.setBasicInfo,'msg1','msg2','msg3','msg4')};
    }
    else if(id=='personalInfoDiv')
    {
        button.onclick=function(){validatePersonalInfoForm(document.setPersonalInfo)};
    }
    else if(id=='interestDiv')
    {
        button.onclick=function(){validateInterestInfoForm(document.setInterestInfo)};    
    }
    
}
/*This function validates that at least, one radio button were selected*/
function valButton(btn) 
{
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
         

function showDivSecondLevel(id)
{
	hideAllSecondDivs();
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}


}

function showSimpleDiv(id)
{
if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
function showDiv(id) 
{
		
	//hideAllDivs();
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}



function hidediv(id) {

	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function goToPage(pageTo, params, admin)
{

	 for (var i in params) 
	  { 
    	var param = new String();
    	param = params[i].toString();
    	param=param.replace(/&/g, "|");
		sendParams+=i+'='+param+'&';
	  } 
	  sendParams = sendParams.substring(0,sendParams.length-1) ;	
	  if(!admin || admin == null)
		  window.location.href="index.php?"+pageTo+"?"+sendParams;
	  else
	  	window.location.href="php/admin/index.php?"+page+"?"+sendParams;	  
	  return false;

}

 String.prototype.trim = function() 
{
	return this.replace(/^\s+|\s+$/g,"");
}
 
function textCounter(input, limit)
{
	if(input.value.length > limit)
	{
		input.value = input.value.substring(0, limit);
	}
}

function GetFileExtension(Filename) 
{
var I = Filename.lastIndexOf(".");
return (I > -1) ? Filename.substring(I + 1, Filename.length).toLowerCase() : "";

} 


function showTabs(numTabs, toShow,onImg, offImg)
{
	
	container = document.getElementById(toShow);
	
	
	for(i=1; i<=numTabs; i++)
	{
		document.getElementById('t'+i).className= offImg;  
	}
	container.className= onImg; 
	


}

function showTabs2(numTabs, toShow,onImg, offImg)
{
	
	container = document.getElementById(toShow);
	
	
	for(i=1; i<=numTabs; i++)
	{
		document.getElementById('tt'+i).className= offImg;  
	}
	container.className= onImg; 
	


}

function selectUnselectAll(form)
{
	for (i=0; i < form.elements.length; i++)
	{
		if ((form.elements[i].type == 'checkbox'))
	
			form.elements[i].checked = !form.elements[i].checked;
			
	}
} 
