
initPageValues();


// construct prefs objects
cfrm = new Object();
all = new Object();
tpc = new Object();
myspace = new Object();
posting = new Object();
members =  new Object();   

menusOpen = new Object();// to track open menu ids used by clearMenus()

 (gs_cookie.parsed && gs_cookie.u && gs_cookie.u!='' && gs_cookie.u!=null) ? userIsLoggedIn = true: userIsLoggedIn = false;

  user_has_cp_access = (gs_cookie.has_cp_access == 'Y');
  gs_cookie.has_cp_access  = (gs_cookie.has_cp_access == 'Y');// convert to boolean	

  if(gs_cookie.user_oid == '' || gs_cookie.user_oid == null ){gs_cookie.user_oid='00000000'};	
	
	
// check if time_zone offset value has been set from the XML
if ((window.site_timezone_offset == null) || (window.site_timezone_offset == '')){ // set default to PST GMT-8 in case it's not defined
  site_timezone_offset = 0;
}

if ((!window.day_names) || (!window.month_names)){ // don't bother doing MyTimeZone if there's no info
	myTimeZone.hasParms = false;
}

// Calculate a msecs offset for browser
var d = new Date()
if (d.getTimezoneOffset) {
  var iMinutes = d.getTimezoneOffset();// from GMT
  browser_offset =  iMinutes/60; // in hours
  offset_correction = (1009872000000 - Date.parse('Tue, 01 January 2002 00:00:00 GMT-0800'))/3600000;
} else {
  browser_offset=0;
  offset_correction = 0;
  myTimeZone.hasParms = false;	
}	

 window.server_gmt_offset ? server_gmt_offset /= 100 :  server_gmt_offset = 8; //  Note error in offset XML:  800 should be -800 and the /100 is not accurate in GMT-330

  if( (gs_cookie.time_zone) && (gs_cookie.time_zone != '') ){
	gmt_offset_ms = 3600000*(gs_cookie.time_zone - (server_gmt_offset - browser_offset) + offset_correction); // 8 is the GMT-8 of the OT server
  } else {// = do community time
	gmt_offset_ms = 3600000*(site_timezone_offset - (server_gmt_offset - browser_offset) + offset_correction)
  }

  if (gs_cookie.date_format && gs_cookie.date_format != '') {//Set Time format Pref
      time_format = unescape(gs_cookie.date_format).replace(/\+/g,' ');
  } else {
      window.default_time_format ? time_format = default_time_format :  time_format = 'MMMM dd, yyyy'; // fallback format
  }	


/* End run on load routines -> begin Infopop functions */

function initPageValues(){
	if (window.site_id_cookie) {
		gs_cookie = parse_query_params(getCookie(window.site_id_cookie));// this extracts all values from user cookie
		gs_cookie.parsed = true;
	} else {
		gs_cookie = new Object();
		gs_cookie.parsed = false;
	}	
	if (window.location.search.substring(1).match(/a=\w+/)) {// parse only if there is a string
		gs_query_params  = parse_query_params(window.location.search.substring(1));
		gs_query_params.raw = window.location.search.substring(1)
		gs_query_params.parsed = true;
	} else {
		gs_query_params = new Object();
		gs_query_params.parsed = false;
	}	
}// end fn

