 
 
 
 
function CheckForJPG(divName)
{
    var fup = document.getElementById(divName);
    if (!fup)
    {
          //alert(divName);
	   return true;
    }
    var fileName = fup.value;
    if (fileName == "") return true;
    var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
    //if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "doc")
    if( ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" || ext == "PNG"  )  
    {
        return true;
    } 
    else
    {
        alert("You may only upload JPG images");
        fup.focus();
        return false;
    }
}

function CheckForJPGMP3(divName)
{
    var fup = document.getElementById(divName);
    if (!fup)
    {
          //alert(divName);
	   return true;
    }
    var fileName = fup.value;
    if (fileName == "") return true;
    var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
    //if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "doc")
    if( ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "MP3" || ext == "mp3" )  
    {
        return true;
    } 
    else
    {
        alert("You may only upload JPG and MP3 files");
        fup.focus();
        return false;
    }
}


 function pupload(  )
 {
       if (!CheckForJPG('uploadfile1')) return false;
       if (!CheckForJPG('uploadfile2')) return false;
       if (!CheckForJPG('uploadfile3')) return false;
       if (!CheckForJPG('uploadfile4')) return false;
       if (!CheckForJPG('uploadfile5')) return false;
       if (!CheckForJPG('uploadfile6')) return false;
       if (!CheckForJPG('uploadfile7')) return false;
        
       alert('press OK to begin upload');
       var div = document.getElementById("photoForm"); 
       div.innerHTML = "Uploading.<P>Please wait...";
       s101Manager.doSubmitForm('form','result',true)
 }

 function puploadfans(  )
 {
       if (!CheckForJPG('uploadfile1')) return false;
       if (!CheckForJPG('uploadfile2')) return false;
       if (!CheckForJPG('uploadfile3')) return false;
       if (!CheckForJPG('uploadfile4')) return false;
       if (!CheckForJPG('uploadfile5')) return false;
       if (!CheckForJPG('uploadfile6')) return false;
       if (!CheckForJPG('uploadfile7')) return false;
        
       var div = document.getElementById("photoForm"); 
       div.innerHTML = "Uploading.<P>Please wait...";
       s101Manager.doSubmitForm('form','result',true)
 }

 function puploadfiles(  )
 {
       if (!CheckForJPGMP3('uploadfile1')) return false;
       if (!CheckForJPGMP3('uploadfile2')) return false;
       if (!CheckForJPGMP3('uploadfile3')) return false;
       if (!CheckForJPGMP3('uploadfile4')) return false;
       if (!CheckForJPGMP3('uploadfile5')) return false;
       if (!CheckForJPGMP3('uploadfile6')) return false;
       if (!CheckForJPGMP3('uploadfile7')) return false;
        
       var div = document.getElementById("photoForm"); 
       div.innerHTML = "Uploading.<P>Please wait...";
       s101Manager.doSubmitForm('form','result',true)
 }


 
 function strstr( haystack, needle, bool ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
 
    var pos = 0;
 
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}

function getYOffset() {
    var pageY;
    if(typeof(window.pageYOffset)=='number') {
       pageY=window.pageYOffset;
    }
    else {
       pageY=document.documentElement.scrollTop;
    }
    return pageY;
}



function isEmpty(str) 
{
  // Check whether string is empty.
  for (var intLoop = 0; intLoop < str.length; intLoop++)
   if (" " != str.charAt(intLoop))
    return false;
  return true;
}

 function checkRequired(f) 
 {
  var strError = "";
  for (var intLoop = 0; intLoop < f.elements.length; intLoop++)
  if (null!=f.elements[intLoop].getAttribute("required")) 
   if (isEmpty(f.elements[intLoop].value))
    strError += "  " + f.elements[intLoop].name + "\n";
   if ("" != strError) {
    alert("Required data is missing:\n" + strError);
    return false;
   } else
  return true       
 }
 
 var s101Manager = 
 {  

    doSubmitForm : function(sFormName,sResultDiv,IsFileUpload)
    {     
     
        YAHOO.namespace("example.container");
        // argument formId can be the id or name attribute value of the
        // HTML form, or an HTML form object.
        var formObject = document.getElementById(sFormName);
        if (!formObject)
        {
            alert('bad formObject: ' + sFormName);
        }
        
        if (!checkRequired(formObject)  )
        {
            return false;
        }  
        
        if (IsFileUpload == undefined)  
        {
            YAHOO.util.Connect.setForm(formObject);
        }
        else
        {
            YAHOO.util.Connect.setForm(formObject,true);   
        }  
        // This example facilitates a POST transaction.
        // An HTTP GET can be used as well.
        //var cObj = YAHOO.util.Connect.asyncRequest('POST', 'http://www.yahoo.com', callback);
        s101Manager.doAjaxGet('index.php',sResultDiv);   
    },
     
    doSubmitForm2 : function(sFormName,sResultDiv,sDisableButton)
    {     

	var DisableButtonID = sDisableButton ;
     
        YAHOO.namespace("example.container");
        // argument formId can be the id or name attribute value of the
        // HTML form, or an HTML form object.
        var formObject = document.getElementById(sFormName);
        if (!formObject)
        {
            alert('bad formObject: ' + sFormName);
        }
        
        if (!checkRequired(formObject)  )
        {
            return false;
        }  

		if (DisableButtonID.length > 0) {

//				alert(DisableButtonID) ;

             document.getElementById(DisableButtonID).type = "hidden" ;

		}
        
//        if (IsFileUpload == undefined)  
//        {
            YAHOO.util.Connect.setForm(formObject);
//        }
//        else
//        {
//            YAHOO.util.Connect.setForm(formObject,true);   
//        }  

        // This example facilitates a POST transaction.
        // An HTTP GET can be used as well.
        //var cObj = YAHOO.util.Connect.asyncRequest('POST', 'http://www.yahoo.com', callback);
        s101Manager.doAjaxGet('index.php',sResultDiv);   
    },
     



    doPopup : function(sPopupName,sTitle,sParams,sWidth)
    {
    
        url_params = "";
        if (sParams != undefined)
            url_params = sParams;
        
        if ((sWidth == undefined) || (sWidth == ''))
            sWidth = "320px";
        
        YAHOO.namespace("example.container");
        
        //sWidth = "100%";
        sY = "10px";
        sX = "10px";
        sHeight="400";
        YAHOO.example.container.panel2 = new YAHOO.widget.Panel("panel2", { width: sWidth, 
                                                                            height: sHeight,
                                                                            visible:false, 
                                                                            effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.7},
                                                                                    {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.7}] ,
                                                                            fixedcenter: false,
                                                                            constraintoviewport : true,
                                                                            modal: true,
                                                                            draggable:false,                                                                            
                                                                            close:true } ); 
        YAHOO.example.container.panel2.setHeader('');//sTitle); 
        YAHOO.example.container.panel2.setBody("<div id='popupContent' class=popupContent>L O A D I N G . . .<P><i>Just a sec.</I></div>"); 
        YAHOO.example.container.panel2.setFooter("<div id='popupFooter' class=popupFooter><P align=right><small>Powered by <A target=new href=http://www.section101.com>Section101</A></small></p></div>"); 
        
    
        //YAHOO.example.container.panel2.cfg.setProperty("xy", [100,window.pageYOffset]);  
        multibrowser_y = getYOffset();
        if ( multibrowser_y > 0)
        {
            multibrowser_y = multibrowser_y + 20;
            YAHOO.example.container.panel2.cfg.setProperty("top", multibrowser_y);  
        }
        
      
        YAHOO.example.container.panel2.render("s101_container2");  
        YAHOO.example.container.panel2.show();   
        //YAHOO.example.container.panel2.cfg.setProperty("width", 1000 ); 
        //YAHOO.example.container.panel2.cfg.setProperty("context", ["popup_placeholder", "tr", "tl"]);  
                                                           
        // 
   

          
           //YAHOO.example.container.panel2.cfg.setProperty("xy", [x,y]);  
        //var divObject = document.getElementById("s101_container2");    
        //divObject.center(); 
        s101Manager.doAjaxGet('index.php?popup=1&action='+sPopupName+url_params,'popupContent');
 if (sWidth == '0px') {
	//	alert('close1') ;
       YAHOO.example.container.panel2.hide() ;
	//	alert('close2') ;
		}
    }, 

   doAjaxGetDirect : function(sUrl,sDiv)
    {
        //lert('doAjaxGet:'+sUrl);
        //       alert('doAjaxGet:'+sDiv);
    
        //var sUrl = "php/get.php?username=anonymous&userid=0"; 
        var div = document.getElementById(sDiv); 
        div.innerHTML = "Loading.  Please Wait...<br><br>";
        
        var
        handleSuccess = function(o)
        { 
        
       
            if(o.responseText !== undefined)
            { 
                sText = "<li>Transaction id: " + o.tId + "</li>"; 
                        sText += "<li>HTTP status: " + o.status + "</li>"; 
                sText += "<li>Status code message: " + o.statusText + "</li>"; 
                sText += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>"; 
                sText += "<li>Server response: " + o.responseText + "</li>"; 
                sText += "<li>Argument object: Object ( [foo] => " + o.argument.foo + 
                             " [bar] => " + o.argument.bar +" )</li>";
                
                //alert(o.responseText); 
                
                div.innerHTML = o.responseText;

		alert('1b') ;

 
			}
		}
		alert('1c') ;

		return(o.responseText) ;
	},



   doAjaxGet : function(sUrl,sDiv)
    {
        //lert('doAjaxGet:'+sUrl);
        //       alert('doAjaxGet:'+sDiv);
    
        //var sUrl = "php/get.php?username=anonymous&userid=0"; 
        var div = document.getElementById(sDiv); 
        div.innerHTML = "Loading.  Please Wait...<br><br>";
        
        var
        handleSuccess = function(o)
        { 
        
       
            if(o.responseText !== undefined)
            { 
                sText = "<li>Transaction id: " + o.tId + "</li>"; 
                        sText += "<li>HTTP status: " + o.status + "</li>"; 
                sText += "<li>Status code message: " + o.statusText + "</li>"; 
                sText += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>"; 
                sText += "<li>Server response: " + o.responseText + "</li>"; 
                sText += "<li>Argument object: Object ( [foo] => " + o.argument.foo + 
                             " [bar] => " + o.argument.bar +" )</li>";
                
                //alert(o.responseText); 
                
                div.innerHTML = o.responseText;
                //YAHOO.example.container.panel2.center(); 
             
                if ( strstr( o.responseText , "##REFRESH##"))
                {
                    //alert('refresh');
                    refresh();
                }
		  if ( strstr( o.responseText , "##TURNON_WYSIWYG##"))
                {
                    alert('TURNON_WYSIWYG2');
      
     tinyMCE.init({
        // General options
        mode : "exact",
        theme : "advanced",
        plugins : "s101rss,example,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        xapply_source_formatting : true,
        xcleanup_on_startup : true,
        xfix_nesting : true,
  
        
        theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,undo,redo ,|,hr,removeformat,|,charmap,emotions,iespell,media,advhr,|,s101rss,example",
        theme_advanced_buttons3 : "cleanup,removeformat ",
        theme_advanced_buttons2 : "bold,italic,underline,|,forecolor,backcolor,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,|,link,unlink,anchor,image,|,save,code,preview,fullscreen,",
   
        xtheme_advanced_buttons4 : "tablecontrols,insertlayer,moveforward,movebackward,absolute,|,styleprops,|,del,ins,attribs,|,visualchars,template",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",   
        theme_advanced_resizing : true,
        xcleanup : false,           
        remove_script_host : true,
        relative_urls : false,
                                       
        // Example content CSS (should be your site CSS)
        content_css : "./schemes/default/skin.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",

        // Replace values for the template plugin
        template_replace_values : {
            username : "Some User",
            staffid : "991234"
        }
    });
      
       tinyMCE.execCommand("mceAddControl", true, "wysiwyg");



                    alert('END_TURNON_WYSIWYG3');
                    //refresh();
                }

                if ( strstr( o.responseText , "##USERPAGE##"))
                {
                    //document.location = "http://mountainjam.com/?page=user";
                    document.location = "http://users.section101.com/?page=user";
                    //alert('userpage');
                }
                if ( strstr( o.responseText , "##REPOST##"))
                {
                    document.location = "?page=repost";
                }
                if ( strstr( o.responseText , "##GOTOPAGE="))
                {

                     var temp = new Array();
                     temp = o.responseText.split('##GOTOPAGE=');

                     var temp2 = new Array();
                     temp2 = temp[1].split('##');

                    document.location = "?page=" + temp2[0] ;
                }

                 if ( strstr( o.responseText , "##BACK##"))
                {
                    //document.location = "http://mountainjam.com/?page=user";
                    //alert("BACK");
                    history.back(1);
                    //alert('userpage');
                }
                if ( strstr( o.responseText , "##GO_HOME##"))
                {
                    //document.location = "http://mountainjam.com/";
                    document.location = "?";
                    //alert('go home');
                }
                if ( strstr( o.responseText , "Error:"))
                {
                    //alert(o.responseText);
                }
            } 
        } 
   
        var handleUpload = function(obj)
        { 
            if(obj.responseText !== undefined)
            { 
                sText = "<li>Transaction id: " + obj.tId + "</li>"; 
                        sText += "<li>HTTP status: " + obj.status + "</li>"; 
                sText += "<li>Status code message: " + obj.statusText + "</li>"; 
                sText += "<li>HTTP headers: <ul>" + obj.getAllResponseHeaders + "</ul></li>"; 
                sText += "<li>Server response: " + obj.responseText + "</li>"; 
                sText += "<li>Argument object: Object ( [foo] => " + obj.argument.foo + 
                             " [bar] => " + obj.argument.bar +" )</li>";
                
                //alert(sText); 
                
                
                div.innerHTML = obj.responseText;
                if ( strstr( obj.responseText , "##REFRESH##"))
                {
                    //alert('refresh');
                    refresh();
                }
                 if ( strstr( obj.responseText , "##USERPAGE##"))
                {
                    //alert('redirect');
                    document.location = "/?page=user";
                }
            } 

        } 
        
        var handleFailure = function(o)
        { 
  

            if(o.responseText !== undefined)
            { 
                sText = "<li>Transaction id: " + o.tId + "</li>"; 
                sText += "<li>HTTP status: " + o.status + "</li>"; 
                sText += "<li>Status code message: " + o.statusText + "</li>"; 
                alert(sText);
                div.innerHTML = sText; 
            } 
        } 
     
        var callback = 
        { 
            upload: handleUpload, 
            success:handleSuccess, 
            failure: handleFailure, 
            cache:false,
            argument: { foo:"foo", bar:"bar" } 
        }; 

        var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback); 
    } /* END FUNCTION */
 
 }

