var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var smf_formSubmitted = false;

// Define document.getElementById for Internet Explorer 4.
if (typeof(document.getElementById) == "undefined")
	document.getElementById = function (id)
	{
		// Just return the corresponding index of all.
		return document.all[id];
	}
// Define XMLHttpRequest for IE 5 and above. (don't bother for IE 4 :/.... works in Opera 7.6 and Safari 1.2!)
else if (!window.XMLHttpRequest && window.ActiveXObject)
	window.XMLHttpRequest = function ()
	{
		return new ActiveXObject(navigator.userAgent.indexOf("MSIE 5") != -1 ? "Microsoft.XMLHTTP" : "MSXML2.XMLHTTP");
	};

// Some older versions of Mozilla don't have this, for some reason.
if (typeof(document.forms) == "undefined")
	document.forms = document.getElementsByTagName("form");

// Load an XML document using XMLHttpRequest.

// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, textarea)
{
	// Can a text range be created?
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos, temp_length = caretPos.text.length;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;

		if (temp_length == 0)
		{
			caretPos.moveStart("character", -text2.length);
			caretPos.moveEnd("character", -text2.length);
			caretPos.select();
		}
		else
			textarea.focus(caretPos);
	}
	// Mozilla text range wrap.
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var newCursorPos = textarea.selectionStart;
		var scrollPos = textarea.scrollTop;

		textarea.value = begin + text1 + selection + text2 + end;

		if (textarea.setSelectionRange)
		{
			if (selection.length == 0)
				textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
			else
				textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
			textarea.focus();
		}
		textarea.scrollTop = scrollPos;
	}
	// Just put them on the end, then.
	else
	{
		textarea.value += text1 + text2;
		textarea.focus(textarea.value.length - 1);
	}
}

// Checks if the passed input's value is nothing.
function isEmptyText(theField)
{
	// Copy the value so changes can be made..
	var theValue = theField.value;

	// Strip whitespace off the left side.
	while (theValue.length > 0 && (theValue.charAt(0) == ' ' || theValue.charAt(0) == '\t'))
		theValue = theValue.substring(1, theValue.length);
	// Strip whitespace off the right side.
	while (theValue.length > 0 && (theValue.charAt(theValue.length - 1) == ' ' || theValue.charAt(theValue.length - 1) == '\t'))
		theValue = theValue.substring(0, theValue.length - 1);

	if (theValue == '')
		return true;
	else
		return false;
}




function changebg(color11,fc)
{
        document.bgColor=color11;
	document.fgColor  = fc;
	document.alinkColor  = fc;
	document.linkColor  = fc;
	document.vlinkColor  = fc;
        SetCookie('color', color11, exp);
        SetCookie('colortxt', fc, exp);



}

function getCookieVal (offset) 
{  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen)
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
      }
return null;
}

function SetCookie (name, value) 
{  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}

function color()
         {
         var favColor = GetCookie('color');
         if (favColor == null)
            {
            favColor = '#000000';
            SetCookie('color', favColor, exp);
            }
         document.bgColor=favColor;
         
         var favColortxt = GetCookie('colortxt');
         if (favColortxt == null)
            {
            favColortxt = '#FFFFFF';
            SetCookie('colortxt', favColortxt, exp);
            }
	document.alinkColor  = favColortxt;
	document.linkColor  = favColortxt;
	document.vlinkColor  = favColortxt;
        document.fgColor  = favColortxt;
         return favColortxt;
       }






function OpenNewWindow(theImg,theTitle)
{
	//var theValue = theField.value;
 	myWin=window.open('','newwindow', config='toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=1');  
	myWin.document.write("<script language='JavaScript' type='text/javascript' src='http://innova/pattern/global/script.js?fin11'></script> \n");

	myWin.document.write('<html><head><title>'+theTitle+'</title></head><body> \n');
	myWin.document.write("<center>\n");
 	myWin.document.write('<a href = "javascript:void(0);" onclick="window.close()"><img src='+theImg+' border = 0></a>\n');

myWin.document.write("	      <TABLE height=11 cellSpacing=2 cellPadding=0 width=95% align=center border=0>\n");

myWin.document.write("                <TR>\n");
myWin.document.write("                  <TD onmouseover='changebg('#FFFFFF','#000000')' bgColor=#ffffff>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#E5E5E5','#000000')' bgColor=#e5e5e5>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#CCCCCC','#000000')' bgColor=#cccccc>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#B3B3B3','#000000')' bgColor=#b3b3b3>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#999999','#000000')' bgColor=#999999>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#808080','#FFFFFF')' bgColor=#808080>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#666666','#FFFFFF')' bgColor=#666666>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#4D4D4D','#FFFFFF')' bgColor=#4d4d4d>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#333333','#FFFFFF')' bgColor=#333333>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#1A1A1A','#FFFFFF')' bgColor=#1a1a1a>&nbsp;</TD>\n");
myWin.document.write("                  <TD onmouseover='changebg('#000000','#FFFFFF')' bgColor=#000000>&nbsp;</TD>\n");
myWin.document.write("                </TR>\n");

myWin.document.write("            </TABLE></td>\n");
  	
	myWin.document.write("</center>\n");
	myWin.document.write("</body></html>\n");
}

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, do_check)
{
    var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
                  ? document.forms[the_form].elements['selected_db[]']
                  : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
          ? document.forms[the_form].elements['selected_tbl[]']
          : document.forms[the_form].elements['selected_fld[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked        = do_check;
    } // end if... else

    return true;
} // end of the 'setCheckboxes()' function

