/* ---- GigaChef.com ---- */
/* this function is called to resolve the IE6 CSS glitch for the main navigator*/
function startList() {
	if (document.all&&document.getElementById){navRoot = document.getElementById("mainnav");
	for (i=0; i<navRoot.childNodes.length; i++){node = navRoot.childNodes[i];
	if (node.nodeName=="LI") {node.onmouseover=function(){this.className+=" over";}
	node.onmouseout=function(){this.className=this.className.replace(" over", "");}}}}
}
function openwindow(URL, popW, popH) {
	var w = 640, h = 480;
	//retrieve available screen dimensions
	if (document.all || document.layers) {w = screen.availWidth; h = screen.availHeight;}
	//calculate the left and top positions based on the screen width & height, along with the popup window width & height
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	//open the popup window
	window.open(URL, "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}
function displaySceenResolution() {
	 var iw, ih; // Set inner width and height
 	if (window.innerWidth == null) {
  		iw = document.body.clientWidth;
 		 ih=document.body.clientHeight;
	 } else {
		  iw = window.innerWidth;
		  ih = window.innerHeight;
 	}
 	document.write("Your current screen resolution is "+screen.width+"x"+screen.height);
}
function preventsubmitonenter(){
	//only allow Enter key for TextArea fields
	if (typeof window.event != 'undefined') {
	        	document.onkeydown = function() {
               	 		if (event.srcElement.tagName.toUpperCase() == 'TEXTAREA'){
				/*allow*/
			}else {
               	         			return (event.keyCode != 13);
               			}
        		}
	} else {
        		document.onkeypress = function(e) {
                		if (e.target.nodeName.toUpperCase() == 'TEXTAREA') {
				/*allow*/
			}else{
                        			return (e.keyCode != 13);
     			}
		}
	}
}
function bookmarkthispage(){
    var w = 640, h = 480;
    if (document.all || document.layers) {w = screen.availWidth;h = screen.availHeight;}
    var popW = 450, popH = 175;
    var leftPos = (w-popW)/2, topPos = (h-popH)/2;
    window.open('/gc/bookmarks.nsf/bookmarkentry?openform', '','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}
function opensb(){
    var w = 640, h = 480;
    if (document.all || document.layers) {w = screen.availWidth;h = screen.availHeight;}
    var popW = 550, popH = 435;
    var leftPos = (w-popW)/2, topPos = (h-popH)/2;
    window.open('/gc/gHome.nsf/suggestion?OpenForm', '','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}
function launchsplitscreen(sourcepath){
	//result=window.confirm('Please be sure to save changes before launching Split-Screen mode.  Do you want to continue?');
	//if (result==true){
		top.location.href= "/gc/ghome.nsf/SSM?openframeset&source=" + sourcepath
	//} 
}
function openimage(imgURL) {
	//default value is available screen dimensions can not be returned
	var w = 640, h = 480;
	//retrieve available screen dimensions
	if (document.all || document.layers) {w = screen.availWidth; h = screen.availHeight;}
	//set the popup windows width and height
	var popW = 640, popH = 480;
	//calculate the left and top positions based on the screen width & height, along with the popup window width & height
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	//open the popup window
	window.open(imgURL, "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}
function isNumberKey(evt){
	//only allows "0123456789./-"
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode < 31 || (charCode > 44 && charCode < 58))
		return true;
	return false;
}
function isAlphaKey(evt){
	//only allows "a-z and A-Z and -"
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode < 33 || charCode==45 || ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123)))
		return true;
	return false;
}
function isAlphaNumKey(evt){
	//only allows "0123456789 and a-z and A-Z and -"
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode < 33 || charCode==45 || ((charCode > 47 && charCode < 58) || (charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123)))
		return true;
	return false;
}
function isValidEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}
function deletedoc(doctitle, returnpath){
	result=window.confirm('Do you really want to delete this entry' + doctitle + '?');
	if (result==true){
		location.href=returnpath
	} 
}
function popupselector(sourceview,targetfld,lutype,catkey,cleardep) {
	//default value is available screen dimensions can not be returned
	var w = 640, h = 480;
	//retrieve available screen dimensions
	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	//set the popup windows width and height
	var popW = 250, popH = 475;
	//calculate the left and top positions based on the screen width & height, along with the popup window width & height
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	//wipe out value in dependent field if required
	if (cleardep!='') {document.getElementById(cleardep).value='';}
	//get the appropriate catkeyvalue (automatically determines text or combobox)
	if (catkey!='') {
		fld = document.getElementById(catkey)
		//text field
		catkeyvalue = fld.value;
		//if blank, assume combobox/radiobutton
		if (catkeyvalue=='') {
			for ( i=0 ; i<fld.length ; i++ ){
				if (fld.options[i].selected == true) {
					catkeyvalue = fld.options[i].text
				}
			}
		}
	}
	//open the popup window
	if (lutype=='Column') {
		msgWindow=open("/" + dbpath + "/popupselector?OpenForm&sourceview=" + sourceview + "&targetfld=" + targetfld + "&lutype=" + lutype, "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
		if (msgWindow.opener == null) msgWindow.opener = self;	
	}else if (lutype=='Lookup'&& catkeyvalue!=''){
		msgWindow=open("/" + dbpath + "/popupselector?OpenForm&sourceview=" + sourceview + "&targetfld=" + targetfld + "&lutype=" + lutype + "&catkey=" + catkeyvalue, "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
		if (msgWindow.opener == null) msgWindow.opener = self;	
	} else {
		//do nothing
		alert('You must provide a ' + catkey + ' value to proceed.');
	}
}
function chkbxselector(fname) {
	//used for cookbooks and categories on the recipe form.
	//default value is available screen dimensions can not be returned
	var w = 640, h = 480;
	//retrieve available screen dimensions
	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	//set the popup windows width and height
	var popW = 250, popH = 300;
	//calculate the left and top positions based on the screen width & height, along with the popup window width & height
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	//open the popup window
	msgWindow=open("/" + dbpath + "/" + fname + "?OpenForm", "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
	if (msgWindow.opener == null) msgWindow.opener = self;
}
// Starts the "replaceSubstring" function
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} 
// Ends the "replaceSubstring" function
//specialty foods
function depcontactselect() {
	//default value is available screen dimensions can not be returned
	var w = 640, h = 480;
	//retrieve available screen dimensions
	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	//set the popup windows width and height
	var popW = 625, popH = 300;
	//calculate the left and top positions based on the screen width & height, along with the popup window width & height
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	//open the popup window
	msgWindow=open("/gc/vendors.nsf/DirVenSelector?OpenForm", "","toolbar=no,modal=yes,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
	if (msgWindow.opener == null) msgWindow.opener = self;	
}
function checkAll(field){
	for (i = 0; i < field.length; i++){field[i].checked = true;}
}
function uncheckAll(field){
	for (i = 0; i < field.length; i++){field[i].checked = false ;}
}
//for main search functionality
function checksearch() {
	var form=document.forms[0];
	if(form.searchtext){
		if(form.searchtext.value!='search this section'){
			ExecuteSearch();
			return false
		}
	}
}
function ExecuteSearch() {
	var f = document.getElementById('searchtext');
	var db = window.location.pathname;
	var firstpart = db.split(".nsf");
	var dbpath = firstpart[0] + ".nsf";
	var ftq = f.value;
	var lftq = ftq.toLowerCase();
	if (lftq == '' | lftq == 'search') {
		f.searchtext.focus();
	} else {
		window.open(dbpath +'/' + searchviewname + '?SearchView&Query='+lftq+'*&ViewRef='+searchviewname+'&SearchOrder=4&Start=1&Count=50','_top');
	}
}
function kill_boxes() {
	for( i=0; i<document.images.length ; i++ ){
		if( document.images[i].src.indexOf('vwicnsr1.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr2.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr3.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr4.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr5.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr6.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if
	
		if( document.images[i].src.indexOf('vwicnsr7.gif') != -1){ 
			document.images[i].height= HEIGHT=0 
			document.images[i].width= WIDTH=0
		} //end if	
	} // end for
}
/* ---------------------- Start of Remember Me Cookie  ---------------------------*/
function getCookie(c_name) {
	if (document.cookie.length>0){ 
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return ""
};
function setCookie(c_name,value,expiredays){
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) + ";path=/"
};
function checkCookie() {
	username=getCookie('gcUsername')
	if (username!=null && username!=""){
		document._gcLogin.username.value = username;
		document.getElementById("rememberme").checked=true
		document._gcLogin.password.focus();
  	}else{
  		document._gcLogin.username.value = '';
		document.getElementById("rememberme").checked=false
		document._gcLogin.username.focus();
  	}
};
function unloadcheck(){
	//set cookie if checkbox has been selected and username is not blank
	username = document._gcLogin.username.value;
	password = document._gcLogin.password.value;
	if (username!='' && password!=''){
		if (document.getElementById("rememberme").checked==true){
			setCookie('gcUsername',username,365)
		}else{
			setCookie('gcUsername','deletecookie',-365)
		}
	}
}
/* ---------------------- End of Remember Me Cookie  ---------------------------*/
