// JavaScript Document
var ns4 = (document.layers);
var ie = (document.all);
var ns6 = (!document.all && document.getElementById);
var Opera = window.opera ? true : false;
var phputil = "scripts/backend.php";
var fileDone = 0;
var myUQry = "";
var theResult = "";
var NewPID = 0;
var CurrentPID = 0;
var CurrentPageID = 0;
var CurrentLPID = 0;
var CurrentNewsID = 0;
var ADMIN = 0;
var showLoading = "<DIV align='center'>Loading Data<BR /><IMG src='images/progress.gif' />";

// Flags
var allowTPoll = 0; var allowRPoll = 0; var allowFPoll = 0; var allowCPoll = 0;

function evalIT() { eval(getObj("iEval").value); }

function sqlIT() { eval(getObj("iEval").value); }

function toggleAdmin() { if ( ADMIN ) { ADMIN = 0; } else { ADMIN = 1; } }

function doLoading( vDiv ) { SetInner( vDiv, showLoading ); }

function SetVar( vVar, vVal ) { eval(vVar+"=\""+vVal+"\";"); }

function changeOrder( vOrder, vDir, vVal , callBack , vDiv) { 
if (eval(vOrder) == eval("\""+vVal+"\"")) { eval(vDir + "= !" + vDir ); } 
else { SetVar( vOrder , vVal ); eval(vDir + "= 1");}
callBack(vDiv); }

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i < (a.length-2);i+=3)
   if ((x=getObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} }

function swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; }   

function setOverTD(pTD,chCur) {
	getObj(pTD).style.backgroundColor = "#CCCCCC";
if ( chCur )
	getObj(pTD).style.cursor = "pointer"; }

function restoreTD(pTD) {
	getObj(pTD).style.backgroundColor = "#FFFFFF";
	getObj(pTD).style.cursor = "default"; }

function fixActiveX(){
	n=navigator.userAgent;
	w=n.indexOf("MSIE");
	if((w>0)&&(parseInt(n.charAt(w+5))>5)){
		T=["object","embed","applet"];
		for(j=0;j < 2;j++){
			E=document.getElementsByTagName(T[j]);
			for(i=0;i<E.length;i++){
				/*P=E[i].parentNode;
				H=P.innerHTML;			
				P.removeChild(E[i]);
				P.innerHTML=H;*/
				E[i].outerHTML = E[i].outerHTML; } } } }

function showObj(id) {
	var theObj = getObj(id);
	if(ns4){ theObj.visibility = "show"; }
	else if(ie){ theObj.style.visibility = "visible"; }
	else if(ns6){ theObj.style.visibility = "visible";	} }

function showSObj(id) { showObj(id); getObj(id).style.height = "100%"; }

function hideObj(id) {
	if(ns4){ document.layers[id].visibility = "hide"; }
	else if(ie){ document.all[id].style.visibility = "hidden"; }
	else if(ns6){ document.getElementById(id).style.visibility = "hidden"; } }

function hideSObj(id) { hideObj(id); getObj(id).style.height = "0px"; }

function getObj( objName ) {
	if(ns4){ return document.layers[objName]; }
	else if(ie){ return document.all[objName]; }
	else if(ns6){ return document.getElementById(objName); } }
	
function getObjN( objName ) {
	if(ns4){ return document.layers[objName]; }
	else if(ie){ return document.all[objName]; }
	else if(ns6){ return document.getElementsByName(objName); } }

function getRadio(objName) {
	radioObj = getObjN(objName);
    for (var i=0; i < radioObj.length; i++) {
        if (radioObj[i].checked) { return radioObj[i]; } }
    return null; }

function GetChecked(objName) {
	radioObj = getObjN(objName); radioStr = "";
    for (var i=0; i < radioObj.length; i++) { if (radioObj[i].checked) { radioStr = radioStr + radioObj[i].value + "-"; } }
	return radioStr.substr(0 , radioStr.length - 1); }

function GetMulti(objName , gAll ) {
	multiObj = getObj(objName); multiStr = "";
    for (var i=0; i < multiObj.length; i++) { if ( multiObj.options[i].selected || gAll ) { multiStr = multiStr + multiObj.options[i].value + "-"; } }
	return multiStr.substr(0 , multiStr.length - 1); }

function pollLoop( callback )
{ setTimeout(callback +"()",10000); }

function pollUpload( callback )
{ setTimeout(callback +"()",1000); }

function finishBackend( vDiv, rString, callback ) { callback(vDiv,rString); }

