 /**
 * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the sql query to submit
 *
 * @return  boolean  whether to run the query or not
 */

function printwin (wname,myvar)
   { 
   mywin=window.open("index.php?myvar="+myvar,wname); 
   mywin.focus(); 
   mywin.print(); 
   mywin.close(); 
   }  

function OpenWin (url,name)
   { 
   mywin=window.open(url,name,"width=600,height=400,status=yes,scrollbars=yes,resizable=yes"); 
   mywin.focus(); 
   mywin.print(); 
   //mywin.close(); 
   }  

function confirmLink(theLink, Warning)
	{
   	// Confirmation is not required in the configuration file
   	// or browser is Opera (crappy js implementation)
   	if (confirmMsg == '' || typeof(window.opera) != 'undefined') 
   		{
	    return true;
	    }
	
	    var is_confirmed = confirm(confirmMsg + ' :\n' + Warning);
	    if (is_confirmed) 
	    	{
	        theLink.href += '&is_js_confirmed=1';
	    	}
		return is_confirmed;
		}

function confirmDel (mylink, text)
	{
	var bolOK = confirm(text);
	return bolOK;
	}


function confirmForm (obj, text)
	{
	var bolOK = confirm(text);
	if (bolOK)
		{
		obj.value=1;
		}
	}

function formSubmit (myform)
	{
	alert ("test");
	//document.forms.myform.submit();
	
	}
function checkSubmit ()
	{
	//if document.forms[0].pass <> ""
	//	{
		var oldpass = window.prompt ("Input your old password to continue");
	//	}
		
	}
	
function getFileName(path) 
	{
  return path.match(/[-_\w]+[.][\w]+$/i)[0];
	}
	
function blur (obj,color)
	{
	obj.style.backgroundColor=color;
	}

function replaceText(text)
	{
	if (document.post.text.createTextRange && document.postmsg.text.caretPos)
		{
		var caretPos = document.post.text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		text + ' ' : text;
		}
	else document.post.text.value += text;
	document.post.text.focus(caretPos)
	}

function surroundText(text1,text2)
	{
	if (document.post.text.createTextRange && document.post.text.caretPos)
		{
		var caretPos = document.post.text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
		}
	else document.post.text.value += text1 + text2;
	document.post.text.focus(caretPos)
	}

function makeLinkHTTP()
	{
	if (document.postmsg.text.createTextRange && document.post.text.caretPos)
		{
		var caretPos = document.postmsg.text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		"<A HREF='http://" + caretPos.text + "' Target='_Blank'>" + caretPos.text + "</A> " :  "<A HREF='http://" + caretPos.text + "' Target='_Blank'>"  + caretPos.text + "</A> " ;
		}
	else document.postmsg.text.value += caretPos.text ;
	document.postmsg.text.focus(caretPos)
	}
	
function makeLinkFTP()
	{
	if (document.postmsg.text.createTextRange && document.postmsg.text.caretPos)
		{
		var caretPos = document.postmsg.text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		"<A HREF='ftp://" + caretPos.text + "' Target='_Blank'>" + caretPos.text + "</A> " :  "<A HREF='ftp://" + caretPos.text + "' Target='_Blank'>"  + caretPos.text + "</A> " ;
		}
	else document.postmsg.text.value += caretPos.text ;
	document.postmsg.text.focus(caretPos)
	}

function storeCaret(text)
	{
	if (text.createTextRange)
		{
		text.caretPos = document.selection.createRange().duplicate();
		}
	}
