var Page_Old=undefined;
var Div_Old=undefined;
var Z_Index=1300;
var Click_Enable=true;
//         DIV Openn FUNCTIONS --------------------------
function Close_Open(Div_Name,X_Finished,X_Start,Which_Page,Frame_Num)
{
        X_Start=-430;     //
        Height_Div=732;
        X_Finished=-10;
//        alert(Which_Page);
//        X_Finished=(screen.height-Height_Div)/2
    X_Active=(Div_Name.style.left=="")?0:parseInt(Div_Name.style.left.substring(0,Div_Name.style.left.indexOf('p')) );
     (Frame_Num==undefined)?Frame_Num=1:'';
        if(Which_Page=='close')
        {//כשלוחצים על סגור
                if(Div_Name.style.left=='0px')
                {
                        Fade_In_Fnc(document.getElementById('Open_Div'),1);
                        Fade_Out_Fnc(document.getElementById('Close_Div'),0.5);
                        Move_Left = new Tween(Div_Name.style,'left',Tween.strongEaseIn,X_Finished,X_Start,Frame_Num,'px');//backEaseIn
                    Move_Left.start();
                        Move_Left.onMotionFinished = function()
                        {
                     (Frame_Num==0.5)?Div_Name.style.display='none':'';//לחצו על גלריה
                     Page_Old=undefined ;
                        }
            }
        }
        else if(Which_Page=='open')
        {//כשלוחצים על פתח
                        Fade_In_Fnc(document.getElementById('Close_Div'),1);
                        Fade_Out_Fnc(document.getElementById('Open_Div'),0.5);
                        Move_Right = new Tween(Div_Name.style,'left',Tween.strongEaseOut,X_Start,X_Finished,2,'px');
                    Move_Right.start();
        }
   else if(Which_Page!=Page_Old)
   {

        Click_Enable=false;
	      Div_Name.style.display='block';
	      if(Page_Old!=undefined)
	      {  //יש סרט שנמצא כבר
		      alert(Div_Old);
          Fade_Out_Fnc(Div_Old,1);
          Active_Page(Which_Page);
          Fade_In_Fnc(Div_Name,1);
	      Page_Old=Which_Page;
          Div_Old=Div_Name;
	      }
      else
      {//פעם ראשונה שיורד סרט
          Active_Page(Which_Page);
          Page_Old=Which_Page;
          Div_Old=Div_Name;
          Fade_In_Fnc(Div_Name,1);
      }
     (document.getElementById('Reg_Div').style.display=='block')?Fade_Out_Fnc(document.getElementById('Reg_Div'),0.5):'';
  }
}
function Active_Page(Which_Page,Which_Div)
{
        ajaxFunction();

        ajaxRequest.onreadystatechange = function()
        {

                if(ajaxRequest.readyState == 1)
                {
                        //document.getElementById('Preloader_Div').style.display='block';
                }
                if(ajaxRequest.readyState == 4)
                {
                        document.getElementById('Preloader_Div').style.display='none';
                        if(Which_Div!=undefined)
                                var ajaxDisplay = Which_Div;
                        else
                                var ajaxDisplay = document.getElementById('Content_Div');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                        if(document.getElementById('Div_Inside')!=undefined && ajaxDisplay != Which_Div)
                        {
                           Fade_In_Fnc(document.getElementById('Div_Inside'),1);
                        }
                        if(ajaxRequest.responseText.indexOf('תודה')!=-1)
                        {
                                 //setTimeout('Close_Open(document.getElementById(\'Content_Div\'),294,120,\'close\');',3000);
                                 setTimeout('Fade_Out_Fnc(document.getElementById(\'Reg_Div\'),1);',3000);

                        }
                }
        }
        ajaxRequest.open("GET", Which_Page, true);
        ajaxRequest.send(null);
}
function Move_Div(Div_Name,Pos,Clean_Other)
{
	if(Clean_Other==true)
	{
	 for(i=1; i<=40; i++)
	 {
	 	if(document.getElementById('Div_'+i)!=undefined)
		 	document.getElementById('Div_'+i).style.left='-500px';
	 }
	 //Div_Name.style.zIndex=++Z_Index;
	}
 Div_Name.style.left=Pos;
}
function Make_Color_TD(Num_TD)
{
	document.getElementById('TD'+Num_TD).style.backgroundColor='#FF6600';
	for(i=1;i<=7;i++)
	{		if(i!=Num_TD)
			document.getElementById('TD'+i).style.backgroundColor='';
	}

}
//         Fade in out FUNCTIONS --------------------------

