
// © Copyright 2011 Willam.L.Scheding, "All rights reserved." wls@wls.org

// if (typeof GSObj === 'undefined') {
// 	var GSObj = new Object;
// }
// if (typeof GSObj.utility === 'undefined') {
// 	GSObj.utility = new Object;
// }
// if (typeof GSObj.genealogyXHR === 'undefined') {
// 	GSObj.genealogyXHR = null;
// }
// 
// GSObj.openNotesWindow = function(theID,theKind) {
//   window.open('http://www.wls.org/family/familynotes.php?id=' + theID + '&theKind=' + theKind, 'FamilyNotes', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=400')
//   return false;
// }
// GSObj.openLinksWindow = function(theID,theKind,theItem,theLink) {
//   window.open('http://www.wls.org/family/familylinks.php?id=' + theID + '&theKind=' + theKind + '&theItem=' + theItem + '&theLink=' + theLink, 'FamilyLinks', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=500,height=200')
//   return false;
// }
// 
/**
 * Short notation for document.getElementById().
 */
function $id(theId) {
	try {return document.getElementById(theId);}
	catch (e) {return null;}
}

// var GSUtils = {
// 
//    obj : null,
//    
//    init : function(o) {
//       if (typeof o === 'undefined') {
//          return true;
//       }
//       if  (o == null) {
//          return true;
//       }
// //       o.onmousedown	= Drag.start;
//    },
//    
//    goto : function(db,group,id) {
// 		var URL = 'http://www.wls.org/cgi-bin/family/db_lookup.pl?Option=Select&A00_db='+db+'&A00_group='+group+'&A00_Id='+id;
// 		parent.revealed.location.href = URL;
// 		window.close();
// 		return false;
//    },
// 
// };

