	
	
	/* MINDING YOUR MIND - BASIC JAVASCRIPT (basic.js) - 
	   this file contains basic JavaScript for rollovers, site inits, etc as well as general utility calls
	   and is included on all pages.  */
	   
	/* var lastMenuOne = null;
	var lastMenuTwo = null;
	var lastHighSub = null; */
	
	// below used for login link scripting
	var KeyID = 0;
	var retURL = null;
	//document.onkeydown = checkKeyDown;
	//document.onkeyup = restoreKeyUp;
	
	// when any page is finished loading, fire global init event
	jQuery(document).ready(doGlobalInits);
	
	function doGlobalInits(){
	    // global init function - will be called on all pages once document is ready
		// does not appear to interfere with page-specific jQuery ready call on admin sidebars page
		
		// for now, only global init to handle is to add keycheck handler to search field
		jQuery('#global_search').keydown(function(e){
			switch(e.keyCode) {
				case 13:
					// hit return in search text field, run search
					runSiteSearch();
					break;
			}
		});
	}
	
	function runSiteSearch() {
		// get value of search field and, if not empty, forward to search page
		
		var sval = $('#global_search').val();
		var gourl = jspath_view;
		
		if (sval.length > 0) {
			gourl = gourl + '/misc/searchmym.cfm?searchtext=' + escape(sval);
			document.location = gourl;
		}
	}
	
	function goAdminMenu() {
		// forward to admin menu (will be directed to login if needed)

		var gourl = jspath_view;
		
		gourl = gourl + '/admin/adminmenu.cfm';
		document.location = gourl;		
	}
	
	
	// below are general functions used for form validation (kept here as general utilities, while specific form validation
	// calls are in valid-form.js 
	function selectRequired(Form, Field) {
		var itemSelected = eval("document." + Form + "." + Field + ".selectedIndex");
		if (itemSelected == 0) {
			return false;
		} else {
			return true;
		}
	}	

	function isChecked(Form, Field) {
		var itemSelected = eval("document." + Form + "." + Field + ".checked");
		if (itemSelected == true) {
			return true;
		} else {
			return false;
		}
	}		

	function isNotEmpty(Form, Field) {
		var itemlen = eval("document." + Form + "." + Field + ".value.length");
		if (itemlen >= 2) {
			return true;
		} else {
			return false;
		}
	}	
	
	function isAnumber(Form, Field) {
		var itemval = eval("document." + Form + "." + Field + ".value");
		if (!isNaN(itemval)) {
			return true;
		} else {
			return false;
		}
	}

	function isAnumberGTzero(Form, Field) {
		var itemval = eval("document." + Form + "." + Field + ".value");
		if (!isNaN(itemval)) {
			if (itemval > 0)
				return true;
			else
				return false;
		} else {
			return false;
		}
	}
	
	function strIsNumGtZero(itemval) {
		if (!isNaN(itemval)) {
			if (itemval > 0)
				return true;
			else
				return false;
		} else {
			return false;
		}
	}
	
	function roundNum(num, dec) {
		var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
		return result;
	}
	
	function decFormatNum(num) {
		// assumes roundNum is called first, will just flesh out decimals
		var s = new String(num);
		if(s.indexOf('.') < 0) 
			s += '.00'; 
		if(s.indexOf('.') == (s.length - 2)) 
			s += '0'; 
		return s;
	}
	
	function allFieldsValid(Form, reqls) {
		var ret = true;
		for (b=0; b<reqls.length; b++) {
			if (!isNotEmpty(Form, reqls[b])) {
				// field not entered, fail
				ret = false;	
			}	
		}	
		return ret;	
	}

	
	// these are init loading scripts for index.cfm
	
	function initIndex(preloadls) {
		cacheImages(preloadls);
		//document.login.username.focus();
	}
	
	function cacheImages(preloadls) {
		// source arguments = ARRAY (this is OLD: image path names in argument of Makearray) of image paths, 
		// in single quotes and separated by commas.
		
		//alert(preloadls);
        //var imgarr = makeArrayFromStrList(preloadls); - OLD just passing in array now
		var imgarr = preloadls;		// just set to passed in array so don't have to rewrite below
		var cachedImages = new Array();
        for (var i=0; i<imgarr.length; i++) {
			//alert(imgarr[i]);
        	cachedImages[i] = new Image();
        	cachedImages[i].src = imgarr[i];
        }
    }
	
	function makeArrayFromStrList() {
	    var num = makeArrayFromStrList.arguments.length;
	    var imgs = new Array(num);
	    for (var i=0; i<num; i++) {
	        imgs[i] = makeArrayFromStrList.arguments[i];
	    }
		return imgs;
	}
	
	// these are open calls for mail, directions, new windows, etc. (NOT USED HERE YET)
	
	function openmail(raddr) {
		var wURL, wAttrs;
	
		wURL = 'ma' + 'il' + 'to:' + raddr + '@' + 'min' + 'dingyourmi' + 'nd' + '.' + 'or' + 'g';
		//wAttrs = "height=464,width=620,resizable=no,scrollbars=no,status=no,toolbar=no,location=no";
		window.open(wURL, "", "");
		window.focus;		
	}
	
	function openmap(office) {
		var mapUrl, wAttrs;
		switch (office) {
			case "Tokyo":
				mapUrl = "";
				break;
			default:
				mapUrl = "http://maps.google.com/maps?f=q&hl=en&geocode=&q=1001+Remington+Road+Wynnewood,+PA+19096&sll=37.0625,-95.677068&sspn=48.50801,73.476563&ie=UTF8&z=16&iwloc=addr";
				break;
		}
		
		if (mapUrl.length > 0) {
			wAttrs = "height=600,width=800,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,location=yes";
			window.open(mapUrl, "", wAttrs);
			window.focus;				
		}
	}
	
	
	// these are key response event scripts
	
	function checkKeyDown(e) {
		// store globally last key press
		retURL = self.location;
		KeyID = (window.event) ? event.keyCode : e.keyCode;
	}
	
	function restoreKeyUp(e) {
		// on key up restore last key press to 0
		retURL = null;
		KeyID = 0;
	}
	
	function clickLogin() {
		// if "a" key is pressed (for "admin"), go to admin login page
		// otherwise, go to FTP 
		var goadm = 0;
		var goURL;
		
		if (KeyID == 65) {
			KeyID = 0;
			//alert("go admin login");
			goURL = "../login/login.cfm";
			if (retURL != null) 
				goURL = goURL + "?jump=" + escape(retURL);
			self.location = goURL;
		} else {
			//alert("go FTP");
			self.location = "ftp://ftp.rtkl.com";
			/* wURL = "ftp://ftp.rtkl.com";
			window.open(wURL, "", "");
			window.focus; */	
		}
	}
	
	
	function goToFAQtopic() {
		id = document.golink.catid.selectedIndex;
		if (id >= 0) {
			cid = document.golink.catid.options[id].value;
			location.href = "#faqcat" + cid;
		}
	}
	
	function findDealerOnEnter(e){ 
		// (e is event object passed from function call)		
		var keyCode 
	
		if (e && e.which) { 
			// key code is contained in mozilla's (netscape/firefox) which property
			e = e;
			keyCode = e.which;
		} else {
			// key code is contained in IE's keyCode property
			e = event;
			keyCode = e.keyCode; 
		}
	
		// if character code is ascii 13 (enter key), submit form
		if (keyCode == 13) { 
			// document.forms[0].submit();
			findDealer();
			return false; 
		} else {
			return true;
		}		
	}
	

	
	// these are ROLLOVER and POPUP MENU related functions
	
	function RolloverSwapFrmImg(obj, himode) {
		// swap image (by object id) out to hi or lo version as requested
		
		var imgOld;
		// get source of object now
		if (document.getElementsByTagName && document.getElementById) {
			//Netscape 6+ model (also works in IE 6)
			imgOld = document.getElementById(obj).src;
			document.getElementById(obj).src = SwapImgNameHiLo(imgOld, himode);
		} else {
			if (document.all) {
				//IE model (at least, versions prior to 6)
				imgOld = document.all(obj).src;	
				document.all(obj).src = SwapImgNameHiLo(imgOld, himode);
			}	
		}		
	}
	
	function RolloverMenu(imgBase) {
		// roll over menu button that activates corresponding popup menu
		
		var imgName = "navimg_" + imgBase;
		var popName = "popMenu_" + imgBase;
		var closepop;
		
		// highlight menu button as usual
		RolloverBasic(imgName, 1);
		
		// loop through pop menu list, closing all menus and buttons except this menu, and turning on this menu
        for (var i=0; i<poplist.length; i++) {
        	if (imgBase == poplist[i]) {
				setElementVisibility (popName, 'v')
			} else {
				closepop = "popMenu_" + poplist[i];
				imgName = "navimg_" + poplist[i];
				setElementVisibility (closepop, 'h');
				RolloverBasic (imgName, 0);
			}
        }
		// also activate menu closer
		setElementVisibility ('popMenuCloser', 'v');		
	}
	
	function CloseAllMenus() {
		// close all pop menus including closer (activated by closer only)
		
		var closepop;
		var imgName;
		
		//alert("closer");
        for (var i=0; i<poplist.length; i++) {
			closepop = "popMenu_" + poplist[i];
			imgName = "navimg_" + poplist[i];
        	setElementVisibility (closepop, 'h');
			RolloverBasic (imgName, 0);
        }
		// also deactivate menu closer
		setElementVisibility ('popMenuCloser', 'h');			
	}
	
	function SwapImgNameHiLo(imgOld, himode) {
		// return corresponding file name for image given, in hi or lo mode requested
		
		var fsfx = "_1.";
		if (himode)
			fsfx = "_2.";
		// save extension
		dotPos = imgOld.lastIndexOf('.');
		imgExt = imgOld.substring(dotPos+1, dotPos+4); 
		// get current file name without extension
		imgFileName = imgOld.substring(0, imgOld.lastIndexOf('_'));
		// create new file name
		imgFileName = imgFileName + fsfx + imgExt;

		return imgFileName;		
	}
 
	function RolloverBasic(imgName, himode) {
		// swap image (by image name) out to hi or lo version as requested
		
		imgOld = document.images[imgName].src;
		document.images[imgName].src = SwapImgNameHiLo(imgOld, himode);
	}


	// these are GENERAL UTILITY functions
	
	function showWinH() {
		var winh;
		//winh = window.innerHeight;
		winh = document.body.clientHeight;
		alert(winh);
	}
		
	
	// *** DMS 5-12-06: pasted in Sarah's IE active content kluge:
	// this function lets javascript output the necessary Flash object and embed tags
	// to workaround IE 6's new 'active content' security warnings 
	// *** DMS 5-13-06: added width & height params so can use for Help or other Flash content as well
	function RunFlash(flashfile, flashW, flashH) {
	   document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,0,0" width="' + flashW + '" height="' + flashH + '">\n');
	    document.write(' <param name=movie value="' + flashfile + '" />\n');
		document.write(' <param name=quality value=high />\n');
		document.write(' <embed src="' + flashfile + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + flashW + '" height="' + flashH + '">\n');
		document.write('</embed>\n');
	    document.write('</object>\n');
	}	
		
		