/**** OLD BELOW ****/
var dlgAjax;

var s101ManagerOld = {
	var1 : null,
	var2 : null,
	var3 : null,
	popupWin : null,

	preInit : function(s) 
	{
	
	},

	DestroyAjaxPopup : function()
	{
			this.popupWin.destroy();
	},
	getPopupWindowHandle : function()
	{
			return this.popupWin;
	},
	HideAjaxPopup : function()
	{
			this.popupWin.hide();
	},
	setPopupTitle : function(titleText)
	{
		if (this.popupWin)
		{
			this.popupWin.setTitle(titleText);
		}
	},



	ShowAjaxPopup : function(ajax_param,p_height,p_width,jsonParams,animation_target)
	{

		

    },
	



	Init : function() 
	{

        alert('sitepages.js init');
        
		dlgAjax = null;
		if (window == top)
		{
			e=document.getElementById("NOSHELL_TOOLBAR");
			if (e)
			{ 
				//alert('topbar');
				//e.style.visibility = "visible";

			}
			else
			{
				//alert('no top bar');
			}
		}
		else
		{
			//alert('no null parent');
		}

	}


};

function showElement(bShow,elementID)
{
    e  =document.getElementById(elementID);   
    if (!e)
    { 
        alert('showElement - Notfound:' + elementID);
        return;
    }  
    if (bShow)
    {
        e.style.visibility = "visible";
        e.style.height = "42px";
        //alert('showed:' + elementID);
    } 
    else
    {
        e.style.height     = "0px";
        e.style.visibility = "hidden";
        //alert('Hid:' + elementID);  
    }
}
function show_toolbar(bShow)
{    

    showElement(bShow,"NOSHELL_TOOLBAR");
    showElement(bShow,"TOOLBAR_BACKDROP");    
}    