/**
 * This array is used to remember mark status of rows in browse mode
 */
	var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
 
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
	{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')|| typeof(theRow.style) == 'undefined')
    	{
        return false;
    	}

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') 
    	{
        theCells = theRow.getElementsByTagName('td');
    	}
    else if (typeof(theRow.cells) != 'undefined')
    	{
        theCells = theRow.cells;
    	}
    else 
    	{
        return false;
    	}

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined')
        {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    	}
    // 3.2 ... with other browsers
    else 
    	{
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    	} 
    // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''|| currentColor.toLowerCase() == theDefaultColor.toLowerCase())
    	{
        if (theAction == 'over' && thePointerColor != '')
        	{
            newColor              = thePointerColor;
        	}
        else if (theAction == 'click' && theMarkColor != '')
        	{
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        	}
    	}
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) 
    	{
        if (theAction == 'out') 
        	{
            newColor              = theDefaultColor;
        	}
        else if (theAction == 'click' && theMarkColor != '')
        	{
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        	}
    	}
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase())
    	{
        if (theAction == 'click')
        	{
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        	}
    	} 
    // end 4

    // 5. Sets the new color...
    if (newColor) 
    	{
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) 
        	{
            for (c = 0; c < rowCellsCnt; c++) 
            	{
                theCells[c].setAttribute('bgcolor', newColor, 0);
            	} // end for
        	}
        // 5.2 ... with other browsers
        else 
        	{
            for (c = 0; c < rowCellsCnt; c++) 
            	{
                theCells[c].style.backgroundColor = newColor;
            	}
        	}
    } // end 5

    return true;
} // end of the 'setPointer()' function

// layer functions

function layer_show (obj)
	{
	document.getElementById(obj).style.visibility = 'visible';
	}

function layer_hide (obj)
	{
	document.getElementById(obj).style.visibility = 'hidden';
	}

function layer_switch (obj, name)
	{
	if (obj.checked)
		{
		document.getElementById(name).style.visibility = 'visible';
		}
	else
		document.getElementById(name).style.visibility = 'hidden';
	
	}

function ChangeBG (theRow, theClass)
	{
	var theCells = null;
	
	theCells=theRow.getElementsByTagName('TD');
	var numCells = theCells.length;
	
    for (i = 0; i < numCells; i++) 
	 	{
        theCells[i].className = theClass;
        }
	}

// BB Codes

	var clientVer = parseInt(navigator.appVersion); // Get browser version
	var clientPC = navigator.userAgent.toLowerCase(); // Get client info
	var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
	var is_moz = 0;
	var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
	var is_mac = (clientPC.indexOf("mac")!=-1);
	
	var bbtags = new Array ('[b]','[/b]', '[i]', '[/i]', '[u]', '[/u]', '[hr]', '', '[url]', '[/url]', '[img]', '[/img]', '[pcm_left]', '[/pcm_left]');
	var bbcodes = new Array ();

	
function unset_element(array_element, my_array)
{
	temp_array = new Array();
	for(var i = 0; i < my_array.length; i++)
	{
		if(my_array[i] != array_element)
		{
			temp_array[temp_array.length] = my_array[i];
		}
	}
	return temp_array;
}

function bbcode (obj, key)
	{
	var msg_text = document.post.text;
	var close = false;
	var oldtext = msg_text.value;

	
	if (key == 0) // close all tags
		{
		//bbcodes.reverse();
		i = bbcodes.length-1;
		while (i >= 0)
			{
			if (bbcodes[i] != 0)
				{
				val = bbcodes[i]-1;
				msg_text.value += bbtags[val*2+1];
				buttval = eval ('document.post.bbcode' + bbcodes[i] + '.value' );
				eval('document.post.bbcode' + bbcodes[i] + '.value ="' + buttval.substr(0,(buttval.length - 2)) + '"');
				i = i -1;
				}
			}
		bbcodes = new Array ();
		return;
		}

	num = (key - 1) * 2;
	
	//search if tag open
	for (i = 0; i < bbcodes.length; i++)
		{
		if (bbcodes[i] == key)
			{
			if (bbcodes[i] != 0)
				{
				msg_text.value += bbtags[num+1];
				element = bbcodes[i];
				bbcodes=unset_element (element, bbcodes);
				oldval = obj.value;
				obj.value = oldval.substr(0,(oldval.length - 2)) ;
				close = true;
				}
			}
		}
	
	// insert new tag
	if (! close)
			{
			j = bbcodes.length +1;
			bbcodes.push (key);
			obj.value += ' *';
			msg_text.value += bbtags[num];
			}
	
		document.post.text.focus();
		//document.post.debug.value = '';
		for (i = 0; i < bbcodes.length; i++)
			{
			//document.post.debug.value += bbcodes[i];
			}
	}

