


$(document).ready(function(){

	if(document.frmBuying) {
		recalcAmount();
	}
//switch_window('order');
});

function init() {
	switch_window('aboutme');
	showFlags();
}

function showFlags() {
	document.getElementById("languages").style.display = "inline";
}

function switch_window(id) {

	if(id == "home") id = "aboutme";
	if(id == "order") {
		//location.href = "buying.php";
		location.href = "buy_" + lang_text;
		// will be directed automatically to https
	} else {
		var canvas = document.getElementById("canvas");
	
		// hide all the divs
		var divs = canvas.getElementsByTagName("DIV");
		for(var i=0; i<divs.length; i++) {
			if(divs[i].id && divs[i].id != "") {
				divs[i].style.display = "none";
			}
		}
		// except this one
		document.getElementById(id).style.display = "inline";
		
		// hide scrollbars in "listen" div
		if(id == "listen") {
			canvas.style.overflow = "hidden";
			canvas.style.marginLeft = "-197px";
			canvas.style.bottom = "145px";
		/*} else if (id == "order") {
			canvas.style.overflow = "hidden";
			canvas.style.marginLeft = "-188px";
			canvas.style.bottom = "150px";*/
		} else {
			canvas.style.overflow = "auto";
			canvas.style.marginLeft = "-188px";
			canvas.style.bottom = "150px";
		}
	}
}

function check_code(val){
	$.ajax({
		type: "POST",
		url: "ajax/check_code.php",
		data: "code=" + val,
		dataType: "json",
		success : function(data){
			if (data.is_ok == "false" || data.is_ok == false) { // wrong code
				show_error("div#cdextras span.error");	
				//isOK = false;
			} else { // right code
				switch_window('pdfs'); 
			}
		}
	});
	
}

/*
function check_code(val) {
	//var errmsg = "קוד שגוי. נסו שוב";
	if(val == right_code) {
		switch_window('pdfs'); 
	} else {
		//alert(errmsg);
		//$("div#cdextras span.error").show().delay(3000).fadeOut('slow');	
		show_error("div#cdextras span.error");	
	}
}
*/

function show_error(obj, msg) {
	//$(obj).val = msg;
	$(obj).show().delay(3000).fadeOut('slow');
}

send_msg = function (id) {
	//alert("send_msg");
	if($('#uname').val() && $('#content').val() && $('#uemail').val()) {
		$.get('mail.php?uname=' + $('#uname').val() + '&uphone=' + $('#uphone').val()    + '&usubject=' + $('#usubject').val() + '&ucontent=' + $('#content').val() + '&uemail=' + $('#uemail').val() +'', function(data) {
					
					//alert('Load was performed.');
		});
		switch_window('thanks');
	} else {
		show_error("div#contact span.error");	
	}
}


$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}

// make a click when pressing 'enter' in code entering
$(function() {  
	$("#cdextras #code").keypress(function (e) {  
   	if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
   		$('#btn_check_code').click(); 
   		return false;  
   	} else {  
   		return true;  
   	}  
	});  
});  

function numericValidation(obj) {
	var re = new RegExp(/^[.\d]+$/);
	if (!obj.value.match(re)) {  // not a numeric value
		// remove last typed character
		obj.value = obj.value.substring(0,obj.value.length-1);
	}
}

// hide "in_process" img
function stopProcessAnimation() {
	$("#in_process").hide();
	$("#btn_submit").removeAttr("disabled");
}