function ie_setup_div_with_backdrop(element_id,element_backdrop_id)
{
 
      
    el_backdrop = document.getElementById(element_backdrop_id);  
      
    if (! el_backdrop )
    {
        alert("el_backdrop not found:" +   element_backdrop_id);
        return;
    }
         
    topx = el_backdrop.style.top;
 
    if (topx == '')
        topx = "0px";

    leftx =  el_backdrop.style.left; 
              
    if (leftx == '')
        leftx = "0px"; 
   
    el = document.getElementById(element_id);  
    if (! el )
    {
        alert("el not found:" +   el);
        return;
    }
              
    wid = el.style.width;
    hi =  el.style.height; 
    
    el.style.top = topx;
    el.style.left = leftx;
    el_backdrop.style.width = wid;
    el_backdrop.style.height = hi;    
    
    el.style.visibility = "visible";
   
}
function setup_div_with_backdrop(element_id,element_backdrop_id)
{

 
 
    if (navigator.appName=="Microsoft Internet Explorer")
    {
        return ie_setup_div_with_backdrop(element_id,element_backdrop_id)  
    }
           
    el_backdrop = document.getElementById(element_backdrop_id);  
     
    if (! el_backdrop )
    {
        alert("el_backdrop not found:" +   element_backdrop_id);
        return;
    }
    
      
    top = el_backdrop.offsetTop + "px";
   
    if (top == '')
    {
        top = "0px";
        //alert('top is blank');
    }
    left =  el_backdrop.offsetLeft + "px"; 
          
    if (left == '')
        left = "0px"; 
   
    el = document.getElementById(element_id);  
    if (! el )
    {
        alert("el not found:" +   el);
        return;
    }
    
                             
    wid = el.offsetWidth + "px";
    hi =  el.offsetHeight + "px"; 

    //alert(wid);
    
    el.style.top = top;
    el.style.left = left;
    //el_backdrop.style.width = wid;
    el_backdrop.style.height = hi;
    el.style.visibility = true;
   
}

