function SwitchLogos(site){
	$('#logo').removeClass();
    $('#logo').addClass('logo_'+site);
	$('#menu_line').removeClass();
    $('#menu_line').addClass('menu-line_'+site);    
    $('#girl').removeClass();
    $('#girl').addClass('character_'+site);
}

function fetch_form_send (formID,divID,typeID){
// prepare the form when the DOM is ready 
	//alert('form:' + formID);
    var options = { 
        target:        $('#'+divID),   // target element(s) to be updated with server response 
        beforeSubmit:  fetch_preload(divID,typeID)  // pre-submit callback 
    }; 
 	//alert('button'+formID.getElementByType('submit'));
    // bind form using 'ajaxForm' 

   	//$('#'+formID).ajaxForm(options); 
    //$('#'+formID).ajaxSubmit(options);
    return false;
}

function fetch_preload(divID,typeID) {
	//alert('preloader ' + divID + '::type '+typeID);
	if (typeID==1) {
	$('#'+divID).html('Loading...');
	$('#'+divID).addClass('status_1');
	}
}

function fetch_load(url,div) {
 	var response = $.ajax({
  			type: 'GET',
  			url: url,
  			async: false
 			}).responseText;
 	$('#'+div).html(response);
 	
}


function fetch_delete(type,id,div) {

	if (confirm("Вы уверены в том что хотите удалить эту запись?")) {
		switch (type) {
			case 'fav_article': 
				url = 'http://www.lady.ru/delete.php?'+s+'type='+type+'&id='+id;
			break;
			case 'pm_msg': 
				url = 'http://www.lady.ru/pm.php?'+s+'do=delete_msg&pm_text_id='+id+'&pm_id='+div;
				div = 'pm_trash_'+id;
			break;			
		}
		
		fetch_load(url,div);
	}

}


function findValue(li) {
	if( li == null ) return alert("No match!");

	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];

	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;

	//alert("The value you selected was: " + li.selectId);
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}

// ################################## RATING ####################################
function fetch_rating (id_rate,rate) {
	
	position_bg = '0 -'+((50*rate)+75)+'px';
	$('#'+id_rate).css({ 'background-position': position_bg, 'width' : '210px', 'z-index' : '12'});

}

function fetch_rating_show (id_rate,now,max) {

	fetch_rating(id_rate,now);
	next = now+1;
	if (next<=max) {
		setTimeout('fetch_rating_show(\''+id_rate+'\','+next+','+max+');',150);
	}

}


// ################################ SUB MENU ####################################
var jsddm_timeout    = 500;
var jsddm_closetimer = 0;
var jsddm_closetimer2 = 0;
var jsddm_ddmenuitem = 0;
var jsddm_lastopened;

function jsddm_open() {
  jsddm_canceltimer();
  jsddm_close();
  jsddm_ddmenuitem = $(this).find('ul').css('visibility', 'visible');
  jsddm_lastopened = this;

  $(jsddm_lastopened).removeClass('li_static');
  $(jsddm_lastopened).addClass('li_hover');  
}

function jsddm_close() {
 if(jsddm_ddmenuitem) jsddm_ddmenuitem.css('visibility', 'hidden');
 jsddm_hide ();
}

function jsddm_hide () {
	$(jsddm_lastopened).removeClass('li_hover');
	$(jsddm_lastopened).addClass('li_static');
}

function jsddm_timer() { 
  
	jsddm_closetimer = window.setTimeout(jsddm_close, jsddm_timeout);
	jsddm_closetimer2 = window.setTimeout(jsddm_hide, jsddm_timeout);
}

function jsddm_canceltimer() {  
	if(jsddm_closetimer) {  
		window.clearTimeout(jsddm_closetimer);
     	jsddm_closetimer = null;
    }
	if(jsddm_closetimer2) {  
		window.clearTimeout(jsddm_closetimer2);
     	jsddm_closetimer2 = null;
    }    
}

$(document).ready(function() {  
		$('#jsddm > li').bind('mouseover', jsddm_open)
		$('#jsddm > li').bind('mouseout',  jsddm_timer)
		if ($.fn.bgiframe){
			$('#jsddm > li ul').bgiframe();
		}  
});

document.onclick = jsddm_close;





// ###########################################################################
function sugget_lookup(inputString,suggestID,typeID) {
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $('#div_'+suggestID).hide();
    } else {
        var response = $.ajax({
  			type: 'GET',
  			url: 'http://www.lady.ru/ajax/guesswho/'+typeID+'/'+suggestID+'/'+encodeURI(inputString),
  			async: false
 			}).responseText;
		if(response.length >0) {
			$('#div_'+suggestID).show();
			$('#list_'+suggestID).html(response);
		}       
    }
} // lookup

function suggest_fill(thisValue,suggestID) {
   // alert( $('#'+suggestID).attr('value'));
   if (thisValue == '' ) { 
   	//alert ('empty value '+ thisValue);
   	$('#div_'+suggestID).hide();
   } else {
    $('#'+suggestID).attr('value',thisValue);
   	$('#div_'+suggestID).hide();
   	//alert('fill' + $('#'+suggestID).attr('value'));
   }
}



