var browser=navigator.appName;
var b_version=parseFloat(navigator.appVersion);
var browser_Ex=true;
if(browser!='Microsoft Internet Explorer')
	browser_Ex=false;

function Close_Open(Div_Name,Bottom_Y,Top_Y,Which_Div,Frame_Num,Lang)
{

   (Frame_Num==undefined)?Frame_Num=0.5:'';
    Bottom_Y=50;
	if(Div_Name.style.display!='block')
	{ //open
		Top_Check=(browser_Ex)?Get_Top(Div_Name):Top_Y;
	        Div_Name.style.display='block';
	        (Which_Div!='close')?Which_Div.style.display='block':'';
			Move_Down = new Tween(Div_Name.style,'top',Tween.strongEaseOut,Top_Y,Bottom_Y,1,'px');
		    Move_Down.start();
		    Move_Down.onMotionFinished = function()
			{
				document.getElementById('Flash_Div').style.display='block';
		    }
	        //Show_Cart();
	}
	else
	{//close


		if(Get_Top(Div_Name)==Bottom_Y )
		{			if(Which_Div!='close')
			{
				if(Which_Div==document.getElementById('About_Div') && (document.getElementById('Clients_Div').style.display=='block' || document.getElementById('Contact_Div').style.display=='block') )
				{
		   			document.getElementById('Clients_Div').style.display=document.getElementById('Contact_Div').style.display='none';
		   			document.getElementById('About_Div').style.display='block';
		   		}
		   		else if(Which_Div==document.getElementById('Clients_Div') && (document.getElementById('About_Div').style.display=='block' || document.getElementById('Contact_Div').style.display=='block'))
				{
		   			document.getElementById('Clients_Div').style.display='block';
		   			document.getElementById('About_Div').style.display=document.getElementById('Contact_Div').style.display='none';;
		   		}
		   		else if(Which_Div==document.getElementById('Contact_Div') && (document.getElementById('About_Div').style.display=='block' || document.getElementById('Clients_Div').style.display=='block') )
				{
		   			document.getElementById('Contact_Div').style.display='block';
		   			document.getElementById('About_Div').style.display=document.getElementById('Clients_Div').style.display='none';;
		   		}
			}
	   	    else
	   	    {
		   	    document.getElementById('Flash_Div').style.display='none';
				Move_Up = new Tween(Div_Name.style,'top',Tween.strongEaseOut,Bottom_Y,Top_Y,Frame_Num,'px');//backEaseIn
			    Move_Up.start();
			    Move_Up.onMotionFinished = function()
				{
					Div_Name.style.display='none';
					document.getElementById('Contact_Div').style.display=document.getElementById('Clients_Div').style.display=document.getElementById('About_Div').style.display='none';
			        (Which_Div!='close')?Which_Div.style.display='none':'';

				}
			}
		}
	}
}
//         SHOPPING CART FUNCTIONS --------------------------
function Show_Cart()
{
	ajaxFunction();
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			var ajaxDisplay = document.getElementById('Div_Inside');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", Path_Level+"Show_Cart.php", true);
	ajaxRequest.send(null);
}


