/***********************************************
* Kool Zone Master Java Script Package
* Contains Various Functions for Boards.
* Last Updated: 3:20 AM 11/4/2008
***********************************************/


<!--


	/***********************************************
	* DHTML Window Widget- © Dynamic Drive (www.dynamicdrive.com)
	* This notice must stay intact for legal use.
	* Visit http://www.dynamicdrive.com/ for full source code
	*
	* Using This For Features Pop-up
	***********************************************/


	/** KZ Features List Function
	**************************/

	function openFeatureList()
	{

		featureBox=dhtmlmodal.open('FeatureBox', 'iframe', 'js/modalfiles/features.htm', 'Kool Zone Feature List', 'width=500px,height=500px,center=1,resize=0,scrolling=1')

	} //End "openFeatureList" function



	/** Standard IPB Scripts
	**************************/

	function do_preview(skin) {
		
		
		window.open( "http://www.koolzone.net/boards/index.php?s=&" + 'skinid='+skin, 'Preview', 'width=800,height=600,top=0,left=0,resizable=1,scrollbars=1,location=no,directories=no,status=no,menubar=no,toolbar=no');
		
	}


	function link_to_post(pid)
	{
		temp = prompt( "Manually copy the direct link to this post below to store the link in your computer's clipboard", "http://www.koolzone.net/boards/index.php?showtopic=8954&view=findpost&p=" + pid );
		return false;
	}
    
	function delete_post(theURL)
	{
		if (confirm('Are you sure you want to delete this message?'))
		{
			p = query2array(theURL);
			AjaxRequest(theURL);
			//window.location.href=theURL;
			ShowHide('postrow'+p['p']+'x1');
			ShowHide('postrow'+p['p']+'x2');
			ShowHide('postrow'+p['p']+'x3');

		} else {
			alert ('Ok, no action has been taken');
		} 
	}
    
	function PopUp(url, name, width,height,center,resize,scroll,posleft,postop)
	{
		if (posleft != 0) { x = posleft }
		if (postop  != 0) { y = postop  }
		if (!scroll) { scroll = 1 }
		if (!resize) { resize = 1 }
		if ((parseInt (navigator.appVersion) >= 4 ) && (center))
		{
			X = (screen.width  - width ) / 2;
			Y = (screen.height - height) / 2;
		}

		if (scroll != 0) { scroll = 1 }

		var Win = window.open( url, name, 'width='+width+',height='+height+',top='+Y+',left='+X+',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
	}
	
	function ShowHide(id1, id2)
	{
		if (id1 != '') expMenu(id1);
		if (id2 != '') expMenu(id2);
	}
	
	function expMenu(id)
	{
		var itm = null;

		if (document.getElementById)
		{
			itm = document.getElementById(id);

		} else if (document.all) {

			itm = document.all[id];

		} else if (document.layers) {

			itm = document.layers[id];
		}
	
		if (!itm)
		{
			// do nothing

		} else if (itm.style) {

			if (itm.style.display == "none")
			{
				itm.style.display = "";
			} else {
				itm.style.display = "none";
			}

	  	} else {
 
			itm.visibility = "show";
		}
	}

	function openpopup(popurl)
	{
		var winpops=window.open(popurl,"","width=300px,height=250px,location,status,resizable");
	}

	function buddy_pop()
	{
		window.open('index.php?act=buddy&s=','BrowserBuddy','width=250,height=500,resizable=yes,scrollbars=yes');
	}

	function chat_pop(cw,ch)
	{
		window.open('index.php?s=&act=chat&pop=1','Chat','width='+cw+',height='+ch+',resizable=yes,scrollbars=yes');
	}

	function multi_page_jump( url_bit, total_posts, per_page )
	{
		pages = 1;
		cur_st = parseInt("");
		cur_page  = 1;

		if ( total_posts % per_page == 0 )
		{
			pages = total_posts / per_page;
		} else { 
			pages = Math.ceil( total_posts / per_page );
		}

		msg = "Please enter a page number to jump to between 1 and" + " " + pages;

		if ( cur_st > 0 ) { cur_page = cur_st / per_page; cur_page = cur_page -1; }

		show_page = 1;

		if ( cur_page < pages )  { show_page = cur_page + 1; }
		if ( cur_page >= pages ) { show_page = cur_page - 1; } else { show_page = cur_page + 1; }

		userPage = prompt( msg, show_page );

		if ( userPage > 0  )
		{
			if ( userPage < 1 )     {    userPage = 1;  }
			if ( userPage > pages ) { userPage = pages; }
			if ( userPage == 1 )    {     start = 0;    } else { start = (userPage - 1) * per_page; }
			window.location = url_bit + "&st=" + start;
		}
	}


	function setPointer(field, action, defaultColor, pointerColor, markColor)
	{

		var newColor
		var currentColor

		currentColor=field.style.backgroundColor;

		if (action == 'over' && currentColor.toLowerCase() == defaultColor.toLowerCase())
		{
			newColor=pointerColor;
		}

		if (action == 'out' && currentColor.toLowerCase() == pointerColor.toLowerCase())
		{
			newColor=defaultColor;
		}

		if (action == 'click' && currentColor.toLowerCase() == defaultColor.toLowerCase())
		{
			newColor=markColor;
		}

		if (action == 'click' && currentColor.toLowerCase() == pointerColor.toLowerCase())
		{
			newColor=markColor;
		}

		if (action == 'click' && currentColor.toLowerCase() == markColor.toLowerCase())
		{
			newColor=pointerColor;
		}

		if (newColor)
		{
			field.style.backgroundColor=newColor;
		}
	}


	/** JS For Favorite Boards
	**************************/

	var allPageTags = new Array(); 

	function toggleForums(id)
	{
		id = 'cat'+id+'forums';
		var Aobj = document.getElementsByTagName('tr');

		for(var i=0; i<Aobj.length;i++)
		{
			if(Aobj[i].className==id)
			{
				if ( Aobj[i].style.display != "none" )
				{
					Aobj[i].style.display = "none";
			
				} else { 

					Aobj[i].style.display = "";
				}
			}
		}
	}


	/** JS For Skin Selector
	**************************/
	function change_skin(skin)
	{
		window.location.href = 'http://www.koolzone.net/boards/index.php?&setskin='+skin;
	}



	/** JS Function Set Used for
	*** Topic Management IGN Style
	*** (links not form)
	**************************/
	function ModTrasher()
	{

		document['modTrasher'].submit();

	}

	function doModAction(code)
	{
		document.modform.CODE.value = code;
		//alert(document.modform.CODE.value);
		document['modform'].submit();

	}

	function qwkMod(uid)
	{
		var winpops=window.open("http://www.koolzone.net/boards/index.php?act=UserCP&CODE=66&clean=yes&uid="+uid,"","width=620px,height=100px,location,status,resizable");
	}



	/** More Toggle Scripts
	**************************/
	function dropFeatureList() 
	{ 
		if ( document.getElementById('featureBar').style.display == "none")
		{
			document.getElementById('featureBar').style.display = "";

		} else { document.getElementById('featureBar').style.display = "none" }
	}

	function showQR(id) 
	{ 
		if ( document.getElementById(id).style.display == "none")
		{
			document.getElementById(id).style.display = "";

		} else { document.getElementById(id).style.display = "none" }
	}

	function showPOpts(id) 
	{ 
		if ( document.getElementById(id).style.display == "none")
		{
			document.getElementById(id).style.display = "";

		} else { document.getElementById(id).style.display = "none" }
	}


	/** Start Quick Reply Code
	**************************/

		var myAgent   = navigator.userAgent.toLowerCase();
		var myVersion = parseInt(navigator.appVersion);

		var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
		var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                	&& (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                	&& (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

		var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
		var is_mac    = (myAgent.indexOf("mac")!=-1);


	function mkBold(where)
	{
		var add = prompt("Enter text to be set as Bold", "");
		add = "[b]" + add + "[/b]";
		where.Post.value = where.Post.value + add;
	}

	function mkUnderline(where)
	{
		var add = prompt("Enter text to be set as Underline", "");
		add = "[u]" + add + "[/u]";
		where.Post.value = where.Post.value + add;
	}

	function mkItalic(where)
	{
		var add = prompt("Enter text to be set as Italic", "");
		add = "[i]" + add + "[/i]";
		where.Post.value = where.Post.value + add;
	}

	function postImg(where)
	{
		var add = prompt("Enter Image Link", "http://");
		add = "[img=" + add + "]";
		where.Post.value = where.Post.value + add;
	}

	function postQT(where)
	{
		var add = prompt("Who are you quoting?", "");
		add = "[quote=" + add + "][/quote]";
		where.Post.value = where.Post.value + add;
	}

	function postYT(where)
	{
		var add = prompt("Enter Youtube Link", "http://");
		add = "[youtube=" + add + "]";
		where.Post.value = where.Post.value + add;
	}

	function postGT(where)
	{
		var add = prompt("Enter Game Trailer Link", "http://");
		add = "[gametrailer=" + add + "]";
		where.Post.value = where.Post.value + add;
	}


	function insertAtCursor(myField, myValue)
	{

		//IE support
		if (document.selection)
		{
			alert("if");
			myField.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
		}

		//MOZILLA/NETSCAPE support
		else if (myField.selectionStart || myField.selectionStart == "0")
		{
			alert("elseif");
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
		} else {
			alert("else: " + myField.value);
			zzz = myField.value + myValue;
			alert(zzz);
		}
	}

	function emoticon(theSmilie)
	{
		doInsert(" " + theSmilie + " ", "", false);
	}


function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var fms = document.forms;

	for (var i = 0; i < fms.length; i++)
	{
		if (fms[i].Post)
		{

			//We Have a Good Box
			var obj_ta = fms[i].Post;

			if ( (myVersion >= 4) && is_ie && is_win) // Ensure it works for IE4up / Win only
			{
				if(obj_ta.isTextEdit){ // this doesn't work for NS, but it works for IE 4+ and compatible browsers
					obj_ta.focus();
					var sel = document.selection;
					var rng = sel.createRange();
					rng.colapse;
					if((sel.type == "Text" || sel.type == "None") && rng != null){
						if(ibClsTag != "" && rng.text.length > 0)
							ibTag += rng.text + ibClsTag;
						else if(isSingle)
							isClose = true;
	
						rng.text = ibTag;
					}
				}
				else{
					if(isSingle)
						isClose = true;
	
					obj_ta.value += ibTag;
				}
			}
			else
			{
				if(isSingle)
					isClose = true;

				obj_ta.value += ibTag;
			}

			obj_ta.focus();
	
			// clear multiple blanks
			//obj_ta.value = obj_ta.value.replace(/  /, " ");



		}
	}


	return isClose;


}


	/** End Quick Reply Code
	**************************/

	/** Hidden Action Code
	**********************/
function Callback(serverData, serverStatus) {       // Called automatically when we get data back from server

//Do nothing

}

function AjaxRequest(feed) {
   var AJAX = null;                                 // Initialize the AJAX variable.
   if (window.XMLHttpRequest) {                     // Does this browser have an XMLHttpRequest object?
      AJAX=new XMLHttpRequest();                    // Yes -- initialize it.
   } else {                                         // No, try to initialize it IE style
      AJAX=new ActiveXObject("Microsoft.XMLHTTP");  //  Wheee, ActiveX, how do we format c: again?
   }                                                // End setup Ajax.
   if (AJAX==null) {                                // If we couldn't initialize Ajax...
      alert("Your browser doesn't support AJAX.");  // Sorry msg.                                               
      return false                                  // Return false, couldn't set up ajax
   }
   AJAX.onreadystatechange = function() {                      // When the browser has the request info..
      if (AJAX.readyState==4 || AJAX.readyState=="complete") { //  see if the complete flag is set.
         //Callback(AJAX.responseText, AJAX.status);       // Pass the response to our processing function
      }                                                        // End Ajax readystate check.
   }
   AJAX.open("GET", feed, true);                                  // Open the url this object was set-up with.  
   AJAX.send(null);                                              // Send the request.
}


function query2array(url) {

	var qsParm = new Array();
	var query = url;
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++)
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0)
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}

	return qsParm;
} 