var IE = (navigator.appName == "Microsoft Internet Explorer") ? 1 : 0;

var	MonthArray= new Array();
	MonthArray[1]="Январь";
	MonthArray[2]="Февраль";
	MonthArray[3]="Март";
	MonthArray[4]="Апрель";
	MonthArray[5]="Май";
	MonthArray[6]="Июнь";
	MonthArray[7]="Июль";
	MonthArray[8]="Август";
	MonthArray[9]="Сентябрь";
	MonthArray[10]="Октябрь";
	MonthArray[11]="Ноябрь";
	MonthArray[12]="Декабрь";

var NS = (navigator.appName == "Netscape") ? 1 : 0;
var OPERA = (navigator.appName == "Opera") ? 1 : 0;
if (OPERA==1) { IE=1; }





/*функция показывающая окно с названиями рубрик  */
timeout=0; stored=-1;

function show_rubr (event, layerID) {
	if (event == 0){
		if (IE) {
			document.all["d"+stored].style.visibility = "hidden";
			document.all["dd"+stored].style.visibility = "hidden";
		}
		if (NS) {
			document.layers["d"+stored].visibility = "hidden";
			document.layers["dd"+stored].visibility = "hidden";
		}
		
	} else {
	bannerOffset = 110;
	pageTop = 200 + bannerOffset;
	bottom0 = 1800;
	rubrStep = 0;
	topMargin = 319;
	topMargin = pageTop;
	if (IE) {
        screenOffset = document.body.scrollTop;
        screenh = screenOffset + document.body.offsetHeight; 
		topx = topMargin + ((layerID - 1) * rubrStep) - screenOffset + bannerOffset;

	} else if (NS){
		screenOffset = pageYOffset;     
		screenh = screenOffset + innerHeight;
		topx = topMargin + ((layerID - 1) * rubrStep) - screenOffset + bannerOffset;
	}

	
	topr=document.all["d"+layerID].style.posTop;
	toprd=document.all["dd"+layerID].style.posTop;
     
	if ( (stored!=-1) && (stored!=layerID) ) {

		if (IE) {
			document.all["d"+stored].style.visibility = "hidden";
			document.all["dd"+stored].style.visibility = "hidden";
		}
		if (NS) {
			document.layers["d"+stored].visibility = "hidden";
			document.layers["dd"+stored].visibility = "hidden";
		}
	}   

	if (IE) {
		document.all["d"+layerID].style.visibility = "visible";
		document.all["dd"+layerID].style.visibility = "visible";
		document.all["d"+layerID].style.posTop = topr;
		document.all["dd"+layerID].style.posTop = toprd;
		
	}
	if (NS) {
		document.layers["d"+layerID].visibility = "visible";
		document.layers["dd"+layerID].visibility = "visible";
		document.layers["d"+layerID].top = topr;
		document.layers["dd"+layerID].top = toprd;
	}
  
	stored = layerID;
	return true;
	}
}

// Функция выделяющая серым фоном подкаталоги
function bggray (num)
{
	if (num <10) {
		num = "0"+num;
	}
	
	var obj = document.getElementById(num);
	obj.style.background= "#F0F0F0";
}

function bgwhite (num)
{
	if (num <10) {
		num = "0"+num;
	}
	var obj = document.getElementById(num);
	obj.style.background= "#ffffff";
}


//функция пересчитывающая дни, месяцы и годы на календаре новостного архива
function previous_month()
{ 
//Дата с которой начинается показ новостей  
  var start_year = 2004;
  var start_month = 2;
  var month = document.getElementById(100);
  var year = document.getElementById(101);
  var selected_day = document.getElementById(111);
  var selected_month = document.getElementById(112);
  var selected_year = document.getElementById(113);
  
  var num_year = year.value;
  var today= new Date();

  var start_date= new Date(start_year, start_month, 1, 0, 0, 0);
  var selected_date= new Date(selected_year.value, selected_month.value-1, selected_day.value, 0, 0, 0);

  for (i=1;i<=12;i++) {
	if (MonthArray[i] == month.value) {
	  var num_month = i;
	  var current_date = new Date(year.value, i-1, today.getDate(), 0, 0, 0);
	  var current_month = (current_date.getMonth()+1);	
	  if ((current_date>start_date)) {
		if (i != 1) {
		  num_month = i-1;
		}
		else {
		  num_month = 12;
		  num_year = year.value-1;
		}
	    month.value = MonthArray[num_month];
		year.value = num_year;
		j=1
		class_name = 'calendar_day';
		for (i=1; i<=42; i++) {
		  var day_num = document.getElementById(i);
		  day_num.style.background= "#E6E6E6";
		  day_num.style.color= "#6E6E6E";
		  
		  var current_first_date = new Date(year.value, num_month-1, 1, 0, 0, 0);
		  first_week_day = (current_first_date.getDay());
		  if (first_week_day == 0) {first_week_day= 7;}
		  var current_end_date = new Date(year.value, num_month-1, 1-first_week_day+i, 0, 0, 0);
		  
	//	  alert (first_week_day);
	      if (current_end_date.getMonth() != current_first_date.getMonth()) {
	        day = '';
	      }
		  else {
		    day = j;
			day_num.style.cursor= "hand";
			if ((selected_date <= current_end_date) && (selected_date >= current_end_date)) {
			  day_num.style.color= "#E6E6E6";
			  day_num.style.background= "#6E6E6E";
	        }				
			j++;
		  }
		  day_num.value = day;
		}
		break;
	  }
	}
  }
}

