// ClanSphere 2009 - www.clansphere.net

// $Id: clansphere.js 1430 2008-12-10 13:08:44Z Fr33z3m4n $



 	



function js_check_all(formobj) {



    exclude = new Array();

    exclude[0] = 'keepattachments';

    exclude[1] = 'allbox';

    exclude[2] = 'removeall';

    js_toggle_all(formobj, 'checkbox', '', exclude, formobj.allbox.checked);

}



function high(which2) {

    theobject=which2

    highlighting=setInterval("highlightit(theobject)",50)

}

function low(which2) {

    clearInterval(highlighting)

    if (which2.style.MozOpacity)

    which2.style.MozOpacity=0.3

    else if (which2.filters)

    which2.filters.alpha.opacity=30

}

function highlightit(cur2) {

    if (cur2.style.MozOpacity<1)

    cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.1

    else if (cur2.filters&&cur2.filters.alpha.opacity<100)

    cur2.filters.alpha.opacity+=10

    else if (window.highlighting)

    clearInterval(highlighting)

}

var timeout;

function hvHide() {

	var showThis = 'hv_home';

	document.getElementById(showThis + '_img').className = 'tabicons img-' + showThis;

	document.getElementById(showThis).style.display = "none";

	document.getElementById(showThis).style.visibility = "visible";	



	var showThis = 'hv_clan';

	document.getElementById(showThis + '_img').className = 'tabicons img-' + showThis;

	document.getElementById(showThis).style.display = "none";

	document.getElementById(showThis).style.visibility = "visible";



	var showThis = 'hv_community';

	document.getElementById(showThis + '_img').className = 'tabicons img-' + showThis;

	document.getElementById(showThis).style.display = "none";

	document.getElementById(showThis).style.visibility = "visible";

}



function hvShow(showThis) {

	/*setTimeout(anzeige(showThis), 5000);*/

	hvHide();

	document.getElementById(showThis + '_img').className = 'tabicons img-' + showThis + '_h';

	document.getElementById(showThis).style.display = "block";

	document.getElementById(showThis).style.visibility = "visible";

}



function hvHover() {

	window.clearTimeout(timeout);

}



function hvClose() {

	timeout = window.setTimeout('hvShow(document.currentMenu)',2000);

}





function cs_clip_nav(id) {

	cs_clip_id = id;

  if(document.getElementById("span_" + id).style.display == 'none') {

    document.getElementById("img_" + id).src = document.getElementById("img_" + id).src.replace(/plus/g,'minus');

    document.getElementById("span_" + id).style.display = "block";

  }

  else {

    document.getElementById("img_" + id).src = document.getElementById("img_" + id).src.replace(/minus/g,'plus');

    document.getElementById("span_" + id).style.display = "none";

  }

}



function cs_clip_home(id) {

	cs_clip_id = id;

  if(document.getElementById("span_" + id).style.display == 'none') {

    document.getElementById("span_" + id).style.display = "block";

  }

  else {

    document.getElementById("span_" + id).style.display = "none";

  }

}



/*** Rolldown ***/



var pixel = 0;

var content = '';

var speed = 5;



function menu(contentid, rows) {

  

  if (pixel != 0) return;

  content = document.getElementById('navcontent' + contentid);

  if (content.style.display == 'block') {

    height = rows * 20;

    pixel = height - 1;

    document.getElementById('pointer' + contentid).src = document.getElementById('pointer' + contentid).src.replace(/plus/g,'minus');

    closing = window.setInterval("MenuClose()",1);

  } else {

    height = rows * 20;

    pixel = 1;

    content.style.height = '0px';

    content.style.display = 'block';

    document.getElementById('pointer' + contentid).src = document.getElementById('pointer' + contentid).src.replace(/minus/g,'plus');

    opening = window.setInterval("MenuOpen()",1);

  }

}



function MenuOpen() {

  

  relation = 100 * pixel / height;

  movement = Math.ceil((-0.0004 * (relation - 50) * (relation - 50) + 1) * speed);

  pixel += movement;

  if (pixel > height) pixel = height;

  

  content.style.height = pixel + 'px';

  

  if (pixel >= height) {

    window.clearInterval(opening);

    pixel = 0;

  }

}



function MenuClose() {

  

  relation = 100 * pixel / height;

  movement = Math.ceil((-0.0004 * (relation - 50) * (relation - 50) + 1) * speed);

  pixel -= movement;

  if (pixel < 0) pixel = 0;

  

  content.style.height = pixel + 'px';

  

  if (pixel <= 0) {

    window.clearInterval(closing);

    pixel = 0;

    content.style.display = 'none';

  }

}



























