/* main js */



var IE = $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent);

var timeout = null;

var flag = false;

var showPU = false;

var popUpID = null;

var timeoutSelect = null;

var text = '';

var oldVal = ' ';



function dateStatus (date, y, m, d) {

    if (date.getTime() < ((new Date()).getTime() - 1000*60*60*24)) {

      return true;

    }

    else if (blockDates && blockDates[y+'-'+(m+1)+'-'+d]) {

      return true;

    }

  return false;

}





$(document).ready(function() {

	dateSelect();

	windowResize();

	$(window).resize(function () {

		if (jQuery.browser.msie) {

			if 	(timeout) clearTimeout (timeout);

			timeout = (function () {windowResize()}, 10)

		}

		windowResize();

		$("#screen").width("auto").height("auto");

		$("#screen").width($("body").width()).height($(document).height());

	});

	

	if ($("#screen").length) {

		$("#screen").bgiframe();

	}

	if (!$.cookie("show_site_info")) {
		$('#siteInfo').show();
	}

//	$("#mainTabs").tabs();

	$("#hotVacansion").tabs();

	$("#group").tabs({selected:0});

	

	if ($("#selectJob").length) eachAddJobRow();

	

	$(window).scroll(function () {

		if (showPU) {

			$(popUpID).css("margin-top", 0-$(popUpID).innerHeight()/2+$(window).scrollTop());

		}

	});

	$('#speciality_dropDown').ajaxdrop({URL:'/sitepages/ajax_get_speciality_list.php?q='});



});





function php_serialize( mixed_value ) {

    // http://kevin.vanzonneveld.net

    // +   original by: Arpad Ray (mailto:arpad@php.net)

    // +   improved by: Dino

    // +   bugfixed by: Andrej Pavlovic

    // +   bugfixed by: Garagoth

    // %          note: We feel the main purpose of this function should be to ease the transport of data between php & js

    // %          note: Aiming for PHP-compatibility, we have to translate objects to arrays

    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);

    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'

    // *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});

    // *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'

 

    var _getType = function( inp ) {

        var type = typeof inp, match;

        var key;

        if (type == 'object' && !inp) {

            return 'null';

        }

        if (type == "object") {

            if (!inp.constructor) {

                return 'object';

            }

            var cons = inp.constructor.toString();

            if (match = cons.match(/(\w+)\(/)) {

                cons = match[1].toLowerCase();

            }

            var types = ["boolean", "number", "string", "array"];

            for (key in types) {

                if (cons == types[key]) {

                    type = types[key];

                    break;

                }

            }

        }

        return type;

    };

    var type = _getType(mixed_value);

    var val, ktype = '';

    

    switch (type) {

        case "function": 

            val = ""; 

            break;

        case "undefined":

            val = "N";

            break;

        case "boolean":

            val = "b:" + (mixed_value ? "1" : "0");

            break;

        case "number":

            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;

            break;

        case "string":

            val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";

            break;

        case "array":

        case "object":

            val = "a";

            /*

            if (type == "object") {

                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);

                if (objname == undefined) {

                    return;

                }

                objname[1] = serialize(objname[1]);

                val = "O" + objname[1].substring(1, objname[1].length - 1);

            }

            */

            var count = 0;

            var vals = "";

            var okey;

            var key;

            for (key in mixed_value) {

                ktype = _getType(mixed_value[key]);

                if (ktype == "function") { 

                    continue; 

                }

                

                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);

                vals += php_serialize(okey) +

                        php_serialize(mixed_value[key]);

                count++;

            }

            val += ":" + count + ":{" + vals + "}";

            break;

    }

    if (type != "object" && type != "array") {

      val += ";";

  }

    return val;

}



function windowResize () {

	var w = $(window).width();

	if ($("#restInfo").is(":visible")) w -=340

	else w -= 25;

	$("#forItems").width(w);

	/*if ($("#body").hasClass("main-layout")) {

		//$(".item-block").width(50000);

		$(".item-block").each(function () {

			$(".item", this).hide();

			for (i = 0; i < parseInt((w+28)/328); i++) {

				$(".item", this).eq(i).css('display','inline-block');
				
				$(".item", this).eq(i).css('_display','inline');

			}

		});

	}*/

	if ($("#body").hasClass("inside-layout")) {

		$("#insideBlock").width(w+28);

	} 

}



function dateSelect () {

	$("#dateCheckbox :checkbox").each (function (i) {

		if ($(this).is(":checked")) {

			$("#dateNameCheck td").eq(i).addClass("active");

		} else {

			$("#dateNameCheck td").eq(i).removeClass("active");

		}

	});

}



