// Title: zNights Body JavaScripts
// URL: http://www.znights.com
// Version: 9.10.22
ajax_popup_refresh = function(znurl) {
	var win = Windows.getFocusedWindow();
	win.setURL(znurl);
	win.refresh();
};
updatecook = function(itemmenu){
	cookitem='span_'+itemmenu;
	if(document.getElementById(cookitem).style.display!='none'){
		var expireDate = new Date();
		expireDate.setMinutes(expireDate.getMinutes()+10);
		document.cookie = "treemenustatus=" + itemmenu + "; expires=" + expireDate.toGMTString();
	}else{
		clearcook();
	}
};
clearcook = function(){
	var expireDate = new Date();
	expireDate.setMinutes(expireDate.getMinutes()+10);
	document.cookie = "treemenustatus=" + "0" + "; expires=" + expireDate.toGMTString();
};
storeCaret = function(textE) {
	if (textE.createTextRange) {textE.caretPos = document.selection.createRange().duplicate();}
};
emote_text = function(text) {
	var txtarea = document.zntext.znmessage;
	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();
	}
};
emote_text_chat = function(text) {
	var txtarea = document.znchat.znmessage;
	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();
	}
};
emote_zchat = function(text) {
	var txtarea = document.zchat.zmessage;
	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();
	}
};
emote_zwall = function(text) {
	var txtarea = document.zwall.zmessage;
	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();
	}
};
emote_text_mail = function(text) {
	var txtarea = document.getElementById('msg').value;
	text = ' ' + text + ' ';
	txtarea += text;
	document.getElementById('msg').value = txtarea;
	document.getElementById('msg').focus();
};
emote_text_quote = function(text1,text2) {
	var delim = "/gi";
	var replaceStr = "\n";
	var regexp = eval("/" + "_br_" + delim);
	text3 = text2.replace(regexp, replaceStr);
	var txtarea = document.getElementById('msg').value;
	txtarea  += "\n" + text1 + "\n" + text3 + "\n";
	document.getElementById('msg').value = txtarea;
	document.getElementById('msg').focus();
};

var agt = navigator.userAgent.toLowerCase();
var originalFirstChild;
var timeout;

createTip = function(string) {
	return '<div><table bgcolor="#000000" width="500" cellspacing="1" cellpadding="2" border="0"><tr><td class="forumheader2"><table cellpadding="0" cellspacing="1" width="100%"><tr><td class="fcaption">Profile Details</td><tr><tr><td class="forumheader2">' + string + '</td></tr></table></td></tr></table></div>';
};

var keylist="234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var temp='';
generatepass = function(plength){
	temp='';
	for (i=0;i<plength;i++) {
		temp+=keylist.charAt(Math.floor(Math.random()*keylist.length));
	}
	return temp;
};
populateform = function(enterlength){
	document.register.passwd.value = generatepass(enterlength);
};
WithoutContent = function(ss) {
	if(ss.length > 0) { return false; }
	return true;
};
NoneWithContent = function(ss) {
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].value.length > 0) { return false; }
		}
	return true;
};
NoneWithCheck = function(ss) {
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].checked) { return false; }
		}
	return true;
};
WithoutCheck = function(ss) {
	if(ss.checked) { return false; }
	return true;
};
WithoutSelectionValue = function(ss) {
	for(var i = 0; i < ss.length; i++) {
		if(ss[i].selected) {
			if(ss[i].value.length) { return false; }
			}
		}
	return true;
};
WithZeroSelectionValue = function(ss) {
	if(ss.options[ss.selectedIndex].value == "0") {
		return true;
	} else {
		return false;
	}
};
WithZeroSelectionValueMail = function(ss) {
	if(ss == "0") {
		return true;
	} else {
		return false;
	}
};
scaleIt = function(v) {
	var scalePhotos = document.getElementsByClassName("scale-image");
	floorSize = 0.21;
	ceilingSize = 1.0;
	v = floorSize + (v * (ceilingSize - floorSize));
	for (i=0; i < scalePhotos.length; i++) {
		scalePhotos[i].style.width = (v*158)+"px";
	}
};
checkchars = function(cur){
	var maxlength=2500;
	if (cur.msg.value.length>maxlength){
		window.alert("Please keep your message to 2500 or less characters!");
		return false;
	}
};
checkLen = function(Target) {
	StrLen = Target.value.length;
	if (StrLen > 2500 ) {
		Target.value = Target.value.substring(0,2500);
		charsLeft = 0;
	} else {
		charsLeft = 2500 - StrLen;
	}
	document.getElementById('charsRemain').value = charsLeft;
};
checkRLen = function(Target) {
	evt = (evt) ? evt : window.event;
	var t;
	var c;
	var mytext = Target.value;
	StrLen = mytext.length;
	if (StrLen > 0 ) {
		t = mytext.charAt(StrLen - 1);
		c = mytext.charCodeAt(StrLen - 1);
		if((c >= 97 && c <= 122) || (c >= 65 && c <= 90) || (c >= 48 && c <= 57)) {
		} else {
			Target.value = mytext.substring(0,(StrLen - 1));
		}
	}
};
setTabs = function(tab,tabid) {
	var i;
	var counter;
	var obj = document.getElementById(tab + tabid);
	if(tab == 'playtab') {counter = 8;}
	if(tab == 'potd') {counter = 4;}
	if(tab == 'Pgroups') {counter = 7;}
	if(tab == 'media') {counter = 4;}
	if(tab == 'interact') {counter = 4;}
	if(tab == 'contacts') {counter = 3;}
	if(tab == 'groupsM') {counter = 5;}
	if(tab == 'subs') {counter = 5;}
	if(tab == 'donate') {counter = 3;}
	if(tab == 'groups') {counter = 7;}
	if(tab == 'mail') {counter = 5;}
	if(tab == 'whoistab') {counter = 4;}
	if(tab == 'account') {counter = 9;}
	if(tab == 'magtab') {counter = 15;}
	if(tab == 'zchattab') {counter = 6;}
	if(tab == 'comms') {counter = 10;}
	if(tab == 'nmail') {counter = 10;}
	if(tab == 'req') {counter = 3;}
	for(i=1;i<=counter;i++) {
		var obj1 = document.getElementById(tab + i);
		obj1.className="";
	}	
	obj.className="selected";
};
startChatUpload = function(){
      document.getElementById('zchat_upload_process').style.display = '';
      document.getElementById('zchat_upload_form').style.display = 'none';
      return true;
};
startIMupload = function(){
      document.getElementById('im_upload_process').style.display = '';
      document.getElementById('im_upload_form').style.display = 'none';
      return true;
};
startProfilePicUpload = function(){
      document.getElementById('profilepic_upload_process').style.display = '';
      document.getElementById('profilepic_upload_form').style.display = 'none';
      return true;
};
startAvatarUpload = function(){
      document.getElementById('avatar_upload_process').style.display = '';
      document.getElementById('avatar_upload_form').style.display = 'none';
      return true;
};
startVerifyUpload = function(){
      document.getElementById('verify_upload_process').style.display = '';
      document.getElementById('verify_upload_form').style.display = 'none';
      return true;
};
startWallUpload = function(){
      document.getElementById('wall_upload_process').style.display = '';
      document.getElementById('wall_upload_form').style.display = 'none';
      return true;
};