function ddtabcontent(tabinterfaceid){

	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container

	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container

	this.enabletabpersistence=true

	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container

	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array

	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)

	this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)

	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")

}



ddtabcontent.getCookie=function(Name){ 

	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair

	if (document.cookie.match(re)) //if cookie found

		return document.cookie.match(re)[0].split("=")[1] //return its value

	return ""

}



ddtabcontent.setCookie=function(name, value){

	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)

}







ddtabcontent.prototype={



	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers

		this.cancelautorun() //stop auto cycling of tabs (if running)

		var tabref=""

		try{

			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr

				tabref=document.getElementById(tabid_or_position)

			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr

				tabref=this.tabs[tabid_or_position]

		}

		







catch(err){alert("Invalid Tab ID or position entered!")}

		if (tabref!="") //if a valid tab is found based on function parameter

			this.expandtab(tabref) //expand this tab

	},









	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )

		if (dir=="next"){

			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0

		}

		else if (dir=="prev"){

			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1

		}

		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function

			this.cancelautorun() //stop auto cycling of tabs (if running)

		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])

	},



	setpersist:function(bool){ //PUBLIC function to toggle persistence feature

			this.enabletabpersistence=bool

	},



	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")

		this.selectedClassTarget=objstr || "link"

	},



	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to

		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref

	},



	urlparamselect:function(tabinterfaceid){

		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL

		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index

	},



	expandtab:function(tabref){

		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand

		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through

		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""

		this.expandsubcontent(subcontentid)

		this.expandrevcontent(associatedrevids)

		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"

			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""

		}

		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers

			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)

		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array

	},



	expandsubcontent:function(subcontentid){

		for (var i=0; i<this.subcontentids.length; i++){

			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)

			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value

		}

	},



	expandrevcontent:function(associatedrevids){

		var allrevids=this.revcontentids

		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface

			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it

			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"

		}

	},



	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)

		for (var i=0; i<this.hottabspositions.length; i++){

			if (tabposition==this.hottabspositions[i]){

				this.currentTabIndex=i

				break

			}

		}

	},



	autorun:function(){ //function to auto cycle through and select tabs based on a set interval

		this.cycleit('next', true)

	},



	cancelautorun:function(){

		if (typeof this.autoruntimer!="undefined")

			clearInterval(this.autoruntimer)

	},



	init:function(automodeperiod){

		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)

		var selectedtab=-1 //Currently selected tab index (-1 meaning none)

		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index

		this.automodeperiod=automodeperiod || 0

		for (var i=0; i<this.tabs.length; i++){

			this.tabs[i].tabposition=i //remember position of tab relative to its peers

			if (this.tabs[i].getAttribute("rel")){

				var tabinstance=this

				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers

				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)

				this.tabs[i].onclick=function(){

					tabinstance.expandtab(this)

					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)

					return false

				}

				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element

					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))

				}

				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){

					selectedtab=i //Selected tab index, if found

				}

			}

		} //END for loop

		if (selectedtab!=-1) //if a valid default selected tab index is found

			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)

		else //if no valid default selected index found

			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr

		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){

			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)

		}

	} //END int() function



}

































































































var cs_textarea_size = 0;



function cs_textarea_resize(id, operation) {



  cs_textarea_size = document.getElementById(id).rows;

  if(operation == '-' && cs_textarea_size > 1) {

    document.getElementById(id).rows = cs_textarea_size - 1;

  }

  else if(operation == '+') {

    document.getElementById(id).rows = cs_textarea_size + 1;

  }

  document.getElementById("span_" + id).innerHTML = document.getElementById(id).rows;

}



function passwordcheck(pass) {



	var password_numbers = '0';

	var password_letters = '0';

	var password_lower = '0';

	var password_upper = '0';

	var special = '0';

	var new_pass = pass.split("");

	

	for (x=0;x<new_pass.length;x++) {	

		if (isNaN(new_pass[x])) {

			password_letters++;

		} else {

			password_numbers++;

		}

		var letter = new_pass[x];

		if (letter.match(/[a-z]/)) {

			password_lower++;

		}

		if (letter.match(/[A-Z]/)) {

			password_upper++;

		}

		if (letter.match(/\W/)) {

			special++;

		}

	}

	

	width = "";

	

	if(new_pass.length >= 8) { width = "25%"; }

	if(new_pass.length >= 8 && password_numbers >= 2) {	width = "50%"; }

	if(new_pass.length >= 8 && password_lower >= 3 && password_upper >= 2 && password_numbers >= 2) {	width = "75%"; }

	if(new_pass.length >= 8 && password_lower >= 3 && password_upper >= 2 && password_numbers >= 2 && special > 0) {	width = "100%"; }

	

	document.getElementById("pass_secure").style.width = width;



	

}



