/*
  Common Javascript Library for kevchat
*/

USER_ICON = "<img src='image/user.gif' hspace=4 align=absmiddle border=0>";

BASE_URL = "http://cmcowan.net/";

function refreshWindows(){
	//alert("refresh");
	chatUrl = "http://cmcowan.net/webcam/chats/today.html";
    window.parent.chatsCurrentFrame.location = chatUrl;
	try{
    window.parent.headerFrame.setDesktop();
	}catch(anErr){

	}
	findFormElement("message").focus();
	return;
  /*
   
   try{

   frame = window.parent.headerFrame;
   ele = findFormElement("username");
   sessionEle = window.parent.whosOnlineFrame.document.getElementById(ele.value);
   lineEle = frame.document.getElementById("lineCell");
   
   loggedInHTML = "<table cellpadding=0 cellspacing=0 border=0>";

     // session row
		if(!sessionEle){
		  //alert("session element not found!");
          loggedInHTML += "<tr><td nowrap><font size='1'>&nbsp;</td></tr>";
		} else {
          loggedInHTML += "<tr><td nowrap><font size='1'><div id='currentlyOnlineAsLayer'>Currently Online As:</div></td></tr>";
		}


  // user row
   loggedInHTML += "<tr><td nowrap><font size='1'>";

   if(ele.value != ""){
        loggedInHTML += USER_ICON+"<font size=3> "+ele.value+"&nbsp;&nbsp;&nbsp;</font>";
		lineEle.style.backgroundColor = "00ff00";
   } else {
        loggedInHTML += "Not Logged In&nbsp;&nbsp;&nbsp;";
		lineEle.style.backgroundColor = "ff0000";
   }
   logEle = frame.document.getElementById("loggedInLayer");
   //alert("Log in status: "+loggedInHTML);
    loggedInHTML += "</font></td></tr>";

	loggedInHTML += "</table>";

   logEle.innerHTML = loggedInHTML;
   }catch(anErr){ alert(anErr.message);  }
   */
}


//****************************************************************************
//  DOCUMENT EXTENSIONS and CROSS-BROWSER DOM ACCESS UTILS
//****************************************************************************

function findFormElement(eleName){
    // This will find ANY element in the browser, but is generally focused on 
	// finding elements in the form with the 'name' attr, but not an 'id' attr
	// which causes the getElementById to fail in Mozilla based browsers.
	// For sanity and IE
	// make an initial effort to return the element via DOM call.
	__ele = document.getElementById(eleName);
	if(__ele){
		return __ele;
	}

    // if no element is found, go through the forms and look for a match
	for(f1=0; f1<document.forms.length; f1++){
		currForm = document.forms[f1];

        // go through each element and focus on the name or id
		for(fe=0; fe<currForm.elements.length; fe++){
			if(currForm.elements[fe].name == eleName || currForm.elements[fe].id == eleName){
				return currForm.elements[fe];
			}
		}
	}

	return false;
}


function getDocumentElement(id){
   return document.getElementById(id);
}


function doShowEmoticonDictionary(){
      var params = 'height=475,width=510,scrollbars=yes,resizable=yes,location=no,toolbar=no,menubar=no';
      var theURL = BASE_URL+'emoticon_dictionary.html';
      window.open(theURL, 'smileyWin', params);

	}

 function doShowChatArchiveBrowser(){
      var params = 'height=575,width=910,scrollbars=yes,resizable=yes,location=no,toolbar=no,menubar=no';
      var theURL = BASE_URL+'cgi-bin/chatlogview.pl?action=init&view=all';
      window.open(theURL, 'archiveWin', params);

	}

 function doShowChatArchiveSearch(){
      var params = 'height=575,width=910,scrollbars=yes,resizable=yes,location=no,toolbar=no,menubar=no';
      var theURL = BASE_URL+'cgi-bin/chatsearch.pl';
      window.open(theURL, 'searchWin', params);

	}