function formatDate(date,format) {
   // adapted from excellent routines by Matt Kruse http://www.mattkruse.com
    format = format+"";
    var result = "";
    var i_format = 0;
    var c = "";
    var token = "";
    var y = date.getYear()+"";
    var M = date.getMonth()+1;
    var d = date.getDate();
    var W = date.getDay(); // day of week  // Added MHF Mar 25/02
    var H = date.getHours();
    var m = date.getMinutes();
    var s = date.getSeconds();
    var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,WWW,WW,HH,H,KK,K,kk,k;
    // Convert real date parts into formatted versions
    // Year
    if (y.length < 4) {
        y = y-0+1900;
        }
    y = ""+y;
    yyyy = y;
    yy = y.substring(2,4);
    // Month
    if (M < 10) { MM = "0"+M; }
        else { MM = M; }
    MMMM = month_names[M-1];
    MMM = month_names[M-1+12];
    // Date
    if (d < 10) { dd = "0"+d; }
        else { dd = d; }
    // Hour
    h=H;//+1; rem
    K=H;
    k=H;//+1; rem
    if (h > 12) { h-=12; }
    if (h == 0) { h=12; }
    if (h < 10) { hh = "0"+h; }
        else { hh = h; }
    if (H < 10) { HH = "0"+K; }
        else { HH = H; }
    if (K > 11) { K-=12; }
    if (K < 10) { KK = "0"+K; }
        else { KK = K; }
    if (k < 10) { kk = "0"+k; }
        else { kk = k; }
    // AM/PM
    if (H > 11) { ampm="PM"; }
    else { ampm="AM"; }
    // Minute
    if (m < 10) { mm = "0"+m; }
        else { mm = m; }
    // Second
    if (s < 10) { ss = "0"+s; }
        else { ss = s; }
    // Now put them all into an object!
    var value = new Object();
    value["yyyy"] = yyyy;
    value["yy"] = yy;
    value["y"] = y;
    value["MMM"] = MMM;
    value["MMMM"] = MMMM;
    value["MM"] = MM;
    value["M"] = M;
    value["dd"] = dd;
    value["d"] = d;
    value["WWW"] = day_names[W]; // Added MHF Mar 25/02
    value["WW"] = day_names[W+7]; // Added MHF Mar 25/02
    value["hh"] = hh;
    value["h"] = h;
    value["HH"] = HH;
    value["H"] = H;
    value["KK"] = KK;
    value["K"] = K;
    value["kk"] = kk;
    value["k"] = k;
    value["mm"] = mm;
    value["m"] = m;
    value["ss"] = ss;
    value["s"] = s;
    value["a"] = ampm;
    while (i_format < format.length) {
        // Get next token from format string
        c = format.charAt(i_format);
        token = "";
        while ((format.charAt(i_format) == c) && (i_format < format.length)) {
            token += format.charAt(i_format);
            i_format++;
            }
        if (value[token] != null) {
            result = result + value[token];
            }
        else {
            result = result + token;
            }
        }
    return result;
}// end fn
 
    
function _isInteger(val) {
    var digits = "1234567890";
    for (var i=0; i < val.length; i++) {
        if (digits.indexOf(val.charAt(i)) == -1) { return false; }
        }
    return true;
}// end fn

function _getInt(str,i,minlength,maxlength) {
    for (x=maxlength; x>=minlength; x--) {
        var token = str.substring(i,i+x);
        if (token.length < minlength) {
            return null;
            }
        if (_isInteger(token)) { 
            return token;
            }
        }
    return null;
}// end fn




function myTimeZone(ietf_time,server_time) {
  if ( (ietf_time == '') || (myTimeZone.hasParms == false) ){
    return server_time;
  }
  var msecs = Date.parse(ietf_time) ; // this is secs per GMT time
  var raw_date = new Date((msecs+gmt_offset_ms)); // gmt_offset_ms is done once on script load
  return formatDate(raw_date,time_format);
}  // end fn


function savePrefsHandler(pageType){
	 if(pageType=='tpc'){
		blah();// add types for a=cfrm; tpc, pprly etc
	 } else {
	 	saveCfrmPrefs();// for cfrm only	
	 }
}// end fn


function saveCfrmPrefs(){// only for the cfrm page

	myPrefs = new Object();	// global obj
	cfrm.show = new Array();// cfrm was created as an Obj earlier
	cfrm.hide = new Array();
	
	var catsIdList = getCatsIdList(); // list of cats ids
	for(var id in catsIdList){// loop thru checking visibility
		if(!document.getElementById('gs_desc_forum_list_' +  catsIdList[id])){ continue };
		document.getElementById('gs_desc_forum_list_' +  catsIdList[id] ).style.display == '' ? cfrm.show.push('gs_desc_forum_list_' + catsIdList[id]): cfrm.hide.push('gs_desc_forum_list_' + catsIdList[id]);
	 }// end for
	

        if(document.getElementById('gs_intro_cfrm')){
		document.getElementById('gs_intro_cfrm').style.display == '' ? cfrm.show.push('gs_intro_cfrm') : cfrm.hide.push('gs_intro_cfrm');
        }
	cfrm.show = cfrm.show.join(',');// convert from array to to a CSV string
	cfrm.hide = cfrm.hide.join(',');
	myPrefs['param_name_list'] = 'cfrm.show,cfrm.hide'; // a CSV list of param names you'll be updating	
	myPrefs['cfrm.show'] = cfrm.show; // include the values too
	myPrefs['cfrm.hide'] = cfrm.hide;
	compilePrefs(myPrefs);
	return true;
}// end fn




