$(function () {	
/*	
$('#content').css( 'min-height', ( $(window).height() - $('header').height() - $('#footer').height() - 75 ) );
	$('#user_content').css( 'min-height', ( $(window).height() - $('header').height() - $('#footer').height() -75 ) );
*/
	//document.href.indexOf(document.location+'#')
	if(window.location.href.indexOf('#')>0){
		if(window.location.href.substr(window.location.href.indexOf('#')+1,window.location.href.length)=='call'){
			hs.htmlExpand( document.getElementById("call"), { objectType: 'iframe', outlineWhileAnimating: true, preserveContent: false, width: 450, height: 500,contentId: 'highslide-html', cacheAjax: false } ); return false;
		}
		if(window.location.href.substr(window.location.href.indexOf('#')+1,window.location.href.length)=='sendmail'){
			hs.htmlExpand( document.getElementById("letter"), { objectType: 'iframe', outlineWhileAnimating: true, preserveContent: false, width: 450, height: 300,contentId: 'highslide-html', cacheAjax: false } ); return false;
		}
	};
	
	$("span.on_a_card").click(function () {
		$(this).blur();
		$("div.atm_list").fadeOut();
		$("div.atm_map").fadeIn("normal");
		showMap();
		$("div.atm_metro").fadeOut();
		$("span.on_a_card").addClass("on_a_card_act");
		$("span.on_a_card_act").removeClass("on_a_card");
		$("span.on_a_card_act").removeClass("default_dashed");
		
		$("span.by_list_act").addClass("by_list");
		$("span.by_list_act").addClass("default_dashed");
		$("span.by_list").removeClass("by_list_act");
		
		$("span.by_metro_act").addClass("by_metro");
		$("span.by_metro").removeClass("by_metro_act");
		$("span.by_metro").addClass("default_dashed");
		
		document.getElementById("by_cash_div").style.visibility="hidden";
		document.getElementById("hours24_div").style.visibility="hidden";
		document.getElementById("ch_cash").style.visibility="hidden";
		document.getElementById("ch24").style.visibility="hidden";
		return false;
	});
	$("span.by_list").click(function () {
		$(this).blur();
		$("div.atm_list").fadeIn("slow");
		$("div.atm_map").hide();
		$("div.atm_metro").hide();
		$("span.by_list").addClass("by_list_act");
		$("span.by_list_act").removeClass("by_list");	
		$("span.by_list_act").removeClass("default_dashed");
		
		$("span.on_a_card_act").addClass("on_a_card");
		$("span.on_a_card").removeClass("on_a_card_act");
		$("span.on_a_card").addClass("default_dashed");
		
		$("span.by_metro_act").addClass("by_metro");
		$("span.by_metro").removeClass("by_metro_act");	
		$("span.by_metro").addClass("default_dashed");
		
		document.getElementById("by_cash_div").style.visibility="visible";
		document.getElementById("hours24_div").style.visibility="visible";
		document.getElementById("ch_cash").style.visibility="visible";
		document.getElementById("ch24").style.visibility="visible";
		
		$("tr.stationclose").show();
		
		return false;
	});
	$("span.by_list_act").click(function () {
		$(this).blur();
		$("div.atm_list").fadeIn("slow");
		$("div.atm_map").hide();
		$("div.atm_metro").hide();
		$("span.by_list").addClass("by_list_act");
		$("span.by_list_act").removeClass("by_list");	
		$("span.by_list_act").removeClass("default_dashed");
		
		$("span.on_a_card_act").addClass("on_a_card");
		$("span.on_a_card").removeClass("on_a_card_act");
		$("span.on_a_card").addClass("default_dashed");
		
		$("span.by_metro_act").addClass("by_metro");
		$("span.by_metro").removeClass("by_metro_act");	
		$("span.by_metro").addClass("default_dashed");
		
		document.getElementById("by_cash_div").style.visibility="visible";
		document.getElementById("hours24_div").style.visibility="visible";
		document.getElementById("ch_cash").style.visibility="visible";
		document.getElementById("ch24").style.visibility="visible";
		
		//$("tr.stationclose").show();
		
		return false;
	});
	$("span.by_metro").click(function () {
		$(this).blur();
		$("div.atm_list").hide();
		$("div.atm_map").hide();
		$("div.atm_metro").fadeIn("slow");
		$("span.by_metro").addClass("by_metro_act");
		$("span.by_metro_act").removeClass("by_metro");
		$("span.by_metro_act").removeClass("default_dashed");
		
		$("span.by_list_act").addClass("by_list");
		$("span.by_list").removeClass("by_list_act");
		$("span.by_list").addClass("default_dashed");
		
		$("span.on_a_card_act").addClass("on_a_card");
		$("span.on_a_card").removeClass("on_a_card_act");
		$("span.on_a_card").addClass("default_dashed");
		
		document.getElementById("by_cash_div").style.visibility="visible";
		document.getElementById("hours24_div").style.visibility="visible";
		document.getElementById("ch_cash").style.visibility="visible";
		document.getElementById("ch24").style.visibility="visible";
		return false;
	});
	
	$(".station").click(function () {
		$(".stationclose").hide();		
		$("."+$(this).attr("id")).show();
		$("div.atm_list").fadeIn("slow");
		$("div.atm_map").hide();

		$("div.atm_metro").hide();
		//$("span.by_list").addClass("by_list_act");		
		//$("span.by_list_act").removeClass("by_list");
		//$("span.by_list_act").removeClass("default_dashed");			
		
		$("span.on_a_card_act").addClass("on_a_card");
		$("span.on_a_card").removeClass("on_a_card_act");
		
		$("span.by_metro_act").addClass("by_metro");
		$("span.by_metro").removeClass("by_metro_act");	
		$("span.by_metro").addClass("default_dashed");
	});
	$(".station_spb").click(function () {
		$(".stationclose").hide();		
		$("."+$(this).attr("id")).show();
		$("div.atm_list").fadeIn("slow");
		$("div.atm_map").hide();
		$("div.atm_metro").hide();
		//$("span.by_list").addClass("by_list_act");
		//$("span.by_list_act").removeClass("by_list");	
		//$("span.by_list_act").removeClass("default_dashed");	
		
		$(".on_a_card_act").addClass("on_a_card");
		$(".on_a_card").removeClass("on_a_card_act");
		
		$("span.by_metro_act").addClass("by_metro");
		$("span.by_metro").removeClass("by_metro_act");	
		$("span.by_metro").addClass("default_dashed");
	});
	$("#ch_cash").change(function () {
		if ($("#ch_cash").attr("checked")==false && $("#ch24").attr("checked")==false){			
			$(".cashyes").show();
			$(".twfour").show();
			updatemap(0,0);			
		}else if($("#ch_cash").attr("checked")==true && $("#ch24").attr("checked")==false){
			$(".twfour").show();
			$(".cashyes").hide();
			updatemap(1,0);	
		}else if($("#ch_cash").attr("checked")==false && $("#ch24").attr("checked")==true){
			$(".cashyes").show();
			$(".twfour").hide();
			$(".cashyes .twfour").show();
			updatemap(0,1);	
		}else if($("#ch_cash").attr("checked")==true && $("#ch24").attr("checked")==true){
			$(".cashyes").hide();
			$(".twfour").hide();
			updatemap(1,1);	
		}
	});
	$("#ch24").change(function () {
		if ($("#ch_cash").attr("checked")==false && $("#ch24").attr("checked")==false){			
			$(".cashyes").show();
			$(".twfour").show();
			updatemap(0,0);	
		}else if($("#ch_cash").attr("checked")==true && $("#ch24").attr("checked")==false){
			$(".twfour").show();
			$(".cashyes").hide();
			updatemap(1,0);	
		}else if($("#ch_cash").attr("checked")==false && $("#ch24").attr("checked")==true){
			$(".cashyes").show();
			$(".twfour").hide();
			$(".cashyes .twfour").show();
			updatemap(0,1);	
		}else if($("#ch_cash").attr("checked")==true && $("#ch24").attr("checked")==true){
			$(".cashyes").hide();
			$(".twfour").hide();
			updatemap(1,1);	
		}
	});
	function updatemap(a,b){
	}
	if(!$.cookie("myCity")){
		//$.cookie("myCity",'Москва', {path: '/', expires: 30 });
		//$.cookie("myCityId", '2', {path: '/', expires: 30 });  
	}
	$("#pseudo_white").text($.cookie("myCity")); 
	
	$(".changeCity").click(function () {
		//$.cookie("myCity", null); 
		$.cookie("myCity", $(this).attr("id"), {path: '/', expires: 30,domain: ".fundservice.ru"});
		$.cookie("myCityId", $(this).attr("alt"), {path: '/', expires: 30,domain: ".fundservice.ru"}); 
		$("#pseudo_white").text($.cookie("myCity")); 
		$("#hide_regions").slideToggle("fast");
	});
	$("div.atm_map").fadeOut();
	$("div.atm_metro").fadeOut();	
	var anketa_opened = false;
	var last_id = 0;
	$("a.styled_a_1").click(function () {
		var asd = $(this);
		if($(this).attr("id")=='vacancy_0'){
			$("#headerformvac").show();
			$("#headerformvac").val("");
		}else{
			$("#headerformvac").hide();
			$("#headerformvac").val("");
		}
		if (last_id == asd.attr("id")) {
			$("#anketa_close").click();
			return false;
		}
		
		last_id = asd.attr("id");
		$("#vacancy_id").val(last_id);
		
		if (anketa_opened)
			$("#anketa").slideUp("normal", function () {
				asd.after($("#anketa"));
				$("#anketa").show();
			});
		else {
			asd.after($("#anketa"));
			$("#anketa").show();
			anketa_opened = true;
		}
		
		return false;
	});
	
	$("#anketa_close").click(function () {
		$("#anketa").slideUp();
		anketa_opened = false;
		last_id = 0;
		
		return false;
	});
	var numobr=0;
	$(".add_this").live("click", function () {
		$(".workit:first>tr").clone().appendTo(".make_it").addClass('todel'+numobr).find(".to_show").attr('todelb',numobr).show();
		if(numobr%2==0)$('.todel'+numobr).addClass('blue');
		numobr++;
		return false;
	});
	
	$(".delete_this").live("click", function () {
		//$(this).parent().parent().parent().detach();
		$('.todel'+$(this).attr('todelb')).detach();
		return false;
	});
	var numobr2=0;
	$(".add_this2").live("click", function () {
		$(".workit2:first>tr").clone().appendTo(".make_it2").addClass('tode2l'+numobr2).find(".to_show2").attr('todel2b',numobr2).show();
		if(numobr2%2==0)$('.tode2l'+numobr2).addClass('blue');
		numobr2++;
		return false;
	});
	
	$(".delete_this2").live("click", function () {
		//$(this).parent().parent().parent().detach();
		$('.tode2l'+$(this).attr('todel2b')).detach();
		return false;
	});
	//---datepicker
	/*var rtime;
		
		$(".data").datepicker({ dateFormat: 'dd.mm.yy' ,
		 beforeShow: function(dateText, inst) { time=getTime($(".data").val()); },
		 onClose: function(dateText, inst) { setTime(); }	 
		 }
		);
		$(".data").keyup(function(){
			getTime(this.value);
			//alert(rtime);
		});
		function setTime(){
			$(".data")[0].value=$(".data")[0].value.replace(/ [0-9]{2}:[0-9]{2}/, "");
			//$(".data")[0].value+=rtime;
		}
		function getTime(str){		
			m=str.match(/ [0-9]{2}:[0-9]{2}/, str);
			rtime=m;
			//alert(rtime);
	}*/
	$(".hide_calendar").click(function(){
		$(".calendar").slideToggle("fast");
	});
	$("#close_my").click(function(){
		$(".calendar").slideToggle("fast");
	});	 
	$(".month").click(function(){
		$(".popup_month").slideToggle("fast");
	});
	$(".year").click(function(){
		$(".popup_year").slideToggle("fast");
	});
	function calendarnews(){
		nyear=$(".year").text();
		nmonth=$(".month").text();
		$.ajax({
			type: "POST",
			url: langu+"/news",
			data: "act=ajax&year="+nyear+"&month="+nmonth,
			success: function(msg){
				document.getElementById("calendardates").innerHTML=msg;
			}
		});
	}
	$(".month_ch").click(function(){
		$(".popup_month").slideToggle("fast");
		$(".month").text($(this).text());
		calendarnews();
	});
	$(".year_ch").click(function(){
		$(".popup_year").slideToggle("fast");
		$(".year").text($(this).text());
		calendarnews();
	});
	function calendarsrnews(){
		nyear=$(".year").text();
		nmonth=$(".month").text();
		$.ajax({
			type: "POST",
			url: "/srnews",
			data: "act=ajax&year="+nyear+"&month="+nmonth,
			success: function(msg){
				document.getElementById("calendardates").innerHTML=msg;
			}
		});
	}
	$(".month_chsr").click(function(){
		$(".popup_month").slideToggle("fast");
		$(".month").text($(this).text());
		calendarsrnews();
	});
	$(".year_chsr").click(function(){
		$(".popup_year").slideToggle("fast");
		$(".year").text($(this).text());
		calendarsrnews();
	});
});
function slideTop(v){
	$('#slide').slideToggle();
	$('#slide2').slideToggle();
}
function capt(){
									        	document.getElementById('captcha').src='/captcha/index.php?'+Math.random();
									        }
											var arr=['ck2','ck5','ck6','ck7','ck8','ck10','ck13','ck18','ck19','ck20','ck21','ck30','ck31','ck32','ck33'];
											function checkFields(){
												var x=0;
												for(i=0;i<document.forms[1].elements.length; i++){
													if(in_array(document.forms[1].elements[i].id, arr)){
														if(document.forms[1].elements[i].value==''){
															document.forms[1].elements[i].style.border='solid 1px red';
															x=1;
														}else{
															document.forms[1].elements[i].style.border='';
														}
													}
												}
												var kcaptcha=document.getElementById('kcaptcha').value;
												$.ajax({
													type: "POST",
													url: "/vacancies",
													data: "act=ajax&kcaptcha="+kcaptcha,
													success: function(msg){
														//document.getElementById("calendardates").innerHTML=msg;
														if(msg=="error"){
															alert("Неправильно введен код с изображения");
															capt();
															return false;
														}
													}
												});
												if(x==1){
													alert('Не все поля заполнены!');
													return false;
												}else{
													//document.forms[1].submit();
													return true;
												}
											}
											function in_array(what, where) {
											    for(var i=0; i<where.length; i++){
											        if(what == where[i]) return true;
											    }
											    return false;
}
