// login

function login_error() {
	document.getElementById('show_login').style.display = 'none';
	document.getElementById('show_loginforget').style.display = 'none';
	document.getElementById('show_loginerror').style.display = 'block';
	document.getElementById('show_loginforgeterror').style.display = 'none';
	document.getElementById('show_loginforgetok').style.display = 'none';
}
	
function login() {
	document.getElementById('show_loginforget').style.display = 'none';
	document.getElementById('show_loginerror').style.display = 'none';	
	document.getElementById('show_login').style.display = 'block';
	document.getElementById('show_loginforgeterror').style.display = 'none';
	document.getElementById('show_loginforgetok').style.display = 'none';
}
	
function forget() {
	document.getElementById('show_login').style.display = 'none';
	document.getElementById('show_loginerror').style.display = 'none';
	document.getElementById('show_loginforget').style.display = 'block';
	document.getElementById('show_loginforgeterror').style.display = 'none';
	document.getElementById('show_loginforgetok').style.display = 'none';
}	

function forget_error() {
	document.getElementById('show_loginforget').style.display = 'none';
	document.getElementById('show_loginforgeterror').style.display = 'block';
}

function forget_ok() {
	document.getElementById('show_loginforgetok').style.display = 'block';
	document.getElementById('show_loginforgeterror').style.display = 'none';
	document.getElementById('show_loginforget').style.display = 'none';
}
	
//random
function swapPic() {  
	if(document.getElementById) {  
	    var thePicture=document.getElementById("rotate");  
	    var picPath="images/public/index"+rnd(5)+".jpg";  
	    thePicture.style.background="url("+picPath+")";  
    }  
}  

function rnd(n) {  
	return Math.floor(Math.random() * n) + 1;  
}  
  
//hover
startList = function() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("users");
		if (navRoot) {
			for (i=0; i < navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					}
	
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}

window.onload=startList;


	
//tabs
function tab1() {
	document.getElementById('tab1').style.display = 'block';
	document.getElementById('tab2').style.display = 'none';
	document.getElementById('tab3').style.display = 'none';
}
function tab2() {
	document.getElementById('tab1').style.display = 'none';
	document.getElementById('tab2').style.display = 'block';
	document.getElementById('tab3').style.display = 'none';
}
function tab3() {
	document.getElementById('tab1').style.display = 'none';
	document.getElementById('tab2').style.display = 'none';
	document.getElementById('tab3').style.display = 'block';
}

	

	
//pop

	function hideDiv() {
	//window.scrollTo(0,0);
	document.getElementById('avatars').style.display = 'none';
	}
	
	function showAvatarsDiv(id) {
	//window.scrollTo(0,0);
	
	document.getElementById('avatars' + id).style.display = 'block';
	
	}

function checkAll(form, field) {

	for (var i=0 ; i < form.elements.length; i++) {
		var e = form.elements[i];
        if (e.type=='checkbox' && e.name==field && !e.disabled)
			e.checked = true;
    }

	if (form.elements['allbox'])
	    form.elements['allbox'].checked = true;

}

function uncheckAll(form, field) {

	for (var i=0 ; i < form.elements.length; i++) {
		var e = form.elements[i];
        if (e.type=='checkbox' && e.name==field && !e.disabled)
			e.checked = false;
    }

	if (form.elements['allbox'])
	    form.elements['allbox'].checked = false;
}


function checkUncheckAll(form, field, allbox) {
	if (allbox.checked)
		return checkAll(form, field);
	return uncheckAll(form, field);
}

function checkAllbox(form, field, allbox) {

	var checked = 0; var unchecked = 0;
	for (var i=0 ; i < form.elements.length; i++) {
		var e = form.elements[i];
        if (e.type=='checkbox' && e.name==field && !e.disabled) {
			if (e.checked) checked++;
			if (!e.checked) unchecked++;
        }
    }
    
    if (checked && !unchecked) allbox.checked = true;
	else allbox.checked = false;	
}

function js_in_array(the_needle, the_haystack, simpleMatch){

    var the_hay = the_haystack.toString();

    if(!the_hay || !the_needle || (the_hay == '')){

        return false;

    }

    for(var i in the_haystack){

        var the_hay = the_haystack[i];

        if(simpleMatch){

            the_hay = the_hay.toString().toLowerCase();

            the_needle = the_needle.toString().toLowerCase();

        }

        if(the_hay == the_needle){

            return true;

        }

    }

    return false;

}

function addMoreInviteFields() {

	var ol = document.getElementById('InviteEmails');

	var mores = ol.getElementsByTagName('a');
	for (i = 0; i < mores.length; i++) {
		mores[i].style.display = 'none';
	}
	ol.innerHTML += '<li><input id="email[]" type="text" /><a href="javascript:;" onclick="addMoreInviteFields();" class="padd_left_5">More</a></li>';	
}

function bClick(zone) {
	$.get(Prefix + "/banners/",{
	            	action: "click",
	            	zone: zone
	           	}, function(xml) { return false; }); 
}

function ReplaceAllTextareas() {

	// replace all of the textareas
    var allTextAreas = document.getElementsByTagName("textarea");
    for (var i=0; i < allTextAreas.length; i++) {
		if (allTextAreas[i].className == 'nofckeditor') continue;
        var oFCKeditor = new FCKeditor( allTextAreas[i].name ) ;
        oFCKeditor.BasePath = Prefix + "/fckeditor/";
        oFCKeditor.Width = allTextAreas[i].style.width;
        oFCKeditor.Height = allTextAreas[i].style.height;
		//CKFinder.SetupFCKeditor( oFCKeditor, Prefix + '/fckeditor/editor/ckfinder/' ) ;
        oFCKeditor.ReplaceTextarea() ;
    }
}

function array_unique( array ) {

    var p, i, j;
    for(i = array.length; i;){
        for(p = --i; p > 0;){
            if(array[i] === array[--p]){
                for(j = p; --p && array[i] === array[p];);
                i -= array.splice(p + 1, j - p).length;
            }
        }
    }
 
    return true;
}

function openChat() {

	var win = window.open(Prefix + '/chat/flashchat.php', 'chat', 'width=800,height=600,menubar=no,toolbars=no');
	win.focus();
	return false;
}