var ie = (/MSIE\s((5\.5)|[6789])/.test(navigator.userAgent)) && (navigator.platform == "Win32");
var ie5 = /MSIE 5\.0/.test(navigator.userAgent) && navigator.platform == "Win32";
var flash = false;
var plugin;
var version = 5;
var body_w;
var first_page=0;

if (navigator.plugins) {
	if (navigator.plugins["Shockwave Flash"]) {
		var plugin_ver = navigator.plugins["Shockwave Flash"].description.match(/Shockwave Flash (\d+)\./);
		if (plugin_ver[1]) {
			flash = parseInt(plugin_ver[1]) >= version;
		}
	} else {
		if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
			var vb = '<script language="vbscript">\n' + '  on error resume next\n'	+ '  flash = IsObject(CreateObject(' + '     "ShockwaveFlash.ShockwaveFlash.' + version + '"))\n' + '<' + '/script>';
			document.write(vb);
		}
	}
}

function showBomond(){
  if(girl_rotate==0){
    fade('bomond1', 'in', 0.6);
    fade('bomond2', 'in', 1.0);
    fade('bomond3', 'in', 1.4);
  }
}

function putGirl(turn){
 if(flash){
  document.write('\
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="318" height="633" align="left">\
    <param name="allowScriptAccess" value="sameDomain" />\
    <param name="movie" value="/i/girl.swf?4" />\
    <param name="FlashVars" value="lib='+(first_page==1?'girl_first':'girl_inside')+'&turn='+turn+'" />\
    <param name="menu" value="false" />\
    <param name="wmode" value="opaque" />\
    <param name="salign" value="l" />\
    <param name="quality" value="high" />\
    <param name="bgcolor" value="#ffffff" />\
    <embed src="/i/girl.swf" FlashVars="lib='+(first_page==1?'girl_first':'girl_inside')+'&turn='+turn+'" menu="false" salign="l" quality="high" wmode="opaque" bgcolor="#ffffff" width="318" height="633" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
    </object>\
');

 }else{
  document.write('<img src="/i/girl'+(first_page==1?'_first':'_inside')+'.jpg" width="318" height="633">');
 }
}

function putFlash(flash_file, img_file, w, h){
 if(flash){
  document.write('\
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" align="left">\
    <param name="allowScriptAccess" value="sameDomain" />\
    <param name="movie" value="'+flash_file+'.swf" />\
    <param name="menu" value="false" />\
    <param name="wmode" value="opaque" />\
    <param name="salign" value="l" />\
    <param name="quality" value="high" />\
    <param name="bgcolor" value="#ffffff" />\
    <embed src="'+flash_file+'.swf" menu="false" salign="l" quality="high" wmode="opaque" bgcolor="#ffffff" width="'+w+'" height="'+h+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
    </object>\
');

 }else{

  document.write('<img src="'+img_file+'" width="'+w+'" height="'+h+'">');

 }
}

function setDelimiter(n1, n2){
 document.getElementById("delimiter_td").style.width=body_w<1100 ? (n1 || '5%') : (n2 || '10%');
}

function png(id, src_png, src_gif){  
	image = document.getElementById(id);
	if (ie5) {image.src = src_gif;}
	else {
		if(!ie){image.src = src_png;}
		else {
			image.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +  src_png + "',sizingMethod='image')"
		}
	}
	return 1;
}

function invertDisplay(id){
 var current = document.getElementById(id).style;
 current.display = current.display == "none" ? "" : "none";
}

function inputText (input, dft_value, cssFilled, cssEmpty){
	var thisCopy = this;
	this.Input = input;
	this.dft_Value = dft_value;
	this.CssFilled = cssFilled;
	this.CssEmpty = cssEmpty;

	this.setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()});
	this.setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()});
	this.setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()});

    if (input.value == dft_value) this.onBlur()
    return this
}

inputText.prototype.setupEvent = function (elem, eventType, handler) {
	if (elem.attachEvent){elem.attachEvent ('on' + eventType, handler)} //IE
	if (elem.addEventListener){elem.addEventListener (eventType, handler, false)} //DOM
}

inputText.prototype.onFocus = function() {
	if (this.Input.value == this.dft_Value) {this.Input.value = ''}
	else {this.Input.className = 'full'}
}

