$(document).ready(function () {


	
		$('#click_to_call').bind("click", function(e){
		
		
		
		$('#c2c_container').modal({
			overlayCss: {
			backgroundColor: '#000000'
		 }
		});
		resizec2c();
		//$('#phone_error_str_content').hide();
		//showClick2Call();
		$('#c2c_middle').find('#input_phone').focus();
	
			//$('#click_to_call_popup').show();
		
	});
	
	$('.popup_cancel').bind("click", function(e){
		
			
			$('#click_to_call_popup').hide();
		
	});
	$('.popup_go').bind("click", function(e){
		
			
			$('#click_to_call_popup').hide();
		
	});
	

	
	$('#c2c_middle').find('.order_cancel').bind("click", function(e){
		$.modal.close();
	});
	$('#c2c_middle').find('.order_close').bind("click", function(e){
		$.modal.close();
	});
	
	$('#c2c_middle').find('.order_continue').bind("click", function(e){
		var error = false;
		var phone_error = '';
		var phone = '';
	
		
		
		phone = $('#c2c_input_phone')[0].value;
		
		if(!phone){
			error=true;
			phone_error = 'No phone number entered';
		}else{
			var re10digit= /^\d{3}-\d{3}-\d{4}$/;  
			if (!re10digit.test(phone))
			{  	
				error=true;
			 	phone_error = 'Invalid phone number';
			}
		}
		
			if(!error){
				
				c2c_onclick(phone);
			}else{
			
				if(phone_error){
						
						
					$('#c2c_middle').find('#phone_error_str_content').html(phone_error);
					
					$('#c2c_middle').find('#phone_error_str_content').show();
					
					resizec2c();
					
				}
			}
	});
	
	
	$('.input_phone').keypress(function(event){
		
		if(event.keyCode!=8){
			
			if($(this)[0].value.length==3 || $(this)[0].value.length==7){	
				if(event.which!=45){
					$(this)[0].value = $(this)[0].value + '-';
				}
			}
			
		}
		
	});
	
	$('#click_to_call').bind("click", function(e){
		
			
			$('#click_to_call_popup').show();
		
	});
	
	$('.popup_cancel').bind("click", function(e){
		
			
			$('#click_to_call_popup').hide();
		
	});
	$('.popup_go').bind("click", function(e){
		
			
			$('#click_to_call_popup').hide();
		
	});



	$('.footer_link.menu_home').bind("click", function(e){
			
				window.location = "/index.php";
	});
	$('.footer_link.menu_order').bind("click", function(e){
		
				window.location = "https://www.libertynoodle.com/order.php";
	});
	$('.footer_link.menu_private').bind("click", function(e){
		
				window.location = "/private-functions.php";
	});
	$('.footer_link.menu_menu').bind("click", function(e){
		
				window.location = "/menu.php";
	});
	$('.footer_link.menu_careers').bind("click", function(e){
		
				window.location = "/careers.php";
	});
	$('.footer_link.menu_contact').bind("click", function(e){
		
				window.location = "/contact.php";
	});
	$('.footer_link.menu_order').bind("click", function(e){
		
				window.location = "https://www.libertynoodle.com/order.php";
	});
	
	 $(document).keypress(function (e) {
	 	var code = (e.keyCode ? e.keyCode : e.which);
	 if(code == 13) { //Enter keycode
	  		enter_buttons = $("body").find(".enter_button");
	  		//alert(printallmembers(enter_buttons));
	  		//alert(enter_buttons.length);
	  		for(i=0; i<enter_buttons.length; i++){
	  			var isVisible = $(enter_buttons[i]).is(':visible');
	  			//alert(isVisible);
	  			if(isVisible){
	  				$(enter_buttons[i]).click();
	  			}

	  		}
	 }

	});
	
});


	function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function resizec2c(){

	$('#c2c_top').css('width',$('#c2c_middle').width()+40);
	$('#c2c_bottom').css('width',$('#c2c_middle').width()+40);
	$('#c2c_left').css('height',$('#c2c_middle').height()+20);
	$('#c2c_right').css('height',$('#c2c_middle').height()+20);


}

function checkEmail(email) {
	
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	
	if (AtPos == -1 || StopPos == -1) {
		return false;
	}
	return true;

}

function printallmembers( obj ) {
	var str = '';
	for( var memb in obj )
		str += memb + ' = ' + obj[memb] + '\n';
	return str;
}