function setTextInInput(input, text, deftext) { 

	if($(input).val() == '' || $(input).val() == deftext) {

		$(input).val(text);

	}

}



function showHideOptSearch (curr) {

	if ($("#optionalSearch").is(":hidden")) {

		$("#basicBtnSearch").hide();

		$(curr).addClass("optional-btn-show");

		$("#optionalSearch").show();

	} else {

		$(curr).removeClass("optional-btn-show");

		$("#optionalSearch").hide();

		$("#basicBtnSearch").show();

	}

}



function showHideSearchForm(curr) {

	$(curr).hide();

	$("#searchForm").removeClass("hide-search");

}



function showHideRightCol (btn) {	

	if ($("#restInfo").is(":visible")) {

		$(btn).addClass("btn-col-min-active");

		$("#mainContainer").addClass("right-hide");

		$(btn).attr("title", "Развернуть");

	} else {

		$(btn).removeClass("btn-col-min-active");

		$("#mainContainer").removeClass("right-hide");

		$(btn).attr("title", "Свернуть");

	}

	windowResize();

}



function showHideForm (curr) {

	var form = $(curr).parents(".form").find(".form-content");

	if (form.is(":visible")) {

		$(curr).parents(".form").addClass("form-hide");

	} else {

		$(curr).parents(".form").removeClass("form-hide");

	}

}



function completionPreview (curr, insert) {

	$(curr).bind("keydown keyup mousedown mouseup blur", function () {

		$("#"+insert).html(''+$(curr).val())

	})

}



function iconInPreview (curr, insert) {

	$(curr).bind("keyup mouseup", function () {

		if ($(curr).val() != '') {

			switch (insert) {

				case 'icq': $("#previewIcons img").eq(0).show().attr({title:$(curr).val(), alt:$(curr).val()});

				break;

				case 'skype': $("#previewIcons img").eq(1).show().attr({title:$(curr).val(), alt:$(curr).val()});

				break;

				case 'gtalk': $("#previewIcons img").eq(2).show().attr({title:$(curr).val(), alt:$(curr).val()});

				break;

				case 'mail': $("#previewIcons a").show().attr({href:'mailto:'+$(curr).val()});

				$("#previewIcons img").eq(3).show().attr({title:$(curr).val(), alt:$(curr).val()});

				break;

				default: break;

			}

		} else {

			switch (insert) {

				case 'icq': $("#previewIcons img").eq(0).hide();

				break;

				case 'skype': $("#previewIcons img").eq(1).hide();

				break;

				case 'gtalk': $("#previewIcons img").eq(2).hide();

				break;

				case 'mail': $("#previewIcons a").hide();

				break;

				default: break;

			}

		}

	});

}



function aboutMePreview (curr) {

	$(curr).bind("keydown keyup mousedown mouseup blur", function () {

		if ($(curr).val() != '') {

			$("#preview .no-inform").hide();

			$("#userInformation").show();

			$("#userInformation .instext").html($(curr).val().substring(0,95));

		} else {

			$("#userInformation").hide();

			$("#preview .no-inform").show();

		}

	});

}



function jobInPeriod (curr) {

	if ($(curr).is(":checked")) {

		switch (parseInt($(curr).val())) {

			case 0: 

				$("#gerPeriodForm .week-grid input, #gerPeriodForm .week-grid select, #gerPeriodForm .cycle-grid input").attr("disabled", "disabled");

				$("#preview .calendar li").addClass("active");

			break;

			case 1: 

				$("#gerPeriodForm .cycle-grid input").attr("disabled", "disabled");

				$("#gerPeriodForm .week-grid input").attr("disabled", "");

				$("#preview .calendar li").removeClass("active");

				$("#gerPeriodForm .week-grid input").each(function (i) {

					if ($(this).is(":checked")) {

						$("#preview .calendar li").eq(i).addClass("active");

						$(this).parents("tr:first").find("select").attr("disabled", "");

					} else {

						$("#preview .calendar li").eq(i).removeClass("active");

						$(this).parents("tr:first").find("select").attr("disabled", "disabled");

					}

				})

			break;

			case 2: 

				$("#gerPeriodForm .week-grid input, #gerPeriodForm .week-grid select").attr("disabled",  "disabled");

				$("#gerPeriodForm .cycle-grid input").attr("disabled", "");

				$("#preview .calendar li").addClass("active");

			break;

			default: break;

		}

	}

}



