
function showCounter() {
		document.write("<a href='http://www.liveinternet.ru/click' "+
				"target=_blank><img src='http://counter.yadro.ru/hit?t15.6;r"+
				escape(document.referrer)+((typeof(screen)=="undefined")?"":
					";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
						screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
				";"+Math.random()+
				"' alt='' title='LiveInternet: показано число просмотров за 24"+
				" часа, посетителей за 24 часа и за сегодня' "+
				"border='0' width='88' height='31'><\/a>")
}

function init() {
	
	
	addCalendar("date_range_from_field");
	addCalendar("date_range_to_field");

	addCalendar("departure_field");
	addCalendar("return_field");

	addCalendar("visa_open_date_field");

	addCalendar("date_hotel_from_field");
	addCalendar("date_hotel_to_field");

	//addOnlyNumber("num_adult_field");
	//addOnlyNumber("num_children_field");
	//addOnlyNumber("ppl_num_field");

	addHelper("where_country_field", null);
	addHelper("where_from_country_field", null);
	addHelper("where_country_to_field", null);
	addHelper("where_country_in_field", null);
	addHelper("where_to_country_field", null);

	addHelper("where_location_field", "where_country_field");
	addHelper("where_from_city_field", "where_from_country_field");
	addHelper("where_to_city_field", "where_to_country_field");
	addHelper("where_location_to_field", "where_country_to_field");

	addHelper("payment_city_field","-1");

	addHelper("company_city_field", "-1");
	addHelper("reg_company_city_field", "-1");

	addCalendar("admDateFrom");
	addCalendar("admDateTo");

	addCheckElem("submit2_button");
	
	//addCheckInfo("checkInfo");
	//addNetBuy("tender_netbuy_possible");
	
	addDoLoadOnEnter();
	
	//addOnlyNumber('phone_code_field');
	
	addDirectionsCheck();
	
	addHoverIE6('tenderMenu', 'tenderMenuHover');
	
	if (document.getElementById('regform_password1_field')) {
	check_lengthpwd();
	check_password();
	}
	
	if (vdata = validateData[document.location.pathname.split('/').join('')]) {
		validateForm(vdata);
	}
	$('form').bind('submit', null, function () { return validateAllElements();} );

}

function inputHint(element, text, flag) {

	if (!flag&&text==element.value) {
		element.value = '';
		element.style.fontWeight = "normal";
		
	} else {
		if (element.value=='') {
			element.value = text;
			element.style.fontWeight = "bold";
		}
	}
}


// функция для вставки javascript файлов в DOM

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

// подключение параметров валидации для страниц 
include_dom('/js/validate_config.js');
include_dom('/js/validate.js');


function addHoverIE6(elementID, hoverClass) {
  	if (element=document.getElementById(elementID)) {
		element.onmouseover = function(){
			element.className += ' '+hoverClass;
		}
		element.onmouseout = function(){
			element.className = element.className.replace(' '+hoverClass, '');
		};
	}
	
}

function addCheckElem(elemID) {
	if (document.getElementById(elemID)) {
		document.getElementById(elemID).onclick=function(){checkElemStatus(elemID)};
	}
}

function addElementFocus(elementID, highlightID, type, color, element) {
	if (element) {
			element.onmousedown=function(){checkFormElementsClear(elementID, highlightID, type, color)};
	}
}


function checkFormElementsClear(elementID, highlightID, type, color) {
			document.getElementById(highlightID).style.background = color;
}


function checkFormElements(elementID, highlightID, type, formID, curColor, newColor) {
 	if (form = document.getElementById(formID)) {
		switch (type) {
			case "checkbox":
				
				for (var i = 0; i < form.elements.length; i++) {
					element = form.elements[i];
					//element.getAttribute('name');
					
					elementName = element.nodeName.toLowerCase();
					curElementID = element.id || element.getAttribute('name').toLowerCase(); 
					
					if (elementID.test(curElementID)&&element.type=='checkbox') {
						addElementFocus(curElementID, highlightID, type, curColor, element);
						if (element.checked) {
							document.getElementById(highlightID).style.background=curColor;
							return true;
						}
					}
				}
				document.getElementById(highlightID).style.background=newColor;
				return false;
			break;
			case "text":
				if (element=document.getElementById(elementID)) {
				//	if (element.required||element.required==null||navigator.appName=="Opera") {
					addElementFocus(elementID, highlightID, type, curColor, element);
					if (element.value=='') {
						document.getElementById(highlightID).style.background=newColor;
						return false
					}
					document.getElementById(highlightID).style.background=curColor;
				//	}
				}
			
			return true;
			break;
		
		} 
	} else {
		return false;
	}
}


function checkElemStatus(elemID) {
	validateCheck=true;
	
	if (document.getElementById("tender_tour")){
		if (document.getElementById("where_country_field")) {
			validateCheck&=checkFormElements("where_country_field","where_country_field","text","form_tender", "#fffdc0" , "#f37a7a");
		}
		if (document.getElementById("hotel_name_field")) {
			validateCheck&=checkFormElements("hotel_name_field","hotel_name_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("date_range_from_field")) {
			validateCheck&=checkFormElements("date_range_from_field","date_range_from_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("date_range_to_field")) {
			validateCheck&=checkFormElements("date_range_to_field","date_range_to_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
	}
	
	if (document.getElementById("tender_ticket")){
		if (document.getElementById("where_from_country_field")) {
			validateCheck&=checkFormElements("where_from_country_field","where_from_country_field","text","form_tender", "#fffdc0" , "#f37a7a");
		}
		if (document.getElementById("where_from_city_field")) {
			validateCheck&=checkFormElements("where_from_city_field","where_from_city_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("where_to_country_field")) {
			validateCheck&=checkFormElements("where_to_country_field","where_to_country_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("where_to_city_field")) {
			validateCheck&=checkFormElements("where_to_city_field","where_to_city_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("departure_field")) {
			validateCheck&=checkFormElements("departure_field","departure_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("return_field")) {
			validateCheck&=checkFormElements("return_field","return_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
	}
	
	if (document.getElementById("tender_hotel")){
		if (document.getElementById("where_country_to_field")) {
			validateCheck&=checkFormElements("where_country_to_field","where_country_to_field","text","form_tender", "#fffdc0" , "#f37a7a");
		}
		if (document.getElementById("where_location_to_field")) {
			validateCheck&=checkFormElements("where_location_to_field","where_location_to_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("hotel_name_field")) {
			validateCheck&=checkFormElements("hotel_name_field","hotel_name_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("num_adult_field")) {
			validateCheck&=checkFormElements("num_adult_field","num_adult_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("date_hotel_from_field")) {
			validateCheck&=checkFormElements("date_hotel_from_field","date_hotel_from_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("date_hotel_to_field")) {
			validateCheck&=checkFormElements("date_hotel_to_field","date_hotel_to_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
	}
	
	if (document.getElementById("tender_visa")){
		if (document.getElementById("where_country_in_field")) {
			validateCheck&=checkFormElements("where_country_in_field","where_country_in_field","text","form_tender", "#fffdc0" , "#f37a7a");
		}
		if (document.getElementById("visa_type_field")) {
			validateCheck&=checkFormElements("visa_type_field","visa_type_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("visa_open_date_field")) {
			validateCheck&=checkFormElements("visa_open_date_field","visa_open_date_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
		if (document.getElementById("visa_period_field")) {
			validateCheck&=checkFormElements("visa_period_field","visa_period_field","text","form_tender", "#fffdc0", "#f37a7a");
		}
	}
	
	if(document.getElementById("checkInfo")&&document.getElementById("phone_number_field")&&document.getElementById("phone_code_field")) {
		if (!document.getElementById("checkInfo").checked) {
				if (document.getElementById("phone_number_field").value!=""||document.getElementById("phone_code_field").value!=""){
					checkFormElements("phone_number_field","phone_number_field","text","form_tender", "#fffdc0", "#f37a7a");
					checkFormElements("phone_code_field","phone_code_field","text","form_tender", "#fffdc0", "#f37a7a");
	
					document.getElementById("checkInfoDesc").style.color="red";
					validateCheck&=false;
				} else {
					document.getElementById("phone_code_field").style.background="#ececec";
					document.getElementById("phone_number_field").style.background="#ececec";
					document.getElementById("checkInfoDesc").style.color="black";
				}

		} else {
			validateCheck&=checkFormElements("phone_number_field","phone_number_field","text","form_tender", "#fffdc0", "#f37a7a");
			validateCheck&=checkFormElements("phone_code_field","phone_code_field","text","form_tender", "#fffdc0", "#f37a7a");
			document.getElementById("checkInfoDesc").style.color="#000";
		}
	}
	
	if(document.getElementById("tender_netbuy_possible")&&document.getElementById("payment_city_field")) {
		if (form = document.getElementById('form_tender')) {
			for (var i = 0; i < form.elements.length; i++) {
				element = form.elements[i];
				curElementID = element.id || element.getAttribute('name').toLowerCase(); 
					
				if (curElementID == 'tender_netbuy_possible'&&element.type=='checkbox') {
			
					if (!element.checked) {
						validateCheck&=checkFormElements("payment_city_field","payment_city_field","text","form_tender", "#fffdc0", "#f37a7a");
						validateCheck&=checkFormElements("payment_area_field","payment_area_field","text","form_tender", "#fffdc0", "#f37a7a");
					} else {
						document.getElementById("payment_city_field").style.background = "#fffdc0";
						document.getElementById("payment_area_field").style.background = "#fffdc0";
						validateCheck&=true;
					}
				}
			}
		}
	}
		
	if (validateCheck) {
		document.getElementById("form_tender").submit();
	}

}

function addCheckInfo(elementID) {
	if(document.getElementById(elementID)) {
		document.getElementById(elementID).onclick=function(){
			
			if (document.getElementById(elementID).checked) {
				document.getElementById("checkInfoDesc").style.color="#000";
			}
		}
	}
}

function addNetBuy(elementID) {
	if (form = document.getElementById('form_tender')) {
		for (var i = 0; i < form.elements.length; i++) {
			element = form.elements[i];
			curElementID = element.id || element.getAttribute('name').toLowerCase(); 
			if (curElementID == elementID&&element.type=='checkbox') {
				element.onclick=function(){
					if (!document.getElementById(elementID).checked) {
						document.getElementById("netbuy_possible_text").style.color="#000";
						document.getElementById("payment_city_field").style.background = "#fffdc0";
						document.getElementById("payment_area_field").style.background = "#fffdc0";
					} else {
						document.getElementById("payment_city_field").style.background = "#fffdc0";
						document.getElementById("payment_area_field").style.background = "#fffdc0";
					}
				}
			}
		}
	}

}


function removeHelper(stepRH) {
	if (stepRH=="1") {
		document.getElementById('helperOut').style.display='none'
	}
	else
	{
		var t=setTimeout("removeHelper(1)",500);
	}
}


function addHelper(elemID1, elemID2) {
	if (document.getElementById(elemID1)) {
		$('#'+elemID1).attr('autocomplete','off');
		$('#'+elemID1).bind('keyup', {_elemID1:elemID1, _elemID2:elemID2}, helper);
		//document.getElementById(elemID1).onkeypress=helper(elemID1, elemID2);
		document.getElementById(elemID1).onblur=function(){removeHelper(0)};
	}
}

function addOnlyNumber(elemID) {
	if (document.getElementById(elemID)) {
		document.getElementById(elemID).onkeypress=function(){onlyNumber()};
	}
}

function onlyNumber() {
	if ((event.keyCode < 48) || (event.keyCode > 57) && (event.keyCode != 43))  event.returnValue = false;
	
} 

function noKeyPress() {
//	event.returnValue = false;
//	this.blur();
}


function addCalendar(elemID) {
	if (document.getElementById(elemID)) {
		document.getElementById(elemID).onclick=function(){if (document.getElementById('calendarDiv')) closeCalendar(); displayCalendar(this,'dd.mm.yyyy',this)};
		//document.getElementById(elemID).onblur=function(){if (document.getElementById('calendarDiv')) closeCalendar()};
		document.getElementById(elemID).onkeypress=function(){noKeyPress()};
		
	}
}

function helper(e) {

	e=e||window.event;
	$('#'+e.data._elemID1).attr('autocomplete','off');
	
	e=e||window.event;
	
	if ((e.keyCode<37 || e.keyCode>40) && e.keyCode!=13 &&e.keyCode!=27 && $('#'+e.data._elemID1).val().length>1)
	    //|| e.keyCode==8)
	{
		var t=setTimeout("helperAJAX('"+e.data._elemID1+"', '"+e.data._elemID2+"')",50);
        }
        else 
		if (e.keyCode==13)
		{
			e.cancelBubble=true;
			e.returnValue=false;
			e.preventDefault();
			e.stopPropagation();
			return false;
		}
}

function getAbsY(inputObj)
{
	  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
	    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	      return returnValue;
}

function getAbsX(inputObj)
{
	  var returnValue = inputObj.offsetLeft;
	    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	      return returnValue;
}


function switchHelperItem(e)
{
	
	//sorry. jquery here!
	
	elem=e.data.elementID;
	
	kcode=e.keyCode;
	
	if ( $('#helperOut').css('display')!='none')
	{
	
		selected=$('#helperOut .helperListItem.selected');
		if (kcode==40)
		{
			if (selected.length==0)
			{
				$('#helperOut .helperListItem:first').addClass('selected');
			}
			else
			{
				$('#helperOut .helperListItem').removeClass('selected');
				selected.next().addClass('selected');
			}
		}
		else
		if (kcode==38)
		{
			if (selected.length==0)
			{
				$('#helperOut .helperListItem:last').addClass('selected');
			}
			else
			{
				$('#helperOut .helperListItem').removeClass('selected');
				selected.prev().addClass('selected');
			}
		}
		else	
			if (kcode==13 && $('#helperOut .helperListItem.selected').length!=0)
			{
				$('#'+elem).val( $('#helperOut .helperListItem.selected a').attr('value'));
				$('#helperOut').hide();
				removeHelper(0);
				$('#'+elem).unbind('keypress');
				e.cancelBubble=true;
				e.returnValue=false;
				
				e.preventDefault();

			}
			
		else 
			if (kcode==27)
			{
				removeHelper(0);
				$('#'+elem).unbind('keypress');
			}
			
		e=null;
	}
	else
	{
		$('#'+elem).unbind('keypress');
	}
	
	return false;
	
}

function helperAJAX(elemID1, elemID2) {	

	
	fromCity=0;
	var req = new Subsys_JsHttpRequest_Js(); 
	req.onreadystatechange = function() { 
		if (req.readyState == 4) { 
			if (req.responseJS) { 
				resultResponseArray=req.responseJS["region"];
				if (resultResponseArray["resultCount"]!=0) {
					document.getElementById('helperOut').style.top="1px";
					document.getElementById('helperOut').style.left="1px";
					switch(elemID1)
					{
						case "where_country_field":
							document.getElementById('helperOut').style.top="86px";
							document.getElementById('helperOut').style.left="91px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_from_country_field":
							document.getElementById('helperOut').style.top="86px";
							document.getElementById('helperOut').style.left="91px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_country_to_field":
							document.getElementById('helperOut').style.top="86px";
							document.getElementById('helperOut').style.left="91px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_country_in_field":
							document.getElementById('helperOut').style.top="86px";
							document.getElementById('helperOut').style.left="91px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_location_field":
							document.getElementById('helperOut').style.top="86px";
							document.getElementById('helperOut').style.left="459px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_from_city_field":
							document.getElementById('helperOut').style.top="86px";
							document.getElementById('helperOut').style.left="459px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_to_country_field":
							document.getElementById('helperOut').style.top="217px";
							document.getElementById('helperOut').style.left="91px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_to_city_field":
							document.getElementById('helperOut').style.top="217px";
							document.getElementById('helperOut').style.left="459px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "where_location_to_field":
							document.getElementById('helperOut').style.top="86px";
							document.getElementById('helperOut').style.left="462px";
							document.getElementById('helperOut').style.width="334px";
							document.getElementById('helperOut').style.display="inline";
							break;    
						case "company_city_field":
							obj = document.getElementById(elemID1);
							document.getElementById('helperOut').style.top="265px";
							document.getElementById('helperOut').style.left="410px";
							document.getElementById('helperOut').style.width="391px";
							document.getElementById('helperOut').style.display="inline";
							break;    							
							
						case "reg_company_city_field":
							obj = document.getElementById(elemID1);
							document.getElementById('helperOut').style.top="492px";
							document.getElementById('helperOut').style.left="460px";
							document.getElementById('helperOut').style.width="333px";
							document.getElementById('helperOut').style.display="inline";
							break;
							
						default:
							obj = document.getElementById(elemID1);
							document.getElementById('helperOut').style.top=getAbsY(obj)-148+"px";
							document.getElementById('helperOut').style.left="91px";
							document.getElementById('helperOut').style.width="334px";

							document.getElementById('helperOut').style.display="inline";
							fromCity=1;
							break;
					}

					htmlResult="";
					for (i=1;i<=resultResponseArray["resultCount"];i++)
					{
						htmlResult=htmlResult+"<div class=\"helperListItem\" OnClick=\"document.getElementById('" + elemID1 + "').value='" + resultResponseArray["resultName"+i] + "'; document.getElementById('helperOut').style.display='none';\"><a value=\"" + resultResponseArray["resultName"+i] + "\">"+resultResponseArray["resultNameHL"+i]+"</a></div>";
					}
					
					if (resultResponseArray['resultCount']>=0)
					{
						$('#'+elemID1).bind("keyup", {elementID:elemID1}, switchHelperItem);
					}

					document.getElementById('helperOut').innerHTML=htmlResult;

				}
				else
				{
					document.getElementById('helperOut').style.display="none";
					document.getElementById('helperOut').innerHTML="";
				}
			} 
		} 
        } 

	req.caching = false; 

	paramName1=document.getElementById(elemID1).value;

	if (elemID2!="null") {

		if (document.getElementById(elemID2)) {
			paramName2=document.getElementById(elemID2).value;
		} else {
			paramName2=elemID2;
		}
		if (elemID2=="-1") {

			if (elemID1=="company_city_field") {
				
				req.open('POST', '/agent/fromcity', true);
				
			} else {

				req.open('POST', '/tender/fromcity', true);
				
			} 
			
		}
		else
		{
			
			req.open('POST', '/tender/city', true); 
		}
		req.send({region: paramName2, text: paramName1}); 
	}
	else
	{		
		req.open('POST', '/tender/region', true); 
		req.send({text: paramName1}); 
	}
	$('#helperOut').mouseover( function() { $('#helperOut .helperListItem').removeClass('selected'); });
}

function switchLoginRegistration(lr) {
	if (lr=='login') {
		document.getElementById('loginFormN').style.display="inline";
		document.getElementById('registrationFormN').style.display="none";

	}
	else
	{
		document.getElementById('loginFormN').style.display="none";
		document.getElementById('registrationFormN').style.display="inline";
	}
}

function frontMenu(fmenu, fmenuS) {
	if (fmenuS==1) {
		document.getElementById('front-menu'+fmenu).style.backgroundPosition="bottom";
	}
	else
	{
		document.getElementById('front-menu'+fmenu).style.backgroundPosition="top";
	}
}

function loginWindow(shWin) {
	if (shWin==1) {
		document.getElementById('loginWindowForm').style.display="inline";
		document.getElementById('login').focus();
	}
	else
	{
		document.getElementById("loginStatus").innerHTML="";
		document.getElementById("login").value="";
		document.getElementById("password").value="";
		document.getElementById('loginWindowForm').style.display="none";
		document.getElementById('loginFORMr').style.display="none";
	}
}

function remindWindow() {
	document.getElementById('loginFORMr').style.display="inline";
}

function showReplay(shWin, replaykID) {
	if (shWin==1) {
		document.getElementById('ReplayLink'+replaykID).style.display="none";
		document.getElementById('ReplayText'+replaykID).style.display="inline";
		var oFCKeditor = new FCKeditor( 'post'+replaykID) ;
		oFCKeditor.BasePath = '/fck/';
		oFCKeditor.Height = 300 ;
		oFCKeditor.ReplaceTextarea() ;
	}
	else
	{
		document.getElementById('ReplayLink').style.display="inline";
		document.getElementById('ReplayText').style.display="none";
	}
}

var divID=0;

function showAgentMenu(name) {
	
	element = document.getElementById('agentMenuDiv'+name);

	if (element.style.display!="inline") {
		if (divID) {document.getElementById(divID).style.display = "none";} 
		element.style.display="inline";
		divID = 'agentMenuDiv'+name;

	}
	else
	{
		if (divID) {document.getElementById(divID).style.display = "none";} 
		element.style.display="none";
	}
	

}

function addDoLoadOnEnter() {

	if (document.getElementById("password")) {
		document.getElementById("password").onkeypress = function(event) { 
			if (window.event) {event = window.event;}
			if (event.keyCode == 0xD ||event.keyCode == 0xA) doLoad();}
		
	}
}

function doLoad() { 
	
	var req = new Subsys_JsHttpRequest_Js(); 
	req.onreadystatechange = function() { 
		if (req.readyState == 4) { 
			if (req.responseJS) { 
				if (req.responseJS["status"]=="1") {
					document.getElementById("loginStatus").innerHTML="";
					document.getElementById("loginWindow").submit();
				}
				else
				{
				    document.getElementById("loginStatus").innerHTML="<b>Неправильная комбинация логина и пароля!</b>";
				}
			} 
		} 
        } 
	req.caching = false; 
	userLogin=document.getElementById("login").value;
	userPassword=document.getElementById("password").value;

	req.open('POST', '/login', true); 
	req.send({ l: userLogin , p: userPassword}); 
} 

function changePasswordEdit(type, status) {
	if (type==1) {
		if (status==1) {
			document.getElementById("userpassword1").disabled=true;
			document.getElementById("userpassword2").disabled=true;
			document.getElementById("userpassword3").disabled=true;
			document.getElementById("userpassword1").style.background="#dddddd";
			document.getElementById("userpassword2").style.background="#dddddd";
			document.getElementById("userpassword3").style.background="#dddddd";
		}
		else
		{
			document.getElementById("userpassword1").disabled=false;
			document.getElementById("userpassword2").disabled=false;
			document.getElementById("userpassword3").disabled=false;
			document.getElementById("userpassword1").style.background="#ffffff";
			document.getElementById("userpassword2").style.background="#ffffff";
			document.getElementById("userpassword3").style.background="#ffffff";
		}
	}
}

function selectPayMethod(status) {
	switch (value=status) {
	case 0:
		document.getElementById("agentPayInput").disabled=false;
		document.getElementById("payMethod").action="/agent/invoice";
	break;
	case 1:
		document.getElementById("agentPayInput").disabled=true;
		document.getElementById("payMethod").action="http://genagent.ru/";
	break;
	case 2:
		document.getElementById("agentPayInput").disabled=true;
		document.getElementById("payMethod").action="http://money.yandex.ru/";
	break;	
	case 5:	
	
		//// убиралка экшена и таргета для демо-аккаунта. Нужно добавить в новую функцию!!!!	
	
		document.getElementById("payMethod").action="";
		document.getElementById("payMethod").target="";	
	break;	
	}

}

function filtrTypeSelect(tenderType) {
	document.getElementById('tender_type1').style.display="none";
	document.getElementById('tender_type2').style.display="none";
	document.getElementById('tender_type3').style.display="none";
	document.getElementById('tender_type4').style.display="none";

	document.getElementById('tender_type'+tenderType).style.display="inline";
}

function changeTender() {
	switch(document.getElementById('tenderSelectType').value)
		{
			case "1":
				window.location="/tender/new/tour";
				break;
			case "2":
				window.location="/tender/new/ticket";
				break;
			case "3":
				window.location="/tender/new/hotel";
				break;
			case "4":
				window.location="/tender/new/visa";
				break;
		}
}

function changeCity() {	
	window.location="/companies/" + document.getElementById('CompanySelectType').value;
}

function changeTendersList() {
	document.getElementById("userTendersS").submit();
}

function showFrontDescription (DIVn, DIVstyle) {
	document.getElementById('descriptionDIV'+DIVn).style.display=DIVstyle;
}

function checkEULE(elemID, formID) {
	if (document.getElementById(elemID)) {
		if (document.getElementById(elemID).checked==true) {
			document.getElementById(formID).submit();
		}
		else
		{
			document.getElementById("errorCheckEuleID").style.display="inline";
			document.getElementById("euleTEXT").style.background="#f37a7a";
		}
	}
}

function tenderBuy(tenderID, tenderPrice, tenderBuys, type) {

		if (type=="-4") {
			cText="Извините, Вы не можете купить данную заявку, потому что она не показывается публично, либо отключена туристом."; 
		}		
		if (type=="-3") {
			cText="Заявка уже куплена вашим Турагенством"; 
		}
		if (type=="-2") {
			cText="Недостаточно денег для покупки!";
		}
		if (type=="-1") {
			cText="Несуществующая заявка";
		}
		if (type=="0") {
			cText="Цена измениласть!\nУверены, что хотите купить за "+tenderPrice+" рублей?";
		}
		if (type=="1") {
			cText="Уверены, что хотите купить за "+tenderPrice+" рублей?";
		}
		if (type>=0) {
			if (confirm(cText)) {
				tenderBuyAJAX(tenderID, tenderBuys);
			}
		}
		else
		{
			alert(cText);
		}
}

function tenderBuyAJAX(tenderID, tenderBuys) { 
	var req = new Subsys_JsHttpRequest_Js(); 
	req.onreadystatechange = function() { 
		if (req.readyState == 4) { 
			if (req.responseJS) { 
				if (req.responseJS["status"]!="1") {
					tenderBuy(tenderID, req.responseJS["price"], req.responseJS["buys"], req.responseJS["status"]);
				}
				else
				{
//					window.location=window.location;
					window.location.reload();
				}
		       }
		} 
        } 
	req.caching = false; 

	req.open('POST', '/agent/check', true); 
	req.send({ id: tenderID , buys: tenderBuys}); 
} 

function changeAgent(tenderID) {
	window.location="/user/talk/"+tenderID+"/"+document.getElementById('agent4changeList').value;
}

function checkSelectFiltr() {
	alert(1);
}
function iframeHeight(element) {
	element.height = element.contentWindow.document.body.scrollHeight+4+'px';
	
}

function showPopUpWindow(id) {
	moveY=0;

	document.getElementById(id).style.display='inline';	
	
	element = document.getElementById('complainWindow');
	if (document.documentElement.scrollTop) {moveY = document.documentElement.scrollTop;}
	if (document.body.scrollTop) {moveY = document.body.scrollTop;}
	element.style.top = moveY+'px'; 
	
	window.onscroll = function() {
		element = document.getElementById('complainWindow');
		if (document.documentElement.scrollTop==0) {moveY = 0}
		if (document.body.scrollTop==0) {moveY = 0}
		if (document.documentElement.scrollTop) {moveY = document.documentElement.scrollTop;}
		if (document.body.scrollTop) {moveY = document.body.scrollTop;}
		
		element.style.top = moveY+'px';
		
	}
}



function confirmActivateUser( type, userId ) {

	if( type==2 ) {
		if( confirm('Деактивировать пользователя?') ) {
			window.location = '/adm/users/deactivate/' + userId;
		} else {
			return false;
		}
	}
	if( type==1 ) {
		if( confirm('Активировать пользователя?') ) {
			window.location = '/adm/users/activate/' + userId;
		} else {
			return false;
		}
	}
} 
function confirmTenderActive( type, tenderId ) {

	if( type==1 ) {
		if( confirm('Отключить заявку?') ) {
			window.location = '/adm/tenders/del/' + tenderId;
		} else {
			return false;
		}
	}
	if( type==2 ) {
		if( confirm('Включить заявку?') ) {
			window.location = '/adm/tenders/add/' + tenderId;
		} else {
			return false;
		}
	}
} 
function confirmForm( obj, text ) {
	
	if( confirm( text ) ) {
		obj.submit();
	}
}
function confirmLink( link, text ) {
	
	if( confirm(text) ) {
		window.location = link;
	}
}
function confirmNewsOn ( type, id ) {
	if( type==1 ) {
		if( confirm('Хотите отключить новость, да?') ) {
			window.location = '/adm/newsadm/off/' + id;
		} else {
			return false;
		}
	}
	if( type==2 ) {
		if( confirm('Выключить новость?') ) {
			window.location = '/adm/newsadm/on/' + id;
		} else {
			return false;
		}
	}
}

var hintcontainer = null;
function showHint(obj) {		
	
	if( obj.getAttribute('hint') && obj.getAttribute('hint')!='' ) {
		if (hintcontainer==null) {
    		hintcontainer = document.createElement("div");  
      		hintcontainer.className="formhint";
      		document.body.appendChild(hintcontainer);
   		}
   		hintcontainer.style.display="inline";
   		hintcontainer.innerHTML = "<span class=\"topBlock\"></span>" + "<div>" + obj.getAttribute('hint')+ "</div>" + "<span class=\"bottomBlock\"></span>"   
		   
		   
		var yyy = hintcontainer.clientHeight;
		var objyyy = obj.offsetHeight;
		var objxxx = obj.offsetWidth;
		
		hintcontainer.style.top = getAbsY(obj) - yyy - objyyy   + "px";
		hintcontainer.style.left = getAbsX(obj) + objxxx/2 - 109 + "px";
   		obj.onblur = hidehint;
	}
}
function hidehint() {
   hintcontainer.style.display="none";
}



/* проверка пароля */

function checkPassStrength(strPassword) {
	var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 
	var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz-"; 
	var m_strNumber = "0123456789"; 
	var m_strChars = "~!@#$%^&*()_+:!\"№;:?,./|\\";
	
	var nScore = 0; 
	if (strPassword.length < 6) { 
		nScore += 0;
	} else if (strPassword.length > 5 && strPassword.length < 10) { 
		nScore += 11; 
	} else if (strPassword.length > 9) { 
		nScore += 33; 
	} 
	
	var nUpperCount = countContain(strPassword, m_strUpperCase); 
	var nLowerCount = countContain(strPassword, m_strLowerCase); 
	var nLowerUpperCount = nUpperCount + nLowerCount; 
		
	if (nUpperCount == 0 && nLowerCount != 0) { 
		nScore += 10; 
	} else if (nUpperCount != 0 && nLowerCount == 0) { 
		nScore += 10; 
	} else if (nUpperCount != 0 && nLowerCount != 0) { 
		nScore += 26; 
	} 
	
	var nNumberCount = countContain(strPassword, m_strNumber); 
	
	if (nNumberCount >= 2) { nScore += 10; } 
	if (nNumberCount >= 4) { nScore += 26; } 
	if (nNumberCount != 0 && nLowerUpperCount != 0) { nScore += 5; }
	
	var nCharsCount = countContain(strPassword, m_strChars);
	if (nCharsCount >= 2) { nScore += 10; } 
	if (nCharsCount >= 4) { nScore += 26; } 
	if (nCharsCount != 0 && nNumberCount != 0 && nLowerUpperCount != 0) { nScore += 15; }
	
	var dCount=0;
	
	for (i=0; i < strPassword.length; i++) {
		for (j=0; j<strPassword.length; j++) {
			if (strPassword[i]==strPassword[j]&&i!=j) {
				dCount++;
			}
		}
	}
	
	nScore = nScore - dCount;
	
return nScore; 
} 

function countContain(strPassword, strCheck) { 
	var nCount = 0; 
	for (i = 0; i < strPassword.length; i++) { 
		if (strCheck.indexOf(strPassword.charAt(i)) > -1) { 
			nCount++; 
		}
	} return nCount; 
} 


function check_lengthpwd() {
		
		element = document.getElementById('regform_password1_field');
		element.onkeyup = function(){
			strength = checkPassStrength(this.value);
			el = document.getElementById("lengthpwd");	
			if (this.value.length<2) {el.style.borderTop = '#999999 5px solid'; el.innerHTML = ''}
			if ((this.value.length<6)&&(this.value.length>0)) {el.style.borderTop = '#AA0000 5px solid'; el.innerHTML = '<font style="color:#AA0000">короткий ('+this.value.length+' символов) </font>';}
			if ((this.value.length>5)&&(this.value.length<21)) {el.style.borderTop = '#FF7700 5px solid'; el.innerHTML = '<font style="color:#FF7700">простой ('+this.value.length+' символов) </font>';} 
			if ((this.value.length>5)&&(this.value.length<21)&&(strength>50)) {el.style.borderTop = '#009900 5px solid'; el.innerHTML = '<font style="color:#009900">надежный ('+this.value.length+' символов) </font>'}
			if (this.value.length>20) {el.style.borderTop = '#AA0000 5px solid'; el.innerHTML = '<font style="color:#AA0000">Внимание! слишком длинный пароль) </font>';}
			if (this.value==$('#login').attr('value')) {el.style.borderTop ='#AA0000 5px solid';}
			
		}
		
}

function check_password() {
		element = document.getElementById('regform_password2_field');
		
		element.onkeyup = function(){
			pwdcheck = document.getElementById("password_check");
			pwdcheck.innerHTML = '';
			pwdcheck.innerHTML = this.value == document.getElementById('regform_password1_field').value?"<i style='color:#777777'>"+'Пароль верен'+"</i>":"<i style='color:#770000'>"+'Пароль не совпадает'+"</i>";
			if (this.value.length==0) {pwdcheck.innerHTML = '';}
		}

}

function addDirectionsCheck(){
	if (document.getElementById('directions_field')) {
		document.getElementById('directions_field').onchange=function()
			{
				el = document.getElementById('directions_field');
				for (i=0; i<el.options.length; i++) {
				 if (el.options[i].selected) {
					if (document.getElementById('return_field').getAttribute('valid')) { 
						//replace(/( illuminate)|(illuminate)/g, '')
						document.getElementById('return_field').removeAttribute('valid');
						document.getElementById('return_field').style.background = "#fff";
						document.getElementById('return_field').className = '';
					} else {
						document.getElementById('return_field').setAttribute('valid','5');
						document.getElementById('return_field').style.background = "#fffec1";
					}
					
					//alert(el.options[i].value + " | ");
				 }
				}
				
			
			};
	}

}

function makeUsersSearch() {
	if( document.getElementById('searchIt').value!='' ) { window.location='/adm/users/search/' + document.getElementById('searchIt').value + '/'; };	
}
function makeCompanySearch() {
	if( document.getElementById('searchIt').value!='' ) { window.location='/adm/agents/list/search/' + document.getElementById('searchIt').value + '/'; };	
}

