var d = document;
var IE = d.all ? true : false;

function getID(id)
{
	return d.getElementById(id);
}

function go(url)
{
	window.location.href = url;
}

function showDIV(id, type)
{
	if(!type)
		type = "block";

	id = getID(id).style;

	if(id.display != "none")
		id.display = "none";
	else
		id.display = type;
}

function addBookmark()
{
	var url = "http://www.coffeeshow.co.il";
	var title = "CoffeeShow יועץ לבחירת מכונת קפה";

	if(window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else if(window.external)
		window.external.AddFavorite(url, title);
	else
		return false;
}

var banners_shown = "block"; //init
function checkBanners()
{
	winW = getWindowWidth();

	if (winW < 1024)
	 	setSideBannersDisplay("none");
	else {
	 	if (banners_shown=="none")
	 		setSideBannersDisplay("block");
	}
}

function setSideBannersDisplay(disp) {
	leftBanners = getID("banners_cont_left");
	if (leftBanners !=null)
		leftBanners.style.display = disp;
		
	rightBanners = getID("banners_cont_right");
	if (rightBanners !=null)
		rightBanners.style.display = disp;
		
	banners_shown = disp;
}

function getWindowWidth() {
	var winW = 1024;

	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  return window.innerWidth;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  return (document.body.offsetWidth + 41); //IE correction
	 }
	}
}
function checkOfficeForm()
{
	var form_object = document.office_form;
	
	if (form_object.employees_num.value == "")
	{
		alert("נא להכניס מספר עובדים");
		return false;
	}
	
	if (form_object.company_name.value == "")
	{
		alert("נא להכניס את שם החברה");
		return false;
	}
	
	if (form_object.contact_phone.value == "")
	{
		alert("נא להכניס טלפון")
		return false;
	}
	
	if (form_object.purchase_type[0].checked || form_object.purchase_type[1].checked || form_object.purchase_type[2].checked)
		form_object.submit();
	else
	{
		alert("נא לסמן סוג מסלול");
		return false;
	}
}

function createCookie(name,value,days) 
{
	if (days) 
	{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
	}
	else 
		var expires = "";
	
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//detect if its a mini site (by checking if the site is loaded in an iframe)
function is_mini()
{	
	
	/*if ($("iframe", parent.document.body).attr('id') == 'mini_iframe') //check if the site is loaded into an iframe
		return true;*/
	
	
	return urlAnchor() == 'mini_iframe';
	
}


function mini()
{

	if (is_mini())
	{
		//hide all the things not needed in the mini site
		
		//$("body").html($("#body").html());
		
		$("#menu").hide();
		$("#top_bar").hide();
		$("#top_bar_img_right").hide();
		$("#top_bar_text_company").hide();
		$("#top_bar_text_moto").hide();
		$("#footer").hide();
		$("h1#title").hide();
		
				
		$("body").css("background", "#fff");
		$("#container").css("border", 0);
		
		//window.setTimeout("resizeFrame()", 500);
		add_mini_links();
	}
	else
	{ //load banners
		$("#banners_cont_left").show();
		$("#banners_cont_right").show();
		$("#ad_horiz").show();
	}
	
}

function add_mini_links()
{
	$("div#container").after('<a href="index.php" class="mini_links">חזרה להתחלה</a>&nbsp;&nbsp;<a href="coffee_map.php" class="mini_links">צפה בכל מכונות הקפה</a><br />');
}

function parentTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
	
	if (parent.document.documentElement) {
	    x1 = parent.document.documentElement.scrollLeft || 0;
	    y1 = parent.document.documentElement.scrollTop || 0;
	}
	
	if (parent.document.body) {
	    x2 = parent.document.body.scrollLeft || 0;
	    y2 = parent.document.body.scrollTop || 0;
	}
	
	x3 = window.parent.scrollX || 0;
	y3 = window.parent.scrollY || 0;
	
	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));
	
	window.parent.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
	
	if (x > 0 || y > 0) {
	    window.setTimeout("parentTop()", 25);
	}
}
	
function resizeFrame() {
	
	var fr = $("#mini_iframe", parent.document.body);
	if (fr.size())
		fr.css('height',document.body.scrollHeight + 70 +"px");

}

function urlAnchor() {
	return unescape(self.document.location.hash.substring(1));
}


$(function() {
	
	window.setTimeout(checkBanners,200); //init call to check banners onload;
	window.onresize = checkBanners; //also check when resizing
	//mini();
	$(window).load(function () {
		mini();
		
	});
});



