﻿function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://www.moviez.co.il');
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         }  
         catch(e)  
         {  
    alert("פעולה זה הופסקה על ידי הדפדפן שלך אם אתה רוצה להפעיל אותה אנא כנס ל about:config בשורת הכתובות ושנה את הערך של signed.applets.codebase_principal_support למאושר");  
         }
    } 
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage','http://www.moviez.co.il');
 }
}


function addBookmark(url,title) {

	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { 
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { 
		return true; }
 }

	function slider(oid,min)
    {
    	obj = document.getElementById(oid);
    	var min_height = (parseInt(min) > 0)? parseInt(min): 0;
    	if(obj.offsetHeight > min_height)
    	{
    		var height = (obj.offsetHeight-1) + "";
    		obj.style.height = height + "px";
    		setTimeout(function() {slider(oid);},33);
    	
    	}	
    }
	count = 0;
	function slideDown(oid,height)
    {
    	obj = document.getElementById(oid);
    	
    	if(height > 0)
    	{
    		var h = height-3;
    		obj.style.height = height+"px";
    		setTimeout(function() {slideDown(oid,h);},1);	
    	}	
		else obj.style.display = 'none';
    	
    }
function vmail(val)
{
		var regex = /([A-Za-z0-9\.\_]+)@([A-Za-z0-9]+)\.([A-Za-z]+)/;
		return regex.test(val);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var 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 eraseCookie(name) {
	createCookie(name,"",-1);
}
function hideShow(oid)
{	
	document.getElementById(oid).style.display = (document.getElementById(oid).style.display == 'none') ? ''  : 'none';
}
function RegisterFormCheck()
{
	var errors = document.getElementById('register_errors');
	var username = document.getElementById('register_username');
	var password = document.getElementById('register_password');
	var email = document.getElementById('register_email');
	var terms = document.getElementById('register_terms');
	username.style.border = "2px solid #f0f0f0";
	password.style.border = "2px solid #f0f0f0";
	email.style.border = "2px solid #f0f0f0";
	//alert(document.regForm.register_username.length);
	ret = true;
	var validuser = /^([A-Za-z0-9א-ת_]+)$/;
	errors.style.display = '';
 	errors.innerHTML = "";
	if(username.value.length < 3 || username.value.length > 10)
	{
		username.style.border = "2px solid red";
		ret = false;
		errors.innerHTML += ((errors.innerHTML == "") ? "<u>שגיאות</u>: " : ",") + "על שם המשתמש להכין בין 3 ל10 תווים";
	}
	if(!validuser.test(username.value))
	{
		username.style.border = "2px solid red";
		ret = false;
		errors.innerHTML += ((errors.innerHTML == "") ? "<u>שגיאות</u>: " : ",") + "שם המשתמש אינו חוקי";
	}
	if(password.value.length < 3)
	{
		password.style.border = "2px solid red";
		ret = false;
		errors.innerHTML += ((errors.innerHTML == "") ? "<u>שגיאות</u>: " : ",") + "על הסיסמה להכיל 3 תווים לכל הפחות";
	}
	if(!vmail(email.value) || email.value.length < 5)
	{
		email.style.border = "2px solid red";
		ret = false;
		errors.innerHTML += ((errors.innerHTML == "") ? "<u>שגיאות</u>: " : ",") + "המייל שהוזן אינו תקין";
	}
	if(!terms.checked)
	{
		terms.style.border = "2px solid red";
		ret = false;
		errors.innerHTML += ((errors.innerHTML == "") ? "<u>שגיאות</u>: " : ",") + "חובה לקורא ולאשר את תנאי השימוש";
	}
	if(ret == false)
		errors.style.display = '';
	return ret;
}

 $(document).ready
	 (
	 	function()
 		{	
       		$("a").click
			(
   				function(event)
			    {
			    	if(!readCookie("popup"))
			    	{
         				createCookie("popup","popup",5);
         				//window.open("http://www.google.co.il","Moviez.co.il Popup","height=300,width=500");
         			}
      			}
   			); 
   			$('#notice_close').click(function() {
				$('#notice').slideUp('slow', function() {
					// Animation complete.
				});
			});
			$('#open_series').click(function() {
				$('#more_series').slideToggle('slow');
			});
			$('#comment_open').click(function() {
				$('#comment_add').slideToggle('slow');
			});
     	}
	 );
     
	function setMovieSize(obj,width,height)
	{
		document.getElementById('watch_small').style.color = 'gray';
		document.getElementById('watch_normal').style.color = 'gray';
		document.getElementById('watch_big').style.color = 'gray';
		document.getElementById('watch_small').style.fontWeight = 'normal';
		document.getElementById('watch_normal').style.fontWeight = 'normal';
		document.getElementById('watch_big').style.fontWeight = 'normal';
		document.getElementById(obj).style.color = 'black';
		document.getElementById(obj).style.fontWeight = 'bold';
		document.getElementById('divmovie').style.width = width +"px";
		document.getElementById('divmovie').style.height = height +"px";
		document.getElementById('movie').style.width = width +"px";
		document.getElementById('movie').style.height = height +"px";
		SetMargin = (800 - width) / 2;
		//document.getElementById('movie').style.marginRight = SetMargin + "px";
		document.getElementById('divmovie').style.marginRight = SetMargin + "px";
	}
function DivToWidth(id,swidth, width)
{
	var elm = document.getElementById(id);
	elm.style.width = swidth+"px";
	DivToWidthPRIVATE(elm,swidth,width);	
}

function DivToWidthPRIVATE(elm,swidth, width)
{
	if(width > swidth)
	{
		swidth+=2.7;
		elm.style.width = swidth+"px";
		setTimeout(function () {DivToWidthPRIVATE(elm,swidth, width);},1);
	}
}

