﻿// GLOBAL VARS
var browser			= navigator.appName;
var browserVer		= navigator.appVersion;
//var flashVersion 	= deconcept.SWFObjectUtil.getPlayerVersion();
function isIE(){
	if(browser.indexOf("Internet Explorer")>-1){
		return true;
	}
	return false;
} 
//TO SOLVE THE FLICKERING BACKGROUND-IMAGES IN IE.
/*
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}
*/
/************************************************************/

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
function findPos(obj) {
	//alert("--")
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return [curleft,curtop];
}
function set_products_height(){
	if((getPageSize()[1])>($('mainPart').offsetHeight + 20)){
		$('mainPart').style.height = (getPageSize()[1] - 26)+"px";
		/*
		$('where_we_r').style.position = "absolute";
		$('where_we_r').style.top = 140+"px";
		*/
	}
}

function openWindow(URL) {
	openWin1 = window.open(URL, 'news_window', 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes, copyhistory=yes,top=100,left=200,width=405,height=500');
	openWin1.focus();
}
function ValidContact(){
	if(IsFieldEmpty($('First_Name').value)){
			alert("חובה למלא שם");
			$('First_Name').focus();
			return false
		}
	if(IsFieldEmpty($('Last_Name').value)){
			alert("חובה למלא שם משפחה");
			$('Last_Name').focus();
			return false
		}
	if(IsFieldEmpty($('Phone').value)){
			alert("חובה למלא טלפון");
			$('Phone').focus();
			return false
		}	
	if(IsFieldEmpty($('Email').value)){
			alert("חובה למלא מייל");
			$('Email').focus();
			return false
		}	
	if(!IsMailIllegel($('Email').value)){
			alert("מייל לא חוקי");
			$('Email').focus();
			return false
		}		
	document.form1.submit();	
				
}
function ValidContactRent(){
	if(IsFieldEmpty($('First_Name').value)){
			alert("חובה למלא שם");
			$('First_Name').focus();
			return false
		}
	if(IsFieldEmpty($('Last_Name').value)){
			alert("חובה למלא שם משפחה");
			$('Last_Name').focus();
			return false
		}
	if(IsFieldEmpty($('Phone').value)){
			alert("חובה למלא טלפון");
			$('Phone').focus();
			return false
		}	
	if(IsFieldEmpty($('Email').value)){
			alert("חובה למלא מייל");
			$('Email').focus();
			return false
		}	
	if(!IsMailIllegel($('Email').value)){
			alert("מייל לא חוקי");
			$('Email').focus();
			return false
		}	
	
	if(document.form1.DeviceKind[0].checked){	
		if(document.getElementById('txtdevice__desc').value==""){
			//alert("חובה למלא ערך בשדה אחר")
			//document.form1.txtdevice__desc.focus();
			//return false
			document.form1.DeviceKind[0].value = "אחר"
		}
		else
			document.form1.DeviceKind[0].value = document.getElementById('txtdevice__desc').value
	}
	
				
	document.form1.submit();						
}

var currentcat = 1;
function over_cat(idx, isEnglish){
	if(currentcat!=idx){
		$('btn_cat_'+idx).className = (isEnglish)?'big_btn_on_en':'big_btn_on';
	}
}
function out_cat(idx, isEnglish){
	if(currentcat!=idx){
		$('btn_cat_'+idx).className = (isEnglish)?'big_btn_off_en':'big_btn_off';
	}
}
function click_cat(idx, isEnglish){
	if(currentcat!=idx){
		$('btn_cat_'+currentcat).className = (isEnglish)?'big_btn_off_en':'big_btn_off';
		$('inner_content_'+currentcat).style.display = 'none';
		$('btn_cat_'+idx).className = (isEnglish)?'big_btn_on_en':'big_btn_on';
		$('inner_content_'+idx).style.display = 'inline';
		var innerClass = (isEnglish)?'inner_class_'+idx+'_en':'inner_class_'+idx;
		$('inner_categories').className = innerClass;
		currentcat=idx;
	}
}

function getQueryVariableURL(query) {
	if(query.indexOf("?")==-1){
		return;
	}
  	query = query.split("?")[1];
  	var vars = query.split("&");
	var arr = new Array();
  	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
    	arr.push(pair)
  	} 
	return arr;
}

