 if (!document.getElementById) {
    window.location =  "http://www.webstandards.org/upgrade/"
}

/**
 * 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 confirmLink(theLink, theMessage)
{
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(theMessage);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function

function viewCalendar(year,month,day,album_id) {
    commentCalendar=window.open('index.php?section=calendar&long=1&album_id=' + album_id + '&currYear=' + year + '#' + year + '-' + month + '-' + day,
    'calendar', 
    'directories=0,height=480,location=0,resizable=1,scrollbars=1,toolbar=0,width=500');
}

function viewComments(n,type,parent,show) {
commentWindow=window.open('index.php?section=comment&id=' + n + '&type=' + type + '&parent_id=' + parent + '&show=' + show, 'comments' + n, 'directories=0,height=480,location=0,resizable=1,scrollbars=1,toolbar=0,width=515');
}

function staf(n,section,parent,show) {
stafWindow=window.open('staf.php?id=' + n + '&section=' + section , 'comments' + n, 'x', 'directories=0,height=330,location=0,resizable=1,scrollbars=1,toolbar=0,width=515');
}

function popup(location, height, width) {
popupWindow=window.open(location, 'x', 'directories=0,height=' + height + ',width=' + width + ',location=0,resizable=0,scrollbars=0,toolbar=0');
}

function submitonce(theform) {
    if (document.all || document.getElementById) {
        for (i=0 ; i < theform.length ; i++ ) {
            var tempobj = theform.elements[i];
            if ( tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "button")
            tempobj.disabled=true;
        }
    }
    return true;
}

function flipImage(id,src) {
	document[id].src = src;
}


function initEditor(doc) {


    tas = doc.getElementsByTagName("textarea");
    if (tas == null) {
    	alert("blah");
        return false;
    }
    
    var config = new HTMLArea.Config();
	config.toolbar = [
		[ "fontname", "space",
		  "fontsize", "space",
		  "formatblock", "space",
		  "bold", "italic", "underline", "separator",
		  "strikethrough", "subscript", "superscript", "separator",
		  "copy", "cut", "paste", "space", "undo", "redo" ],
		
		[ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
		  "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
		  "forecolor", "hilitecolor", "textindicator", "separator",
		  "inserthorizontalrule", "createlink", "insertimage", "inserttable", "htmlmode", "separator"]
		]; 
		
		
		
	config.fontname = {
		"Verdana":	   'verdana,arial,helvetica,sans-serif',
		"Arial":	   'arial,helvetica,sans-serif',
		"Courier New":	   'courier new,courier,monospace',
		"Georgia":	   'georgia,times new roman,times,serif',
		"Tahoma":	   'tahoma,arial,helvetica,sans-serif',
		"Times New Roman": 'times new roman,times,serif',
		"impact":	   'impact',
		"WingDings":	   'wingdings'
	};
		
//	config.height="200";
//	config.width="auto";
	config.statusBar = false;
	
    for(var x = 0; x < tas.length; x++){
        att = tas[x].id;
        var ta = /ta\d+/;
    	if (ta.test(att)) {
	        editor = new HTMLArea(att,config);
	        editor.generate();
    	}
        
    }
}

function resetIframes(target) {
    iframes = target.getElementsByTagName("iframe");
    for(var x = 0; x < iframes.length; x++) {
        try {
            iframes[x].contentDocument.designMode = "off";
        } catch(e) {
            alert("couldn't turn iframe off:" + "\n\n" + e);
        }
        
        try {
            iframes[x].contentWindow.document.designMode = "on";
        } catch(e) {
            alert("couldn't turn iframe on:" + "\n\n" + e);
        }
        
    }
}
    
function display(id) {
    var target = document.getElementById(id);
    var c = document.getElementById('toggle' + id);
    
    if (target.style.display == 'block') {
        target.style.display = 'none';
        c.innerHTML = '[+]';
    } else {
        target.style.display = 'block';
        c.innerHTML = '[-]';
    }
    resetIframes(c);
}

function initPage() {
    domTab();
}

function domTab(){
	
	var tabsDiv = document.getElementById("tabs");
    if (tabsDiv == null) return;
	var spans = tabsDiv.getElementsByTagName("span");
	
	var tabID = /(\d+)/;
	for (f=0; f < spans.length; f++){
	   result = spans[f].id.match(tabID);
       var id = result[1];

       var target = document.getElementById('content' + id);
       
       if (target != null) {
            if (_use_htmlarea) initEditor(target);
            if (id != "1") target.style.display='none';
            
       }
	}
	
	document.getElementById('tab1').className = 'tabActive';
}

function activateTab(n) {

	var tabsDiv = document.getElementById("tabs");
    if (tabsDiv == null) return;
	var spans = tabsDiv.getElementsByTagName("span");
	
	var tabID = /(\d+)/;
	for (f=0; f < spans.length; f++){
	   result = spans[f].id.match(tabID);
       var id = result[1];

       var target = document.getElementById('content' + id);
       if (n == id) {
            target.style.display = 'block';
            document.getElementById('tab'+id).className = 'tabActive';
            if (_use_htmlarea) resetIframes(target);
       } else {
            target.style.display = 'none';
            document.getElementById('tab'+id).className = 'tab';
       }            
	}
}
