var win_opened2 = new Array();
var ajaxObjects = new Array();

function open_messwindow (uid, uname) { 

  var top = (screen.height-600)/2;
  var left = (screen.width-600)/2;
  
  win_opened2[uid] = window.open('/chat/index.php?id='+uid, 'TChat'+uname, "status=no,height=400,width=585,screenx="+left+",screeny="+top+",left="+left+",top="+top);
  win_opened2[uid].focus();
}

var scrOfY = 0;
var scrOfX = 0;
var IE = document.all?true:false;
var NN = document.layers?true:false;
var MB = document.getElementById?true:false;
var use_css;
var use_layers;
var visible = 0;

//--------------------------- SEND MARKER ---------------------------
var req;
var url;

function send_marker(url, process) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = process;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = process;
            req.open("GET", url, true);
            req.send();
        }
    }
}
//--------------------------- SEND MARKER THAT USER IGNORED THE PERSON ---------------------
function ignore_user (id) {	
    var process = all_ok;
	send_marker('/chat/engine.php?ignore='+id, process);	
}
function all_ok () {
    var all_ok = true;	
}

//------------------------------ [ RATE ] -------------------------------
function send_rating(){
	document.rate_form.submit();
}
//-----------------------[ Language menu ]---------------------------
/*
function langmenu_show() {
	//alert(document.getElementById("show_lang").innerHTML); 
	document.getElementById("show_lang").style.display = "block";
//	var main_menu = document.getElementById('main_menu');
//	main_menu.style.zIndex = '1';
}
function langmenu_hide() {
	document.getElementById("show_lang").style.display = "none";
//	var main_menu = document.getElementById('main_menu');
//	main_menu.style.zIndex = '20';
}
*/
/*
//-----------------------[ Login ]---------------------------------
function login_popup(show_hide) {
	
	var login_pop = document.getElementById('login_flat');
	var main_menu = document.getElementById('main_menu');
	if (login_pop.style.display != 'block' && show_hide != 1 ) {
		login_pop.style.display = 'block';
		main_menu.style.zIndex = '1';
	} else {
		login_pop.style.display = 'none';
		if (show_hide != 1 ) {
			main_menu.style.zIndex = '20';
		}		
	}

}
*/
//----------------------[ Search ]-------------------------------
function top_search_set_active (set_this) {
	
	if (set_this == 'video') {
	  document.getElementById("top_search_video").className = 'ser_video ser_act_video';
	  document.getElementById("top_search_user").className = 'ser_user ser_dact_user';
	  document.getElementById("top_sertab").value = 'videos';
	} else {
	  document.getElementById("top_search_video").className = 'ser_video ser_dact_video';
	  document.getElementById("top_search_user").className = 'ser_user ser_act_user';
	  document.getElementById("top_sertab").value = 'users';
    }	
}
//-------------------[ Family filter ]------------------------
function turn_filter_on(linkbtn){

     var maks = ajaxObjects.length;
     ajaxObjects[maks] = new sack();
     ajaxObjects[maks].requestFile = '/other.php?p=family_filter&xmlreturn=true';
	 ajaxObjects[maks].onCompletion = function(){ familychange_to_on(maks, linkbtn); };
	 ajaxObjects[maks].runAJAX();

}
function familychange_to_on(maks, linkbtn){ /* Set family filter to on: starts when xml is returned */
    var rssContent = ajaxObjects[maks].responseXML; 
	if ( rssContent == null ) {  return; }
	var XmlContent = rssContent.documentElement;
	
	linkbtn.innerHTML = XmlContent.getElementsByTagName('name')[0].firstChild.data;
    linkbtn.className='f_on';
	linkbtn.onclick=function() { window.location = '/other.php?p=family_filter';}
    
}
//---------------------------[ Email check ]------------------------------------
function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){return false;}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {return false;}
if (str.indexOf(at,(lat+1))!=-1) {return false;}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {return false;}
if (str.indexOf(dot,(lat+2))==-1) { return false;}
if (str.indexOf(" ")!=-1) { return false;}
   return true					
}
/*
For acting menu
*/
function menu_selecter (mnu_id, item_id){
    if (mnu[mnu_id][item_id] == true){ return; } // allready selected menu
	//find the activ element and deactivate
	for (a=0;a<mnu[mnu_id].length;a++) {

		if (mnu[mnu_id][a] == true) { 
		   // DeSelect menu
		   var old_actmenu = document.getElementById(mnu[mnu_id]['id']+a);
		   old_actmenu.className = '';
		   old_actmenu.firstChild.className = '';
		   // DeSelect container div
		   document.getElementById(mnu[mnu_id]['div']+a).style.display = 'none';
		   
		   mnu[mnu_id][a] = false;
		   break; 		    
		}
	}
	// Select menu
	var new_actmenu = document.getElementById(mnu[mnu_id]['id']+item_id);
	new_actmenu.className = 'activ_ita';
    new_actmenu.firstChild.className = 'activ_its';
	// Select container div
	document.getElementById(mnu[mnu_id]['div']+item_id).style.display = 'block';
	
	mnu[mnu_id][item_id] = true;
	
	load_menu_function(mnu_id, item_id);
    
   return false;
}
/* special */
String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};
// lists
var act_menu_visible = new Array();
var act_menu_timeout = new Array();
var act_menu_array = new Array();
function show_act_menu(menu_id, inside){

	if (act_menu_visible[menu_id] == true && inside == false) {
	   clearTimeout(act_menu_timeout[menu_id]);
	   act_menu_timeout[menu_id] = setTimeout("hide_act_menu("+menu_id+");", 500); 
	} else if (act_menu_visible[menu_id] == false && inside == true) {
	   Effect.Appear(act_menu_array[menu_id], {duration:0.6});	
	   act_menu_visible[menu_id] = true;
	} else if (inside == true){
		clearTimeout(act_menu_timeout[menu_id]); 
		Effect.Appear(act_menu_array[menu_id], {duration:0.6});	 
		act_menu_visible[menu_id] = true;
	}
}
function hide_act_menu(menu_id) {
	act_menu_visible[menu_id] = false;
	Effect.Fade(act_menu_array[menu_id],{duration:0.6});	
}