function compilePrefs(myPrefs){ // put values into a form and submit it. 

var html_prefs_input = new Object();
html_prefs_input.values = new String();

html_prefs_input.params = '<input type="hidden" name="xfooptionlist,' + gs_cookie.pref_oid + ',u_prefs" value="' + myPrefs['param_name_list'] + '"/>';

for(var i in myPrefs){
	if(i == 'param_name_list'){continue};
	html_prefs_input.values += '<input type="hidden" name=\"xfo,' + gs_cookie.pref_oid + ',u_prefs,' + i + '\" value="' + myPrefs[i] + '"/>';
}// end for

if(!compilePrefs.backupPrefsFormObj){ compilePrefs.backupPrefsFormObj = document.getElementById('gs_prefs_form')};// make backup copy in case of reuse
document.getElementById('gs_prefs_form').innerHTML = compilePrefs.backupPrefsFormObj.innerHTML;

replaceAll('gs_prefs_form', '\\\$GS_HTML_PREFS_INPUT.PARAMS',html_prefs_input.params);
replaceAll('gs_prefs_form', '\\\$GS_HTML_PREFS_INPUT.VALUES',html_prefs_input.values);

document.getElementById('gs_message').style.visibility='visible';
// open iframe and copy gs_prefs_form Into it
	parent.gs_msg_iframe.document.open();
	parent.gs_msg_iframe.document.write("<HTML><BODY></BODY></HTML>");
	parent.gs_msg_iframe.document.close();
	parent.gs_msg_iframe.document.body.innerHTML = document.getElementById('gs_prefs_form').innerHTML;
	parent.gs_msg_iframe.document.update_prefs.submit();
confirm_message = setTimeout("document.getElementById('gs_message').style.visibility='hidden'",3500);

}// end fn 


function makeList(stringValues) {
	if(stringValues==null){
		return('');	
	}	
	var myArray = stringValues.split(',') 
	return 	myArray;
}


function setDisplayByArray(list,displayVal) {
 (displayVal==null || displayVal=='') ? displayVal='' : displayVal='none';
 for(var i in list) {
      if(!document.getElementById(list[i])){
         continue;
      } else {
         document.getElementById(list[i]).style.display=displayVal;
      }
 }
}// end  fn



function setStyleAttributeByArray(list, styleAttribute, attributeVal) {
  if (styleAttribute == '') {
  	alert('missing styleAttribute val')
        return;
  }	
 for(var i in list) {
      if(!document.getElementById(list[i])){
         continue;
      } else {
         document.getElementById(list[i]).style[styleAttribute] = attributeVal;
      }
 }
}// end  fn



function replaceAll(objId, replaceWhat, replaceWith ){ // this replaces all innerHTML of an element called objId
     var obj = document.getElementById(objId);
     var regX = new RegExp(replaceWhat,"g");
     obj.innerHTML = obj.innerHTML.replace(regX, unescape(replaceWith));
}// end fn



function getCookie(name) {
    if(name=='') {return null};
    var start = document.cookie.indexOf(name+"=");
    var len = start + name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}// end fn




function setCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}// end fn


function parse_query_params(querystring_string) { // parses &param=val string and returns Obj
        query_params = new Object();
	if ( (querystring_string=='')||(querystring_string==null) ){return query_params};
	var query_pairs = querystring_string.split('&');
	for (var i=0; i<query_pairs.length; i++){
		name_value = query_pairs[i].split('=');
		query_params[name_value[0]] = name_value[1];
	}
        return(query_params); // return obj as required
}//end fn



function getFrmsIdList(){ // returns an array of forum ids
      var cfrmIdList= new Array()
      for(i in hoptoArray) {
        if(hoptoArray[i].value){
      		cfrmIdList.push(hoptoArray[i].value);
        }
      }
      return(cfrmIdList);
}// end fn



function getCatsIdList(){  // returns an array of *category* only ids
      var catsIdList= new Array();
      for(i in hoptoArray) {
        if(hoptoArray[i].value && hoptoArray[i].value.match(/^c_/)){
      		catsIdList.push(hoptoArray[i].value.replace(/c_/,''))
        }
      }
      return(catsIdList);
}// end fn
  

function showMenu(anchor_id, nudgeX, nudgeY){ // shows the layer called id + '_menu' div matching anchor_id
	ColorEffectOn(anchor_id);
	BorderEffectOn(anchor_id);
	if(window.activemenu!=true) {return};
	if(nudgeX==null){nudgeX=0};
	if(nudgeY==null){nudgeY=0};
	clearMenus('activemenu=true');
	var position = getAnchorPosition(anchor_id);
	if(document.getElementById('gs_menu_y_baseline')) {position.y = getAnchorPosition('gs_menu_y_baseline').y};
        moveObject(anchor_id + '_menu', position.x-1+nudgeX,position.y + nudgeY);
        changeObjectVisibility(anchor_id + '_menu','visible');
	menusOpen[anchor_id + '_menu'] = true;// track open ids - this obj was instantiated on script load
} // end fn