function makeHTTPObject() {
	XMLobj = false;
    if(window.XMLHttpRequest && !(window.ActiveXObject)) { try { XMLobj = new XMLHttpRequest(); } catch(e) { XMLobj = false; }
    } else if(window.ActiveXObject) { try { XMLobj = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(e) { try { XMLobj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { XMLobj = false; } } }
	return XMLobj; }

function swapList( theList , theDir ) {
	theObj = getObj( theList ); theIndex = theObj.selectedIndex;
	if ( theDir && !theIndex ) { return; } 	if ( !theDir && ( (theIndex + 1) == theObj.length ) ) { return; } 
	if ( theDir ) { theDestI = theIndex - 1; } else { theDestI = theIndex + 1; }
	srcValue = theObj[theIndex].value; srcText = theObj[theIndex].text; 
	tempValue = theObj[theDestI].value; tempText = theObj[theDestI].text; 
	theObj[theIndex].value = tempValue; theObj[theIndex].text = tempText;
	theObj[theDestI].value = srcValue; theObj[theDestI].text = srcText;
	theObj.selectedIndex = theDestI; }

function removeFList(theList,theObj) {
	theVal = getObj(theObj).value; myList = getObj(theList); myIndex = myList.selectedIndex;
	if ( myList.length <= 0 ) {return;}
	myList[ myIndex ] = null; }

function add2List(theList,theObj,theID) {
	theVal = getObj(theObj).value; myList = getObj(theList); curLen = myList.length;
	myList.options[curLen]= new Option(theVal, theID); }
		

function doPLoad( vCmd ) {
	clearDIV("errorDIV");
	clearDIV("outputDIV");
	doLoading("pageContent");
	var pageName = "pages/" + vCmd + ".php";
	var rString = JJPage.doCGET( pageName );
	showPage(rString, vCmd);
	return; }

function doAPLoad( vCmd ) {
    if ( !ADMIN ) { alert("You must be an Admin to preform this function"); return; }
    doPLoad( vCmd ); return; }

function loadLB( vCmd ) {
	clearDIV("errorDIV");
	clearDIV("lbCDIV");
	var pageName = "pages/" + vCmd + ".php";
	var rString = JJPage.doCGET( pageName );
	SetInner("lbCDIV",rString);
	return; }

function showResult( vDiv , rString ) { SetInner(vDiv, trim(rString)); }

function showResultD( vDiv , rString ) { 
	rString = rString + "<br><textarea name='backendDebug' cols='40' rows='20'></textarea>"; 
	SetInner(vDiv, rString); 
	getObj("backendDebug").value = rString; }

function showPage( rString , vCmd) { 
	SetInner("pageContent", rString);
    resetItems();
	switch (vCmd) {
		case "nproduct": { CurrentPID = NewPID = JJPage.doNow( "do=nextai&table=sjProducts" ); break;}
		default: return; } }

function resetItems() { CurrentPID = 0; CurrentPageID = 0; CurrentLPID = 0; CurrentNewsID = 0; }

function clearDIV( vDiv ) { SetInner(vDiv, "&nbsp;"); }

function SetInner(DestDIV, FullString) { if (DestDIV == null) { return; } try { getObj(DestDIV).innerHTML=FullString; } catch(err) { } }

function GetInner(DestDIV) {
	if (DestDIV == null) { return; }
	if(ns4){ return document.layers[DestDIV].innerHTML; }
	else if(ie){ return document.all[DestDIV].innerHTML; }
	else if(ns6){ return document.getElementById(DestDIV).innerHTML; } }
	
function wrapTA( theArea, sTxt, eTxt) {
	theObj = getObj(theArea);
  	if (theObj.setSelectionRange) {
 		theObj.value = theObj.value.substring(0,theObj.selectionStart) + sTxt + theObj.value.substring(theObj.selectionStart,theObj.selectionEnd) + eTxt + theObj.value.substring(theObj.selectionEnd,theObj.value.length); } else {
		var selectedText = document.selection.createRange().text;
		if (selectedText != "") { 
            var newText = sTxt + selectedText + eTxt; 
            document.selection.createRange().text = newText; } } }

function undoStyle( eID ) { getObj(eID).removeAttribute("style"); }

function setLBw( eID , vWidth ) { vHalf = Math.round( vWidth / 2 ); toNeg = vHalf - vWidth; getObj(eID).style.marginLeft = toNeg + "px"; getObj(eID).style["width"] = vWidth+"px"; }

function DoSwap(srcID,objID) { if( srcID ) { getObj(objID).disabled = false; } else { getObj(objID).disabled = true; } }

function getKey( e ) { if( window.event ) { return window.event.keyCode; } else { return e.which; } } 
    
function stopBubbles(e) { if (!e) var e = window.event; e.cancelBubble = true; if (e.stopPropagation) e.stopPropagation(); }