function enabledSelect (curr) {

	if ($(curr).is(":checked")) {

		$("#preview .calendar li").eq($("#gerPeriodForm .week-grid input").index($(curr))).addClass("active");;

		$(curr).parents("tr:first").find("select").attr("disabled", "");

	} else {

		$("#preview .calendar li").eq($("#gerPeriodForm .week-grid input").index($(curr))).removeClass("active");;

		$(curr).parents("tr:first").find("select").attr("disabled",  "disabled");

	}

}



function colorRowJobGrid () {

	$("#myJob table tr").removeClass("blue-row");

	$("#myJob table tr:nth-child(odd)").addClass("blue-row");

}



function showMyJobGrid () {

	if (!$("#myJob table").length) {

		$("#myJob").html('<table><col width="*" /><col width="108px" /><col width="58px" /><col width="148px" /><col width="27px" /><tr><th><h4>Работа</h4></th><th><h4>Форма Оплаты</h4></th><th><h4>Сумма</h4></th><!--th><h4>Валюта</h4></th--><th><h4 class="img"><img src="/images/ico/ico-info.gif" width="16" height="16" alt="" /> Объем работ</h4></th><th><h4>&nbsp;</h4></th></tr></table>');

	}

}



function addJobRow (curr) {

	if ($(curr).is(":checked")) {

		showMyJobGrid();	

		

		var fl = false;

		var checkLabel = $(curr).parents("td:first").find("label").html();

		$("#myJob .species span").each(function () {		

			if ($(this).html() == checkLabel) {

				fl = true;

				return false;

			}

		});

		

		if(!fl){

		$("#myJob table").append('<tr><td class="species"><span class="update">'+$(curr).parents("td:first").find("label").html()+'</span></td><td><input type="hidden" name="job_name[]" value="'+$(curr).parents("td:first").find("label").html()+'"/><select onchange="disableFildsAnket(this)" name="type_oplata[]"><option value="1">Сдельная</option><option value="2">Почасовая</option><option value="3" selected=selected>Договорная</option></select></td><td class="price"><input style="display:none;" type="text" class="text" name="price[]"/></td><td class="volume"><input style="display:none;" type="text" class="text" name="job_about[]"/></td><td><a href="#"><img src="/images/ico/ico-delete.gif" width="16" height="16" alt="Удалить" title="Удалить" onclick="removeMyJob(this); return false;" /></a></td></tr>');

		}

		colorRowJobGrid();

	} else {

		var checkLabel = $(curr).parents("td:first").find("label").html();

		$("#myJob .species span").each(function () {

			if ($(this).html() == checkLabel) {

				$(this).parents("tr:first").remove();	

			}

		});

		if ($("#myJob tr").length == 1) {

			$("#myJob").html('');

		} else {

			colorRowJobGrid();

		}

	}

}



function eachAddJobRow () {

	$("#selectJob .job-grid .j input").each(function () {

		//addJobRow(this)

	});	

}



function addNewJob () {

	var newJob = $("#addNewJob").val();

	var fl = false;

	if (newJob != undefined && (newJob = jQuery.trim(newJob)).length > 0) {

		$("#myJob .species span").each(function () {

			if ($(this).html() == newJob) {

				fl = true;

				return false;

			}

		});

		if (!fl) {

			showMyJobGrid();

			$("#myJob table").append('<tr><td class="species"><span class="update">'+newJob+'</span></td><td><input type="hidden" name="job_id[]"/><input type="hidden" name="job_name[]" value="'+newJob+'"/><select name="type_oplata[]" onchange="disableFildsAnket(this)"><option value="1">Сдельная</option><option value="2">Почасовая</option><option value="3" selected=selected>Договорная</option></select></td><td class="price"><input type="text" style="display:none;" class="text" name="price[]"/></td><td class="volume"><input type="text" style="display:none;" class="text" name="job_about[]"/></td><td><a href="#"><img src="/images/ico/ico-delete.gif" width="16" height="16" alt="Удалить" title="Удалить" onclick="removeMyJob(this); return false;" /></a></td></tr>');

			

			$("#addNewJob").val('');

			$("#myJob table tr").removeClass("blue-row");

			$("#myJob table tr:nth-child(odd)").addClass("blue-row");

		} else {

			alert('Вы уже добавили эту работу.');	

		}

	}

}


function addJobFromInput(){
	$(document).bind('keydown', function(e) {
							if (e == null) { // ie 
								keycode = event.keyCode; 
							} else { // mozilla 
								keycode = e.which; 
							} 
							if(keycode == 13){ // escape, close box 
								addNewJob ();
								return false;
							} 
										 });
}

function addJobLink(){
	addNewJob ();
}