function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}

function noenter() {

  return !(window.event && window.event.keyCode == 13); 

}

function insert_text(el,ins) {

alert(ins) ;

    if (el.setSelectionRange){
        el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length);
    }
    else if (document.selection && document.selection.createRange) {
        el.focus();
        var range = document.selection.createRange();
        range.text = ins + range.text;
    }

}	

function S101_Insert_Link(el,ins) {

var oForm = document.forms['form']; 

var oTagsList = oForm.elements['link_name']; 

var link_name = oTagsList.value;

var oTagsList = oForm.elements['link_url']; 

var link_url = oTagsList.value;

var oTagsList = oForm.elements['link_target']; 

var link_target = oTagsList.value;


var link_data = '<a href="' + link_url + '" target="' + link_target + '" id="s101_insert_link">' + link_name + '</a>' ;

//alert(link_data) ;

    if (el.setSelectionRange){
        el.value = el.value.substring(0,el.selectionStart) + link_data + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length);
    }
    else if (document.selection && document.selection.createRange) {
        el.focus();
        var range = document.selection.createRange();
        range.text = link_data + range.text;
    }

S101_toggleDiv('form_link');

}


function S101_Insert_Pic_Link(el,ins) {

//alert(ins) ;

var oForm = document.forms['form']; 

var oTagsList = oForm.elements['image_width']; 

var image_width = oTagsList.value;

var oTagsList = oForm.elements['image_url_loc']; 

var image_url_loc = oTagsList.value;

var oTagsList = oForm.elements['image_ext_link']; 

var image_ext_link = oTagsList.value;

var oTagsList = oForm.elements['image_link_target']; 

var image_link_target = oTagsList.value;

var link_target = '' ;

if (image_link_target.length >  1) {

var link_target = ' target="' + image_link_target + '"' ;

}

if (image_url_loc.length >  1) {
   
  ins = image_url_loc ;

}


if (image_width < 1) {

var link_data = '<img src="' + ins + '" >' ;

} else {

//alert(ins) ;

if (image_width > 200) {

ins = ins.replace("_sm.","_md.") ;

}

if (image_width > 500) {

ins = ins.replace("_md.","_lr.") ;

}

//alert(ins) ;

var link_data = '<img src="' + ins + '" width="' + image_width + '">' ;

}

if (image_ext_link.length >  1) {

var link_data = '<a href="' + image_ext_link + '" ' + link_target + '>' + link_data + '</a>' ;

}

//alert(link_data) ;

    if (el.setSelectionRange){
        el.value = el.value.substring(0,el.selectionStart) + link_data + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length);
    }
    else if (document.selection && document.selection.createRange) {
        el.focus();
        var range = document.selection.createRange();
        range.text = link_data + range.text;
    }