function bbcolor(obj)
	{
	var msg_text = document.post.text;
	
	opentag = '[color=' + obj.value + ']';
	closetag = '[/color]';
	textWrap (msg_text, opentag, closetag);
	}

function bbhelp (key)
	{
	var b_help = "Bold text: [b]text[/b]  (alt+b)";
	var i_help = "Italic text: [i]text[/i]  (ALT+i)";
  var u_help = "Underline text: [u]text[/u]  (ALT+u)";
  var q_help = "Quote text: [quote]text[/quote]  (ALT+q)";
  var h_help = "Insert H-Line: [hr] (ALT+h)";
  var l_help = "Insert Url: [url]text[/url] (ALT+l)";
  var m_help = "Insert Image: [img]text[/img] (ALT+m)";
  var c_help = "Font Color: [color=NAME/VALUE]text[/color] (ALT+c)";
  var a_help = "Close all open BBCode tags (ALT+a)";
  var L_help = "Left Align (ALT+SHIFT+L)";
	document.post.bbcode_help.value = eval (key + '_help');
	}

// From http://www.massless.org/mozedit/
function textWrap(txtarea, open, close)
	{
	
	if ((clientVer >= 4) && is_ie && is_win) 
		{
		theSelection = document.selection.createRange().text;
		if (!theSelection) 
			{
			txtarea.value += open + close;
			txtarea.focus();
			return;
			}
			document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
		}
		else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
		{
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + open + s2 + close + s3;
		return;
		}
	else
		{
		txtarea.value += open + close;
		txtarea.focus();
		}
	storeCaret(txtarea);
	
	}

//Simple Font Resizer Javascript//

/**

* Simple Font Resizer Javascript

* @package Joomla 1.5

* @copyright Copyright (C) 2008 UnDesign. All rights reserved.

* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL

* This program is free software; you can redistribute it and/or

* modify it under the terms of the GNU General Public License

* as published by the Free Software Foundation; either version 2

* of the License, or (at your option) any later version.

* 

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

* GNU General Public License for more details.

*/



var prefsLoaded = false;

var defaultFontSize = 100;

var currentFontSize = defaultFontSize;



function revertStyles(){



	currentFontSize = defaultFontSize;

	changeFontSize(0);



}







function changeFontSize(sizeDifference){

	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 10);


	if(currentFontSize > 150){

		currentFontSize = 150;

	}else if(currentFontSize < 70){

		currentFontSize = 70;

	}



	setFontSize(currentFontSize);

};



function setFontSize(fontSize){

	var stObj = (document.getElementById) ? document.getElementById('art-main') : document.all('art-main');

	document.body.style.fontSize = fontSize + '%';



	//alert (document.body.style.fontSize);

};





function createCookie(name,value,days) {

  if (days) {

    var date = new Date();

    date.setTime(date.getTime()+(days*24*60*60*1000));

    var expires = "; expires="+date.toGMTString();

  }

  else expires = "";

  document.cookie = name+"="+value+expires+"; path=/";

};



function readCookie(name) {

  var nameEQ = name + "=";

  var ca = document.cookie.split(';');

  for(var i=0;i < ca.length;i++) {

    var c = ca[i];

    while (c.charAt(0)==' ') c = c.substring(1,c.length);

    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

  }

  return null;

};



window.onload = setUserOptions;



function setUserOptions(){

	if(!prefsLoaded){



		cookie = readCookie("fontSize");

		currentFontSize = cookie ? cookie : defaultFontSize;

		setFontSize(currentFontSize);



		prefsLoaded = true;

	}



}



window.onunload = saveSettings;



function saveSettings()

{

  createCookie("fontSize", currentFontSize, 365);

}