function addSRVJob (newJob) {	

	var fl = false;

	

		$("#myJob .species span").each(function () {

			if ($(this).html() == newJob) {

				fl = true;

				return false;

			}

		});

		if (!fl) {

			showMyJobGrid();

			$("#myJob table").append('<tr><td class="species"><span class="update"><input type="hidden" name="job_name[]" value="'+newJob+'"/>'+newJob+'</span></td><td><select name="type_oplata[]" onchange="disableFildsAnket(this)"><option value="1">Сдельная</option><option value="2">Почасовая</option><option value="3" selected=selected>Договорная</option></select></td><td class="price"><input type="text" class="text" name="price[]"/></td><td class="volume"><input type="text" class="text" name="job_about[]"/></td><td><a href="#"><img src="/images/ico/ico-delete.gif" width="16" height="16" alt="Удалить" title="Удалить" onclick="removeMyJob(this); return false;" /></a></td></tr>');

			

			$("#addNewJob").val('');

			$("#myJob table tr").removeClass("blue-row");

			$("#myJob table tr:nth-child(odd)").addClass("blue-row");

		} else {

			alert('Вы уже добавили эту работу.');	

		}	

}



function removeMyJob (curr) {

	var jobName = $(curr).parents("tr:first").find(".species span").html();

	$("#selectJob .job-grid .j label").each(function () {

		if ($(this).html() == jobName) {

			$(this).parents("td:first").find("input").attr("checked", "");	

		}

	});	

	$(curr).parents("tr:first").remove();

	if ($("#myJob tr").length == 1) {

		$("#myJob").html('');

	} else {

		colorRowJobGrid();

	}

}



function showVacancyGrid () {

	if (!$("#myJob table").length) {

		$("#myJob").html('<table><col width="*" /><col width="108px" /><col width="58px" /><col width="114px" /><col width="90px" /><col width="105px" /><col width="90px" /><col width="90px" /><col width="27px" /><tr><th><h4>Работа</h4></th><th><h4>Форма Оплаты</h4></th><th><h4>Сумма</h4></th><!--th><h4>Валюта</h4></th--><th><h4 class="img"><img src="/images/ico/ico-info.gif" width="16" height="16" alt="" /> Объем работ</h4></th><th><h4>Требования</h4></th><th><h4>Дата\\Время</h4></th><th><h4>Описание</h4></th><th><h4>Группы</h4></th><th><h4>&nbsp;</h4></th></tr></table>');

	}

}

groupsdefault="1";	

function addNewVacancy (defgroups_param) {	
	var newVacancy = $("#addNewVacancy").val();

	var fl = false;

	if (newVacancy != undefined && (newVacancy = jQuery.trim(newVacancy)).length > 0) {

		$("#myJob .species span").each(function () {

			if ($(this).html() == newVacancy) {

				fl = true;

				return false;

			}

		});

		if (!fl) {

			showVacancyGrid();

			var claim = "{sex:2, ageS:0, ageF:100}";			

			



	

			var day = "{type:0, day:{regMonday:{check:0, timeS:0, timeF:24}, regTuesday:{check:0, timeS:0, timeF:24}, regWednesday:{check:0, timeS:0, timeF:24}, regThursday:{check:0, timeS:0, timeF:24}, regFriday:{check:0, timeS:0, timeF:24}, regSaturday:{check:0, timeS:0, timeF:24}, regSunday:{check:0, timeS:0, timeF:24}}, period:{p1:'', p2:''}}";

			var day1 = new Object();

			day1 = eval("("+day+")");

			day2 = php_serialize(day1);

			var claim1 = new Object();

			claim1 = eval("("+claim+")");

			claim2 = php_serialize(claim1);

			groupsdefault = $('#defgroups').val();	

			if(groupsdefault==''){

				groupsdefault = defgroups_param

			}

			var html = '';

			html += '<tr>';

			html += '<td class="species"><span class="update">'+newVacancy+'</span></td>';

			html += '<td><input type="hidden" name="job_id[]" /><input type="hidden" name="job_name[]" value="'+newVacancy+'"/><select onchange="disableFilds(this)" name="type_oplata[]"><option value="1">Сдельная</option><option value="2">Почасовая</option><option value="3" selected=selected>Договорная</option></select></td>';

			html += '<td class="price"><input type="text" class="text" name="price[]" style="display:none;"/></td>';

			//html += '<td class="usd"><select name="currency[]"><option>USD</option><option>EUR</option><option>BYR</option></select></td>';

			html += '<td class="volume"><input type="text" class="text" name="about[]" style="display:none;"/></td>';

			html += '<td class="claim"><input type="hidden" name="claim[]" value="'+claim+'" /><input class="php" type="hidden" name="claimPHP[]" value=\''+claim2+'\'/><a href="#" onclick="changeVacClaim(this); return false;">Нет</a></td>';

			html += '<td class="time"><input type="hidden" name="days[]" value="'+day+'" /><input class="php" type="hidden" name="daysPHP[]" value=\''+day2+'\'/><a href="#" onclick="changeVacPeriod(this); return false;">Всегда</a></td>';

			html += '<td><input type="hidden" name="description[]"/><a href="#" class="description" onclick="changeVacDescription(this); return false;">Нет</a></td>';

			if(groupsdefault!=''){

			html += '<td class="group"><input name="groups[]" type="hidden" value="'+groupsdefault+'"/><a href="#" onclick="changeVacGroup(this); return false;">Есть</a></td>';

			}else{

			html += '<td class="group"><input name="groups[]" type="hidden" value=""/><a href="#" onclick="changeVacGroup(this); return false;">Нет</a></td>';

			}			

			html += '<td><a href="#"><img src="/images/ico/ico-delete.gif" width="16" height="16" alt="Удалить" title="Удалить" onclick="removeMyJob(this); return false;" /></a></td>';

			html += '</tr>';

			$("#myJob table").append(html);

			$("#addNewVacancy").val('');				

			colorRowJobGrid();

			$('#defgroups').val('');

		} else {

			alert('Вы уже добавили вакансию по указанной специальности.');	

		}

	}

}