var GS = {
   gsLoading: null,
   gsLoadingImg: '',
   genealogyXHR: null,
   shiftUp: 10,
   dialogOpen: false,
   fadedBackground: false,
   
	'init':
	function() {
	   this.genealogyXHR = null;
   },
   
   'newHREF':
   function(theURL,theTarget) {
     window.open(theURL, theTarget, 'tooblar=0,location=0,menubar=0');
     return false;
   },
   
   'openLinksWindow':
   function(theID,theKind,theItem,theLink) {
     GS.getLink(theID,theKind,theItem,theLink);
     GS.toggleLinkPickerDisplay();
     return false;
   },
   
   'openNotesWindow':
   function(theID,theKind) {
     GS.getNote(theID,theKind);
     GS.toggleNotePickerDisplay();
     return false;
   },
   
   'getLink':
   function(id, theKind, theItem, theLink) {
      id = id || '65'; // default to wls
      theKind = theKind || '0'; // default to the Husband (Wife = 1, Child = 2, other Wife = 3, other Husbands = 4)
      theItem = theItem || '0'; // default to the first. (Father = 6, Mother = 7)
      theLink = theLink || 'none'; // default to remove
   
      if (! theLink) return false;
//    window.open('http://www.wls.org/family/familylinks.php?id=' + theID + '&theKind=' + theKind, 'FamilyNotes', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=400')
      var URL = 'http://www.wls.org/family/familylinks.php';
      var reqParams = '';
      if (id) reqParams += 'id=' + id;
      if (theKind) reqParams += '&theKind=' + theKind;
      if (theItem) reqParams += '&theItem=' + theItem;
      if (theLink) reqParams += '&theLink=' + theLink;
      
//       alert('URL:'+URL);
//       alert('id:'+id);
//       alert('theKind:'+theKind);
//       alert('theItem:'+theItem);
//       alert('theLink:'+theLink);
//       alert('reqParams:'+reqParams);
   
      if (this.genealogyXHR) this.genealogyXHR.abort();
      this.genealogyXHR = new HTTPReq('GS.getLinkHandler',URL,'genealogy');
      if (!this.genealogyXHR) return;
      this.genealogyXHR.sendRequest(URL, reqParams);
   },
   
   'getLinkHandler':
   function(response) {
   // 	alert('response: '+response);
      $id('linkPickerBody').innerHTML = response;
   },

   'getNote':
   function(id, theKind) {
      id = id || '65'; // default to wls
      theKind = theKind || '0'; // default to the Husband (Wife = 1, Child = 2, family = 3, <none> = 4)
   
//    window.open('http://www.wls.org/family/familynotes.php?id=' + theID + '&theKind=' + theKind, 'FamilyNotes', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=400')
      var URL = 'http://www.wls.org/family/familynotes.php';
      var reqParams = '';
      if (id) reqParams += 'id=' + id;
      if (theKind) reqParams += '&theKind=' + theKind;
      
   // 	alert('URL:'+URL);
   // 	alert('id:'+id);
   // 	alert('theKind:'+theKind);
   // 	alert('reqParams:'+reqParams);
   
      if (this.genealogyXHR) this.genealogyXHR.abort();
      this.genealogyXHR = new HTTPReq('GS.getNoteHandler',URL,'genealogy');
      if (!this.genealogyXHR) return;
      this.genealogyXHR.sendRequest(URL, reqParams);
   },
   
   'getNoteHandler':
   function(response) {
   // 	alert('response: '+response);
      $id('notePickerBody').innerHTML = response;
   },

	/**
	 * Set a Husband, Wife, Child, Mother or Father link
	 */
   'setLink':
   function(id, theKind, theItem, theLink) {
      theKind = theKind || '0'; // default to the Husband (Wife = 1, Child = 2, other Wife = 3, other Husbands = 4)
      theItem = theItem || '0'; // default to the first. (Father = 6, Mother = 7)
      theLink = theLink || 'none'; // default to remove
   
      if (! theLink) return false;
   // http://wls.org/cgi-bin/db_utils.pl?Option=set_link&id=65&theKind=2&theItem=4&theLink=blank 6 and 7 are the father/mother indexes.
      var URL = 'http://www.wls.org/cgi-bin/family/db_utils.pl';
      var reqParams = 'Option=set_link';
      if (id) reqParams += '&id=' + id;
      if (theKind) reqParams += '&theKind=' + theKind;
      if (theItem) reqParams += '&theItem=' + theItem;
      if (theLink) reqParams += '&theLink=' + theLink;
      
   // 	alert('URL:'+URL);
   // 	alert('id:'+id);
   // 	alert('theKind:'+theKind);
   // 	alert('theItem:'+theItem);
   // 	alert('theLink:'+theLink);
   // 	alert('reqParams:'+reqParams);
   
      if (this.genealogyXHR) this.genealogyXHR.abort();
      this.genealogyXHR = new HTTPReq('GS.setLinkHandler',URL,'genealogy');
      if (!this.genealogyXHR) return;
      this.genealogyXHR.sendRequest(URL, reqParams);
		// does not work here // GS.toggleLinkPickerDisplay();
   },
   
   'setLinkHandler':
   function(response) {
   	// alert('response: '+response);
		// does not work here // GS.toggleLinkPickerDisplay();
   },
   
	// http://www.wls.org/cgi-bin/family/db_lookup.pl?Option=EditNotes&A00_Id=317&A00_db=scheding&B04_hNotes=----O%27Husband%20Note\n--second%20line.&C04_wNotes=----Wife%20Note\n--second%20line.&D01_child_info=----Child%28info%29%20Note\n--second%20line.\n--third%20line.
   'EditNotes':
   function(A00_Id, A00_db, theItem, theID) {
      if (!A00_Id) return false;
      if (!A00_db) return false;
      if (!theItem) return false;
      if (!theID) return false;
   	var text = document.getElementById(theID).value;
   	var pattern = /\n/;
   	if (text.match(pattern)) {
			text = text.replace(/\n/g, "\\n"); // use '\n' for database.
   	}
      var B04_hNotes,C04_wNotes,D01_child_info,family;
      if (theItem == 0) {
			B04_hNotes = text;
      } else if (theItem == 1) {
			C04_wNotes =  text;
      } else if (theItem == 2) {
			D01_child_info =  text;
      } else if (theItem == 3) {
			family =  text;
      } else if (theItem == 4) {
			return false; // n/a.
      } else if (theItem == 5) {
      	B04_hNotes = document.getElementById('hNotes').value.replace(/\n/g, "\\n");
      	C04_wNotes = document.getElementById('wNotes').value.replace(/\n/g, "\\n");
      	D01_child_info = document.getElementById('child_info').value.replace(/\n/g, "\\n");
      	family = document.getElementById('family').value.replace(/\n/g, "\\n");
      	
// 			GS.toggleNotePickerDisplay(); // can't edit all yet.
// 			return true; // can't edit all of them yet.
      }

      var URL = 'http://www.wls.org/cgi-bin/family/db_lookup.pl';
      var reqParams = 'Option=EditNotes';
      if (A00_Id) reqParams += '&A00_Id=' + A00_Id;
      if (A00_db) reqParams += '&A00_db=' + A00_db;
      if (theItem) reqParams += '&theItem=' + theItem;
      if (B04_hNotes) reqParams += '&B04_hNotes=' + B04_hNotes;
      if (C04_wNotes) reqParams += '&C04_wNotes=' + C04_wNotes;
      if (D01_child_info) reqParams += '&D01_child_info=' + D01_child_info;
      if (family) reqParams += '&family=' + family;
      
// 	alert('URL:'+URL);
// 	alert('B04_hNotes:'+B04_hNotes);
// 	alert('C04_wNotes:'+C04_wNotes);
// 	alert('D01_child_info:'+D01_child_info);
// 	alert('family:'+family);
// 	alert('A00_Id:'+A00_Id);
// 	alert('theItem:'+theItem);
// 	alert('reqParams:'+reqParams);
// 	return true;
   
      if (this.genealogyXHR) this.genealogyXHR.abort();
      this.genealogyXHR = new HTTPReq('GS.EditNotesHandler',URL,'genealogy');
      if (!this.genealogyXHR) return;
      this.genealogyXHR.sendRequest(URL, reqParams);
   },
   
   'EditNotesHandler':
   function(response) {
//       alert('response: '+response);
      GS.toggleNotePickerDisplay();
   },
   
   'addLink':
   function(sex, husband, wife, father, mother, f_birth, m_birth, parents_id, theItem) {
      if (!sex) return false;
      if (!(husband || wife)) return false;
      // http://www.wls.org/cgi-bin/family/db_lookup.pl?Option=AddLink&B00_Husband=%20Robert%20Otto%20Leanard
      var URL = 'http://www.wls.org/cgi-bin/family/db_lookup.pl';
      var reqParams = 'Option=AddLink';
      if (sex) reqParams += '&sex=' + sex;
      if (husband) reqParams += '&husband=' + husband;
      if (wife) reqParams += '&wife=' + wife;
      if (father) reqParams += '&father=' + father;
      if (mother) reqParams += '&mother=' + mother;
      if (f_birth) reqParams += '&f_birth=' + f_birth;
      if (m_birth) reqParams += '&m_birth=' + m_birth;
      if (parents_id) reqParams += '&parents_id=' + parents_id;
      if (theItem) reqParams += '&theItem=' + theItem;
      
   // 	alert('URL:'+URL);
   // 	alert('sex:'+sex);
   // 	alert('husband:'+husband);
   // 	alert('wife:'+wife);
   // 	alert('father:'+father);
   // 	alert('mother:'+mother);
   // 	alert('reqParams:'+reqParams);
   
      if (this.genealogyXHR) this.genealogyXHR.abort();
      this.genealogyXHR = new HTTPReq('GS.addLinkHandler',URL,'genealogy');
      if (!this.genealogyXHR) return;
      this.genealogyXHR.sendRequest(URL, reqParams);
   },
   
   'addLinkHandler':
   function(response) {
//       alert('response: '+response);
      GS.toggleLinkPickerDisplay();
   },
   
   'goto':
   function(db,group,id) {
      var URL = 'http://www.wls.org/cgi-bin/family/db_lookup.pl?Option=Select&A00_db='+db+'&A00_group='+group+'&A00_Id='+id;
      window.location.href = URL;
      window.close();
      return false;
   },

   'checkEmail;':
   function(form) {
        //alert('check form');
        for (i=0; i < form.length; i++) {
            fieldname = form.elements[i].name;
            fieldvalue = form.elements[i].value;
            //alert ('field : '+fieldname+' data : \''+fieldvalue+'\'');
            if (fieldname == 'email') {
                if (fieldvalue == '') {
                    alert ('Please complete \''+fieldname+'\'. It is required.');
                    return false;
                }
                // email must have an @ and a dot and don't accept wls.org or wls@wls, accept wls@wls.org 
                if ((fieldvalue.indexOf('\@') == -1) || (fieldvalue.indexOf('\.') == -1) 
        //          || ((fieldvalue.indexOf('@')+1) > fieldvalue.indexOf('.'))  // error: wls.org@verizon
                    || ((fieldvalue.indexOf('@')+1) > fieldvalue.lastIndexOf('.')) // what about ken.marsh@wls.org
                    || (fieldvalue.indexOf('<') != -1) ) {
                    alert ('Please change \''+fieldname+'\'. It is invalid.');
                    return false;
                }
            } else if ((fieldname == 'firstname') || (fieldname == 'lastname') || (fieldvalue.indexOf('<') != -1)) {
                if (fieldvalue == '') {
                    alert ('Please complete \''+fieldname+'\'. It is required.');
                    return false;
                }
            }
        }
        return true;
    },
   
   'getWindowHeight':
   function() {
       if (typeof window.innerHeight === 'number') {
           return window.innerHeight;
   
       } else {
           if (document.documentElement && document.documentElement.clientHeight) {
              return document.documentElement.clientHeight;
   
           } else {
              if (document.body && document.body.clientHeight) {
                 return document.body.clientHeight;
              }
           }
       }	        	        
   },
   
   'getWindowWidth':
   function() {
      if (typeof window.innerWidth === 'number') {
            return window.innerWidth;
   
       } else if (document.documentElement && document.documentElement.clientWidth) {
            return document.documentElement.clientWidth;
   
       } else if (document.body && document.body.clientWidth) {
            return document.body.clientWidth;
       }	        	        
   },
   
   'getContentWidth':
   function() {
      var w=document.body.offsetWidth;
      
      for (var i=0;i<document.body.childNodes.length;i++) {
         if (document.body.childNodes[i].offsetWidth) {
            w=Math.max(w,document.body.childNodes[i].offsetWidth);
         }
      }
      return w;	
   },
   
   'getContentHeight':
   function() {
      var h =	document.body.offsetHeight;
      for (var i=0;i<document.body.childNodes.length;i++) {
         if (document.body.childNodes[i].offsetHeight) {
            h=Math.max(h,document.body.childNodes[i].offsetHeight);
         }
      }
      return h;	
   },
   
   'addContentShieldToBody':
   function (argId,argOpacity,argColor) {
      // make a content Shield from scratch & add after the passed object
      var elem = $id(argId);
      if (!elem) {
         var elem = document.body.appendChild( GS.createContentShieldElement(argId,argOpacity,argColor));
      }	   
      elem.style.display='block';
      elem = null;
   },
   
   'createContentShieldElement':
   function (argId, argOpacity, argColor) {
      argId = argId || 'contentShield'; // default name
      argOpacity = Number(argOpacity) || 0.01;
      argColor = argColor || '#FFF';
      
      var div = document.createElement('div');
      div.id = argId;
      div.style.opacity = argOpacity;
      div.style.filter = 'alpha(opacity=' + (argOpacity*100)+ ')'; 
      div.style.display= 'none';
      div.style.width=GS.getContentWidth()+'px';
      div.style.height=GS.getContentHeight()+'px';
      div.style.backgroundColor=argColor;
      div.style.position='absolute';
      div.style.top='0px';
      div.style.left='0px';
      div.style.zIndex='1000';
   
      return div;	   
   },
   
   /* start of 'loading...' routines */
   'createLoading':
   function(argText, fnCancelLoading, loadingElem) {
      fnCancelLoading = fnCancelLoading || GS.cancelLoading; // set default cancelLoading function
      loadingElem = loadingElem || this.gsLoading; // set default 'loading...' element
      var elem = $id(loadingElem);
      if (!elem) { // only add it if it's not there
         var div = document.createElement('button');
         div.id=loadingElem;
         div.disabled=true;
         elem = document.body.appendChild(div);
         elem.innerHTML='<span style="width:200px;height:25px;padding:5px;font-size:18px;padding-left:20px;background-color:#FFF3B3;color:black;border:1px solid black;">' + argText + '</span>';
         elem.style.position='absolute';
         elem.style.border = '0px black'; 
         elem.style.backgroundColor='transparent';
         elem.style.width = '100%';
         elem.style.height = '100%';
         elem.style.zIndex=2000;
         elem.style.top='0px';
         elem.style.left='0px';
   
    //     GS.addEvent(window,'blur',fnCancelLoading);  //only used in when using cvs export and is explicitly added in setLoading in reports.js
      } else {
      }
      div=elem=null; // release space 2b nice
   },	
   
   'showLoading':
   function(argImg) {
      if (!$id(this.gsLoading)) {
         GS.createLoading('Generating Report ...');
      }	
      var myObj = $id(this.gsLoading);
      GS.centerLoadingShield(); 
      if (myObj) { // only if it exists, please.
//          GS.hideDropDowns();
   
         myObj.style.display = 'block';
         if (myObj.firstChild) {
            myObj.firstChild.style.background ='#FFF3B3 url("images/' + GS.loadingGif + '") no-repeat 5px 11px';
         }
      }
      myObj = null;
   },
   
   'hideLoading':
   function() {
      var myObj = $id(this.gsLoading);
      if (myObj) { // only if it exists, please.
         myObj.style.display = 'none';
         if (myObj.firstChild) {
            myObj.firstChild.style.backgroundImage ='none';
         }
      }
      GS.showDropDowns();
      myObj = null;
   },
   
   'cancelLoading':
   function (e) {
      GS.hideLoading();
      GS.showDropDowns();
      var myObj = $id(this.gsLoading);
      if (myObj) { // only if it exists, please.
         myObj.style.display = 'none';
      }
   },
   /* end of 'loading...' routines */
   
   'sentryRowToggle':
   function(elem) {
      var trRow;
      var chkbox;
      if (elem.nodeName == 'INPUT') {
         trRow = elem.parentNode?elem.parentNode.parentNode:false;
         chkbox = elem;
   
      } else if (elem.nodeName == 'TR') {
         trRow = elem;
         chkbox = elem.getElementsByTagName('input')[0];
      }
   
      if (trRow) {
         if (trRow.className.indexOf('selected') >= 0) {
            trRow.className = trRow.className.replace('selected','');
            if (chkbox) chkbox.checked = false;
   
         } else {
            trRow.className += ' selected';
            if (chkbox) chkbox.checked = true;
         }
         
      }
      return false;
   },
   
	'curParentScrollTop':
	function (obj) {
		var elem = obj.parentNode;
		while (elem && elem.scrollTop === 0) {
			elem = elem.parentNode;
		}
		return (elem && elem.scrollTop) ? elem.scrollTop : 0;
	}, 
	
	'curParentScrollLeft':
	function(obj) {
		var elem = obj.parentNode;
		while (elem && elem.scrollLeft===0) {
			elem = elem.parentNode;
		}
		return (elem && elem.scrollLeft ) ? elem.scrollLeft : 0; 
	},
	 
	'getBodyScroll':
	function () {
		var x, y;
		if (!document.all) {
			x = self.pageXOffset;
			y = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		} else if (document.body) {
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		return {x:x, y:y};
	},

   // loading... (Shield) to show we are loading the page, please wait.
   'showLoadingShield':
   function(argImg) {
      var myShld = $id(this.gsLoading);
      if (myShld && ! GS.loading) { // only if it exists and is not showing, please.
         myShld.style.top  = GS.getBodyScroll().y+'px'; // just down from the current scroll position
         myShld.style.left = GS.getBodyScroll().x+'px'; // just down from the current scroll position
         myShld.style.display = 'block';
         var myImg = $id(this.gsLoadingImg);
         if (myImg && argImg) { // set the bg image
            myImg.style.background ='#FFF3B3 url(images/' + argImg + ') no-repeat 5px 11px';
         }
         GS.loadingCount++;
         // position btn:
         GS.centerLoadingShield(this.gsLoadingImg);
         GS.loading = true; // it's showing
      }
   },
   
   'hideLoadingShield':
   function() {
      if (GS.loadingCount > 0) { // don't hide till count is zero...
         GS.loadingCount--;
         if (GS.loadingCount > 0) {
            return;
         }
      }
      var myShld = $id(this.gsLoading);
      var myImg = $id(this.gsLoadingImg);
      if (myShld && myImg && GS.loading && GS.loadingCount==0) { // only if it exists and is showing, please.
         myShld.style.display = 'none';
         myImg.style.backgroundImage = 'none';
         GS.loading = false; // it's not
      }
   },
   
   'createContentShieldElement':
   function (argId, argColor, argOpacity) {
      argId = argId || 'contentShield'; // default name
      argColor = argColor || '#FFF'; // white, not black
      argOpacity = Number(argOpacity) || 0.1;
   
      var div = document.createElement('div');
      div.id = argId;
      div.style.backgroundColor=argColor;
      div.style.opacity = argOpacity;
      div.style.filter = 'alpha(opacity=' + (argOpacity*100)+ ')';
      div.style.width='100%';  // GS.getContentWidth()+'px';
   
      div.style.height=GS.getContentHeight()+'px';
      div.style.position='absolute';
      div.style.top='0px';
      div.style.left='0px';
      div.style.zIndex='1000';
   
      return div;	   
   },
   
   'cancelLoadingShield':
   function (e) {
      GS.hideLoadingShield(); /* page specific -- pd only */
      GS.showDropDowns();
      var myShld = $id(this.gsLoading);
      if (myShld) { // only if it exists, please.
         myShld.style.display = 'none';
      }
      GS.loading = false;
   },
   
   'createLoadingShield':
   function(argText, argColor, argOpacity) {
      var elem = $id(this.gsLoading); // already there?
      if (!elem) { // only add it if it's not there (and no image already)
         var Img = $id(this.gsLoadingImg); // img already there?
         if (Img) {
            return false; // yes don't make two.
         }
   
         var div = document.createElement('button');
         div.id=this.gsLoading; // button element id that is
         div.disabled = true;
         argOpacity = Number(argOpacity) || 0.1;
         elem = document.body.appendChild(div);
         elem.innerHTML = '<span id='+this.gsLoadingImg+' class="util_loading">' + argText + '</span>';
         elem.style.position = 'absolute';
         elem.style.display = 'none';
         elem.style.zIndex = 2000;
         elem.style.width  = '100%'; // GS.getContentWidth()+'px';
         elem.style.height = '100%'; // GS.getContentHeight()+'px';
         elem.style.backgroundColor = argColor;
   //      GS.addEvent(window,'blur',GS.cancelLoading);
         GS.addEvent(window,'scroll',GS.centerLoadingShield);
      } else {
      }
      div=elem=null; // release space 2b nice
   },
   
   'centerLoadingShield':
   function () {
      var elem = $id(this.gsLoading); // now position the btn
      var theScrollX = GS.getBodyScroll().x;
      var theScrollY = GS.getBodyScroll().y;
      elem.style.left = theScrollX+'px';
      elem.style.top  = theScrollY+'px';
   },
   
   'setLoadingShieldText':
   function (title) {
      title = title || 'Loading';
      GS.loadingText = title;
   },
   
   // set a loadingShield to indicate we're loading a page...
   'setLoadingShield':
   function (title) {
      title = title || 'Loading';
      GS.loadingText = title;
      // loading button shield to tell them what we are doing...
      GS.createLoadingShield(GS.loadingText, 'transparent','.05'); // 'Loading...'
      GS.showLoadingShield(GS.loadingGif);
      /* Mac Safari 2.0 does not prompt a save dialog so the window.blur is not triggered 
       * putting a 4 sec delay on the shield instead
       * */
      if (/WebKit/i.test(navigator.userAgent) && !/Windows/i.test(navigator.userAgent) ) {
         window.setTimeout(function() {GS.cancelLoadingShield();},4000);
      }
      GS.loading = true; // we have it
      return true;
   },
   // end of loading shield
   
   // contentShield for protection of components from user clicking
   'addContentShieldToBody':
   function (argId, argColor, argOpacity) {
      // make a content Shield from scratch & add it to the body
      var elem = $id(argId); // see if the element exists already.
      if (!elem) { // no supplied element, make one.
         var elem = document.body.appendChild(GS.createContentShieldElement(argId, argColor, argOpacity));
      }	   
      elem = null; // return space
   },
   
   'setContentShield':
   function (argColor, argOpacity, argVisibility) {
//       GS.hideDropDowns();
      argColor = argColor || '#FFF'; // white, not black
      argOpacity = Number(argOpacity) || 0.1;
      GS.addContentShieldToBody(GS.gsContentShield, argColor, argOpacity); // for protection of other components, that are visible (' ');
      GS.showContentShield(argVisibility);
      return true;
   },
   
   // show the content shield, if any
   'showContentShield':
   function(argVisibility) {
      argVisibility = argVisibility || 'block'; // default to block
//       GS.hideDropDowns();
      var shield = $id(GS.gsContentShield);
       if (shield) { // only if it exists
         // measuring where the bottom of the page is after everything has rendered
   
         setTimeout(function() {$id(GS.gsContentShield).style.height =  GS.getContentHeight();
                              }, 1000);
   
         shield.style.display = argVisibility;
      }
       shield = null;
   },
   
   // hide the content shield, if any
   'hideContentShield':
   function() {
      var shield = $id(GS.gsContentShield);
      if (shield) { // only if it exists
         shield.style.display = 'none';
      }
      GS.showDropDowns();
   },
   // end of content shield
   
   'saveScrollXY':
   function (scrollXId, scrollYId) {
      GS.scrollX = document.getElementById(scrollXId);
      if (GS.scrollX) {
         GS.scrollX.value = document.body.scrollLeft;
      }
      
      GS.scrollY = document.getElementById(scrollYId);
      if (GS.scrollY) {
         GS.scrollY.value = document.body.scrollTop;
      }
   
   },

   'resetScrollPosition':
   function (scrollXId, scrollYId) {
      GS.scrollX = document.getElementById(scrollXId);
      GS.scrollY = document.getElementById(scrollYId);
      if (typeof GS.scrollX === 'undefined' || typeof GS.scrollY === 'undefined') {
      } else {
         window.scrollTo(GS.scrollX.value, GS.scrollY.value);
      }
   },

   'addLoadingToForm':
   function(argForm) {
      Jam.ready(
         function() {
            for (var i=0;i<document.forms.length;i++) {
               GS.addEvent(document.forms[argForm], 'submit', GS.showLoading);
            };	
         });
      
   },		

   'resizeOverlay':
   function(argId) {
      GS.resizeOverlayFirstTime = true;
      if($id('contentShield')) {
         $id('contentShield').style.height=document.body.scrollHeight;
         if (GS.resizeOverlayFirstTime) {
            GS.addEvent($id('contentShield'), 'mouseup', function() {window.scrollTo(0,0);});
            GS.resizeOverlayFirstTime = false;
         }	
      }
      if ($id(argId)) {
         $id(argId).style.top = Math.max(10,document.body.clientHeight/2 - $id(argId).offsetHeight/2) + 'px';
         $id(argId).style.left = Math.max(10,document.body.clientWidth/2 - $id(argId).offsetWidth/2) + 'px';
      }
   },

	'showLinkPicker':
	function(argCaption) {
		
		if (typeof reloadPage != 'undefined') {
			
			this.tempTimer = reloadPage;
			if (reloadTimerID) {
				clearTimeout(reloadTimerID);
			}
			reloadPage = null;
		}
		
		$id('caption').innerHTML = argCaption;
		
		GS.addContentShieldToBody(GS.gsContentShield,'#ddd', 0.50)
		$id("linkPicker").style.display = "block";
		$id("linkPicker").style.visibility = 'visible';
		$id(this.SOURCE).parentNode.style.display = 'block';

		GS.resizeOverlay('linkPicker');

		if ($id('find').value.length > 0) {
			$id('find').value = "";
		}

		this.show();
		this.undo = GP.selectedData;
// 		this.undoStr = Util.convertToJson(GP.selectedData);
		GS.showContentShield();
		this.ieHack();	
		
// 		setTimeout(function() {GS.hideDropDowns();},50);
	},	

   'toggleLinkPickerDisplay':
   function () {
      var fadedBackground = document.getElementById('fadedBackground');
      var elem = document.getElementById('linkPickerContainer');
      
      var objLeft = (document.body.clientWidth - elem.offsetWidth) / 2;
      var objTop = (document.body.clientHeight - elem.offsetHeight) / 2;
      objLeft = objLeft + document.body.scrollLeft;
      objTop = objTop + document.body.scrollTop;
      
      // Position object
      elem.style.position = "absolute";
      elem.style.top = objTop - 150 - this.shiftUp + "px";
      elem.style.left = objLeft - 360 + "px"; 
      
      //setlinkPickerHeight(document.getElementById('linkPickerBody'));
      if (elem.style.display == 'block') {
         elem.style.display = 'none';
         if (fadedBackground) {
            GS.hideFadedBackground(fadedBackground); 
         }
   
      } else {
         elem.style.display = 'block';
         
         var body = document.getElementById('linkPickerBody');
         body.style.height = 280-document.getElementById('linkPickerTitleBar').clientHeight-document.getElementById('linkPickerFooter').clientHeight+ "px";
         if (fadedBackground) {
            GS.showFadedBackground();
         }
      }
      //elem.style.display = 'none';
   },
   
	'showNotePicker':
	function(argCaption) {
		
		if (typeof reloadPage != 'undefined') {
			
			this.tempTimer = reloadPage;
			if (reloadTimerID) {
				clearTimeout(reloadTimerID);
			}
			reloadPage = null;
		}
		
		$id('caption').innerHTML = argCaption;
		
		GS.addContentShieldToBody(GS.gsContentShield,'#ddd', 0.50)
		$id("notePicker").style.display = "block";
		$id("notePicker").style.visibility = 'visible';
		$id(this.SOURCE).parentNode.style.display = 'block';

		GS.resizeOverlay('notePicker');

		if ($id('find').value.length > 0) {
			$id('find').value = "";
		}

		this.show();
		this.undo = GP.selectedData;
// 		this.undoStr = Util.convertToJson(GP.selectedData);
		GS.showContentShield();
		this.ieHack();	
		
// 		setTimeout(function() {GS.hideDropDowns();},50);
	},	

   'toggleNotePickerDisplay':
   function () {
      var fadedBackground = document.getElementById('fadedBackground');
      var elem = document.getElementById('notePickerContainer');
      
      var objLeft = (document.body.clientWidth - elem.offsetWidth) / 2;
      var objTop = (document.body.clientHeight - elem.offsetHeight) / 2;
      objLeft = objLeft + document.body.scrollLeft;
      objTop = objTop + document.body.scrollTop;
      
      // Position object
      elem.style.position = "absolute";
      elem.style.top = objTop - 150 - this.shiftUp + "px";
      elem.style.left = objLeft - 360 + "px"; 
      
      //setlinkPickerHeight(document.getElementById('notePickerBody'));
      if (elem.style.display == 'block') {
         elem.style.display = 'none';
         if (fadedBackground) {
            GS.hideFadedBackground(fadedBackground); 
         }
   
      } else {
         elem.style.display = 'block';
         
         var body = document.getElementById('notePickerBody');
         body.style.height = 280-document.getElementById('notePickerTitleBar').clientHeight-document.getElementById('notePickerFooter').clientHeight+ "px";
         if (fadedBackground) {
            GS.showFadedBackground();
         }
      }
      //elem.style.display = 'none';
   },
   
   'showFadedBackground':
   function () { /* bugfix 2598 */
      var fadedBackground = document.getElementById('fadedBackground');
      fadedBackground.style.height = GS.getContentHeight() + 'px';
      fadedBackground.style.width = GS.getContentWidth() + 'px';
   
      fadedBackground.style.top = 0;
      fadedBackground.style.left = 0;
//       GS.hideDropDowns();
      fadedBackground.style.display = 'inline';
      fadedBackground = null;
   },

   'hideFadedBackground':
   function (argElem) { 
//       this.showDropDowns();
      if (argElem) {
         argElem.style.display = 'none';
      }
      this.dialogOpen = false;
   },

	'ieHack':
	function() {
		if (this.IS_IE6) {
			$id("sourcePorts").style.height='200px';
			$id("targetPorts").style.backgroundColor='transparent';
		}
	},
	
};

// set focus to the first for item.
var bFound = false;
//  alert('bFound'+document.forms.length);
for(f = 0; f< document.forms.length; f++) {
 alert('bFound'+f);
 alert('bFound'+document.forms[f].length);
 for(i=0; i < document.forms[f].length; i++) {
  alert('bFound'+document.forms[f][i]);
  if (document.forms[f][i].type != "hidden") {
    if (document.forms[f][i].disabled != true) {
        document.forms[f][i].focus();
        var bFound = true;
    }
  }
  if (bFound == true)
    break;
 }
}


