$(document).ready(function(){

	//if ($('#jq_message_enter_phone').is(':visible')) {
	  //~ $(document).bind("keydown",function(ev){
			//~ if (in_array(ev.keyCode,[8,112,113,114,115,116,117,118,119,120,121,122,123]))
				//~ return false;
	  //~ });
	   //~ $(document).bind("keyup",function(ev){
			//~ if (in_array(ev.keyCode,[8,112,113,114,115,116,117,118,119,120,121,122,123]))
				//~ return false;
	  //~ });
	//}
	/*Инициализируем форму отправки мобильника*/
	$("#jq_message_enter_phone input[type=text]").bind("keydown",function(ev){
		if (in_array(ev.keyCode,[35,36,37,39,8,9,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105]))
		{
			if (in_array(ev.keyCode,[48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105]))
			{
				if ($(this).val().length>=$(this).attr("maxdigits"))
				{
					return false;
				}
			}else
			{
			}
		}else
		{
			return false;
		}
	});
	$("#jq_message_enter_phone input[type=text]").bind("keyup",function(ev){
		if (in_array(ev.keyCode,[48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105]))
		{
			
				if ($(this).val().length>=$(this).attr("maxdigits"))
				{	
					if ($("#"+$(this).attr("next")) != 'jq_message_enter_phone_submit')
						$("#"+$(this).attr("next")).focus();	
					else
						$(this).focus();
				}
			
		}
	}); 
});
function in_array(needle, haystack, strict)
{  
	var found = false, key, strict = !!strict;  
	for (key in haystack)
	{
		if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle))
		{
			found = true;  
			break;  
		}  
	}  
	return found;  
}  

/* Относится к TB_Window */
function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}
function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}
function showShadow(block_id,old_block_id)
{
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}
	
	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}
	
	$("#"+block_id).css("z-index",101);
	var scr_size = getPageSize();
	var wid = $("#"+block_id).width();
	var hei = $("#"+block_id).height();
	var yScroll = $.browser.msie ? document.documentElement.scrollTop : self.pageYOffset;
	$("#"+block_id).css("z-index","500").css({"left":((scr_size[0]-wid)/2),"top":(yScroll+(scr_size[1]-hei)/2)});
	if (old_block_id.length>0)
		$("#"+old_block_id).hide();
	$("#"+block_id).show();
	/*Ставим фокус*/
	if (block_id=="jq_message_enter_phone")
		$("#"+block_id).find("input[name=phone_1]").focus();
	if (block_id=="jq_message_captcha")
		$("#"+block_id).find("input[name=captcha_code]").focus();
}