function init_act_menu(menu_id, item_id) {
    act_menu_array[menu_id] = item_id;
	act_menu_visible[menu_id] = false;
	act_menu_timeout[menu_id] = false;
}

/* slider */
var SlideisExtended = 0;
function slideSideBar(){
    
	$('sideBarTab').blur();
	
	new Effect.toggle('sideBarContents', 'blind', {scaleX: 'true', scaleY: 'true;', scaleContent: false, afterFinish: slideSideBarDone});
	
	return false;
}
function slideSideBarDone() {
	if(SlideisExtended==0) {		
		//new Effect.Fade('sideBarContents',	{ duration:1.0, from:0.0, to:1.0 });
		$('sideBarTabimg').className = 'bg_link extended';
		SlideisExtended=1;
	} else {
		//new Effect.Fade('sideBarContents',	{ duration:1.0, from:1.0, to:0.0 });
		$('sideBarTabimg').className = 'bg_link';
		SlideisExtended=0;
	}
}

function init_sidebar(){
	Event.observe('sideBarTab', 'click', slideSideBar, true);
}
var image_resizing = false;
var image_size_now = 0;
function img_screen_resize(){
   if (cm_visible) {
      return;
   }
   var scr_viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal

   var exdate=new Date();
   exdate.setDate(exdate.getDate() + 2);   
   document.cookie="pic_resize=" + escape(scr_viewport.width-340)+','+escape(scr_viewport.height)+'; expires='+exdate.toUTCString()+'; path=/';

  for (var index = 0, len = image_dimgsizes.length; index < len; ++index) {
       var item = image_dimgsizes[index];
  
	   if((scr_viewport.width-340)>item.width && (scr_viewport.height)>item.height || index == image_dimgsizes.length-1 ) {
 	        $('comment_infos').setStyle({width: item.width+'px',height: item.height+'px'});
			$('comment_infos_holder').setStyle({width: item.width+'px',height: item.height+'px'});
			$('pic_prevm').writeAttribute({width: item.width, height: item.height });
						
		    var load_image = new Image();
 			load_image.src = item.img;
 			load_image.onload = function() {     
			  $('pic_prevm').writeAttribute({src: item.img});
			}
		   return false;
	   }
  }
 
}