function insertMovie(showCell, placeMediaIn){
	if(movie_type_id==1){
		openWindow(movieURL);
	}else if(movie_type_id==2){
		if(movieURL.indexOf('.flv')>-1){
			$(showCell).style.display = 'inline';
			var so = new SWFObject("images/atsMoviePlayer.swf", "product_movie", "400", "300", "8", "#000000");
			so.addParam("menu", "false");
			so.addVariable("movieURL", movieURL);
			//so.addParam("movieURL", "http://www.helpexamples.com/flash/video/clouds.flv");
			so.write(placeMediaIn);
		}else{
			movieStr = ''+
			'<object width="400" height="350" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="mediaplayer'+placeMediaIn+'">'+
			'<param name="AutoRewind" value="True">'+
			'<param name="AutoSize" value="0">'+
			'<param name="AutoStart" value="True">'+
			'<param name="ClickToPlay" value="-1">'+
			'<param name="Enabled" value="True">'+
			'<param name="Filename" value="'+movieURL+'"'+
			'<param name="ShowControls" value="True">'+
			'<param name="ShowStatusBar" value="False">'+
			'<param name="ShowDisplay" value="False">'+
			'<param name="uiMode" value="Full">'+
			'<param name="windowlessVideo" value="True">'+
			'<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/mediaplayer/" width="400" height="350" src="'+movieURL+'" filename="'+movieURL+'" autostart="True" showcontrols="True" showstatusbar="False" showdisplay="False" autorewind="True" uiMode="Full"></embed>'+
			'</object>';
			$(showCell).style.display = 'inline';
			$(placeMediaIn).innerHTML = movieStr;
			if(isIE()){
				setTimeout(function(){
						$("mediaplayer'+placeMediaIn+'").play();
					}, 150);
			}
		}
	}else if(movie_type_id==3){
		openWindow(movieURL);
	}else if(movie_type_id==4){	
		var PARAMS = new Array();
		if(movieURL.indexOf('autoplay')==-1 && movieURL.indexOf('http://www.youtube.com/')>-1){
			movieURL = movieURL + "&autoplay=1";
		}else{
			PARAMS = getQueryVariableURL(movieURL);
		}
		$(showCell).style.display = 'inline';
		var so = new SWFObject(movieURL, "product_movie", "400", "300", "8", "#000000");
		if(PARAMS.length>0){
			for(i=0;i<PARAMS.length;i++){
				so.addVariable(PARAMS[i][0], PARAMS[i][1]);
				//console.log(PARAMS[i][0]+" : "+ PARAMS[i][1])
				
			}
		}
		//var so = new SWFObject("http://www.youtube.com/v/H_KdFvLvZIM&hl=en&fs=1&autoplay=true", "product_movie", "400", "300", "8", "#000000");
		so.write(placeMediaIn);
	}
}
// 
var nowPlaying = -1;
function insertMovieList(index, movie_type){
	if(nowPlaying>=0 && nowPlaying!=index){
		var showCell_OLD = $('mediaPlayer_'+nowPlaying);
		var placeMediaIn_OLD = $('moviePlayer_'+nowPlaying);
		$(placeMediaIn_OLD).innerHTML = " ";
		$(showCell_OLD).style.display = 'none';
		nowPlaying = -1;
	}
	if(nowPlaying==index)
		return;
		
	var showCell = $('mediaPlayer_'+index);
	var placeMediaIn = $('moviePlayer_'+index);
	var movieURL = $('path_'+index).value;
	if(movie_type==1){
		openWindow(movieURL);
	}else if(movie_type==2){
		nowPlaying = index;
		if(movieURL.indexOf('.flv')>-1){
			$(showCell).style.display = 'inline';
			var so = new SWFObject("images/atsMoviePlayer.swf", "product_movie", "400", "300", "8", "#000000");
			so.addParam("menu", "false");
			so.addVariable("movieURL", movieURL);
			//so.addParam("movieURL", "http://www.helpexamples.com/flash/video/clouds.flv");
			so.write(placeMediaIn);
		}else{
			movieStr = ''+
			'<object width="400" height="350" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="mediaplayer'+placeMediaIn+'">'+
			'<param name="AutoRewind" value="True">'+
			'<param name="AutoSize" value="0">'+
			'<param name="AutoStart" value="True">'+
			'<param name="ClickToPlay" value="-1">'+
			'<param name="Enabled" value="True">'+
			'<param name="Filename" value="'+movieURL+'"'+
			'<param name="ShowControls" value="True">'+
			'<param name="ShowStatusBar" value="False">'+
			'<param name="ShowDisplay" value="False">'+
			'<param name="uiMode" value="Full">'+
			'<param name="windowlessVideo" value="True">'+
			'<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/mediaplayer/" width="400" height="350" src="'+movieURL+'" filename="'+movieURL+'" autostart="True" showcontrols="True" showstatusbar="False" showdisplay="False" autorewind="True" uiMode="Full"></embed>'+
			'</object>';
			$(showCell).style.display = 'inline';
			$(placeMediaIn).innerHTML = movieStr;
			if(isIE()){
				setTimeout(function(){
						$("mediaplayer'+placeMediaIn+'").play();
					}, 150);
			}
		}
	}else if(movie_type==3){
		openWindow(movieURL);
	}else if(movie_type==4){
		nowPlaying = index;
		if(movieURL.indexOf('autoplay')==-1 && movieURL.indexOf('http://www.youtube.com/')>-1){
			movieURL = movieURL + "&autoplay=1";
		}else{
		
		}
		$(showCell).style.display = 'inline';
		var so = new SWFObject(movieURL, "product_movie", "400", "300", "8", "#000000");
		//var so = new SWFObject("http://www.youtube.com/v/H_KdFvLvZIM&hl=en&fs=1&autoplay=true", "product_movie", "400", "300", "8", "#000000");
		so.write(placeMediaIn);
	}
}
