var browser=navigator.appName;
var b_version=parseFloat(navigator.appVersion);
var browser_Ex=true;
if(browser!='Microsoft Internet Explorer')
	browser_Ex=false;
var Add_Mes=false; // רק בגלל שעגלת הקניות והתשלום באותו עמוד
//         SHOPPING CART FUNCTIONS --------------------------

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 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 Update_Sum(how_much,Form_Name,Total_Price)
{
//   Form_Name.Price_Order.value=(parseInt(Total_Price)+parseInt(how_much));
	var Old=parseInt(Form_Name.Price_Order.value);
	if(how_much==0 && Add_Mes==true)
		how_much=-50;
   	Form_Name.Price_Order.value=(Old+(parseInt(how_much)) );

}
function Change_Display(Which_Div,Other_Div)
{
	for (i=1; i<=2; i++)
	{
		document.getElementById(Which_Div+'_Div_'+i).style.display='block';
		document.getElementById(Other_Div+'_Div_'+i).style.display='none';
	}

}
function Toggle_Display(Div_Name)
{
	if(Div_Name.style.display=='block')
	{
		document.getElementById('Iframe_In').src=document.getElementById('Iframe_In').src;
		Div_Name.style.display='none';
	}
	else
	{
		Div_Name.style.display='block';

	}
}
function nl2br (str, is_xhtml)
{
 var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br>';

    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
//         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();
    }
  };

function Submit_It()
{
 if(document.Search_Item.onsubmit())
 {
		document.Search_Item.action='Search_Results.php';
  document.Search_Item.submit();
 }
}
function Submit_It2(Form_Name)
{
 if(Form_Name.onsubmit())
 {
  Form_Name.submit();
 }
}
//         VALIDATION FUNCTIONS --------------------------
function Validate_Search_Item()
{
 if(document.Search_Item.Word_Search.value.length<3 || document.Search_Item.Word_Search.value=='לחיפוש מוצר')
   {
     alert("נא להקליד לפחות 3 אותיות לחיפוש");
     document.Search_Item.Word_Search.focus();
     return false;
   }
	document.Search_Item.action='Search_Results.php';
   return true;
 };