S101_toggleDiv('form_pic');

}


function S101_Pop_Up(file_name,width,height) {

//var windowprops = width + "=300,height=" + height + ",location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

var PARAMETERS = {};

    PARAMETERS.map = {};
    window.location.search.substring(1).replace(/([^&=]+)([=]([^&]*))?(&|$)/g,function(s,k,q,v){
        if (undefined === PARAMETERS.map[k]) {
            PARAMETERS.map[k] = [];
        }
        PARAMETERS.map[k].push(decodeURIComponent(v));
    });
    for (var k in PARAMETERS.map) {
        var a = PARAMETERS.map[k];
        PARAMETERS.map[k] = ((1 == a.length) ? a[0] : a);
    }



			jQuery(document).ready(function(){
	
				jQuery.facebox(function() {
  					jQuery.get(file_name, function(data) {
    					jQuery.facebox(data)
  					})
				}) 
			});



}

function S101_Pop_Up2(file_name,width,height) {

jQuery.facebox(function() { 
  jQuery.get('code.js', function(data) {
    jQuery.facebox('<textarea>' + data + '</textarea>')
  })
})

}


function S101_show_galleries(gallery_id, username) {

//alert(username) ;

var oForm = document.forms['form']; 

var oTagsList = oForm.elements['photo_gallery']; 

var i = oForm.elements['photo_gallery'].selectedIndex ; 

var gallery_id = oTagsList.options[i].value;

//alert(gallery_id) ;

S101_replace_div('js/get_gallery_pics.php?gallery=' + gallery_id + '&username=' + username) ;

//alert('test3a') ;

}

