language = "JavaScript"
/*
This form validation is based on my homework:
ITC 216 Assignment 5 - Form Validation
Student: Aidar Galeev 
Instructor: Kimberlee Jensen
Date: March 2003
url: http://edison.seattlecentral.org/~agalee01/itc216/hw5/
*/

<!--
/* function to check international form */

function intCheck()
{
	//alert(document.forms['order'].elements['year_depart'].selectedIndex);
	
	// string variable that will collect all errors
	// and act as a flag as well
	var message = "";
	
	// an array that keeps track of which elements on 
	// the form need to get focus
	var focusElement = new Array;
	
	// an array that keeps track of which images 
	// need to be changed to error images
	var errorImages = new Array;
	
	var totalErrors = 0;

	// reload blank images
	// document.images['imgNumber'].src="images/blank.gif";
	document.images['imgFrom'].src="images/blank.gif";
	document.images['imgTo'].src="images/blank.gif";
	document.images['imgDate'].src="images/blank.gif";
	
	// check if the city from was entered
	if(document.forms['order'].elements['departure_city'].selectedIndex == 0)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter departure city<br>";
		focusElement.push("departure_city");
		errorImages.push("imgFrom");
	}
	
	// check if the destination city was entered
	if(document.forms['order'].elements['destination'].selectedIndex == 0)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter destination city<br>";
		focusElement.push("destination");
		errorImages.push("imgTo");
	}

	// check if the departure date was entered
	if(document.forms['order'].elements['month_depart'].selectedIndex == 0 || 
			document.forms['order'].elements['day_depart'].selectedIndex == 0 ||
			document.forms['order'].elements['year_depart'].selectedIndex == 0)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter departure date<br>";
		focusElement.push("month_depart");
		errorImages.push("imgDate");
	}
	
				
	if(message == ""){return true;}
	else
	{
	
		for (i=0; i<errorImages.length; i++)
		{
				var imageName = errorImages[i];
				document.images[imageName].src="images/error.gif";
		}
		
		myFocus = focusElement[0];
		document.forms['order'].elements[myFocus].focus();
		
		// tell the visitors exactly what they need to fill out
		message = "There is a problem with your form:<br><br>" + message;
		// tell the visitors exactly what they need to fill out
		myWindow(message);
		return false;
	}
}

function reserveCheck()
{
	// string variable that will collect all errors
	// and act as a flag as well
	var message = "";
	
	// an array that keeps track of which elements on 
	// the form need to get focus
	var focusElement = new Array;
	
	// an array that keeps track of which images 
	// need to be changed to error images
	var errorImages = new Array;
	
	var totalErrors = 0;

	// reload blank images
	document.images['imgName'].src="images/blank.gif";
	document.images['imgEmail'].src="images/blank.gif";
	document.images['imgPhone'].src="images/blank.gif";
	document.images['imgDate'].src="images/blank.gif";
	document.images['imgPasInfo1'].src="images/blank.gif";
								
	// check if the name was entered
	if(!document.forms['order'].elements['name'].value)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter your name<br>";
		focusElement.push("name");
		errorImages.push("imgName");
	}
	
	// check if telephone was entered
	if(!document.forms['order'].elements['phone'].value)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter your phone<br>";
		focusElement.push("phone");
		errorImages.push("imgPhone");
	}
	
	// check if Passengers Information was entered
	if(!document.forms['order'].elements['first1'].value || !document.forms['order'].elements['last1'].value)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter Passengers Information<br>";
		focusElement.push("first1");
		errorImages.push("imgPasInfo1");
	}

	// check if the departure date was entered
	if(document.forms['order'].elements['month_depart'].selectedIndex == 0 || 
			document.forms['order'].elements['day_depart'].selectedIndex == 0 ||
			document.forms['order'].elements['year_depart'].selectedIndex == 0)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter departure data<br>";
		focusElement.push("month_depart");
		errorImages.push("imgDate");
	}
	
	// check if e-mail was entered
	if(!document.forms['order'].elements['email'].value)
	{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "You forgot to enter your e-mail<br>";
		focusElement.push("email");
		errorImages.push("imgEmail");
	}	
	else 
	{
		// if it was entered, check if it was valid
		// using regular expression for e-mail
		emailReg = new RegExp("[\\w-]{2,}[@]{1,1}[\\w-]{2,}[\.]{1,1}\\w{2,}", "g");
		
		if(!emailReg.test(document.forms['order'].elements['email'].value))
		{
		totalErrors ++;
		message += totalErrors + ") ";
		message += "Your e-mail does not seem to be valid<br>";
		focusElement.push("email");
		errorImages.push("imgEmail");
		}
	}			
	if(message == ""){return true;}
	else
	{
	
		for (i=0; i<errorImages.length; i++)
		{
				var imageName = errorImages[i];
				document.images[imageName].src="images/error.gif";
		}
		
		myFocus = focusElement[0];
		document.forms['order'].elements[myFocus].focus();
		
		// tell the visitors exactly what they need to fill out
		message = "There is a problem with your form:<br><br>" + message;
		// tell the visitors exactly what they need to fill out
		myWindow(message);
		return false;
	}
}

// new window function
function myWindow(listOfErrors)
{

// with positioning in the center
//	x = (screen.availWidth / 2) - 150;
//	y = (screen.availHeight / 2) - 100;
//	var windowB=window.open('','name','menubar=no,width=300,height=200,top='+y+'+,left='+x+',screenx='+x+',screeny='+y+'');
  
	// with positioning in the left top part
	var windowB=window.open('','Errors','menubar=no,width=300,height=170,top=50,left=20,screenx=20,screeny=50');
  windowB.document.write("<html><head><title>Errors on your form</title>");
	windowB.document.write("<link href=\"style.css\" type=text/css rel=stylesheet>");
  windowB.document.write("</head><body bgcolor= #999999"); 			
	windowB.document.write(" onBlur=\"self.close()\">");
  windowB.document.write("<div class='formbpad'>" + listOfErrors + "</div>");
	windowB.document.write("<form><center><input name=\"hide\" type=\"button\" id=\"hide\" value=\"Close Window\" onClick = \"self.close()\"></center></form>");
  windowB.document.write('</body></html>');
  windowB.document.close();
	//setTimeout("windowB.close", 1000);
}

// -->