function addVacancyFromInput(defgroups){
	$(document).bind('keydown', function(e) {
							if (e == null) { // ie 
								keycode = event.keyCode; 
							} else { // mozilla 
								keycode = e.which; 
							} 
							if(keycode == 13){ // escape, close box 
								addNewVacancy(defgroups);
								return false;
							} 
										 });
}

function addVacancyLink(defgroups){
	addNewVacancy(defgroups);
}

function disableFilds (curr) {

	switch(parseInt($(curr).val())) {

		case 1: 

			$(curr).parents("tr:first").find(".price input").show();

			//$(curr).parents("tr:first").find(".usd select").attr("disabled", "");

			$(curr).parents("tr:first").find(".volume input").show();

			break;

		case 2:

			$(curr).parents("tr:first").find(".price input").show();

			//$(curr).parents("tr:first").find(".usd select").attr("disabled", "");

			$(curr).parents("tr:first").find(".volume input").hide();

			break;

		case 3:

			$(curr).parents("tr:first").find(".price input").hide();

			//$(curr).parents("tr:first").find(".usd select").attr("disabled", "disabled");

			$(curr).parents("tr:first").find(".volume input").hide();

			break;

		default : break;

	}

}



function disableFildsAnket (curr) {

	switch(parseInt($(curr).val())) {

		case 1: 

			$(curr).parents("tr:first").find(".price input").show();

			//$(curr).parents("tr:first").find(".usd select").attr("disabled", "");

			$(curr).parents("tr:first").find(".volume input").show();

			break;

		case 2:

			$(curr).parents("tr:first").find(".price input").show();

			//$(curr).parents("tr:first").find(".usd select").attr("disabled", "");

			$(curr).parents("tr:first").find(".volume input").hide();

			break;

		case 3:

			$(curr).parents("tr:first").find(".price input").hide();

			//$(curr).parents("tr:first").find(".usd select").attr("disabled", "disabled");

			$(curr).parents("tr:first").find(".volume input").hide();

			break;

		default : break;

	}

}



function disableFildsSearch (curr) {

	switch(parseInt($(curr).val())) {		

		case 3:

			$("#searchPayFormFrom").attr("disabled", "disabled");

			$("#searchPayFormTo").attr("disabled", "disabled");			

			break;

		default : 

			$("#searchPayFormFrom").attr("disabled", "");

			$("#searchPayFormTo").attr("disabled", "");	

		break;

	}

}







function changeVacClaim (curr) {

	var j = new Object();

	j = eval("("+$(curr).parents('td:first').find('input:hidden').val()+")");

	var $popup = $('#changeСlaim');

	$popup.find("button:submit").unbind('click');

	$popup.find("#sex").val(j.sex);

	$popup.find("#ageS").val(j.ageS);

	$popup.find("#ageF").val(j.ageF);

	showPopUp($popup);

	$popup.find("button:submit").bind('click', $(curr), function () {

		var s = '{sex:'+$popup.find("#sex option:selected").val()+', ageS:'+$popup.find("#ageS option:selected").val()+', ageF:'+$popup.find("#ageF option:selected").val()+'}';

		var j1 = new Object();

		j1 = eval("("+s+")");

		j2 = php_serialize(j1);

		$(curr).parents('td:first').find('input:hidden').val(s);

		$(curr).parents('td:first').find('input.php').val(j2);

		if ($popup.find("#sex option:selected").val() != 2) {

			$(curr).html('Есть');

		} else if ($popup.find("#ageS option:selected").val() != 0) {

			$(curr).html('Есть');

		} else if ($popup.find("#ageF option:selected").val() != 0) {

			$(curr).html('Есть');

		} else {

			$(curr).html('Нет');

		}

		hidePopUp();

		return false;

	})

}