function fetch_homepage (object) {
 	if (document.all) {
		object.style.behavior = 'url(#default#homepage)'; 
		object.setHomePage('http://www.lady.ru/');
	}else{
		alert("Для добавления \"Стартовой странцы\"\nзайдите в общие настройки вашего браузера, \nнажмите кнопку \"Использовать текущую страницу\"");
	}
 return false;
}

function fetch_favorites() { 

	if (document.all && document.all.item && !(window.opera)) { 
		window.external.AddFavorite('http://www.lady.ru', 'Lady.RU') ;
	} else { 
		alert("Для добавления нашей страницы \nв \"Избранное\" вашего браузера, \nнажмите сочетание клавиш на клавиатуре Ctrl + D \nили выберите меню \"Закладки\" - \"Добавить\""); 
	} 
	return false;
}	


function fetch_popup_blog (url) {
	window.open (url,"fetch_blog","menubar=0,resizable=0,scrollbars=yes,width=550,height=550");
}

// ############################ STRANNAYA FLASHKA ####################
function recieveFromFlash(str) {
	
	if (str=='stop') {
		fetch_load('/advert/bottom.html?v=12','flashbottomdiv');
		document.location.href='#bottomflash';
		$('#flashbottomdiv').css({ 'display': 'block'});
		$('#girl').css({ 'display': 'block'});	
		$('#flashtopdiv').html('');
		$('#flashtopdiv').css({ 'display': 'none','width':'1px','height':'1px'});
		//window.scroll(0,document.height);
	} else if (str=='stopallflash') {
		$('#flashtopdiv').html('');
		$('#flashtopdiv').css({ 'display': 'none','width':'1px','height':'1px'});
		$('#flashbottomdiv').html('');
	}
}

function closeallflash() {
		//alert('do:');
		$('#flashtopdiv').css({ 'display': 'none','width':'1px','height':'1px'});		
		$('#flashtopdiv').html('');
		$('#flashbottomdiv').css({ 'display': 'none','width':'1px','height':'1px'});
		$('#flashbottomdiv').html('');
}

function sendFromJS() {
    var movie = (navigator.appName.indexOf("Microsoft")!=-1 ? window : document)["topflash_id"]    
    movie.sendFromJS("start");    
}

function fetch_flashstart() {
	$('#girl').css({ 'display': 'none'});
	$('#flashtopdiv').css({ 'display': 'block','width':'1000px','height':'400px'});
	document.location.href='#flashtopname';
	sendFromJS();
	flashtopcounter();
}

function flashstop() {
	$('#flashtopdiv').html('');
	$('#flashbottomdiv').html('');
}

function flashtopcounter() {
	//$.ajax({type: 'GET',url: 'http://www.lady.ru/ajax.php?do=flashtopcounter': false});
	var response = $.ajax({type: 'GET',url: 'http://www.lady.ru/ajax.php?do=flashtopcounter',async: false}).responseText;
}



// ################################ REGISTER ############################
function fetch_register_question(val) {
	if (val==-1) {
		$('#register_custom_question').css({ 'display': 'block'});
	} else {
		$('#register_custom_question').css({ 'display': 'none'});
	}
}

function fetch_register_password(objpass) {
	$('#status_passwords > div').css({ 'display': 'none'});
	if (objpass.name=='password') {
		//alert('len'+objpass.value.length);
		if (objpass.value.length<6) {
			$('#status_password_1').css({ 'display': 'block'});
		} else {
			$('#status_password_2').css({ 'display': 'block'});
		}
	} else {
		if ($('#password').attr("value")!=$('#passwordconfirm').attr("value")) {
			$('#status_password_3').css({ 'display': 'block'});
		}
	}

	if ($('#password').attr("value")==$('#passwordconfirm').attr("value") && objpass.value.length>5) {
		$('#status_password_4').css({ 'display': 'block'});
	}	
	
}

function fetch_register_username (username) {
	$('#statuses_username > div').css({ 'display': 'none'});

	if (username.length>2) {
		 	var response = $.ajax({type: 'GET',url: 'http://www.lady.ru/club/register/checkuser/'+username,async: false}).responseText;
		 	result = response.split("::");

		 if (result[0]==1) {
		 	
		 	$('#status_username_ok > span').html(result[1]);
		 	$('#status_username_ok').css({ 'display': 'block'});
		 } else {
		 	//alert('test'+$('#status_username_ok > span').html());
		 	$('#status_username_wrong > span').html(result[1]);
		 	$('#status_username_wrong').css({ 'display': 'block'});
		 }
	} else {
		 	$('#status_username_wrong > span').html('Ник меньше 3 символов');
		 	$('#status_username_wrong').css({ 'display': 'block'});
	}

}