inputText.prototype.onKeyDown = function() {this.Input.className = 'full'}

inputText.prototype.onBlur = function() {
	if (this.Input.value == '' || this.Input.value == this.dft_Value)
	{
		this.Input.value = this.dft_Value;
		this.Input.className = this.CssEmpty
	}
	else {this.Input.className = ''}
}

function resize(n1, n2){
 body_w = document.body.clientWidth;
 setDelimiter(n1, n2);
}

function resize_new(n1){
 body_w = document.body.clientWidth;
 setDelimiter();
}

function fade(id, kuda, firstDelay, step, delay) {
 var element = document.getElementById(id);
 if (!element) return;
 if (element.style.display == 'none'){element.style.display = ''};
 if (element.timeoutId) clearTimeout(element.timeoutId);
 element.fadeValue = (kuda == 'in' ? 0 : 1);
 if (typeof(element.style.filter) != 'undefined')
  element.style.filter = 'alpha(opacity='+(element.fadeValue*100)+')'
 else if (typeof(element.style.opacity) != 'undefined')
  element.style.opacity = element.fadeValue
 else {
  element.style.visibility = (kuda == 'in' ? 'visible' : 'hidden');
  return;
 }
 element.fadeStep = (kuda == 'in' ? 1 : -1) * (step || 0.25);
 element.fadeDelay = (delay || 50);
 element.style.visibility = 'visible';
 element.timeoutId = setTimeout('stepFade("'+id+'")', firstDelay*1000);
}

function stepFade(id) {
 var element = document.getElementById(id);
 if (!element) return;
 element.fadeValue += element.fadeStep;
 if (element.fadeValue > 1) element.fadeValue = 1
 else if (element.fadeValue < 0) element.fadeValue = 0;
 if (typeof(element.style.filter) != 'undefined') 
  element.style.filter = 'alpha(opacity='+(element.fadeValue*100)+')'
 else 
  element.style.opacity = element.fadeValue;
 if (0 < element.fadeValue && element.fadeValue < 1)
  element.timeoutId = setTimeout('stepFade("'+id+'")', element.fadeDelay);
}

function s_mail(s1,s2)
{
	document.write('<A href="mailto:'+s1+'@'+ s2 +'">'+s1+'@'+s2+'</a>' );
}

var curSelectNum = 2;
var metro=0;

function closeGeoFilter(){
  document.getElementById("select2_container").innerHTML='';
  document.getElementById("select3_container").innerHTML='';
}

function switchTo(id){
 
  if(id == 'metro'){
   document.getElementById("search_link").className = '';
   document.getElementById("metro_link").className = 'bgpale';

   document.getElementById("search_table").style.display = 'none';
   document.getElementById("metro_table").style.display  = ''; 
  }else{

   closeGeoFilter();

   document.getElementById("metro_table").className = '';
   document.getElementById("search_link").className = 'bgpale';
   document.getElementById("metro_link").className = ''; 

   document.getElementById("search_table").style.display = '';
   document.getElementById("metro_table").style.display  = 'none'; 
  }

}

function setSelectWidth() {
  var num = curSelectNum;
  document.getElementById("please_wait").style.display="none"; 
  document.getElementById("search_filter"+num+"_select").style.display="block"; 
  document.getElementById("search_filter"+num+"_select").style.width = document.getElementById("metro_select").offsetWidth+"px";
}

function loadDataToSelect2(num) {
  metro = num;
  curSelectNum = 2;
  document.getElementById("select3_container").innerHTML='';
  document.getElementById("select2_container").innerHTML='секундочку...';
  document.getElementById("metro_table").className = 'border';
  loader.onload = setSelectWidth;
  loader.loadInto('/cgi-bin/rub_get.fcgi?m=' + num, 'select2_container');
}

function loadDataToSelect3(num) {
  curSelectNum = 3;
  document.getElementById("select3_container").innerHTML='секундочку...';
  loader.onload = setSelectWidth;
  loader.loadInto('/cgi-bin/rub_get.fcgi?m=' + metro + '&l=' + num, 'select3_container');
}

function invertLinkText(link, offText, onText) {
  link.innerHTML = (link.innerHTML == offText ? onText : offText);
}