function changeVacPeriod (curr) {

	var j = new Object();	

	j = eval("("+$(curr).parents('td:first').find('input:hidden').val()+")");

	var $popup = $('#changePeriod');

	$popup.find("button:submit").unbind('click');

	$popup.find("input:radio").eq(j.type).attr('checked', 'checked');

	for (dayName in j.day) {

		var $ch = $popup.find('#'+dayName);

		if (j.day[dayName].check == 0) {

			$ch.attr('checked', '');

		} else {

			$ch.attr('checked', 'checked');

		}

		$ch.parents('tr:first').find('select').eq(0).val(j.day[dayName].timeS);

		$ch.parents('tr:first').find('select').eq(1).val(j.day[dayName].timeF);

	}

	jobInPeriod($popup.find("input:radio").eq(j.type));

	$popup.find(".cycle-grid input:text").eq(0).val(j.period.p1);

	$popup.find(".cycle-grid input:text").eq(1).val(j.period.p2);

	

	showPopUp($popup);

	$popup.find("button:submit").bind('click', $(curr), function () {

		var s = '';

		var type = 0;

		$popup.find("input:radio").each(function () {

			if ($(this).is(":checked")) {

				type = $popup.find("input:radio").index(this);				

				s = "{type:"+type+", ";

				return false;

			}

		});

		s += "day:{";

		for (dayName in j.day) {

			var str = '';

			str += dayName+":";

			var $ch = $popup.find('#'+dayName);

			if ($ch.is(":checked")) {

				str += "{check:1, ";

			} else {

				str += "{check:0, ";

			}

			str += "timeS:"+$ch.parents('tr:first').find('select').eq(0).val()+", ";

			str += "timeF:"+$ch.parents('tr:first').find('select').eq(1).val()+"}";

			if (dayName != 'regSunday') str += ", "

			s += str;

		}

		s += "}, period:{p1:'";

		s += $popup.find(".cycle-grid input:text").eq(0).val()+"', p2:'"+$popup.find(".cycle-grid input:text").eq(1).val()+"'}}";		

		var sobj = new Object();

		sobj = eval("("+s+")");

		sstr = php_serialize(sobj);

		$(curr).parents('td:first').find('input:hidden').val(s);

		$(curr).parents('td:first').find('input.php').val(sstr);

		

		if (type == 0) {

			$(curr).html('Всегда');

		} else if (type == 1) {

			$popup.find(".week-grid:first input:checkbox").each(function () {

				if ($(this).is(":checked")) {

					$(curr).html('день недели');

					return false;

				} else {

					$(curr).html('Всегда');

				}

			});

		} else if (type == 2 && ($popup.find(".cycle-grid input:text").eq(0).val() !== '' || $popup.find(".cycle-grid input:text").eq(1).val() !== '')) {

			$(curr).html('период');

		} else {

			$(curr).html('Всегда');

		}

		

		hidePopUp();

		return false;

	});

}



function changeVacDescription (curr) {

	var v = $(curr).parents('td:first').find('input:hidden').val();

	var $popup = $('#changeDescription');

	$popup.find("button:submit").unbind('click');

	$popup.find("#descriptionArea").val(v);

	showPopUp($popup);

	$popup.find("button:submit").bind('click', $(curr), function () {

		var arVal = $popup.find("#descriptionArea").val();

		arVal = jQuery.trim(''+arVal);

		$(curr).parents('td:first').find('input:hidden').val(arVal);

		if (arVal.length > 0) {

			$(curr).html('Есть');

		} else {

			$(curr).html('Нет');

		}

		

		hidePopUp();

		return false;

	})

}