function showGlobeMenu(anchor_id, nudgeX, nudgeY){
	var position = getAnchorPosition(anchor_id);
	clearMenus();
	if(nudgeX==null){nudgeX=0};
	if(nudgeY==null){nudgeY=0};
	moveObject('gs_global_menu', position.x + nudgeX, position.y + nudgeY);
        changeObjectVisibility('gs_global_menu','visible');
        menusOpen['gs_global_menu'] = true;// track open menu ids
}// end fn	


function resetMenuButtonColors(anchor_id){// will append _border and _color to id
	ColorEffectOff(anchor_id);
	BorderEffectOff(anchor_id);
} // end fn


function clearMenus(activeMenuSwitch){ // will hide all open menus that used: menusOpen[anchor_id + '_menu']
	if(window.doDrag){clearDragEvent()};
	for(var id in menusOpen){
		if(document.getElementById(id) != null) {
	           document.getElementById(id).style.visibility = 'hidden';
	           //delete(menusOpen[id]);// remove from openMenus obj property list
	           menusOpen[id] =  null;// remove from openMenus obj property list
		}
	}	
	if(activeMenuSwitch != 'activemenu=true'){// activemenu=true keeps the onmouseover showMenu() active
		window.activemenu=false
	}	
}// end fn


function getAnchorPosition(anchor_id) {// This function will return an Object with x and y properties
	var position=new Object();
	// Logic to find position
	position.x=AnchorPosition_getPageOffsetLeft(document.getElementById(anchor_id));
	position.y=AnchorPosition_getPageOffsetTop(document.getElementById(anchor_id));		
	return position;
}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while((el=el.offsetParent) != null) { 
	  ol += el.offsetLeft; 
	}
	return ol;
}// end fn


	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while( (el=el.offsetParent) != null) { 
	  ot += el.offsetTop; 
	}
	return ot;
}// end fn



function show_member_menu(thisObj,menu_id,user_name,user_oid,non_ot_user_id) {
	menuObj = document.getElementById(menu_id);
	window.menu_id = menu_id;// make it global in case of multiple fn calls.
	// create backup menu template so it can be reused
	(window.backupMenu)?menuObj.innerHTML=window.backupMenu:window.backupMenu=menuObj.innerHTML;
	replaceAll(menu_id,'\\\$GS_USERNAME', user_name);
	replaceAll(menu_id,'\\\$GS_USER_OID', user_oid);
	replaceAll(menu_id,'\\\$GS_NON_OT_USER_ID', non_ot_user_id);
	position = getAnchorPosition(thisObj.id);
	moveObject(menu_id,position.x,position.y+5);
	changeObjectVisibility(menu_id,'visible');
	menusOpen[menu_id] = true;// track open menu ids
}// end fn


function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
    	return false;
    }
} // end fn




function getStyleObject(objectId) {
     if(document.getElementById(objectId)){
	   return (document.getElementById(objectId).style);
     } else {
	   return false;
     }
} // end fn




function moveObject(objectId, newXCoordinate, newYCoordinate) {
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
    }
} // end fn

  

function showElement(){ //usage showElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=showElement.arguments.length; i++) {  
    element = document.getElementById(showElement.arguments[i]);
      if(element == null) { continue };
    element.style.display=''; 
 }   
}// end fn

  
  
function hideElement(){  //usage hideElement('id1','id2','id3','id4','etc')
 var element;
 for (var i=0; i<=hideElement.arguments.length; i++) {  
    element = document.getElementById(hideElement.arguments[i]);
      if(element == null) { continue };
    element.style.display='none';
 } 
}// end fn


function toggleView(){ //usage toggleView('id1','id2','id3','id4','etc')
  var element;
  for (var i=0; i<=toggleView.arguments.length; i++) {  
    element = document.getElementById(toggleView.arguments[i]);
       if(element == null) { continue };
    element.style.display=='' ?  element.style.display='none' : element.style.display='';
  }// end for   
 }

function toggleImg(img, fromThis, toThat) {// toggles images usage is toggleImg(this,img1,img2)
     var regX = new RegExp(fromThis,'');
     img.src.match(regX) ? img.src=img.src.replace(fromThis,toThat) : img.src=img.src.replace(toThat,fromThis);
}// end fn 