var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
} 


function S101_replace_div(file_name) {
  http.open("GET", file_name , true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById('gallery_pics').innerHTML = http.responseText;
    }
  }
  http.send(null);
}




function S101_toggleDiv(divid){

    var e = document.getElementById(divid);
	
//  alert(e.style.display) ;

 if (e.style.display != 'block') {

    e.style.display = 'block';

 } else {

   e.style.display = 'none';

}

//  alert(e.style.display) ;

}


function S101_toggleDivTags(button){

    var e = document.getElementById('form_tags');
	
//  alert(e.style.display) ;

 if (button == 'smart') {

    e.style.display = 'block';

 } 

 if (button == 'text') {

   e.style.display = 'none';

}

 if (button == 'html') {

   e.style.display = 'none';

   start_MCE() ;

var id = document.getElementById('NewsItem');

tinyMCE.execCommand("mceAddControl", true, id); 

   tinyMCE.idCounter=0;

   tinyMCE.execCommand("mceAddControl", true, 'NewsItem') ;    


   tinyMCE.execCommand("mceAddControl", true, document.getElementById('NewsItem')) ;    

   tinyMCE.execCommand("mceAddControl", true, "edit_content"); 

//   alert('exec started') ;

}


//  alert(e.style.display) ;

}





var playerWin = null; 

function S101_launchPopup(link,width,height,top,left) {

//    link = '/player/popup.html' ;

//alert(link) ;

  var win_params = 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + top + ',left=' + left ;

//alert(win_params) ;

    if (playerWin != null && playerWin.closed == false) {
        playerWin.location = link;
        playerWin.focus();
    }
    else {
        playerWin = window.open(link, '', win_params);
    }

}


function showFormElements(oForm) {
   var cnt = 0;
   var msg = "Form with 'name' attribute='" + oForm.name + "'";
   var str = "\nThe elements are: \n\n";
   for (i = 0; i < oForm.length; i++) {
	cnt ++; 
	str += oForm.elements[i].tagName + " with 'name' attribute='" + oForm.elements[i].name + "'\n";
   }

   msg += " has " + cnt + " elements. \n" + str;
   alert(msg);
}

function showFormData(oForm) {
   var msg = "The data that you entered for the form with 'name' attribute='" + oForm.name + "': \n";
   
   for (i = 0; i < oForm.length, oForm.elements[i].getAttribute("type") !== 'button'; i++) {
	   msg += oForm.elements[i].tagName + " with 'name' attribute='" + oForm.elements[i].name + "' and data: ";
	   if(oForm.elements[i].value == null || oForm.elements[i].value == '') {
		msg += "NOT SET \n";
	   } else {
		   msg += oForm.elements[i].value + "\n";
	   }
   }

   alert(msg);
}