function changeVacGroup (curr) {

	var v = $(curr).parents('td:first').find('input:hidden').val();

	var arr = new Array();

	var $popup = $('#changeGroup');

	$popup.find("button:submit").unbind('click');

	if (v != '') arr = v.split(',');

	$popup.find("input:checkbox").attr('checked', '');

	for (i=0; i<arr.length; i++) {

		$('#group'+arr[i]).attr('checked', 'checked');

	}

	showPopUp($popup);

	$popup.find("button:submit").bind('click', $(curr), function () {

		var s = '';

		var count = 0;

		var a = new Array();

		$popup.find("input:checkbox").each(function () {

			if ($(this).is(":checked")) {

				//a[count]= $(this).attr("id");

				a[count]= $(this).attr("value");

				count++;

			}

		});

		s = a.join(",");

		$(curr).parents('td:first').find('input:hidden').val(s);

		if (count != 0) {

			$(curr).html(count+' группы');

		} else {

			$(curr).html('Нет');

		}

		

		hidePopUp();

		return false;

	})

}





function showNextForm (curr) {

	var formBlock = $(curr).parents(".form").next(".form");

	if ($(formBlock).length) {

		$(formBlock).removeClass("form-hide");

		return false;

	} else {

		alert(1);

	}

}



function showPopUp (el) {

	$("#screen").width($("body").width()).height($(document).height()).show();

	$(el).css("margin-top", 0-$(el).innerHeight()/2+$(window).scrollTop()).show();

	popUpID = $(el);
	
	$(document).bind('keydown', function(e) {
							if (e == null) { // ie 
								keycode = event.keyCode; 
							} else { // mozilla 
								keycode = e.which; 
							} 
							if(keycode == 27){ // escape, close box 
								hidePopUp (); 
							} 
										 });

	showPU = true;

}



function hidePopUp () {

	$(".popup").hide();

	$("#screen").hide();
	$(document).bind('keydown', function(e) {});

	showPU = false;

}







function ajaxSearchAnk () {

	$.ajax({

		url: "test.html",

		cache: false,

		timeout: 30000,

		success: function(html){

			if ($("#restInfo").is(":visible")) {

				var btn = $(".btn-col-min");

				$(btn).addClass("btn-col-min-active");

				$("#mainContainer").addClass("right-hide");

				$(btn).attr("title", "Развернуть");

			}

			$("#body").removeClass('main-layout').addClass('inside-layout');

			$("#centerCol").html(''+html);

			windowResize();

			$("#searchForm").addClass('hide-search');

			$("#showSearchParam").show();

			if (!$(".top-date").length) {

				$("#mainContainer").before('<div class="top-date"><strong>Набор Текста:</strong> <a href="#" class="date">Дата</a> | <a href="#" class="d-red">Оплата</a></div>');

			}

		},

		error: function(){

			ajaxSearchInForm ();

		}

	});	

}



function ajaxSearchVac () {

	$.ajax({

		url: "test-vac.html",

		cache: false,

		timeout: 30000,

		success: function(html){

			if ($("#restInfo").is(":visible")) {

				var btn = $(".btn-col-min");

				$(btn).addClass("btn-col-min-active");

				$("#mainContainer").addClass("right-hide");

				$(btn).attr("title", "Развернуть");

			}

			$("#body").removeClass('main-layout').addClass('inside-layout');

			$("#centerCol").html(''+html);

			windowResize();

			$("#searchForm").addClass('hide-search');

			$("#showSearchParam").show();

			if (!$(".top-date").length) {

				$("#mainContainer").before('<div class="top-date"><strong>Набор Текста:</strong> <a href="#" class="date">Дата</a> | <a href="#" class="d-red">Оплата</a></div>');

			}

		},

		error: function(){

			ajaxSearchInForm ();

		}

	});	

}



function addThisItem (curr,ctype) {

	var v = $('#selectItemArray').val();

	var ar = new Array();

	var id = $(curr).parents('.item:first').attr('id');

	var fl = false;

	if (v.length > 0) {

		ar = v.split(',');

		for (i=0; i<ar.length; i++) {

			if (id == ar[i]) {

				ar.splice(i,1);

				fl = true;

				break;

			}

		}

	}

	if (!fl) {

		ar.splice(0,0, id);

		$(curr).parents('.item:first').find('.check').addClass('check-active');

	} else {

		$(curr).parents('.item:first').find('.check').removeClass('check-active');

	}

	$('#selectItem h4').html(ar.length);

	v = ar.join(',');

	$('#selectItemArray').val(v);

	if (ar.length > 0) {		

		$('#selectItem').show();

	} else {

		$('#selectItem').hide();

	}

	$.cookie(ctype, v,{path:'/'});

}









// Select