function next_month()
{ 
  var month = document.getElementById(100);
  var year = document.getElementById(101);
  var selected_day = document.getElementById(111);
  var selected_month = document.getElementById(112);
  var selected_year = document.getElementById(113);
  

  
  var num_year = year.value;
  var today= new Date();
  var end_date= new Date(today.getYear(), today.getMonth(), today.getDate(), 0, 0, 0);
  var selected_date= new Date(selected_year.value, selected_month.value-1, selected_day.value, 0, 0, 0);
  
  for (i=12;i>=1;i--) {
	if (MonthArray[i] == month.value) {
	  var current_date = new Date(year.value, i-1, today.getDate(), 0, 0, 0);
	  var current_month = (current_date.getMonth()+1);
	  if ((current_date<end_date)) {
		if (i != 12) {
		  num_month = i+1;
		}
		else {
		  num_month = 1;
		  num_year = (year.value*1+1);
		}	  
	    month.value = MonthArray[num_month];
		year.value = num_year;
		j=1
		for (i=1; i<=42; i++) {
		  var day_num = document.getElementById(i);
		  day_num.style.background= "#E6E6E6";
		  day_num.style.color= "#6E6E6E";
		  day_num.style.cursor= "default";
		  
		  var current_first_date = new Date(year.value, num_month-1, 1, 0, 0, 0);
		  first_week_day = (current_first_date.getDay());
		  if (first_week_day == 0) {first_week_day= 7;}
		  var current_end_date = new Date(year.value, num_month-1, 1-first_week_day+i, 0, 0, 0);
		  
	//	  alert (first_week_day);
	      if (current_end_date.getMonth() != current_first_date.getMonth()) {
	        day = '';
	      }
		  else {
		    day = j;
			day_num.style.cursor= "hand";
	        if (today < current_end_date) {
			  day_num.style.color= "#AAACAE";
			  day_num.style.cursor= "default";
	        }
			if ((selected_date <= current_end_date) && (selected_date >= current_end_date)) {
			  day_num.style.color= "#E6E6E6";
			  day_num.style.background= "#6E6E6E";
			  
	        }		
			j++;
		  }
		  day_num.value = day;
		}
		break;
	  }
	}
  }
}

function select_day (id)
{
  var obj_month = document.getElementById(100);
  var obj_year = document.getElementById(101);
  var obj_day = document.getElementById(id);
  var day = obj_day.value;
  var year = obj_year.value;

  var month;
  for (i=12;i>=1;i--) {
    if (MonthArray[i] == obj_month.value) {
	  month = i;
	}
  }
  var today= new Date();
  var select_date= new Date(year, month-1, day, 0, 0, 0);
  if (day != "" && (today >= select_date)) {
    for (temp_day=1;temp_day<=42;temp_day++) {
	  obj_temp_day = document.getElementById(temp_day);
	  obj_temp_day.style.cursor= "wait";
	}

    var obj_body = document.getElementById("body");
    obj_body.style.cursor= "wait";	
    window.location.href = "news.php?page_menu=2&selected_year="+year+"&selected_month="+month+"&selected_day="+day;
  }
//  alert(year);
  
}

function OpenMailWindow(firm_id){
    var mail, winMail;
    mail = "mail.php?firm_id="+firm_id;
    winMail= open(mail, "MailWindow", 
      "width=400,height=400,status=no,toolbar=no,menubar=no,scrollbars=no");
    winMail.focus();	
}