function copyFormElementToElementOfDifferentForm(oForm1Name, oForm2Name, oForm1ElementName, oForm2ElementName) {

	var oForm1 = document.forms[oForm1Name];
	var oForm2 = document.forms[oForm2Name];
	var oForm1Element = oForm1[oForm1ElementName];
	var oForm2Element = oForm2[oForm2ElementName];

	if(oForm2Element.value == '') {
		oForm2Element.value += oForm1Element.value;
	} else {
		oForm2Element.value += ', ' + oForm1Element.value;
	}
}


function start_MCE() {

//alert('init mce') ;

             tinyMCE.init({
                // General options
                mode : "textareas",
                xmode : "exact",
               
                theme : "advanced",
                pxlugins : "s101rss,example,code,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                plugins : "code,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

                // Theme options
                apply_source_formatting : true,
                cleanup_on_startup : true,
                fix_nesting : true,
                
                // Theme options
                theme_advanced_buttons1 : "undo,redo,|,link,unlink,anchor,image,|,cut,copy,paste,|,advhr,|,bullist,numlist,outdent,indent,|,code,|,pastetext,pasteword",   
                theme_advanced_buttons2 : ",fontselect,fontsizeselect,forecolor,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,emotions,inserttime,sub,sup,|,fullscreen" ,
                theme_advanced_buttons3 : "",              
                theme_advanced_toolbar_location : "top",
                theme_advanced_resizing : true,                                                  
                extended_valid_elements : "hr[class|width|size|noshade]",

           
                //cleanup : false,           
                //remove_script_host : true,
                //relative_urls : false,
                                               
                // Example content CSS (should be your site CSS)
                content_css : "./schemes/default/skin.css",

                // Drop lists for link/image/media/template dialogs
                template_external_list_url : "lists/template_list.js",
                external_link_list_url : "lists/link_list.js",
                external_image_list_url : "lists/image_list.js",
                media_external_list_url : "lists/media_list.js",

                // Replace values for the template plugin
                template_replace_values : {
                    username : "Some User",
                    staffid : "991234"
                }
            });

//alert('start mce') ;

}


var tooltip=function(){
 var id = 'tt';
 var top = 3;
 var left = 3;
 var maxw = 300;
 var speed = 10;
 var timer = 20;
 var endalpha = 95;
 var alpha = 0;
 var tt,t,c,b,h;
 var ie = document.all ? true : false;
 return{
  show:function(v,w){
   if(tt == null){
    tt = document.createElement('div');
    tt.setAttribute('id',id);
    t = document.createElement('div');
    t.setAttribute('id',id + 'top');
    c = document.createElement('div');
    c.setAttribute('id',id + 'cont');
    b = document.createElement('div');
    b.setAttribute('id',id + 'bot');
    tt.appendChild(t);
    tt.appendChild(c);
    tt.appendChild(b);
    document.body.appendChild(tt);
    tt.style.opacity = 0;
    tt.style.filter = 'alpha(opacity=0)';
    document.onmousemove = this.pos;
   }
   tt.style.display = 'block';
   c.innerHTML = v;
   tt.style.width = w ? w + 'px' : 'auto';
   if(!w && ie){
    t.style.display = 'none';
    b.style.display = 'none';
    tt.style.width = tt.offsetWidth;
    t.style.display = 'block';
    b.style.display = 'block';
   }
  if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
  h = parseInt(tt.offsetHeight) + top;
  clearInterval(tt.timer);
  tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  },
  pos:function(e){
   var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
   var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
   tt.style.top = (u - h) + 'px';
   tt.style.left = (l + left) + 'px';
  },
  fade:function(d){
   var a = alpha;
   if((a != endalpha && d == 1) || (a != 0 && d == -1)){
    var i = speed;
   if(endalpha - a < speed && d == 1){
    i = endalpha - a;
   }else if(alpha < speed && d == -1){
     i = a;
   }
   alpha = a + (i * d);
   tt.style.opacity = alpha * .01;
   tt.style.filter = 'alpha(opacity=' + alpha + ')';
  }else{
    clearInterval(tt.timer);
     if(d == -1){tt.style.display = 'none'}
  }
 },
 hide:function(){
  clearInterval(tt.timer);
   tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
  }
 };
}();