function toggleClass(objId, fromThisClass, toThatClass) {// toggles classes, usage is toggleClass(id,class1,class2)
     var obj = document.getElementById(objId);
     obj.className == fromThisClass ? obj.className = toThatClass : obj.className = fromThisClass;
}// end fn

function ColorEffectOn(anchor_id){
	if(document.getElementById(anchor_id + '_color')){
		document.getElementById(anchor_id + '_color').className = "gs_tab_color_alt";
	}
}// end fn



function BorderEffectOn(anchor_id){
	if(document.getElementById(anchor_id + '_border')){
		document.getElementById(anchor_id + '_border').className = 'gs_nav_sub_tab_on';
	}
}// end fn


function ColorEffectOff(anchor_id){
 	if(document.getElementById(anchor_id + '_color')){
		document.getElementById(anchor_id + '_color').className = 'gs_tab_color';
	}
}// end fn



function BorderEffectOff(anchor_id){
	if(document.getElementById(anchor_id + '_border')){
		document.getElementById(anchor_id + '_border').className = 'gs_nav_sub_tab';
	}
}// end fn


function writeWinMessage(winName,winMessage) {
	window[winName].document.write('<body><table width="100%" height="100%" border="0" align="center"><tr><td align="center" valign="middle" style="font-family:Verdana,Arial,Geneva;font-size:10pt">' + wait_message + '</td></tr></table></body>');
	window[winName].document.close();
}// end fn


function sizePopup(window_name, url, command){ 

       if(!window.gs_popup_w){ gs_popup_w = '600';};
       if(!window.gs_popup_h){ gs_popup_h = '400'};
       if(window.scalePopupPercent){gs_popup_w=parseInt(gs_popup_w*parseInt(scalePopupPercent)/100);gs_popup_h=parseInt(gs_popup_h*parseInt(scalePopupPercent)/100)};

	sizePopup.gs_popup_w_orig ? gs_popup_w = sizePopup.gs_popup_w_orig : sizePopup.gs_popup_w_orig = gs_popup_w;
	sizePopup.gs_popup_h_orig ? gs_popup_h = sizePopup.gs_popup_h_orig : sizePopup.gs_popup_h_orig = gs_popup_h;

       if (command == 'open'){ // for now only one command option

        if (url.match('x_is_topic_lead_enabled=Y') && (window_name == 'topic') ) {window_name = 'lead'}; // this increases size

	switch (window_name) {
	    case ('reply') : gs_popup_h = parseInt(gs_popup_h*0.94); break;
	    case ('topic') : break;
	    case ('conf') : gs_popup_w =  parseInt(gs_popup_w*0.9); break;
	    case ('poll') :  gs_popup_h = parseInt(gs_popup_h*1.44); break;
	    case ('email_a_friend') : gs_popup_h = parseInt(gs_popup_h*1.25); break;
	    case ('lead') : gs_popup_h = parseInt(gs_popup_h*1.3); break;
	    case ('help') : gs_popup_w =  parseInt(gs_popup_w*1.24); gs_popup_h = parseInt(gs_popup_h*1.44); break;
	 } 

	    childWin = window.open('',window_name,'width=' + gs_popup_w + ',height=' + gs_popup_h + ',toolbar=no, location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes');
	    writeWinMessage('childWin',wait_message);
	    childWin.location = url;
       }

}// end fn


function positionDiv(divId,xAlign,yAlign,newWidth,newHeight,nudgeX,nudgeY,closeAfterMs) { // only divId is mandatory
        var horiz,vert,obj;
	obj=document.getElementById(divId);
	if(newWidth!=null) {obj.style.width=newWidth + 'px'};
        if(newHeight!=null) {obj.style.height=newHeight + 'px'};
        if(nudgeX==null){nudgeX=0};
	if(nudgeY==null){nudgeY=0};
         // use either DOM or NS4+ to get window size and position
        document.body.clientWidth ? horiz=document.body.clientWidth : horiz=window.innerWidth;
        document.body.clientHeight ? vert=document.body.scrollTop+document.body.clientHeight : vert=window.innerHeight+window.pageYOffset;
        if (xAlign=='right') {
              horiz = (horiz-parseInt(obj.style.width)-20);
        } else if (xAlign=='left')  {
        	horiz = horiz - (horiz - 20);
        } else {// center it
               horiz = (horiz - parseInt(obj.style.width))/2;
        }      
        if (yAlign=='top') {
            if(window.pageYOffset){document.body.scrollTop=window.pageYOffset};// kludge for IE
             vert = 20 + document.body.scrollTop;
        } else if (yAlign=='bottom')  {       
        	vert = vert - (parseInt(obj.style.height) +  40);
        } else {// middle
        	document.body.clientHeight ? vert=document.body.scrollTop+document.body.clientHeight/2 : vert=window.innerHeight/2+window.pageYOffset;
        	vert -= parseInt(obj.style.height)/2;
        }     
        obj.style.left = horiz + nudgeX;
        obj.style.top = vert + nudgeY;
        obj.style.visibility='visible';
        if(closeAfterMs!=null) { // optional hide after x ms
        	positionDiv[divId]=  setTimeout("changeObjectVisibility('" + divId + "', 'hidden') ", closeAfterMs);
        }
}// end fn 


