﻿var hasCalledFromThisPageLoad = false;

function callMeSuccess()
{
	var callMeFormStartObj = document.getElementById("callMeFormStart");
	var callMeFormSuccessObj = document.getElementById("callMeFormSuccess");
	
	
	//hide the form we had
	callMeFormStartObj.style.display='none';
	//hide the text
	document.getElementById("callMeText").style.display='none';
	
	//display the success notice!
	callMeFormSuccessObj.style.display='inline';
}

function toggleCallMeBox()
{
	if (hasCalledFromThisPageLoad)
	{
		document.getElementById("callMeBox").style.display='none';
		return false;
	}
	var callMeFormBoxObj	= document.getElementById("callMeFormBox");
	var callMeTextObj		= document.getElementById("callMeText");
	
	callMeFormBoxObj.style.display = (callMeFormBoxObj.style.display=='none')?'inline':'none';
	callMeTextObj.style.display = (callMeTextObj.style.display=='none')?'inline':'none';
	
	if (callMeFormBoxObj.style.display=='inline') //after toggling, focus on input box if its visible
		document.getElementById("callMeNumber").focus();
}



var ddsitelogo={
	setting: {orientation:2, visibleduration:0, fadeduration:[1000, 500]}, //orientation=1|2|3|4, duration=millisec or 0, fadedurations=millisecs
	offsets: {x:785, y:180},//offset of logo relative to window corner
	logoHTML: '<a style="float:right;" href="#" title="התקשרו אליי עכשיו!" onclick="toggleCallMeBox(); return false;"><img src="images/callme.png" style="width:48px; height:48px; border:0" /></a>\
		<div id="callMeText" style="display: inline; width:93px; float:right;">\
		    <img src="images/callMeTitle.png" alt="יש לך שאלה?" title="יש לך שאלה?" style="margin:0 4px 0 0; width: 67px;" /><br />\
		    <img src="images/callMeText.png" alt="הקש מספר ונתקשר אליך" title="הקש מספר ונתקשר אליך" style="margin:3px 4px 0 0; width: 88px;" />\
		</div>\
		<br style="clear:both" />\
		<div id="callMeFormBox" style="display: inline;">\
			<iframe src="" id="callMeFrame" name="callMeFrame" style="width: 100px; display:none;"></iframe>\
			<div style="width:132px; height:29px; background: url(images/callMeFormBG.png);">\
				<div id="callMeFormStart" style="padding-top:7px;">\
					<form action="callMe_p.asp" method="post" target="callMeFrame">\
						<input type="text" name="callMeNumber" id="callMeNumber" style="float:right; border:0; background:transparent; width:90px; direction:ltr; text-align:center;" maxlength="11" />\
						<input type="image" src="images/callMeGo.png" title="לחץ ונתקשר" style="float:right; cursor:pointer; width:21px; height:16px; border:0;" />\
					</form>\
				</div>\
				<div id="callMeFormSuccess" style="display: none;">\
					<table cellspacing="0" cellpadding="0">\
						<tr>\
							<td><img src="images/callMeSuccess.png" title="מיד נתקשר, המתן" alt="מיד נתקשר, המתן" onclick="toggleCallMeBox();" style="cursor:pointer; width:31px; height:30px; border:0;" /></td>\
							<td style="font-size:13px; padding:0 5px 4px 0;" class="b">מיד נתקשר!</td>\
						</tr>\
					</table>\
				</div>\
			</div>\
		</div>',

	coord: {},

	keepfixed:function(){
		if (!this.cssfixedsupport){
			var $window=jQuery(window)
			var is1or3=/^[13]$/.test(this.setting.orientation)
			var is1or2=/^[12]$/.test(this.setting.orientation)
			var x=$window.scrollLeft() + (is1or3? this.offsets.x : $window.width()-this.$control.width()-this.offsets.x)
			var y=$window.scrollTop() + (is1or2? this.offsets.y : $window.height()-this.$control.height()-this.offsets.y)
			this.$control.css({left:x+'px', top:y+'px'})
		}
	},

	showlogo:function(){
		var mainobj=ddsitelogo
		this.$control.animate({opacity:1}, this.setting.fadeduration[0])
		if (this.setting.visibleduration>0){
			setTimeout(function(){
				mainobj.$control.stop().animate({opacity:0}, mainobj.setting.fadeduration[1], function(){
					jQuery(window).unbind('scroll.fixed resize.fixed')
				})
			}, this.setting.visibleduration+this.setting.fadeduration[0])
		}
	},
	
	init:function(){
		jQuery(document).ready(function($){
			var mainobj=ddsitelogo
			var iebrws=document.all
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
			if (mainobj.cssfixedsupport){
				mainobj.coord[(/^[13]$/.test(mainobj.setting.orientation))? 'left' : 'right']=mainobj.offsets.x
				mainobj.coord[(/^[12]$/.test(mainobj.setting.orientation))? 'top' : 'bottom']=mainobj.offsets.y
			}
			mainobj.$control=$('<div id="callMeBox">'+mainobj.logoHTML+'</div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', opacity:0})
				.css(mainobj.coord)
				.appendTo('body')
			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
			mainobj.keepfixed()
			mainobj.showlogo()
			$(window).bind('scroll.fixed resize.fixed', function(){mainobj.keepfixed()})
		})
	}
}

var screenW = (screen.width)*1;
if (screenW > 850)
    ddsitelogo.init();