function inSelect (curr) {

	$('#selectContent li').removeClass('active');	

	if (jQuery.browser.msie) {

		$('#selectContent').width($(curr).width()+18);

		$('#selectContent .selectContentInside').width($(curr).width()+18);

		$('#selectContent').css('left', 0).css('top', $(curr).innerHeight()+3+'px');

	} else {

		$('#selectContent').width($(curr).width()+20);

		$('#selectContent').css('left', 0).css('top', $(curr).innerHeight()+2+'px');

	}

	text = jQuery.trim($(curr).val().toLowerCase());

	compareInSelect();

	$('#selectContent li').hover(function () {$('#selectContent li').removeClass('active'); $(this).addClass('active')}, function () {$(this).removeClass('active')});

	$('#selectContent li').bind('click', function () {

		$(curr).val($(this).text());

	});

	/*$(document).bind('click', function (event) {

		var ev = $(event.target);

		if (!ev.is('#selectContent') && !ev.is('#searchInput')) {

			$('#selectContent').hide();

			outSelect($(curr));

		}

	});

*/

	$(curr).bind('keyup mousedown', function(e) {

		var ind = null;

		if (e.which == 40) {

			ind = $('#selectContent li').index($('#selectContent li.active'))+1;

			$('#selectContent li').removeClass('active');

			while (!$('#selectContent li').eq(ind).is(':visible') && ind <= $('#selectContent li').length) {

				ind++;

			}

			$('#selectContent li').eq(ind).addClass('active');

		}

		if (e.which == 38) {

			ind = $('#selectContent li').index($('#selectContent li.active'))-1;

			if (ind == -2) ind = $('#selectContent li').length-1; 

			$('#selectContent li').removeClass('active');

			while (!$('#selectContent li').eq(ind).is(':visible') && ind >= 0) {

				ind--;

			}

			$('#selectContent li').eq(ind).addClass('active');

		}

		if (e.which == 13) {

			$('#selectContent li').each(function () {

				if ($(this).hasClass('active')) {

					$(curr).val($(this).text());

					return false;

				}

			});

			outSelect($(curr));

			$(curr).blur();

			return false;

		} else {

			if (timeoutSelect) clearTimeout(timeoutSelect);

			timeoutSelect = setTimeout(function () {

				text = jQuery.trim($(curr).val().toLowerCase());

				if (text.length > 0) {

					compareInSelect();

					if (text.indexOf(oldVal) == -1) {

						oldVal = text;

						$('#ajaxJob').remove();

						ajaxLoadInSelect($(curr));

					}

				} else {

					$('#ajaxJob li').hide();

					$('#defoultJob li').show();

				}

			}, 1000);

		}

	});

}



function outSelect (curr) {

	setTimeout(function () {

		$(curr).unbind('keyup mousedown');

		$(document).unbind('click');

		$('#selectContent').hide();

		return false;

	}, 100);

}



function compareInSelect () {

	var fl = false;

	$('#selectContent li').each(function () {

		if ($(this).text().indexOf(text) == -1) {

			$(this).hide();	

		} else {

			$(this).show();

			fl = true;

		}

	});

	if (fl) {

		$('#selectContent').show();

	} else {

		$('#selectContent').hide();

	}

}



function ajaxLoadInSelect (curr) {

	$.ajax({

		url: "/sitepages/ajax_get_speciality_list.php?q="+curr.val(),

		cache: false,

		timeout: 30000,

		success: function(html){

			var items = new Array();

			items = html.split(',');

			$('#ajaxJob').remove();

			$('#selectContent .selectContentInside').append('<ul id="ajaxJob" class="ajax-job-list"></ul>')

			for (i=0; i<items.length; i++) {

				$('#ajaxJob').append('<li>'+items[i]+'</li>');

			}

			compareInSelect();

			$('#selectContent li').hover(function () {$('#selectContent li').removeClass('active'); $(this).addClass('active')}, function () {$(this).removeClass('active')});

			$('#selectContent li').bind('click', function () {

				$(curr).val($(this).text());

			});

		},

		error: function(){
 
			ajaxSearchInForm ();

		}

	});

}

function toggleInputVal (curr, text, bl) {
 if (!bl) {
  if ($(curr).val() == text) {$(curr).val('');$(curr).css('color','#000000')}
 } else {
  if ($(curr).val() == '') {$(curr).val(text); $(curr).css('color','#cccccc')}
 }
}

// 3 blocks


function hideSiteInfo () {
	$.cookie("show_site_info", true, {expires: 365, path: '/' });
	
	$('#siteInfo').hide();
	
	return false;
}

function switchSiteInfo (id, el) {
	$('div.site-info-content', $('#siteInfo')).hide();
	
	$(el).parents('tr:first').find('td').removeClass('active');
	
	$(el).parents('td:first').addClass('active');
	
	$('#'+id).show();
	
	return false;
}