function initDragEvent(objId){
   if(objId != initDragEvent.prevId){
   	doDrag.divObj = document.getElementById(objId).style; // only set as needed
        initDragEvent.prevId = objId;
   }
   doDrag.active=true;
} // end fn


function clearDragEvent() { 
   doDrag.offsetX=null;
   doDrag.offsetY=null;
   doDrag.active=false;
}// end fn


function doDrag(e){ // Required init for IE: document.body.attachEvent('onmousemove', doDrag); initDragEvent(Id)
     if (!doDrag.active){ return};
     if (window.event){ e = window.event}; // for ie only
     if (!doDrag.offsetX) {if(!e.clientX){e.clientX=e.x}; doDrag.offsetX = e.clientX - parseInt(doDrag.divObj.left)};
     if (!doDrag.offsetY) {if(!e.clientY){e.clientY=y.y}; doDrag.offsetY = e.clientY - parseInt(doDrag.divObj.top)};
     doDrag.divObj.left = e.clientX - doDrag.offsetX;
     doDrag.divObj.top = e.clientY - doDrag.offsetY;
}// end fn



function showHoptoMenu(anchorObj, listType, startPoint,catOID){
	if(window.mapHopto && mapHopto[listType]!=null) { // redirects type as required
		listType=mapHopto[listType];	
	}	
	showHoptoNav(anchorObj, listType, startPoint,catOID);
}// end fn	