function fetch_pm(pmid,u) {
	if (pmid) {
		query = 'pmid='+pmid;
		window_name =  'pmid_'+pmid;
	} else {
		query = 'u='+u;
		window_name = 'u_'+u;
	}
	window.open ('http://www.lady.ru/pm.php?'+s+'do=new&'+query,window_name,"menubar=0,resizable=0,scrollbars=no,width=475,height=555");
}


function fetch_menu_show() {

	
	if ($('#block_header_login > div > ul > .more').css('display')=='none') { 
		$('#block_header_login > div > ul > .more').css({ 'display': 'block'})		
		$('#block_header_login_expand_img').attr({ 'src': 'http://img.lady.ru/themes/images/arrow_up.gif'})	
	} else {
		$('#block_header_login > div > ul > .more').css({ 'display': 'none'})
		$('#block_header_login_expand_img').attr({ 'src': 'http://img.lady.ru/themes/images/arrow_down.gif'})	
	}

}

function fetch_url(url) {
	document.location = url ;
}



jQuery.preloadImages = function() {
   jQuery.each (arguments,function (e) {
       jQuery("<img>").attr("src", this);
   });
}

$.preloadImages("http://img.lady.ru/themes/images/arrow_down.gif", "http://img.lady.ru/themes/images/arrow_up.gif");

function show_shockwave(src, height, width) {
	document.write('<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0" width="' + width + '" height="' + height + '">');
	document.write('<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'">');
	document.write('<param name="swStretchStyle" value="meet">');
	document.write('<param name="bgColor" value="#000000">');
	document.write('<param name="src" value="' + src + '">');
	document.write('<embed src="' + src + '" width="' + width + '" height="' + height + '" bgColor="#000000" swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'" swStretchStyle="meet" type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/"></embed>');
	document.write('</object>');
}


var last_sub_opened = '';
var sub_closetimer = 0;
function fetch_show_sub (ID) {
		//alert('ID:'+ID);
		//if (ID=='') { ID = last_sub_opened ;alert('test');} else {ID=ID;alert('test2:'+last_sub_opened+':'+ID)}
	//alert($('#'+ID).css('visibility')+'::'+$('#'+ID).css('display'));
	if ($('#'+ID).css('display')=='none') { 
		$('#'+ID).show();
		last_sub_opened = ID ;
		fetch_cleartimer_sub();
		//alert('test:'+ID+'::'+$('#'+ID+'> .wrapper > ul > li').html());
		//$('#'+ID).bind('mouseover', fetch_show_sub(ID));
		//$('#'+ID+' > .wrapper > ul').bind('mouseover', fetch_show_sub(ID));
		//$('#'+ID+'> .wrapper > ul > li').bind('mouseover', fetch_show_sub(ID));
		//$('#'+ID+'> .wrapper > ul > li').bind('mouseout', fetch_close_sub(ID));
	} else {
		$('#'+ID).hide();
	}
}

function fetch_close_sub () {
 	sub_closetimer = window.setTimeout(fetch_hide_sub, 500);
}

function fetch_hide_sub () {
	$('#'+last_sub_opened).hide();
}

function fetch_cleartimer_sub () {  
	if(sub_closetimer) {  
		window.clearTimeout(sub_closetimer);
     	sub_closetimer = null;
    }
}

function openInNewWindow(url) {
// Change "_blank" to something like "newWindow" to load all links in the same new window
	var newWindow = window.open(url, '_blank');
	newWindow.focus();
	return false;
}

function fetch_load_select (url,selobj){

    $.getJSON(url, function(j){
      var sel_options = '';
      for (var i = 0; i < j.length; i++) {
        sel_options += '<option value="' + j[i].value + '">' + j[i].option + '</option>';
      }
      if (j.length==0) {
      	 sel_options = '<option value="0" disabled>нет записей</option>';
      }
      
      selobj.html(sel_options);
    });
}

//document.onclick = fetch_hide_sub;


function switch_tab (tab_block,next_tab) {
	//alert ("id" + '#switch_'+tab_block);
	prev_tab = $('.switch_'+tab_block+' > h4.selected').attr('id').replace('title_','');
	//alert ('prev:' + prev_tab);
	if (prev_tab==next_tab) {
		return false;
	}
	
	$("#title_"+prev_tab).removeClass('selected');
	$("#"+prev_tab).css('display','none');
	
	$("#title_"+next_tab).toggleClass('selected');
	$("#"+next_tab).css('display','block');
	
}


function fetch_unescape(str) {
	str=str.replace(/\&nbsp;/g,' ');
	str=str.replace(/\&laquo;/g,'"');
	str=str.replace(/\&raquo;/g,'"');
	str=str.replace(/\&ldquo;/g,'"');
	str=str.replace(/\&bdquo;/g,'"');
	str=str.replace(/<br \/>/g,"\n");
	str=str.replace(/\&mdash;/g,"-");
	
	
	str=str.replace(/\&quot;/g,'"');
	str=str.replace(/\&apos;/g,'"');
	str=str.replace(/\&#39;/g,'"');

	//alert (str);
	return str;
}