//
//Chris Jamison 2009-2009; commonScripts.js
// Use Notepad to edit.
// 20090203 Include file for common site JavaScript code.
// 20090205 added show/hide functions for home page.
// 20090210 added searchSite & ifEnter.
// 20090219 added gotoHref for quickLinks drop down support.
//
//

//This function will use current system date & lookup
// matching information from associated thisDayInHistory file.
function checkToday(){

  var month, date, lookupDate;

  today = new Date();
  //alert("today is " + today.toLocaleString());
  month=today.getMonth() + 1;
  date=today.getDate();
  //alert("today is " + month +"/"+ date+".");

  //get month-date in mmdd format for array lookup
  if (month < 10) {
   if (date < 10) {
     lookupDate = "0" + month.toString() + "0" + date.toString();}
   else {
     lookupDate = "0" + month.toString() + date.toString();}}
  else{
   if (date < 10) {
     lookupDate = month.toString() + "0" + date.toString();}
   else {
     lookupDate = month.toString() + date.toString();}
  }
  //alert("lookup date= " + lookupDate);

  var birthdays=loadBirthdayArray();  //in a separate file.
  //if (birthdays[lookupDate]) alert(birthdays[lookupDate]);
  
  var birthdayDisplay = "";
  if (birthdays[lookupDate]) birthdayDisplay = birthdays[lookupDate];

return birthdayDisplay;
}//end function checkToday



//This function is used to show/hide a <div> tag using display inline/none
//the second variable is used to control a subsequent spacer <div> to manage
//form display
function showHide(divId,divId2){
  obj = document.getElementById(divId);
  obj2 = document.getElementById(divId2);
  if (obj && obj2){  //check if divId is defined!
    obj.style.display = "none";
    //note: property in javascript is 'marginTop', not 'margin-top'
    obj2.style.marginTop = "4in";
    if (screen.width > 1200) {
    	//show a right-side area of links
    	obj.style.display = "inline";
    	obj2.style.marginTop = "1in";  //and adjust the spacer
    }
  }
}//end function showHide


//This function is used to show/hide a <div> tag using the visibility
// property.  It works along with a button to toggle visibility on-off.
function toggleCow(divId){
  obj = document.getElementById(divId);
  if (obj){  //check if divId is defined!
    oldVisibility = obj.style.visibility;
    if (oldVisibility == "hidden") obj.style.visibility = "visible";
    if (oldVisibility == "visible") obj.style.visibility = "hidden";
  }
}//end function toggleCow


//20090210
//Call this function from onClick on a button, will open up a new window
// to google.com and execute a search of all my current websites.
//Usage:  called from the onClick event of a button.
//        ex: onclick="searchSite(searchString.value)"  //where searchString is an input field
function searchSite(searchString) {
  //alert("search site called with " + searchString);
  //open a new window and launch the search of my sites
  var siteString= "site:www.mindspring.com/~cjamison";     //main site; from ISP
    siteString += " OR site:cujamison.home.comcast.net";   //from cable modem provider
    siteString += " OR site:chrisjamison.100webspace.net"; //free site
    siteString += " OR site:members.tripod.com/cujamison"; //depreciate this free site
    siteString += " OR site:www.geocities.com/cujamison";  //depreciate this free site
    siteString += " OR site:chrisjamison.blogspot.com";    //my blog
    //future:  picasa, liveSpaces, mySpace, facebook, etc.
  var searchURL= "http://www.google.com/";
    searchURL += "search?q=";
    searchURL += searchString + " " + siteString;
  var windowName="googleSearch"; 
  var windowProperties= "toolbar=yes, location=yes, directories=no, status=yes";
    windowProperties += ", menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=900, height=750";
  //
  //launches a new window with the search criteria in place and executed.
  window.open(searchURL,windowName,windowProperties);
  //
return;
}//end function searchSite


//20090210 check value of key pressed in an input field.  If it is a carriage return, 
// then execute the function with the value passed in (note only handles single-parameter functions).
//this is used primarily with pairs of input fields & 'Go' buttons (for example, the searchSite function above).
//Usage:  called on the onKeyPress event of an input field.
//        ex: onkeypress="return ifEnter('searchSite',this.value);"
function ifEnter(_function,_value) {
  //check if carriage return is pressed:  (handle IE and Netscape browsers)
  var keyCode = window.event.keyCode ? window.event.keyCode : window.event.which ? window.event.which : window.event.charCode;
  if (keyCode == 13) {
    eval(_function+"(_value)");
    return false;
  }
  else {
    return true;  //continue accepting characters for input field
  }
}//end function ifEnter


//20090219 simple hyperlink execution (stays in current window).
function gotoHref(_href){
  if (_href){parent.location = _href;}
}


//20090421
function searchPage(site,searchString) {
  //alert("searchPage called with " + site + " " + searchString);
  //open a new window and launch the search of my sites
  var searchURL= "";
  if (site == 'google')
  {
    searchURL += "http://www.google.com/";
    searchURL += "search?q=";
  }
  if (site == 'wikipedia')
  {
    searchURL += "http://www.google.com/";
    searchURL += "search?q=";
  }
    searchURL += searchString;
  var windowName="searchPage_" + site; 
  var windowProperties= "toolbar=yes, location=yes, directories=no, status=yes";
    windowProperties += ", menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=900, height=750";
  //
  //launches a new window with the search criteria in place and executed.
  window.open(searchURL,windowName,windowProperties);
  //
return;
}//end function searchSite



//<end of file>
