﻿/* scrollTo jQuery extention */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('3.R=6(e){7 l=0;7 t=0;7 w=3.a(3.X(e,\'1e\'));7 h=3.a(3.X(e,\'1f\'));7 m=e.L;7 B=e.F;1a(e.S){l+=e.T+(e.8?3.a(e.8.W):0);t+=e.V+(e.8?3.a(e.8.10):0);e=e.S}l+=e.T+(e.8?3.a(e.8.W):0);t+=e.V+(e.8?3.a(e.8.10):0);c{x:l,y:t,w:w,h:h,m:m,B:B}};3.1d=6(e){b(e){w=e.k;h=e.C}f{w=(d.Y)?d.Y:(1.4&&1.4.k)?1.4.k:1.9.L;h=(d.H)?d.H:(1.4&&1.4.C)?1.4.C:1.9.F}c{w:w,h:h}};3.U=6(e){b(e){t=e.i;l=e.A;w=e.r;h=e.D}f{b(1.4&&1.4.i){t=1.4.i;l=1.4.A;w=1.4.r;h=1.4.D}f b(1.9){t=1.9.i;l=1.9.A;w=1.9.r;h=1.9.D}}c{t:t,l:l,w:w,h:h}};3.a=6(v){v=12(v);c 14(v)?0:v};3.16.E=6(s){o=3.17(s);c u.18(6(){n 3.P.E(u,o)})};3.P.E=6(e,o){7 z=u;z.o=o;z.e=e;z.p=3.R(e);z.s=3.U();z.J=6(){1b(z.j);z.j=1c};z.t=(n N).Z();z.M=6(){7 t=(n N).Z();7 p=(t-z.t)/z.o.I;b(t>=z.o.I+z.t){z.J();11(6(){z.q(z.p.y,z.p.x)},13)}f{G=((-g.O(p*g.Q)/2)+0.5)*(z.p.y-z.s.t)+z.s.t;K=((-g.O(p*g.Q)/2)+0.5)*(z.p.x-z.s.l)+z.s.l;z.q(G,K)}};z.q=6(t,l){d.19(l,t)};z.j=15(6(){z.M()},13)};',62,78,'|document||jQuery|documentElement||function|var|currentStyle|body|intval|if|return|window||else|Math||scrollTop|timer|clientWidth||wb|new|||scroll|scrollWidth|||this||||||scrollLeft|hb|clientHeight|scrollHeight|ScrollTo|offsetHeight|st|innerHeight|duration|clear|sl|offsetWidth|step|Date|cos|fx|PI|getPos|offsetParent|offsetLeft|getScroll|offsetTop|borderLeftWidth|css|innerWidth|getTime|borderTopWidth|setTimeout|parseInt||isNaN|setInterval|fn|speed|each|scrollTo|while|clearInterval|null|getClient|width|height'.split('|'),0,{}))

$(function(){
	//DD_roundies.addRule('#addToCart, #buyNow', '15px', true);
	//DD_roundies.addRule('input.roundy, button.roundy, a.roundy', '5px', true);
		   
	$("#header ul li a").hover(function(){
			$(this).parent().addClass("hover");
		},function(){
			$(this).parent().removeClass("hover");
	});
/*
	$('#catalogList a').each(function(){
		$(this).append("<b></b>");
	}).hover(function(){
			$(this).find("b").show();
		},function(){
			$(this).find("b").hide();
	})
	//.lightBox();
*/	
/*
	if( $("#content").hasClass('order') ){
		var t_size = document.forms[0].elements['size'].value = $("#content.order form fieldset.size li.active a").text();
		var t_color = document.forms[0].elements['color'].value = $("#content.order form fieldset.color li.active a").text();
	
		$("#content.order form fieldset.size li a").click(function(){
			$(this).parent().addClass("active").siblings().removeClass("active");
			document.forms[0].elements['size'].value = this.innerHTML;
		});
		
		$("#content.order form fieldset.color li a").click(function(){
			$(this).parent().addClass("active").siblings().removeClass("active");
			document.forms[0].elements['color'].value = this.innerHTML;
		});
	}
*/
});

/* View page */

function changed_selected_color(sizeName) {
	$("ul." + sizeName).eq(0).addClass("active").siblings().removeClass("active");
	$("ul." + sizeName + " li").removeClass("active");
	colorName = $("ul." + sizeName + " li").eq(0).text();
	$('#color input').val(colorName);
}

if( $("#content").hasClass("view") ){
	
	// select sizes and change the colors to match
	$('#size > ul > li > a').click(function(){
		var sizeName = this.innerHTML;
		$('#size input').val(sizeName);
		$(this).parent().addClass("active").siblings().removeClass("active");
		$('#color').find("ul."+sizeName).fadeIn("150").siblings("ul").hide();
		changed_selected_color(sizeName);
	}).eq(0).trigger("click");
	
	// select colors
	$('#color > ul > li > a').click(function(){
		var colorName = this.innerHTML;
		$('#color input').val(colorName);
		$(this).parent().addClass("active").siblings().removeClass("active");
	}).eq(0).trigger("click");
	
	$('#sizeChartBtn').toggle(function(){
		$('#sizeChartBtn').html('סגור טבלה');
		//$('#imageBox div.sizeChart').show();
		$('#imageBox img:first').fadeTo(220,0, function(){
			$('#imageBox div.sizeChart').fadeIn('fast');
		});
	},function(){ 
		$('#sizeChartBtn').html('טבלאת מידות');
		$('#imageBox div.sizeChart').fadeOut('fast', function(){
			$('#imageBox img:first').fadeTo(220,1);
		});
	});
}