function Fade_In_Fnc(Div_Name,Frame_Num)
{
        (Frame_Num==undefined)?Frame_Num=0.5:'';
        Div_Name.style.display='block';
    Fade_In_Out = new OpacityTween(Div_Name,Tween.EaseOut, 0, 100, Frame_Num);
    Fade_In_Out.start();
}
function Fade_In_Out_Fnc(Div_Name,Frame_Num)
{
        (Frame_Num==undefined)?Frame_Num=0.5:'';
        var Fade_Out_This = new OpacityTween(Div_Name,Tween.strongEaseOut, 100, 0, Frame_Num);
        var Fade_Lis = new Object();
        Fade_Lis.onMotionFinished = function()
        {
           Div_Name.style.filter.opacity=0;
           Fade_In_Fnc(Div_Name,Frame_Num);
        };
        Fade_Out_This.addListener(Fade_Lis);
        Fade_Out_This.start();
}
function Fade_Out_Fnc(Div_Name,Frame_Num)
{
        (Frame_Num==undefined)?Frame_Num=0.5:'';
        var Fade_Out_This = new OpacityTween(Div_Name,Tween.strongEaseIn, 100, Frame_Num, 1);
        var Fade_Lis = new Object();
        Fade_Lis.onMotionFinished = function()
        {
       Div_Name.style.display='none';
           Div_Name.style.filter.opacity=0;
        };
        Fade_Out_This.addListener(Fade_Lis);
        Fade_Out_This.start();
}
function Make_Visible(Div_Name)
{
       Div_Name.style.display='none';
}
var ajaxRequest;  // The variable that makes Ajax possible!
function ajaxFunction()
{
        try
        {
                ajaxRequest = new XMLHttpRequest();// Opera 8.0+, Firefox, Safari
        }
        catch (e)
        {
                try// Internet Explorer Browsers
                {
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e)
                        {
                                alert("Your browser broke!");// Something went wrong
                                return false;
                        }
                }
        }
        //alert(ID_Item);
}

function Validate_Reg(Which_Page,Which_Div)
{
  if(! (Has_Value(document.getElementById('Name_Client'),"שם")) ) return false;
  if(! (Has_Value(document.getElementById('Address_Client'),"כתובת")) ) return false;
  if(! (Has_Value(document.getElementById('City_Client'),"עיר")) ) return false;
  if(document.getElementById('ZipCode_Client')==undefined)
  {
          var ZipCode_Client="";
  }
  else
  {
          if(!( Is_Number(document.getElementById('ZipCode_Client'),"המיקוד",true,5,false) ) )
                  return false
          else
                  var ZipCode_Client=document.getElementById('ZipCode_Client').value;
  }
  if (!( Is_Number(document.getElementById('Telephone_Client'),"מספר הטלפון",true,5,false) ) )      return false;
  if(document.getElementById('Birthday_Client')==undefined)
  {
          var Birthday_Client="";
  }
  else
  {
          if(!( Is_Number(document.getElementById('Birthday_Client'),"תאריך לידה",true,6,false) ) )
                  return false
          else
                  var Birthday_Client=document.getElementById('Birthday_Client').value;
  }
  if(document.getElementById('Cellolar_Client')==undefined)
  {
          var Cellolar_Client="";
  }
  else
  {
          if(!( Is_Number(document.getElementById('Cellolar_Client'),"מספר הטלפון הנייד שלך",true,5,false) ) )
                  return false
          else
                  var Cellolar_Client=document.getElementById('Cellolar_Client').value;
  }

  if(! (Is_Correct_Email(document.getElementById('Email_Client'))) ) return false;
  if(Which_Page=='Send_Email.php')
  {
          if(! (Has_Value(document.getElementById('Messege_txt'),"ההודעה")) ) return false;
      if(! (Validate_letter(document.getElementById('Messege_txt').value,document.getElementById('Messege_txt') ) )) return false;
            var Messege_txt=document.getElementById('Messege_txt').value;
          var Verification_Code="";
  }
  else
  {
        //  if(! (Has_Value(document.getElementById('Verification_Code'),"הקוד לאימות שמצוי בתמונה")) ) return false;
          var Messege_txt="";
          //var Verification_Code=document.getElementById('Verification_Code').value;
  }
  Which_Page=Which_Page+'?Name_Client='+document.getElementById('Name_Client').value+'&City_Client='+document.getElementById('City_Client').value+
  '&Address_Client='+document.getElementById('Address_Client').value+'&Telephone_Client='+document.getElementById('Telephone_Client').value+
  '&ZipCode_Client='+ZipCode_Client+'&Birthday_Client='+Birthday_Client +'&Cellolar_Client='+Cellolar_Client +
  '&Email_Client='+document.getElementById('Email_Client').value+ '&Verification_Code='+Verification_Code +'&Messege_txt='+Messege_txt;
  Active_Page(Which_Page,Which_Div);
}
function Check_Enter(Which_Page)
{
    if (( window.event.keyCode == 13)  )
    {
                Validate_Reg(Which_Page);
    }
};