function TestMailField() {
	var name,phone,email,text;
	name = Form1.name.value;
	phone = Form1.phone.value;
	email = Form1.email.value;
	text = Form1.text.value;
	if ((name == "") || (phone == "") || (text == "")) {
		alert ('Вы не заполнили все обязательные поля!');
	}
	else {
		Form1.submit();
	}
}

function CloseWindow() {
	this.close();
}

function OpenChoiceEditWindow(firm_id){
    var choiceedit, winChoiceEdit;
    choiceedit = "choiceedit.php?firm_id="+firm_id;
    winChoiceEdit= open(choiceedit, "ChoiceEditWindow", 
      "width=350,height=195,status=no,toolbar=no,menubar=no,scrollbars=no,screenX=330,screenY=250");
    winChoiceEdit.focus();	
}

function EnterToEdit(){
	var firm_id,login,password;
	firm_id = Form1.firm_id.value;
	login = Form1.login.value;
	password = Form1.password.value;
	location.href="choiceedit.php?enter=1&firm_id="+firm_id+"&login="+login+"&password="+password;
}

function IsPasswordCorrect(){
	var corect_password,firm_id,session;
	var edit_firm_info, winEditFirmInfo;
	firm_id = Form1.firm_id.value;
	corect_password = Form1.corect_password.value;
	session = Form1.session.value;
	if (corect_password == 1) {
		CloseWindow();
		window.opener.location="edit_firm_info.php?edit=1&firm_id="+firm_id+"&session="+session;
        window.opener.focus();
		var obj_body = window.opener.document.getElementById("body");
		obj_body.style.cursor= "wait";
		
/*		
	    edit_firm_info = "edit_firm_info.php?firm_id="+firm_id;
    	winEditFirmInfo= open(edit_firm_info, "EditFirmInfoWindow",
		"status=yes,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
    	winEditFirmInfo.focus();	
*/		
	}
}




function cursorwait() {
  for (id=1;id<=9;id++) {
    var menu_id = 'menu'+id;
    var obj_menu = document.getElementById(menu_id);
    obj_menu.style.cursor= "wait";
  }
  var obj_body = document.getElementById("body");
  obj_body.style.cursor= "wait";
}

function ClearField(field_name) {
  var field_name;
  var name_hidden = field_name+'_hidden';
  var name_text = field_name+ '_text';
  obj_name_hidden = document.getElementById(name_hidden);
  obj_name_text = document.getElementById(name_text);
  name_hidden_value = obj_name_hidden.value;
  if (name_hidden_value == "") {
     obj_name_hidden.value = 1;
	 obj_name_text.value = "";
  }
}

function OpenBigImgFirm(type){
    var bigimgfirm, winBigImgFirm;
    bigimgfirm = "bigimgfirm.php?registration_type="+type;
    winBigImgFirm= open(bigimgfirm, "BigImgFirmWindow", 
      "width=570,height=210,status=no,toolbar=no,menubar=no,scrollbars=no");
    winBigImgFirm.focus();	
}