function Move_Img(Cur_Div)
{

	Width_Divid=(document.images['Img_Choose'].width)/2;
	currentXPos = Get_Left(Cur_Div);
	currentYPos = Get_Top(Cur_Div);
	Pixel_Diff=(browser_Ex)?'':-150;
	Target_x =Get_Left(document.getElementById('Sal_Btn_Div'))-Width_Divid+60;
	Target_y = Get_Top(document.getElementById('Sal_Btn_Div'))-50;
	var Moving_Div = document.getElementById('Moving_Div');
	Moving_Div.style.display="block";
	var Copy_Div = Cur_Div.cloneNode(true);
	Copy_Div.id='';
	Moving_Div.innerHTML = '';
	Moving_Div.style.left = currentXPos + 'px';
	Moving_Div.style.top = currentYPos + 'px';
	Moving_Div.appendChild(Copy_Div);
	Moving_Div.style.width = Cur_Div.offsetWidth + 'px';
	Moving_Div.className = "Move_Img";
	Move_Up = new Tween(Moving_Div.style,'top',Tween.strongEaseOut,currentYPos,Target_y,0.5,'px');//backEaseIn
    Move_Up.start();
	Move_right = new Tween(Moving_Div.style,'left',Tween.strongEaseOut,currentXPos,((Target_x)),0.5,'px');//backEaseIn
    Move_right.start();
	/*Move_Width = new Tween(Moving_Div.style,'width',Tween.strongEaseOut,Cur_Div.offsetWidth,(Cur_Div.offsetWidth/8),0.5,'px');//backEaseIn
    Move_Width.start();
	Move_Height = new Tween(Moving_Div.style,'height',Tween.strongEaseOut,Cur_Div.offsetHeight,(Cur_Div.offsetHeight/8),0.5,'px');//backEaseIn
    Move_Height.start();*/
    Move_Up.onMotionFinished = function()
	{
		Moving_Div.style.display="none";

	}
}
function Fade_Img(Cur_Div)
{
	    Fade_Out = new OpacityTween(Cur_Div,Tween.EaseIn, 100, 0, 0.5);
        Fade_Out.start();
	    Fade_Out.onMotionFinished = function()
		{
  		    Fade_In = new OpacityTween(Cur_Div,Tween.EaseOut, 0, 100, 0.5);
	        Fade_In.start();
		    Fade_Out2 = new OpacityTween(document.getElementById('Sal_Btn_Div'),Tween.EaseIn, 100, 0, 0.5);
    	    Fade_Out2.start();
		    Fade_Out2.onMotionFinished = function()
			{

	  		    Fade_In2 = new OpacityTween(document.getElementById('Sal_Btn_Div'),Tween.EaseOut, 0, 100, 0.5);
		        Fade_In2.start();

			}
		}
}
function Fade_In_Func(Div_Name,Frame_Num)
{
	document.getElementById(Div_Name).style.display='block';
    Fade_In_Out = new OpacityTween(document.getElementById(Div_Name),Tween.EaseOut, 0, 100, Frame_Num);
    Fade_In_Out.start();
}
function Fade_Out_Func(Div_Name)
{

	var Fade_Out = new OpacityTween(document.getElementById(Div_Name),Tween.EaseIn, 100, 0, 0.4);
	var Fade_Lis = new Object();
	Fade_Lis.onMotionFinished = function()
	{
		document.getElementById(Div_Name).style.display='none';
	    document.getElementById(Div_Name).style.filter.opacity=0;
	};
	Fade_Out.addListener(Fade_Lis);
	Fade_Out.start();
}