var cs_clip_id = 0;



function cs_clip(id) {



	cs_clip_id = id;

  if(document.getElementById("span_" + id).style.display == 'none') {

    document.getElementById("img_" + id).src = document.getElementById("img_" + id).src.replace(/plus/g,'minus');

    document.getElementById("span_" + id).style.display = "block";

  }

  else {

    document.getElementById("img_" + id).src = document.getElementById("img_" + id).src.replace(/minus/g,'plus');

    document.getElementById("span_" + id).style.display = "none";

  }

}



function cs_select_multiple(id, status) {



  var cs_select = document.getElementById(id);

  if(status == 'reverse') {

    for(var i = 0; i < cs_select.options.length; i++) {

      cs_select.options[i].selected = cs_select.options[i].selected == 0 ? 1 : 0;

    }

  }

  else {

    for(var i = 0; i < cs_select.options.length; i++) {

      cs_select.options[i].selected = status;

    }

  }

}



function cs_gamechoose (formular) {

  img = document.getElementById('game_1');

  img.src = img.src.substr(0,img.src.lastIndexOf("/")) + "/" + formular.games_id.options[formular.games_id.selectedIndex].value + ".gif";

}



function abc_set(text, id) {

  

  document.getElementById(id).value = text;

  

}



function abc_insert(aTag,eTag, name) {



	//http://aktuell.de.selfhtml.org/tippstricks/javascript/bbcode/ modified

  var input = document.getElementById(name);

  input.focus();

  /* fuer Internet Explorer */

  

  if(typeof document.selection != 'undefined') {

    /* Einfuegen des Formatierungscodes */

    var range = document.selection.createRange();

    var insText = range.text;

    range.text = aTag + insText + eTag;

    /* Anpassen der Cursorposition */

    range = document.selection.createRange();

    if(insText.length == 0) {

      range.move('character', -eTag.length);

    } else {

      range.moveStart('character', aTag.length + insText.length + eTag.length);      

    }

    range.select();

  }

  /* fuer neuere auf Gecko basierende Browser */

  else if(typeof input.selectionStart != 'undefined')

  {

    /* Einfuegen des Formatierungscodes */

    var start = input.selectionStart;

    var end = input.selectionEnd;

    var insText = input.value.substring(start, end);

    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);

    /* Anpassen der Cursorposition */

    var pos;

    if(insText.length == 0) {

      pos = start + aTag.length;

    } else {

      pos = start + aTag.length + insText.length + eTag.length;

    }

    input.selectionStart = pos;

    input.selectionEnd = pos;

  }

  /* fuer die uebrigen Browser */

  else

  {

    /* Abfrage der Einfuegeposition */

    var pos;

    var re = new RegExp('^[0-9]{0,3}$');

    while(!re.test(pos)) {

      pos = prompt("Einfuegen an Position (0.." + input.value.length + "):", "0");

    }

    if(pos > input.value.length) {

      pos = input.value.length;

    }

    /* Einfuegen des Formatierungscodes */

    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");

    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);

  }

}



function abc_insert_list(aTag,eTag, name) {



	//http://aktuell.de.selfhtml.org/tippstricks/javascript/bbcode/ modified

  var input = opener.document.getElementById(name);

  input.focus();

  /* fuer Internet Explorer */

  

  if(typeof opener.document.selection != 'undefined') {

    /* Einfuegen des Formatierungscodes */

    var range = opener.document.selection.createRange();

    var insText = range.text;

    range.text = aTag + insText + eTag;

    /* Anpassen der Cursorposition */

    range = opener.document.selection.createRange();

    if(insText.length == 0) {

      range.move('character', -eTag.length);

    } else {

      range.moveStart('character', aTag.length + insText.length + eTag.length);      

    }

    range.select();

  }

  /* fuer neuere auf Gecko basierende Browser */

  else if(typeof input.selectionStart != 'undefined')

  {

    /* Einfuegen des Formatierungscodes */

    var start = input.selectionStart;

    var end = input.selectionEnd;

    var insText = input.value.substring(start, end);

    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);

    /* Anpassen der Cursorposition */

    var pos;

    if(insText.length == 0) {

      pos = start + aTag.length;

    } else {

      pos = start + aTag.length + insText.length + eTag.length;

    }

    input.selectionStart = pos;

    input.selectionEnd = pos;

  }

  /* fuer die uebrigen Browser */

  else

  {

    /* Abfrage der Einfuegeposition */

    var pos;

    var re = new RegExp('^[0-9]{0,3}$');

    while(!re.test(pos)) {

      pos = prompt("Einfuegen an Position (0.." + input.value.length + "):", "0");

    }

    if(pos > input.value.length) {

      pos = input.value.length;

    }

    /* Einfuegen des Formatierungscodes */

    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");

    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);

  }

}