function OpenBigMetroMap(){
    var winBigMetroMap;
    winBigMetroMap= open("http://www.stroyelite.ru/bigmetromap.html", "BigMetroMapWindow", 
      "width=815,height=650,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
    winBigMetroMap.focus();	
}

function GetScreenSize(){
	var height=0;
	var width=0;

	if (self.screen) {     // for NN4 and IE4
        width = screen.width
        height = screen.height
	}
	else if (self.java) {   // for NN3 with enabled Java
       var jkit = java.awt.Toolkit.getDefaultToolkit();
       var scrsize = jkit.getScreenSize();       
       width = scrsize.width; 
       height = scrsize.height; 
	}
	document.cookie = "screen_width="+width;
	document.cookie = "screen_height="+height;
}

function OpenGalleryBigPhotoWindow(photo,width_photo,height_photo){
    var gallery_big_photo, winGallery_big_photo;
	var width = width_photo*1+20;
	var height = height_photo*1+10;
    gallery_big_photo = "gallery_big_photo.php?photo="+photo;
    winGallery_big_photo= open(gallery_big_photo, "Gallery_big_photoWindow", 
      "width="+width+",height="+height+",status=no,toolbar=no,menubar=no,scrollbars=no");
    winGallery_big_photo.focus();	
}

function OpenCouponForDiscountWindow(discount_id){ 
    var coupon, winCoupon;
    coupon = "coupon_for_discount.php?discount_id="+discount_id;
    winCoupon= open(coupon, "CouponWindow", 
      "width=470,height=400,status=no,toolbar=no,menubar=no,scrollbars=no");
    winCoupon.focus();	
}


function printing_image(nam,w,h,title) {
 myWin= open("", "displayWindow", "width="+w+",height="+h+",status=no,toolbar=no,menubar=no");
  // открыть объект document для последующей печати 
  myWin.document.open();
  // генерировать новый документ 
  myWin.document.write("<html><head><title>"+title+"</title></head>");
  myWin.document.write("<body bgcolor=#FFFFFF text=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad='window.print()'>");
  myWin.document.write("<img src='"+nam+"'>");
  myWin.document.write("</head><body>");
  myWin.document.write("</body></html>");
  // закрыть документ - (но не окно!)
  myWin.document.close();
 }
 
function GetLink(link_array) {
	alert (link_array);
}

//функция, проверяющая, выбран ли ответ в голосовании
function VoteControl(answer_id_list) {
	var answer_id_array = answer_id_list.split(',')
	var array_length = answer_id_array.length;
	for (id=0; id<array_length; id++) {
    	var answer_id = answer_id_array[id];
		var obj_answer = document.getElementById(answer_id);
		var vote_answer = obj_answer.checked;
		if (vote_answer == true) {
			var selected = 1;
		}
    }
	if (selected != 1) {		
		alert ("Вы не выбрали ответ!");
	}
	else {
		alert ("Спасибо. Ваш голос учтен.");
		VoteForm.submit();
	}
}

//функция, проверяющая, введен ли e-mail в блоке подписки
function SubscriptionControl() {
	if (SubscriptionForm.e_mail.value == "") {		
		alert ("Вы не ввели E-mail!");
	}
	else {
		alert ("Вы подписались на новости компании \"Солярис Тур\". ");
		SubscriptionForm.submit();
	}
}

function OpenPhotoWindow(photo_id,width,height,table){
    var photo, win_photo;
	var width = width*1+20;
	var height = height*1+20;
    photo = "photo.php?photo_id="+photo_id+"&table="+table;
    win_photo= open(photo, "PhotoWindow", 
      "width="+width+",height="+height+",status=no,toolbar=no,menubar=no,scrollbars=no");
    win_photo.focus();	
}

function OpenPhotoWindow1(photo_id,width,height,table){
    var photo, win_photo;
	var width = width*1+20;
	var height = height*1+20;
    photo = "photo.php?photo_id="+photo_id+"&table="+table;
    win_photo= open(photo, "PhotoWindow", 
      "width=800,height=600,status=no,toolbar=no,menubar=no,scrollbars=yes");
    win_photo.focus();	
}

function AddSelectedItems(selected, destination) {
	var selected_obj = document.getElementById(selected);
	var destination_obj = document.getElementById(destination);
	var name = selected_obj.value;
	var newName = document.createElement("OPTION");
	newName.text = name;
	newName.value = name;
	(destination_obj.options.add) ? destination_obj.options.add(newName) : destination_obj.add(newName, null);
}

function RemoveSelectedItems(destination) {
	var destination_obj = document.getElementById(destination);
	var option_num = destination_obj.selectedIndex;
	destination_obj.options[option_num] = null;
}

function RemoveAllItems(destination) {
	var destination_obj = document.getElementById(destination);
	destination_obj.length = 0;
	var newName = document.createElement("OPTION");
	newName.text = 'Выбранные станции метро..';
	newName.value = '';
	(destination_obj.options.add) ? destination_obj.options.add(newName) : destination_obj.add(newName, null);
}

function GetOptionList(destination) {
	var destination_obj = document.getElementById(destination);
	var option_num = destination_obj.length;
	var list_string = '';
	for (var i=1; i < option_num; i++) {
		name = destination_obj[i].value;
		list_string = list_string + name + ';';
	}
	document.SerchForm.metro_list.value = list_string;
}

function ClearForm() {
	var destination_obj = document.getElementById("metro_d");
	destination_obj.length = 0;
	var newName = document.createElement("OPTION");
	newName.text = 'Выбранные станции метро..';
	newName.value = '';
	(destination_obj.options.add) ? destination_obj.options.add(newName) : destination_obj.add(newName, null);
	
	SerchForm.num_room.value='';
	SerchForm.num_flat_on_page.value='';
	SerchForm.cost_start.value='';
	SerchForm.cost_finish.value='';
}
