/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, do_check)
{

	var elts  = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;
    var i = 0;
	
    for ( i; i < elts_cnt; i++)
    {
        elts[i].checked = do_check;
		v = the_form + "_submit";
		if (elts[i].name.indexOf(v) != -1)
		{
			elts[i].disabled = !do_check;
		}
    } // end for
	return true;
} // end of the 'setCheckboxes()' function


function setCheckbox(the_form)
{
    var elts = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;
    
    var allUnchecked = true;
	
    for (var i = 0; i < elts_cnt; i++)
    {
        if(elts[i].checked) allUnchecked = false;
    }
    
    for (var i = 0; i < elts_cnt; i++)
    {
		v = the_form + "_submit";
        if (elts[i].name.indexOf(v) != -1) elts[i].disabled = allUnchecked;
    }

    return true;
}

var win = "width=500,height=600,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
function get_gallery(id_prof)
{
   window.open("photos_gallery.php?ID="+id_prof,'gallery',win);
}


function launchTellFriend ()
{
    var win = "width=300,height=300,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php",'tellfriend',win);
    return false;
}


function launchTellFriendProfile ( sID )
{
    var win = "width=300,height=300,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php?ID="+sID,'tellfriendprofile',win);
    return false;
}


function ShowShowHide ( show_name, show_name2, hide_name )
{
    if (hide_name) hide_name.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
    if (show_name2) show_name2.style.display = 'inline';
}

function ShowHideHide ( show_name, hide_name, hide_name2 )
{
    if (hide_name) hide_name.style.display = 'none';
    if (hide_name2) hide_name2.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
}

function charCounter(field,maxLength,countTarget)
{

	field = document.getElementById(field);
	countTarget = document.getElementById(countTarget);
	var inputLength=field.value.length;

	if(inputLength >= maxLength)
	{
		field.value=field.value.substring(0,maxLength);

	}
	countTarget.innerHTML=maxLength-field.value.length;
	
	
}



/**
 * change images onHover mouse action
 */
function show(FileName,jpg1Name)
{
	document.images[FileName].src = jpg1Name;
}

/**
 * set status of the browser window to 's'
 */
function ss(s) 
{
	window.status = s;
	return true;
}

/**
 * set status of the browser window to empty
 */
function ce()
{
	window.status='';
}


/**
 * insert emotion item
 */
function emoticon( txtarea, text ) {

	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function docOpen(text)
{
	newWindow=window.open('','','toolbar=no,resizable=yes,scrollbars=yes,width=400,height=300');
	newWindow.document.open("text/html");
	newWindow.document.write(unescape(text));
	newWindow.document.close();
}


function get_data( container, url, siteUrl )
    {

        if ( container )
        {
	    var container = document.getElementById( container );
	    container.innerHTML = " ... ";
        }

        var XMLHttpRequestObject = false;

        if ( window.XMLHttpRequest )
        {
			XMLHttpRequestObject = new XMLHttpRequest();
        }
        else if ( window.ActiveXObject )
        {
			XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }

	if( XMLHttpRequestObject )
        {
    	    var data_source = siteUrl + 'menu_xml.php' + url;
    	    XMLHttpRequestObject.open( "GET", data_source );
    	    XMLHttpRequestObject.onreadystatechange = function()
    	    {
				if ( XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 )
				{
					var xmlDocument = XMLHttpRequestObject.responseXML;
					delete XMLHttpRequestObject;
					XMLHttpRequestObject = null;
					
					names = xmlDocument.getElementsByTagName("name");
					links = xmlDocument.getElementsByTagName("link");
					
					list_sublinks(names, links);
				}
    	    }
            XMLHttpRequestObject.send( null );
	}
	//container.innerHTML = '';

	
	function list_sublinks(names, links)
	{	    
    	var loopIndex, name, link, maxIndex = names.length;
    
	    container.innerHTML = '';
	    for ( loopIndex = 0; loopIndex < maxIndex; loopIndex++ )
   	    {
	    
		    //if ( values[loopIndex].firstChild.nodeName=="name")
			name = names[loopIndex].firstChild.nodeValue;
		    
		    //if ( values[loopIndex].childNodes[1].nodeName=="link")
			link = links[loopIndex].firstChild.nodeValue;
					    
		    container.innerHTML += '<a href="' + link + '" class="member_submenu">' + name + '</a><br />';
	    }
	
	}
}


function createNamedElement( type, name )
{
	
    var element;
		
    try
    {
        element = document.createElement('<'+type+' name="'+name+'">');
    } catch (e) { }

    if (!element || !element.name) // Cool, this is not IE !!
    {
        element = document.createElement(type)
        element.name = name;
    }
								
    return element;
}
									
function display_node(node, siteUrl)
{

    var nn = document.getElementById( node );
    
	var sub_name = node.split('_')[1];
    if ( 'none' == nn.style.display )
    {
	nn.style.display='block';
	if ( '' == nn.innerHTML )    
	    get_data( node, '?action=menu&ID=' + sub_name, siteUrl);
    }
    else
    {
		nn.style.display='none';
    }
    
}

function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  
  return true;
}


function toggle(d)
{
	var sm = document.getElementById("upper_submenu");
	var list = sm.childNodes;
	for (var i = 0; i < list.length; i++) { list[i].style.display="none";}

	var dd = document.getElementById("s" + d);
	if (!dd) { d = 4; var dd = document.getElementById("s" + d); }
	dd.style.display="block";

	var um = document.getElementById("upper_menu");
	var list = um.getElementsByTagName("A");
	for (var i = 0; i < list.length; i++) { list[i].style.color="#FFFFFF";}

	var ll = document.getElementById("l" + d);
	if (ll) { ll.style.color="#FBFFD7"; }

	$.cookie('menu_id', d);
}

function standard_toggle(d)
{
	var dd = document.getElementById(d);
	if (dd.style.display=='none') { dd.style.display="block"; }
	else  { dd.style.display="none"; }
}

function toggle_sub(d)
{
	standard_toggle(d);
	if (d == 'sub_c1') { document.getElementById('sub_c2').style.display = "none"; document.getElementById('sub_c3').style.display = "none"; }
	if (d == 'sub_c2') { document.getElementById('sub_c1').style.display = "none"; document.getElementById('sub_c3').style.display = "none"; }
	if (d == 'sub_c3') { document.getElementById('sub_c1').style.display = "none"; document.getElementById('sub_c2').style.display = "none"; }
}

// Мигание строки
var sR=1,sG=5,sB=5; var R=255,G=255,B=255; var b=true;
function h(color)
{hn=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")
if (color<0) return "00"; else if (color>255) return "FF";
else { s=""+hn[Math.floor(color/16)]+hn[color%16]; return s;}
}
function toH(red, green, blue) {return '#' + h(red)+h(green)+h(blue)}
function RGB(red, green, blue) {return toH(red, green, blue)}
function setElementColor(r,g,b,ename) { document.getElementById(ename).style.color=RGB(r,g,b);}
function BlinkIt(ename)
{ if(b==true)
{ if((R>256)||(G>256)||(B>256)) b=false;
R+=sR; G+=sG; B+=sB;
} else
{ if((R<0) || (G<0) || (B<0)) b=true;
R-=sR; G-=sG; B-=sB;
}
setElementColor(R,G,B,ename);
setTimeout("BlinkIt('"+ename+"')", 1)
}