// function cs_visible(id) {

//

//  if (document.getElementById(id).style.visibility == "hidden") func = "visible"; else func = "hidden";

//  document.getElementById(id).style.visibility = func;

// }  



function cs_display(id) {



  if (document.getElementById(id).style.display == "none") func = "block"; else func = "none";

  document.getElementById(id).style.display = func;

}



function cs_validate(language, module) {

  

  modcontent = document.getElementById('mod_' + language + '_' + module);

  if (modcontent.style.display != "none") {

    modcontent.style.display = "none";

    return;

  }

  modcontent.style.display = "block";

  cs_ajax_getcontent('mods/clansphere/lang_modvalidate.php?language=' + language + '&module=' + module,'mod_' + language + '_' + module);

  

}



function cs_chmod_CheckChange(Checkbox, Value) {

	

	if (document.getElementById(Checkbox).checked == true) {

	

		document.getElementById('chmod').value = parseInt(document.getElementById('chmod').value) + Value;

	

	} else {

		

		document.getElementById('chmod').value = parseInt(document.getElementById('chmod').value) - Value;

		

	}

	

}



function cs_chmod_TextChange() {

	

	var chmod = parseInt(document.getElementById('chmod').value);

	

	document.getElementById('owner_read').checked = false;

	document.getElementById('owner_write').checked = false;

	document.getElementById('owner_execute').checked = false;

	

	document.getElementById('group_read').checked = false;

	document.getElementById('group_write').checked = false;

	document.getElementById('group_execute').checked = false;

	

	document.getElementById('public_read').checked = false;

	document.getElementById('public_write').checked = false;

	document.getElementById('public_execute').checked = false;

	

	if (chmod >= 400) {

		document.getElementById('owner_read').checked = true;

		chmod = chmod - 400;

	}

	if (chmod >= 200) {

		document.getElementById('owner_write').checked = true;

		chmod = chmod - 200;

	}

	if (chmod >= 100) {

		document.getElementById('owner_execute').checked = true;

		chmod = chmod - 100;

	}

	

	if (chmod >= 40) {

		document.getElementById('group_read').checked = true;

		chmod = chmod - 40;

	}

	if (chmod >= 20) {

		document.getElementById('group_write').checked = true;

		chmod = chmod - 20;

	}

	if (chmod >= 10) {

		document.getElementById('group_execute').checked = true;

		chmod = chmod - 10;

	}

	

	if (chmod >= 4) {

		document.getElementById('public_read').checked = true;

		chmod = chmod - 4;

	}

	if (chmod >= 2) {

		document.getElementById('public_write').checked = true;

		chmod = chmod - 2;

	}

	if (chmod >= 1) {

		document.getElementById('public_execute').checked = true;

		chmod = chmod - 1;

	}

}



function cs_shoutbox_select() {

  

  elements = document.getElementsByTagName('input');

  

  for (run = 0; run < elements.length; run++) {

    if (elements[run].name.substr(0,7) == 'select_') {

      elements[run].checked = true;

    }

  }

  

}



function js_toggle_all(formobj, formtype, option, exclude, setto) {

	for (var i =0; i < formobj.elements.length; i++)

	{

		var elm = formobj.elements[i];

		if (elm.type == formtype)

		{

			switch (formtype)

			{

				case 'radio':

					if (elm.value == option) // option == '' evaluates true when option = 0

					{

						elm.checked = setto;

					}

				break;

				case 'select-one':

					elm.selectedIndex = setto;

				break;

				default:

					elm.checked = setto;

				break;

			}

		}

	}

}



function js_check_all(formobj) {



    exclude = new Array();

    exclude[0] = 'keepattachments';

    exclude[1] = 'allbox';

    exclude[2] = 'removeall';

    js_toggle_all(formobj, 'checkbox', '', exclude, formobj.allbox.checked);

}



var cs_debugheight = 0;



function cs_debugmode() {



  if(cs_debugheight == 0)

    cs_debugheight = document.getElementById('debug').style.height;

  if(cs_debugheight == 0)

    cs_debugheight = document.getElementById('debug').offsetHeight + 'px';

  if(cs_debugheight == 0)

    cs_debugheight = document.getElementById('debug').clientHeight + 'px';



  height = document.getElementById('debug').style.height;

  document.getElementById('debug').style.height = height == '100%' ? cs_debugheight : '100%';

}



 function cs_visible(id) {



  var cs_lines_shown = document.getElementById(id).style.visibility;



  if(cs_lines_shown == 'hidden')

    document.getElementById(id).style.visibility = 'visible';

  else

    document.getElementById(id).style.visibility = 'hidden';

 }

 