//         VALIDATION FUNCTIONS --------------------------
function Is_Number(Field_F,Field_Name,Heb,Lengh_F,Key_Up)
{
   if(Key_Up==false)
   {
           if(! (Has_Value(Field_F,Field_Name,Heb)) )
           return false;
   }
   if (((Field_F.value / Field_F.value) != 1) && (Field_F.value != 0) || (Field_F.value.indexOf('.')!=-1) )
   {
       if(Heb==true)
                   alert("בבקשה להקיש ספרות בלבד בשדה ה "+Field_Name);
       else
               alert("please type digits only in the "+Field_Name+" field");
       Field_F.select();
       return false;
   }
   if(Field_F.value.length<Lengh_F && Key_Up==false)
   {
       if(Heb==true)
                   alert("בבקשה להקיש מספר ספרות מדוייק בשדה ה "+Field_Name);
       else
               alert("please type the right sum of Digits in the "+Field_Name+" field");
       Field_F.select();
       return false;
   }
   return true;
}
function Has_Value(Field_F,Field_Name)
{
   if (Field_F.value=="")
   {
     alert("בבקשה להכניס את "+Field_Name);
     Field_F.focus();//מחזיר את הסמן לשדה הטקסט החסר
     return false;
   }
   return true;
}
function Is_Correct_Email(Field_F)
{
 if(! (Has_Value(Field_F,"הדואר האלקטרוני")) )   return false;
 if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Field_F.value)))
  {
     alert("הכנס כתובת דואר אלקטרוני נכונה \n   info@cnn.com  - לדוגמא ");
         Field_F.focus();
     Field_F.select();
     return false;
   }
  return true;
}
function Validate_letter(str,Field)
{//check if there is a word with more then 20 letters without space
  var count_i=0;
  for (var i = 0; i < str.length; i++)
  {
     var ch = str.substring(i, i + 1);
     if ((ch != ' ') )
     {
         count_i++;
         if (count_i>20)
         {
                 alert("\n.יש מילה עם יותר מ20 אותיות בתוכן שכתבת\n\n! בבקשה לבדוק את הכתוב ");
                 Field.focus();
                 Field.select();
                 return false;
         }
     }
     else if ((ch == ' ') )
          count_i=0;
  }
  return true;
}
//         SCROLLING FUNCTIONS --------------------------

var ourInterval;
var origColor = "#F3F9F1";
var overColor = "#36FF00";
var scrollSpeed = 50;
var scrollHeight = 5;

function scrollStart(direction, divID, elementID)
{	//CHANGE THE BACKGROUND COLOR OF THE TD THE MOUSE IS OVER
	document.getElementById(elementID).style.backgroundColor = overColor;
	// REPEATED CALL EITHER scrollUp OR scrollDown
	ourInterval = setInterval("scroll"+direction+"('"+divID+"')", scrollSpeed);
}
function scrollEnd(which)
{
	document.getElementById(which).style.backgroundColor = origColor;
	clearInterval(ourInterval);
}
function scrollUp(which)
{
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop - scrollHeight;
}
function scrollDown(which)
{ // SET THE SCROLL TOP
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop + scrollHeight;
}
//         GENERAL FUNCTIONS --------------------------

function saveImageAs (imgOrURL)
{
        if (typeof imgOrURL == 'object')
                imgOrURL = imgOrURL.src;
        window.win = open (imgOrURL);
//        setTimeout('win.close()', 9000);
        setTimeout('win.document.execCommand("SaveAs")', 500);

}
function Change_Background()
{
        document.body.style.backgroundImage = 'url(images/sunset_bg.jpg)';

}
function Change_BG_Color(This_Name)
{
        (This_Name.style.backgroundColor=="#ff6699")?This_Name.style.backgroundColor="":This_Name.style.backgroundColor="#ff6699";
}

//         FLASH FUNCTIONS --------------------------

var movieName = "Default";
function thisMovie(movieName)
{
  if (navigator.appName.indexOf ("Microsoft") !=-1)
    return window[movieName]
  else
    return document[movieName]
}
function movieIsLoaded (theMovie)
{
  if (typeof(theMovie) != "undefined")
    return theMovie.PercentLoaded() == 100;
  else
    return false;
}

function GoTo_Frame(This_Level,Name_Frame,Movie_Name)
{
  if (movieIsLoaded(thisMovie(Movie_Name)))
  {
    thisMovie(Movie_Name).TGotoLabel(This_Level,Name_Frame);
  }
}