// this function creates a hopto menu
function showHoptoNav(anchorObj, listType, startPoint,catOID) {
	if(!window.hoptoArray){ // check and exit if there is no data for the hopto menu
		return;
	}	
	 this.dataObj = hoptoArray; // this was defined by the XSL from the forum node
	 this.total_length = dataObj.length;
	 this.tableObj = document.getElementById("hopto_table"); // used to build menu on

	 if (listType == null){listType='all'};// default is to show both cats and frms
	
	 if(showHoptoNav.created == listType){ // if list matching listType is already made, just show it.
		if((listType =='post_to_topic')|| (listType =='post_to_poll')) { // no need to re-position
			changeObjectVisibility('gs_hopto_menu','visible');
			menusOpen['gs_hopto_menu'] = true;
		} else { // these are cats or forums	
	   		positionHopto(anchorObj.id,listType,16,3 );
	   	}
	 	return;
	 } else {
	 	clearTable(this.tableObj);
	 }	
	
	if(startPoint==null){startPoint=0}; 

	// insert initial row with scroll up arrow
	tr = tableObj.insertRow(0);
	td = tr.insertCell(0);
	td.setAttribute("align", "center");
	td.setAttribute("id", "hopto_scroll_up");
	td.className = 'gs_header';
	td.innerHTML='<div onMouseover="doScrollUp()" style="text-decoration:none;cursor:hand;" onMouseout="clearInterval(window.ScrollAction);" style="width:100%; height:100%;">&nbsp;</div>';	

	j=1;// this is the counter for the table constructor.

	rollover_event_hop_to = ' onmouseover=this.parentNode.parentNode.className="gs_nav_layer_hover" onmouseout=this.parentNode.parentNode.className="gs_hopto_forum" ';
	rollover_event_hop_to_cat = ' onmouseover=this.parentNode.parentNode.className="gs_nav_layer_hover" onmouseout=this.parentNode.parentNode.className="gs_hopto" ';

        if (listType =='single_cat') {  
          crval = createRowValues(listType,'hoptoNav','hoptoNav','gs_hopto','gs_hopto_forum',rollover_event_hop_to_cat,rollover_event_hop_to);  
	  for(this.i=startPoint; i<total_length; i++){
	      if( (dataObj[i].value.indexOf(catOID) !=-1) || (window.started) ) { 
	          createRow(j,i);
		  started=true;// flag to ensure only one cat forum list
		  if ( !dataObj[i+1] || isCategory(dataObj[i+1].value) ){// stop if end of data or next data row is a cat
		   	started=false;
		  }	
		  j++;// increment to build next row		   
	       }// end if
           }// end for

	} else if (listType =='all') {
	   crval = createRowValues(listType,'hoptoNav','hoptoNav','gs_hopto','gs_hopto_forum',rollover_event_hop_to_cat,rollover_event_hop_to);
           for(this.i=startPoint; i<total_length; i++){          	
		if(this.tableObj.offsetHeight > (document.body.clientHeight-52) ){
			break; // don't build table bigger than screen height
		}         	
           	createRow(j,i);	
	        j++;
  	   }// end for

	} else if ((listType =='post_to_topic')||(listType =='post_to_poll')) {
	   rollover_event_post_to = ' onmouseover=this.parentNode.parentNode.className="gs_nav_layer_hover" onmouseout=this.parentNode.parentNode.className="gs_postto_forum" ';
	   crval = createRowValues(listType,'void','post_toNav','gs_nav_layer','gs_postto_forum','',rollover_event_post_to);
           for(this.i=startPoint; i<total_length; i++){         	
           	if(this.tableObj.offsetHeight > (document.body.clientHeight-52) ){
			break; // don't build table bigger than screen height
	        }          	    	
	        createRow(j,i);
        	j++;	
  	   }// end for		   
  
	} else if(listType =='cats') {   
	  crval = createRowValues(listType,'hoptoNav','hoptoNav','gs_hopto','gs_hopto_forum',rollover_event_hop_to_cat,rollover_event_hop_to);
	  for(this.i=startPoint; i<total_length; i++){
   	     if(this.tableObj.offsetHeight > (document.body.clientHeight-52) ){
		break; // don't build table bigger than screen height
	     }	
	     if(isCategory(dataObj[i].value)){
	          createRow(j,i);
	          j++;// increment to build next row   
             }
	  }// end for

	} // end else ifs

	// add final row with scroll down arrow
 	tr = tableObj.insertRow(j);
	td = tr.insertCell(0);
	td.setAttribute("align", "center");
	td.setAttribute("id", "hopto_scroll_down");
	td.className = 'gs_header';
	td.innerHTML='<div onMouseover="doScrollDown();" style="text-decoration:none;cursor:hand;" onMouseout="clearInterval(window.ScrollAction);" style="width:100%; height:100%;">&nbsp;</div>';
 	showHoptoNav.lastRowDisplayed = j;
	showHoptoNav.display_height = this.tableObj.offsetHeight;

	if(j >= total_length || listType=='cats' || listType=='single_cat'){// routine deletes the up/down scroll arrow rows if everything is on the list already
	  tableObj.deleteRow(j);
	  tableObj.deleteRow(0);
	}
	if ((listType =='post_to_topic')|| (listType =='post_to_poll')) {
		positionHopto(anchorObj.id,listType, document.getElementById('gs_tab_new_menu_topic').offsetWidth, -1);// NB nudgeX/Y values
	} else {// this are cats or all	
		positionHopto(anchorObj.id,listType,16,-2);// NB nudgeX/Y values
	}
	showHoptoNav.created = listType;// used by show hide to NOT redraw the menu each time if it's the same.
 } // end fn


function createRowValues(listType,doWhatCat,doWhatFrm,catClass,forumClass,catRoll,forumRoll){
	this.listType = listType;
	this.doWhatCat = doWhatCat;
	this.doWhatFrm = doWhatFrm;
	this.catClass = catClass;
	this.forumClass = forumClass;
	this.catRoll = catRoll;
	this.forumRoll = forumRoll;
	return this;
}// end fn

function createRow(j,i){
	 tr = tableObj.insertRow(j);
	 tr.setAttribute("id", 'row_id_' + dataObj[i].value);
	 td = tr.insertCell(0);
	 td.setAttribute("id", dataObj[i].value);
	  if (isCategory(dataObj[i].value)){	// check if this should be a category class = matches ID value c_nnnnnnn
	    td.className = crval.catClass;	 
	    td.innerHTML='<span class="gs_small"><a href="javascript:'+ crval.doWhatCat + '(\'' + dataObj[i].value + '\',\'' + crval.listType +   '\')" style="text-decoration:none;"' + crval.catRoll + '>' +dataObj[i].text + '</a></span>'; 
	  } else {
	    td.className = crval.forumClass;
	    td.innerHTML='<span class="gs_small"><a href="javascript:' + crval.doWhatFrm + '(\'' + dataObj[i].value + '\',\'' + crval.listType +   '\')" style="text-decoration:none;"' + crval.forumRoll + '>' +dataObj[i].text + '</a></span>';	 
	  }   	   	
}// end fn


	 
 
