<!--
	// Global variables
	rnd.today = new Date();
	rnd.seed = rnd.today.getTime();
	newImg = new Array ("Images/FolderClose.gif", "Images/FolderOpen.gif"); // load images
	var isIE = (document.all) ? true : false;
	var isNetscape6 = (document.getElementById&&!document.all) ? true : false;
	var isNetscape4 = (document.layers) ? true : false;
	var normalColor = '#000000', highlitedColor = '#FF0000';
	var expdate = new Date();
	var domain = "MarcosConsulting.com";
	var last = newImg.length - 1;
	var browserMessage = "This site best viewed with Microsoft Internet Explorer.";
	var newWindow = null;

	expdate.setTime(expdate.getTime() +  3E11);  // Set expiration date to ten years from now.
	//******************************************************************//	
	// This function does nothing
	//******************************************************************//	
	function voidFunction(message) { 
		if (typeof(message) == 'undefined' || typeof(message) == 'null') window.status = '';
		else window.status = message;
	}
	//******************************************************************//	
	// Scroll the page 
	//******************************************************************//	
	function scrollPage(x,y) { 
		if (document.layers || document.all) {
	    	window.scrollBy(x,y);
		}
	}
	//******************************************************************//	
	// Swap images
	//******************************************************************//	
	function changeImages() {
	
	  if (document.images)
	    for (var i=0; i<changeImages.arguments.length; i+=2) {
	      document[changeImages.arguments[i]].src =
				eval(changeImages.arguments[i+1] + ".src");
	    }
	}
	//******************************************************************//
	// return the month name
	//******************************************************************//	
	function getNameOfMonth(month) {
		// create an array to hold the names of the months
		var monthName = new Array(12);
		
		monthName[0] = "January";
		monthName[1] = "February";
		monthName[2] = "March";
		monthName[3] = "April";
		monthName[4] = "May";
		monthName[5] = "June";
		monthName[6] = "July";
		monthName[7] = "August";
		monthName[8] = "September";
		monthName[9] = "October";
		monthName[10] = "November";
		monthName[11] = "December";
		
		// return the name of the month in the specified language
		return monthName[month];
	}
	//******************************************************************//	
	//  Used to open a popup window
	//******************************************************************//	
	function openWindow(windowURL, windowName, windowFeatures, windowReplace) { 
	/*
		Syntax
			oNewWindow = window.open( [windowURL] [, windowName] [, windowFeatures] [, windowReplace])
			
		Parameters
			windowURL Optional. String that specifies the URL of the document to display. If no URL is specified, a new window with about:blank is displayed. 
			windowName Optional. String that specifies the name of the window. This name is used as the value for the TARGET attribute on a form or an a element._blank The windowURL is loaded into a new, unnamed window. 
				_media The windowURL is loaded into the HTML content area of the Media Bar. Available in Internet Explorer 6 or later. 
				_parent The windowURL is loaded into the current frame's parent. If the frame has no parent, this value acts as the value _self. 
				_search Available in Internet Explorer 5 and later. The windowURL is opened in the browser's search pane. 
				_self The current document is replaced with the specified windowURL . 
				_top windowURL replaces any framesets that may be loaded. If there are no framesets defined, this value acts as the value _self. 
		 
			windowFeatures Optional. This String parameter is a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (for example, "fullscreen=yes, toolbar=yes"). The following features are supported.channelmode = { yes | no | 1 | 0 } Specifies whether to display the window in theater mode and show the channel band. The default is no. 
				directories = { yes | no | 1 | 0 } Specifies whether to add directory buttons. The default is yes. 
				fullscreen = { yes | no | 1 | 0 } Specifies whether to display the browser in full-screen mode. The default is no. Use full-screen mode carefully. Because this mode hides the browser's title bar and menus, you should always provide a button or other visual clue to help the user close the window. ALT+F4 closes the new window. A window in full-screen mode must also be in theater mode (channelmode).  
				height = number Specifies the height of the window, in pixels. The minimum value is 100. 
				left = number Specifies the left position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to 0.  
				location = { yes | no | 1 | 0 } Specifies whether to display the input field for entering URLs directly into the browser. The default is yes. 
				menubar = { yes | no | 1 | 0 } Specifies whether to display the menu bar. The default is yes. 
				resizable = { yes | no | 1 | 0 } Specifies whether to display resize handles at the corners of the window. The default is yes. 
				scrollbars = { yes | no | 1 | 0 } Specifies whether to display horizontal and vertical scroll bars. The default is yes. 
				status = { yes | no | 1 | 0 } Specifies whether to add a status bar at the bottom of the window. The default is yes. 
				titlebar = { yes | no | 1 | 0 } Specifies whether to display a title bar for the window. This parameter is ignored unless the calling application is an HTML Application or a trusted dialog box. The default is yes. 
				toolbar = { yes | no | 1 | 0 } Specifies whether to display the browser toolbar, making buttons such as Back, Forward, and Stop available. The default is yes. 
				top = number Specifies the top position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to 0.  
				width = number Sets the width of the window, in pixels. The minimum value is 100. 
		 
			windowReplace Optional. When the windowURL is loaded into the same window, this Boolean parameter specifies whether the windowURL creates a new entry or replaces the current entry in the window's history list. true windowURL replaces the current document in the history list 
				false windowURL creates a new entry in the history list.  
 	*/
	
		var w = 480, h = 340, popW = 480, popH = 600;

		if (isIE) {
		   // the following is only available after onLoad 
		   w = document.body.clientWidth;
		   h = document.body.clientHeight;
		}
		else if (isNetscape4 || isNetscape6) {
		   w = window.innerWidth;
		   h = window.innerHeight;
		}
		
		var leftPos = (w-popW)/2, topPos = (h-popH)/2;

		if (typeof(windowFeatures) == 'undefined' || windowFeatures.length == 0)
			windowFeatures = 'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos;
			
		if (typeof(windowReplace) == 'undefined' || windowReplace.length == 0)
			windowReplace = true;
	
		if(newWindow == null || newWindow.closed) {
			newWindow = window.open(windowURL, windowName, windowFeatures, windowReplace);
		} else {
			newWindow.focus();
		}
	}
	//******************************************************************//	
	// get cookie by name
	//******************************************************************//	
	function getCookie(name) {
	  var cookies = document.cookie;
	  var start = cookies.indexOf(name + '=');
	  if (start == -1) return null;
	  var len = start + name.length + 1;
	  var end = cookies.indexOf(';',len);
	  if (end == -1) end = cookies.length;
	  return unescape(cookies.substring(len,end));
	}
	//******************************************************************//	
	// create a cookie
	//******************************************************************//	
	function setCookie(name, value, expires, path, domain, secure) {
	  value = escape(value);
	  expires = (expires) ? ';expires=' + expires.toGMTString() : '';
	  path    = (path)    ? ';path='    + path : '';
	  domain  = (domain)  ? ';domain='  + domain : '';
	  secure  = (secure)  ? ';secure' : '';
	
	  document.cookie =
	    name + '=' + value + expires + path + domain + secure;
	}
	//******************************************************************//	
	// remove a cookie
	//******************************************************************//	
	function deleteCookie(name, path, domain) {
	  var expires = ';expires=Thu, 01-Jan-70 00:00:01 GMT';
	  (path)    ? ';path='    + path : '';
	  (domain)  ? ';domain='  + domain : '';
	
	  if (getCookie(name))
	    document.cookie = name + '=' + expires + path + domain;
	}	
	//******************************************************************//	
	// mark an item as selected in a multi select box
	//******************************************************************//	
	function checkSelectItem(toObject, value) {
		for (var i = 0;i < toObject.options.length; i++) {
			if (toObject.options[i].value == value) {
		    	toObject.options[i].selected = true;
				return;
			}
	    }
	}
	//******************************************************************//	
	// addes an item to a multi select box
	//******************************************************************//	
	function addSelectItem(object, text, value) {
		var defaultSelected = true;
		var selected = true;
		var optionName = new Option(text, value, defaultSelected, selected);
		object.options[object.length] = optionName;
	}
	//******************************************************************//	
	// expand or contract
	//******************************************************************//	
	function expandLayer(obj, imgObj) {
		var nObj = 'n' + obj;
		var xObj = 'x' + obj;
		if (typeof(imgObj) != 'undefined' || typeof(imgObj) != 'null') {
			if (isIE) {
				if (document.all[xObj].style.display == 'none') {
					document.all[xObj].style.display = 'block';
					document.images[imgObj].src = newImg[1];
				} 
				else {
					document.all[xObj].style.display = 'none';
					document.images[imgObj].src = newImg[0];
				}
			}
		}
	}
	//******************************************************************//	
	// change the color when invalid field
	//******************************************************************//	
	function changeColor(fieldName, newColor) {
		if (isIE) document.all[fieldName].style.color = newColor;
		else if (isNetscape6) document.getElementById(fieldName).style.color = newColor;
			else if (isNetscape4) eval('document.' + fieldName + '.color = ' + newColor); 
	}
	//******************************************************************//	
	// Random number generator
	//******************************************************************//	
	function rnd() {
		rnd.seed = (rnd.seed*9301+49297) % 233280;
		return rnd.seed/(233280.0);
	}
	function rand(number) {
		return Math.ceil(rnd()*number);
	}
	//******************************************************************//	
	// This function display an error message
	//******************************************************************//	
	function displayMessage(message) {
		alert(message);
	}
	//******************************************************************//	
	// This function changes an image	
	//******************************************************************//	
	function changeImage(obj, image){ 
		eval('document.images["' + obj + '"].src = "' + image + '"');
	}
	//******************************************************************//	
	// validatre a phone number
	//******************************************************************//	
	function isPhoneNumber(phoneNumber) {
		var reg = /[0-9\-\.\)\(\s]{10,}/;
		return reg.test(phoneNumber);
	}
	//******************************************************************//	
	// validate a zip code
	//******************************************************************//	
	function isZipCode(zipCode) {
		 var reg = /[0-9]{5}(-[0-9]{4})?/;
		 var reg2 = /[0-9]{10,}/;
		 return (reg.test(zipCode) && !reg2.test(zipCode));
	 } 
	//******************************************************************//	
	// validate an email address
	//******************************************************************//	
	function isEmailAddress(emailAddress) {
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;  // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;  // valid
		return (!reg1.test(emailAddress) && reg2.test(emailAddress));  // if syntax is valid
	}
	//******************************************************************//	
	// validatre a password
	//******************************************************************//	
	function isPassword(password) {
		var reg = /[0-9a-zA-Z_]{1,15}/;  //at least 1 number and letter including the underscore
		return reg.test(password);
	}
	//******************************************************************//	
	// clear the values in the fields
	//******************************************************************//	
	function clearFields() {
		document.forms[0].MovieID.value = '';
		document.forms[0].Title.value = '';
		document.forms[0].Description.value = '';
		document.forms[0].ActorName.value = '';
		document.forms[0].RunTime.value = '';
		document.forms[0].FormatID.options.selectedIndex = 0;  
		document.forms[0].AspectID.options.selectedIndex = 0;  
		document.forms[0].GenreID.options.selectedIndex = 0;  
		document.forms[0].Review.options.selectedIndex = 0;
		document.forms[0].StudioID.options.selectedIndex = 0;
		document.forms[0].RatingID.options.selectedIndex = 0;
		document.forms[0].ReleaseDate.options.selectedIndex = 0;
		document.forms[0].RegionID.options.selectedIndex = 0;
		document.forms[0].StudioID.options.selectedIndex = 0;
		document.forms[0].OnLoanTo.checked = false;
		document.forms[0].MovieNight.checked = false;
		document.forms[0].ShowAll.checked = false;
	}
	//******************************************************************//	
	// The following 6 function are used to manipulate select boxes
	//******************************************************************//	
	function deleteOption(object,index) {
		object.options[index] = null;
	}

	function addOption(object,text,value) {
		var defaultSelected = true;
		var selected = true;
		var optionName = new Option(text, value, defaultSelected, selected)
		object.options[object.length] = optionName;
	}

	function copySelected(fromObject,toObject) {
		for (var i=0, l=toObject.options.length;i<l;i++) {
			if (toObject.options[i].value == "")
	     	deleteOption(toObject,i);
    	}
		for (var i=0, l=fromObject.options.length;i<l;i++) {
			if (fromObject.options[i].selected)
					if (fromObject.options[i].value != "")
				addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
	    }
		for (var i=fromObject.options.length-1;i>-1;i--) {
			if (fromObject.options[i].selected)
			deleteOption(fromObject,i);
    	}
	}
	
	function copyAll(fromObject,toObject) {
		for (var i=0, l=toObject.options.length;i<l;i++) {
			if (toObject.options[i].value == "")
	     	deleteOption(toObject,i);
	    }
		for (var i=0, l=fromObject.options.length;i<l;i++) {
			if (fromObject.options[i].value != "") 
		  	addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
		}
		for (var i=fromObject.options.length-1;i>-1;i--) {
			deleteOption(fromObject,i);
		}
	}

	function populateHidden(fromObject,toObject) {
		var output = '';
		for (var i=0, l=fromObject.options.length;i<l;i++) {
			output += escape(fromObject.options[i].value);
				if (i<(l-1))
					output += ',';
		}
		toObject.value = output;
	}	
	//******************************************************************//	
	// This function will validate all the fields on the Attending  screen
	//******************************************************************//	
	function validateAttendingForm(formName) {
		var ok = true, message = '\nThe field(s) highligthed in RED are invalid:\n\n';
		if (typeof(formName) == 'undefined') formName = 0;
		changeColor('_Name', normalColor); 
		changeColor('_Email', normalColor);
		changeColor('_Phone', normalColor);
		changeColor('_NumberOfPeople', normalColor);
		if (document.forms[formName].Name.value.length == 0 && document.forms[formName].Email.value.length == 0 && 
			document.forms[formName].Phone.value.length == 0 && 
			document.forms[formName].NumberOfPeople.options[document.forms[formName].NumberOfPeople.selectedIndex].value.length == 0) {
			changeColor('_Name', highlitedColor); 
			changeColor('_Email', highlitedColor);
			changeColor('_Phone', highlitedColor);
			changeColor('_NumberOfPeople', highlitedColor);
			document.forms[formName].elements[0].focus();
			ok = false;	}
		if (document.forms[formName].NumberOfPeople.options[document.forms[formName].NumberOfPeople.selectedIndex].value.length == 0) {
			changeColor('_NumberOfPeople', highlitedColor); 
			document.forms[formName].NumberOfPeople.focus();
			message += "Invalid number of guest. \n";
			ok = false;	}
		if (document.forms[formName].Phone.value.length == 0 || !isPhoneNumber(document.forms[formName].Phone.value)) {
			changeColor('_Phone', highlitedColor); 
			document.forms[formName].Phone.focus();
			message += "Missing or invalid phone number. \n";
			ok = false;	}
		if (document.forms[formName].Email.value.length == 0 || !isEmailAddress(document.forms[formName].Email.value)) {
			changeColor('_Email', highlitedColor); 
			document.forms[formName].Email.focus();
			message += "Missing or invalid email address. \n";
			ok = false;	}
		if (document.forms[formName].Name.value.length == 0) {
			changeColor('_Name', highlitedColor); 
			document.forms[formName].Name.focus();
			message += "Missing name. \n";
			ok = false;	}
		if (!ok) displayMessage(message);
		return ok;
	}
	//******************************************************************//	
	// This function will validate all the fields on the Preference screen
	//******************************************************************//	
	function validatePreferenceForm() {
		var ok = true, message = '\nThe field(s) highligthed in RED are invalid:\n';
		
		changeColor('DisplayRows_', normalColor); 

		if ( document.PreferenceForm.DisplayRows.value < 1 || document.PreferenceForm.DisplayRows.value > 500 ) {
			changeColor('DisplayRows_', highlitedColor);
			document.PreferenceForm.DisplayRows.focus();
			message += "\nMax Rows must be a number between 1 and 500";
			ok = false;
		}
		if ( isNaN(document.PreferenceForm.DisplayRows.value)  ) {
			changeColor('DisplayRows_', highlitedColor);
			document.PreferenceForm.DisplayRows.focus();
			message += "\nYou must use NUMBERS only";
			ok = false;
		}
		
		if (!ok) 
			displayMessage(message);
		else {
			Set_Cookie('DisplayRows', document.PreferenceForm.DisplayRows.value, new Date(2099, 11, 31), '/', domain, 0);
			Set_Cookie('FieldOrder', document.PreferenceForm.Preference.value, new Date(2099, 11, 31), '/', domain, 0);
		}
		return ok;
	}
	//******************************************************************//	
	// This function will validate all the fields on the Checkout screen
	//******************************************************************//	
	function validateCheckoutScreen() {
		var ok = true, message = '\nThe field(s) highligthed in RED are invalid:\n';
		
		changeColor('OnLoanTo_', normalColor); 
		changeColor('DateLoaned_', normalColor); 
		
		if (document.forms[0].OnLoanTo.value.length == 0 && document.forms[0].DateLoaned.value.length == 0) {
			changeColor('OnLoanTo_', highlitedColor); 
			changeColor('DateLoaned_', highlitedColor); 
			document.forms[0].elements[0].focus();
			ok = false;
		}
		if (document.forms[0].OnLoanTo.value.length == 0) {
			changeColor('OnLoanTo_', highlitedColor); 
			document.forms[0].OnLoanTo.focus();
			message += 'You must enter a on loan to name.\n';
			ok = false;
		}		
		if (document.forms[0].DateLoaned.value.length == 0) {
			changeColor('DateLoaned_', highlitedColor); 
			document.forms[0].DateLoaned.focus();
			message += 'The date loaned can not be blank.\n';
			ok = false;
		}
		if (!ok) 
			displayMessage(message);
		return ok;
	}
	//******************************************************************//	
	// This function will validate all the fields on the Checkout screen
	//******************************************************************//	
	function validateLoanRequestScreen() {
		var ok = true, message = '\nThe field(s) highligthed in RED are invalid:\n';
		
		changeColor('OnLoanTo_', normalColor); 
		changeColor('DateLoaned_', normalColor); 
		
		if (document.forms[0].OnLoanTo.value.length == 0 && document.forms[0].DateLoaned.value.length == 0) {
			changeColor('OnLoanTo_', highlitedColor); 
			changeColor('DateLoaned_', highlitedColor); 
			document.forms[0].elements[0].focus();
			ok = false;
		}
		if (document.forms[0].OnLoanTo.value.length == 0) {
			changeColor('OnLoanTo_', highlitedColor); 
			document.forms[0].OnLoanTo.focus();
			message += 'You must enter your name.\n';
			ok = false;
		}		
		if (document.forms[0].DateLoaned.value.length == 0) {
			changeColor('DateLoaned_', highlitedColor); 
			document.forms[0].DateLoaned.focus();
			message += 'The date requested can not be blank.\n';
			ok = false;
		}
		if (!ok) 
			displayMessage(message);
		return ok;
	}
	//******************************************************************//	
	// This function will validate all the fields on the add actor screen
	//******************************************************************//	
	function validateAddActorsScreen() {

		var ok = true, message = '\nThe field(s) highligthed in RED are invalid:\n';
		
		changeColor('ActorName_', normalColor); 

		if (document.forms[0].ActorName.value.length == 0 ) {
			changeColor('ActorName_', highlitedColor); 
			document.forms[0].elements[0].focus();
			ok = false;
		}

		if (!ok) 
			displayMessage(message);
		return ok;
	}
	//******************************************************************//	
	// This function will validate all the fields on the add Studio screen
	//******************************************************************//	
	function validateAddStudiosScreen() {

		var ok = true, message = '\nThe field(s) highligthed in RED are invalid:\n';
		
		changeColor('Studio_', normalColor); 

		if (document.forms[0].Studio.value.length == 0 ) {
			changeColor('Studio_', highlitedColor); 
			document.forms[0].elements[0].focus();
			message += 'You must enter a studio name.\n';
			ok = false;
		}

		if (!ok) 
			displayMessage(message);
		return ok;
	}
	//******************************************************************//	
	// This function will validate all the fields on the Update movie screen
	//******************************************************************//	
	function validateUpdateScreen() {
	
		var ok = true, message = '\nThe field(s) highligthed in RED are invalid:\n';
	
		changeColor('Title_', normalColor); 
		changeColor('FormatID_', normalColor); 
		changeColor('AspectID_', normalColor); 
		changeColor('NumberOfDisks_', normalColor); 

		if (document.forms[0].Title.value.length == 0 && document.forms[0].FormatID.options[document.forms[0].FormatID.options.selectedIndex].value == 0 &&
			document.forms[0].AspectID.options[document.forms[0].AspectID.options.selectedIndex].value == 0) {
			changeColor('Title_', highlitedColor); 
			changeColor('FormatID_', highlitedColor); 
			changeColor('AspectID_', highlitedColor); 
			document.forms[0].elements[0].focus();
			ok = false;
		}

		if (document.forms[0].Title.value.length == 0) {
			changeColor('Title_', highlitedColor); 
			document.forms[0].Title.focus();
			message += 'The movie title can not be blank.\n';
			ok = false;
		}
		
		if (document.forms[0].NumberOfDisks.options[document.forms[0].NumberOfDisks.selectedIndex].value == 0) {
			document.forms[0].NumberOfDisks.selectedIndex = 1;
		}
		
		if (document.forms[0].FormatID.options[document.forms[0].FormatID.options.selectedIndex].value == 0) {
			changeColor('FormatID_', highlitedColor); 
			document.forms[0].FormatID.focus();
			message += 'Select the media format.\n';
			ok = false;
		}

		if (document.forms[0].AspectID.options[document.forms[0].AspectID.options.selectedIndex].value == 0) {
			changeColor('AspectID_', highlitedColor); 
			document.forms[0].AspectID.focus();
			message += 'Select the movie aspect.\n';
			ok = false;
		}
				
		if (!ok) 
			displayMessage(message);
		else	
			document.forms[0].submit();
		return ok;

	}
// End of script -->