function Validate_Contact(Form_Name)
{
 	if(! (Has_Value_Correct_Arr(Form_Name.Name_Client)) ) return false;
  	if(! (Is_Correct_Email(Form_Name.Email_Client)) ) return false;
/* 	if (!( Is_Telephone(Form_Name.Telephone_Client,"טלפון",true,9,false) ) )      return false;
 	if (!( Is_Cell(Form_Name.Cellolar_Client,"נייד",true,10,false) ) )      return false;
 	if(! (Has_Value_Correct_Arr(Form_Name.Messege_txt)) ) return false;
 	if(! (Has_Value_Correct_Arr(Form_Name.City_Client)) ) return false;*/

    for(i=0; i<Form_Name.length; i++)
    {
    	if(Form_Name[i].value==Name_Array[i])
	    	Form_Name[i].value='';
    }

  return true;
}
function Validate_Login(Which_Page,Which_Div)
{                                                          //info@32bit.co.il
	if(! (Is_Correct_Email(document.getElementById('Email_Client') )) )		return false;
	 if (document.getElementById('Password_Client').value=="")
   	{
     alert("נא לרשום את ה your password");
     return false;
   	}
      	var Remmeber_Me='on';
  Which_Page=Which_Page+'?Email_Client='+document.getElementById('Email_Client').value+'&Password_Client='+document.getElementById('Password_Client').value;//+'&Remmeber_Me='+Remmeber_Me
  Active_Page(Which_Page,Which_Div);
//  setTimeout('location.href = "index.php";',2500);
}
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("נא לרשום את ה numbers only"+Field_Name);
       else
               alert("נא לרשום את ה 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("נא לרשום את ה correct phone number 036785412");
	       Field_F.select();
	       return false;
	   }
   }
   if(Field_F.value.length!=Lengh_F && Key_Up==false)
   {
       if(Heb==true)
                   alert("נא לרשום את ה the right sum of Digits in the "+Field_Name);
       else
               alert("נא לרשום את ה 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("נא לרשום את ה digits only in the "+Field_Name);
       else
               alert("נא לרשום את ה 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("נא לרשום את ה correct phone number 052658741");
	       Field_F.select();
	       return false;
	   }
   if(Field_F.value.length!=Lengh_F && Key_Up==false)
   {
       if(Heb==true)
                   alert("נא לרשום את ה the right sum of Digits in the "+Field_Name);
       else
               alert("נא לרשום את ה the right sum of Digits in the "+Field_Name+" field");
       Field_F.select();
       return false;
   }
   return true;
}
function Validate_FBK(Form_Name)
{
  if(! (Has_Value_Correct_Arr(Form_Name.Name_Fbk,"Name ")) ) return false;
  if(! (Has_Value_Correct_Arr(Form_Name.Title_Fbk,"Subject ")) ) return false;
//  if (!(Validate_letter(Form_Name.Text_Fbk.value,Form_Name.Text_Fbk)))    return false;
  if(Form_Name.Acept.checked==false)
  {
    alert('validate terms and conditions');
  	return false;
  }
  (Form_Name.Email_Fbk.value=='email')?Form_Name.Email_Fbk.value='':'';
  (Form_Name.Address_Fbk.value=='address')?Form_Name.Address_Fbk.value='':'';
  (Form_Name.Text_Fbk.value=='messege')?Form_Name.Text_Fbk.value='':'';

}
function Has_Value_Correct_Arr(Field_F)
{
	var Cur_Form=document.Contact;
	if(Cur_Form.Exist!=undefined)
	{
	    if(Cur_Form.Exist.value=='yes' && Field_F.value!='' )
	    {
	    	return true;
	    }
	}
	for(i=0; i<Name_Array.length; i++)
	{
	  	if(Field_F.value==Name_Array[i] || Field_F.value=='')
	  	{
	     	alert("נא לרשום את ה "+Field_F.value);
	    	Field_F.focus();//מחזיר את הסמן לשדה הטקסט החסר
	     	return false;
		}
	}
   return true;
}
function Has_Value_Correct_Arr_Form(Field_F)
{
	var Cur_Form=document.Contact;
	for(i=0; i<Name_Array.length; i++)
	{
	  	if(Field_F.value==Name_Array[i] || Field_F.value=='')
	  	{
	     	alert("נא לרשום את ה"+Field_F.value);
	    	Field_F.focus();//מחזיר את הסמן לשדה הטקסט החסר
	     	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("נא לרשום את ה digits only in the  "+Field_Name);
       else
               alert("נא לרשום את ה 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("נא לרשום את ה the right sum of Digits in the "+Field_Name);
       else
               alert("נא לרשום את ה 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,"email")) )   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;
}
function Checked_RedioBottons(Feild)
{
  for (i=Feild.length-1; i > -1 ; i--)
  {
   if (Feild[i].checked)
       return true;
  }
  return false;
}
//         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;
                }
        }
        ajaxRequest.open("GET", Which_Page, true);
        ajaxRequest.send(null);
}
function Operate_Page(Which_Page)
{
        ajaxFunction();
        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 Resize_Img(elem, max_WIdth,Max_Height)
{
	if (elem == undefined || elem == null)
		return false;
	if (max_WIdth == undefined)
		max_WIdth = 100;
	if (elem.width > elem.height)
	{
		if (elem.width > max_WIdth)
		{
			elem.width = max_WIdth;
			if (elem.height > Max_Height)
				elem.height = Max_Height;
		}
	}
	else
	{
		if (elem.height > Max_Height)
		{
			elem.height = Max_Height;
			if (elem.width > max_WIdth)
				elem.width = max_WIdth;
		}
	}
	if (elem.height < Max_Height)
	{
	//	elem.style.marginTop=(Max_Height-elem.height)/2 + 'px';
	}
}

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';
	}
 }
}