function addEvent(obj,event,callFunc){
	if(window.attachEvent){
	     event ='on'+ event;
	     obj.attachEvent(event,callFunc);
	} else if(document.addEventListener){
	     obj.addEventListener(event,callFunc,false);
	}
}// end fn

 
function positionHopto(anchorObjId,listType,nudgeX,nudgeY){
	var position=getAnchorPosition(anchorObjId);
  	var gs_hopto_menu_style = getStyleObject('gs_hopto_menu');
  	if(nudgeX==null){nudgeX=0};
	if(nudgeY==null){nudgeY=0};
  	if ( (listType != 'post_to_topic') && (listType != 'post_to_poll') ){clearMenus()};	
	document.body.clientHeight ? vert=document.body.scrollTop+document.body.clientHeight : vert=window.innerHeight+window.pageYOffset;
        if( (position.y + showHoptoNav.display_height) > vert ){ position.y -= (position.y + showHoptoNav.display_height - vert) }; 
  	moveObject('gs_hopto_menu', position.x + nudgeX, position.y + nudgeY) 
	changeObjectVisibility('gs_hopto_menu','visible');
	menusOpen['gs_hopto_menu'] = true;// track open menu ids	 	
}// end fn


function clearTable(tableObj) {
  while(tableObj.rows.length > 0) {
  	tr = tableObj.deleteRow(0);
  }	
  showHoptoNav.created = null;// menu must be redrawn if called again
 }// end fn	



function doScrollUp(){
	ScrollAction = setInterval("scrollUp(listType)",70)
}// end fn


function doScrollDown(){
	ScrollAction = setInterval("scrollDown(listType)",70)	
}// end fn


function scrollDown(){
	 if(!dataObj[i]){// check if there is a *next* data item
	   clearInterval(ScrollAction);
	   return;	
	 }	
	 tableObj.deleteRow(1); 
	 createRow(showHoptoNav.lastRowDisplayed-1,i);
	 i++; 	 
}// end fn


function scrollUp(){
	if (i-showHoptoNav.lastRowDisplayed < 0){// check if there is any *previous* data item
		clearInterval(ScrollAction);
		return;	
	}
	// continue inserts and count back in data object
	tableObj.deleteRow(showHoptoNav.lastRowDisplayed-1);
        createRow(1,i-showHoptoNav.lastRowDisplayed);
        i--;
} // end fn


function isCategory(forumOID){
       if(forumOID.match(/^c_/)){return true} else{return false};	
}// end fn




function hoptoNav(forumId,listType){// only for forum/cat nav
	var newlocation  =  hoptoArray.servleturl +  '?a=corfrm&s=' +  hoptoArray.siteid + '&q=Y&cf=' + forumId;
	clearMenus();
	window.location = newlocation;
}// end fn


function post_toNav(forumId,listType){ // only for post to actions
	var newlocation  =  hoptoArray.servleturl +  '?a=ptpc&s=' +  hoptoArray.siteid + '&f=' + forumId + '&x_popup=Y';
	var postType = 'topic'; //default
	if(listType=='post_to_poll'){newlocation += '&ispoll=Y';postType='poll'};// designate this as a poll
	clearMenus();
	sizePopup(postType, newlocation, 'open')
}// end fn


// Hide Edit Links
function hideEditLinks() {
  if(user_has_cp_access) {
    return;
  } 
  for (var i=0; i< document.images.length; i++) { // loop through images array
    if ((document.images[i].name.indexOf('edit')== -1) || (document.images[i].name.indexOf(gs_cookie.user_oid)!= -1)) { // skip non 'edit' images
      continue;
    } else { // this is an edit image NOT matching the user ID so hide it
        window.document.images[i].style.display='none'; // hide with CSS
    }
  }
}// end fn

function getIframeContent(newURL){
	var funcString = "getIframeContent('"+newURL+"')";
	if(!window.attempts){attempts=0};// instantiate counter for attempts
	if(!parent.gs_msg_iframe.location.href.match(newURL) ) { parent.gs_msg_iframe.location.href=newURL };
	if(!parent.gs_msg_iframe.isContentloaded && (attempts < 7)) { openLib=setTimeout(funcString,1500); attempts++; return}
        iframeContent = parent.gs_msg_iframe.document;
}//end fn



constructorFileLoaded = true;