function Update_Sum(how_much,Form_Name,Total_Price)
{
   Form_Name.Price_Order.value=(parseInt(Total_Price)+parseInt(how_much));
}
//         GALLERY FUNCTIONS --------------------------
function swapImage(swapImg)
{
   document.getElementById('imageBIG').style.display="block";
 //  document.getElementById('Text_Title').style.display="none";
   document.images['Image_Name'].src=swapImg;
}
function swapImage_Gallery(swapImg,Name_Image)
{
        document.images['Image_Name'].src='../Gallery/'+swapImg;
        document.images['Image_Name'].alt=Name_Image;
        document.getElementById('Text_Img').value=Name_Image;
}
function Show_Next_Prev(RowStart,Genral_QueryString)
{
        ajaxFunction();
        ajaxRequest.onreadystatechange = function()
        {
                if(ajaxRequest.readyState == 4)
                {
                        var ajaxDisplay = document.getElementById('content_Div');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
        }
        var queryString = "?RowStart=" + RowStart+ "&"+Genral_QueryString;
        ajaxRequest.open("GET", "Gallery_Inc.php" + queryString, true);
        ajaxRequest.send(null);
}
function Check_Enter(Word_Search)
{
    if (( window.event.keyCode == 13) && (Word_Search.length>0) )
    {
                //Search_Item(Word_Search);
                Submit_It();
    }
  };
//         VALIDATION FUNCTIONS --------------------------
function Validate_Contact(Form_Name)
{

 if(! (Has_Value(Form_Name.Name_Client,"השם")) ) return false;
  if(! (Is_Correct_Email(Form_Name.Email_Client)) ) return false;
  return true;
}
function Is_Telephone(Field_F,Field_Name,Heb,Lengh_F,Key_Up)
{
   if (((Field_F.value / Field_F.value) != 1) && (Field_F.value != 0))
   {
       if(Heb==true)
                   alert("בבקשה להקיש ספרות בלבד בשדה ה "+Field_Name);
       else
               alert("please type digits only in the "+Field_Name+" field");
       Field_F.select();
       return false;
   }
   var Str_Phone=Field_F.value.substring(0,2);
   if(Str_Phone==02 || Str_Phone==03 || Str_Phone==04 || Str_Phone==06 || Str_Phone==08 || Str_Phone==09)
   	Lengh_F=9;
   else
   {	   var Str_Phone2=Field_F.value.substring(0,3);
   		if (Str_Phone2=='077' || Str_Phone2=='074' || Str_Phone2=='072' || Str_Phone2=='078')
   		{
		   	Lengh_F=10;
		}
		else
	   {	       alert("נא להקיש טלפון נכון לדוגמא 036785412");
	       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 Is_Cell(Field_F,Field_Name,Heb,Lengh_F,Key_Up)
{
   if (((Field_F.value / Field_F.value) != 1) && (Field_F.value != 0))
   {
       if(Heb==true)
                   alert("בבקשה להקיש ספרות בלבד בשדה ה "+Field_Name);
       else
               alert("please type digits only in the "+Field_Name+" field");
       Field_F.select();
       return false;
   }
   var Str_Phone2=Field_F.value.substring(0,3);
  		if (Str_Phone2=='050' || Str_Phone2=='052' || Str_Phone2=='054' || Str_Phone2=='057')
  		{
		   	Lengh_F=10;
		}
		else
	   {
	       alert("נא להקיש טלפון נכון לדוגמא 052658741");
	       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 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))
   {
       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,4})+$/.test(Field_F.value)))
  {
     alert("הכנס כתובת דואר אלקטרוני נכונה \n   info@cnn.com  - לדוגמא ");
         Field_F.focus();
     Field_F.select();
     return false;
   }
  return true;
}
//         MISCELINIOUS FUNCTIONS --------------------------

function Get_Top(inputObj)
{
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null)
  {
          if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}
function Get_Left(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)
  {
          if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}
function Get_Right(inputObj)
{
  var returnValue = inputObj.offsetRight;
  while((inputObj = inputObj.offsetParent) != null)
  {
          if(inputObj.tagName!='HTML')returnValue += inputObj.offsetRight;
  }
  return returnValue;
}
function Fade_Out_Fnc(Div_Name,Frame_Num)
{
	(Frame_Num==undefined)?Frame_Num=0.5:'';
	var Fade_Out_This = new OpacityTween(Div_Name,Tween.strongEaseOut, 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 Active_Page(Which_Page,Which_Div)
{
        ajaxFunction();
        ajaxRequest.onreadystatechange = function()
        {
                if(ajaxRequest.readyState == 4)
                {
                        if(Which_Div!=undefined)
                                var ajaxDisplay = Which_Div;
                        else
                                var ajaxDisplay = document.getElementById('Reg_Div');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
						if(Which_Page=='blank.html')
    	                    ajaxDisplay.style.display='none';
                        else
                        {
	                        ajaxDisplay.style.display='block';
	                        //Fade_In_Func('Reg_Div',0.5) ;
	                    }
                }
        }
        ajaxRequest.open("GET", Which_Page, true);
        ajaxRequest.send(null);
}

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 Resise_It()
{
 _img = document.getElementsByTagName('img');
 for ( var x = 0; x < _img.length; x++ )
 {
// 	if(_img[x].width==320 || _img[x].height==240 || _img[x].height==135 || _img[x].width==180 )
	Name_Img=_img[x].id.toString();
	if(Name_Img.indexOf("Pic_View")!=-1)
 	{
	 	(_img[x].width>_img[x].height )?_img[x].style.width = '50px':_img[x].style.height = '38px';
	}
 }
}
function Submit_It2(Form_Name)
{
 if(Form_Name.onsubmit())
 {
  Form_Name.submit();
 }
}