$.fn.center = function () {
	this.css("position","absolute");
	this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
	this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
	return this;
}

function userMessage(text){
	var box = $('<div class="alert roundy shadow">' + text + '</div>');
	
	box.appendTo("body").center().fadeIn(300,function(){
		var that = $(this);
		setTimeout(function(){ that.fadeOut(900); }, 1000);
	});
}

$(document).ready(function()
{
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('').fadeIn(1000);
		userMessage('בודק נתונים....');
		//check the username exists or not from ajax
		$.post("ajax_login.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{
			  //add message and change the class of the box and start fading
			  $(this).html('').addClass('messageboxok').fadeTo(900,1,
              function()
			  {
			  	 //redirect to secure page
				 document.location='index.php';
			  });
			  			 userMessage('מתחבר.....');
 
			});
		  }
		  else
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{
			  //add message and change the class of the box and start fading
			 // $(this).html('שם משתמש / סיסמה שגויים').addClass('messageboxerror').fadeTo(900,1);
			 userMessage('שם משתמש / סיסמה שגויים');
			});
          }
 
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from
	$("#password").blur(function()
	{
		$("#login_form").trigger('submit');
	});
});

$('#leave1').click(function() {
	gostep(1);
});

$('#leave2').click(function() {
	gostep(2);
});
$('#leave3').click(function() {
	gostep(3);
});
function gostep(x) {
	if (x == 1) {
		document.getElementById('leave1').className = 'btn status active';
		document.getElementById('leave2').className = 'btn status';
		document.getElementById('leave3').className = 'btn status';
		$(".step2").hide();
		$(".step3").hide();
		$(".step1").show();
		document.getElementById( "nextStep" ).onclick = function() {gostep(2)}
		window.setTimeout("document.getElementById('nextStep').innerHTML = 'המשך לשלב הבא'", 30);
	}
	if (x == 2) {
		// quick reference
		var name = document.frmCheckout.name;var email = document.frmCheckout.email;var address = document.frmCheckout.address;
		// reset bg colors
		name.style.borderColor = email.style.borderColor = address.style.borderColor = '#98988a';
		// start validating:
		if(notEmpty(name)) {
			if (emailValidator(email)) {
				if (notEmpty(address)) {
					document.getElementById('leave2').className = 'btn status active';
					document.getElementById('leave1').className = 'btn status';
					document.getElementById('leave3').className = 'btn status';
					$(".step1").hide();
					$(".step3").hide();
					$(".step2").show();
					document.getElementById( 'nextStep' ).onclick = function() {gostep(3)};
					window.setTimeout("document.getElementById('nextStep').innerHTML = 'המשך לשלב הבא'", 30);					
				}
			}
		}
	}
	if (x == 3) {

		// check page 1
		// quick reference
		var name = document.frmCheckout.name;var email = document.frmCheckout.email;var address = document.frmCheckout.address;
		// reset bg colors
		name.style.borderColor = email.style.borderColor = address.style.borderColor = '#98988a';
		// start validating:
		if(notEmpty(name)) {
			if (emailValidator(email)) {
				if (notEmpty(address)) {
					// check page 2
					document.getElementById('leave2').className = 'btn status active';
					document.getElementById('leave1').className = 'btn status';
					document.getElementById('leave3').className = 'btn status';
					$(".step1").hide();
					$(".step3").hide();
					$(".step2").show();
					document.getElementById( "nextStep" ).onclick = function() {gostep(3)}
					window.setTimeout("document.getElementById('nextStep').innerHTML = 'המשך לשלב הבא'", 30);
					// quick reference
					var name2 = document.frmCheckout.name2;var address2= document.frmCheckout.address2;
					// reset bg colors
					name2.style.borderColor = address2.style.borderColor = '#98988a';
					// check for shipping information:
					if (!document.frmCheckout.send_to_me.checked) {
						// start validating:
						if(notEmpty(name2)) {
							if(notEmpty(address2)) {
								document.getElementById('leave3').className = 'btn status active';
								document.getElementById('leave1').className = 'btn status';
								document.getElementById('leave2').className = 'btn status';
								$(".step1").hide();
								$(".step2").hide();
								$(".step3").show();
								document.getElementById( "nextStep" ).onclick = checkShippingAndPaymentInfo;
								window.setTimeout("document.getElementById('nextStep').innerHTML = 'בצע הזמנה'", 30);
							}
						}
					} else {
						document.getElementById('leave3').className = 'btn status active';
						document.getElementById('leave1').className = 'btn status';
						document.getElementById('leave2').className = 'btn status';
						$(".step1").hide();
						$(".step2").hide();
						$(".step3").show();
						document.getElementById( "nextStep" ).onclick = checkShippingAndPaymentInfo;
						window.setTimeout("document.getElementById('nextStep').innerHTML = 'בצע הזמנה'", 30);
					}
				}
			}
		}
	}
}
