// kaleidio interactive media
//	general navigation script
//
	
	function imgOver(idname) {
		if (document.images) {	document["img_" + idname].src = "shared/images/" + idname + "_02.gif"; }
		if (document.layers) {	document.images["img_" + idname].src = "shared/images/" + idname + "_02.gif"; 	}
	}
	function imgOut(idname) {
		if (document.images) {	document["img_" + idname].src = "shared/images/" + idname + "_01.gif"; }
		if (document.layers) {	document.images["img_" + idname].src = "shared/images/" + idname + "_01.gif"; 	}
	}
	
	
	function rollOver(id) {
		if (document.images && bolImagesLoaded==true) {	
		if (gSelectedItem != id) {
			arwOver('arw'+id, true);
			lnOver('ln'+id+'_1');
			lnOver('ln'+id+'_2');
		}
		if (gSelectedItem == id) {
			arwOver('arw'+id, true);
		}
		}
	}
	function rollOut(id) {
		if (document.images && bolImagesLoaded==true) {		
		if (gSelectedItem != id) {
			arwOut('arw'+id, true);
			lnOut('ln'+id+'_1');
			lnOut('ln'+id+'_2');
		}
		if (gSelectedItem == id) { 
			arwClick('arw'+id);
		}
		}
	}
	function lnClick(id) {
		if (document.all) { document.all[id].src = eval("ln_over.src"); }
		if (document.layers) { document.images[id].src = eval("ln_over.src"); }
	}
	function lnOver(id) {
		if (document.all) { document.all[id].src = eval("ln_over.src"); }
		if (document.layers) { document.images[id].src = eval("ln_over.src"); }
	}
	function lnOut(id) {
		if (document.all) { document.all[id].src = eval("ln_out.src"); }
		if (document.layers) { document.images[id].src = eval("ln_out.src"); }
	}
	function arwClick(id) {
		if (document.all) { document.all[id].src = eval("arw_click.src"); }
		if (document.layers) { document.images[id].src = eval("arw_click.src"); }
	}
	function arwOver(id, isnav) {
		
		if (isnav == true) {
			if (document.all) { document.all[id].src = eval("arw_over.src"); }
			if (document.layers) { document.images[id].src =  eval("arw_over.src"); }
		} else {
			if (document.all) { document.all[id].src =  eval("arw_out.src"); }
			if (document.layers) { document.images[id].src = eval("arw_out.src"); }
		}
	}
	function arwOut(id, isnav) {
		if (isnav == true) {
			if (document.all) { document.all[id].src =  eval("arw_out.src"); }
			if (document.layers) { document.images[id].src =  eval("arw_out.src"); }
		} else {
			if (document.all) { document.all[id].src =  eval("arw_over.src"); }
			if (document.layers) { document.images[id].src =  eval("arw_over.src"); }
		}
	}
	
	function popit(url, name, width, height,scroll) { 
		var movey;
		var movex;
		var screenheight=600;
		var screenwidth=800;
		
		if (typeof(screen)!='undefined'){
			screenheight=screen.height;
			screenwidth=screen.width;
		}
	
		movex=Math.round((screenwidth-width)/2)-20;
		movey=Math.round((screenheight-height)/2)-60;
		n=window.open (url, name, 'toolbar=1,resizable=1,status=0,scrollbars='+scroll+',width=' + width + ',height=' + height + ',left='+movex+',top='+movey + ',screenX=' + movex + ',screenY=' + movey);
	
	  	if (typeof(n)=='object'){
	  		TId=setTimeout('n.focus()', 500);
	 	}
	}
	
	function popup(url,name) {
		popit(url, name, 650, 500, 'yes');
	}
	
	// Returns the full year - 1999, from a year string
	function  GetFullYear(year) {
		var d = new Date();
		d.setYear(year);
		var y = d.getYear();
		// two digit year, check for millenium bug
		if (year.length <= 2) {
			if (y < 50) { return y += 2000; }
			if (y >= 50) { return y += 1900; }
		} else	{
			if (year.length == 3) { return y += 2000; }
			if (y < 1000) y += 1900;
			return y;
		}		
	} // end function

	// Returns maximum days allowable for the month
	function GetDaysInMonth(month,year) {
		var days;
		if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) {
			days=31;
		} else if (month==4 || month==6 || month==9 || month==11) { 
			days=30;
		} else if (month==2)  {
			if (isLeapYear(year)) { days=29; }
			else { days=28; }
		}
		return (days);
	} // end function
	
	// Returns true is year is a leap year, used in combination with GetDaysInMonth()
	function isLeapYear(year) {
		if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0)) {
			return (true);
		} else { return (false); }
	} // end function

	// Returns the month number from a month text string, if invalid month string then returns false
	function MonthNumber(s) {
		s = s.toLowerCase();
		var n = s.indexOf(",", 0);
		if (n != -1) { s = s.substring(0, n); }
		//alert("monthnumber:" + s);
		if (s == "january") 	return 1;
		if (s == "february") 	return 2;
		if (s == "march") 		return 3;
		if (s == "april") 		return 4;
		if (s == "may") 		return 5;
		if (s == "june") 		return 6;
		if (s == "july") 		return 7;
		if (s == "august") 		return 8;
		if (s == "september") 	return 9;
		if (s == "october") 	return 10;
		if (s == "november") 	return 11;
		if (s == "december") 	return 12;
		return false;
	} // end function
	
	// Returns the month text string from a month number, if invalid month number then returns false
	function MonthName(n) {
		if (n == 1) 	return "January";
		if (n == 2) 	return "February";
		if (n == 3) 	return "March";
		if (n == 4) 	return "April";
		if (n == 5) 	return "May";
		if (n == 6) 	return "June";
		if (n == 7) 	return "July";
		if (n == 8) 	return "August";
		if (n == 9) 	return "September";
		if (n == 10) 	return "October";
		if (n == 11) 	return "November";
		if (n == 12) 	return "December";
		return false;
	} // end function
	
	// Default error message for date validation, optional element object to display the error color indication
	function DateErrorMsg(e) {
		var msg;
		msg  = "==============================================================\n\n";
		msg += "The date is incorrectly entered with the wrong format.\n";
		msg += "Please check that you have the day, month and year in the right order.\n";
		msg += "For Example: 12-July-2003 or 12 July, 1999 or 12/07/1999 ( day-month-year ) \n\n";
		msg += "The light blue area(s) are the fields that require correction.\n";
		msg += "==============================================================\n\n";
		alert(msg);	
		var type = typeof e;
		if (type != "undefined") {			
			e.style.background = "#EAE1EF";
		}  
	} // end function

	// Returns true if is number, else retuns false	
	function isNumber(s) {
		var n = new Number(s);
		if (isNaN(n)) {			
			return false;
		} else {
			return true;
		}
	} // end function

	// A utility function that returns true if a string conains only whitespace characters.
	function isBlank(s) {
		for (var i=0; i < s.length; i++) {
			var c = s.charAt(i);
			if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
		}
		return true;
	} // end function
	
	// Checks the date format is correct
	function CheckDate(e) {	
		var strDate = e.value;
		var date = new Date();
				
		if ((strDate.length >= 6) && (strDate.length <=18 )) {
			var datesign = " ";
			var daypos = strDate.indexOf(datesign, 0);
			
			if (daypos == -1) { datesign = "-"; }
			var daypos = strDate.indexOf(datesign, 0);
			
			if (daypos == -1) { datesign = "/"; }
			var daypos = strDate.indexOf(datesign, 0);
			
			if (daypos == -1) { return DateErrorMsg(e); }
			
			var monthpos = strDate.indexOf(datesign, daypos + 1);
			if (monthpos == -1) { return DateErrorMsg(e); }
			
			var day	= strDate.substring(0,daypos);			
			if (!isNumber(day)) { return DateErrorMsg(e); }
			
			var month = strDate.substring(daypos + 1, monthpos);
			//alert("month:[" + month + "]");
			if (isNumber(month)) {
				var monthname = MonthName(month);
				if (monthname == false) { return DateErrorMsg(e); }
				date.setMonth(month - 1);
			} else {
				var monthnumber = MonthNumber(month);
				//alert("monthnumber:" + monthnumber);
				if (monthnumber == false) { return DateErrorMsg(e); }
				date.setMonth(monthnumber - 1);
				month = monthnumber;
				var monthname = MonthName(month);
			}			
			var year = strDate.substring(monthpos + 1, strDate.length);
			if (!isNumber(year)) { return DateErrorMsg(e); }
			year = GetFullYear(year);
			var maxdays = GetDaysInMonth(month, year);			
			if (day <= maxdays) {
				date.setDate(day);
			} else { 
				return DateErrorMsg(e);
			}
			e.style.background = "#FFFFFF";
			e.value = day + " " + monthname + ", " + year;
			return true;
		} else {			
			return DateErrorMsg(e);
		}
	} // end function
	
	
//	Removes all whitespace characters
// from start and end of a string

function trim(sString)
{
   sTrimmedString = "";
   if (sString != "")
   {
      var iStart = 0;
      var iEnd = sString.length - 1;
      var sWhitespace = " \t\f\n\r\v";
     
      while (sWhitespace.indexOf(sString.charAt(iStart)) != -1)
      {
         iStart++;
         if (iStart > iEnd)
            break;
      }
     
      // If the string not just whitespace
      if (iStart <= iEnd)
      {
         while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
            iEnd--;
         sTrimmedString = sString.substring(iStart,++iEnd);
      }
   }
   return sTrimmedString;
}

function InsertFlash(movie,width,height,FlashVars)
{
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'); 
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"');  
	document.write('ID="axflash" WIDTH=' + width + ' HEIGHT=' + height + '>');
	document.write('<PARAM NAME=movie VALUE="' + movie + '">');
	document.write('<PARAM NAME=quality VALUE=high>');
	document.write('<PARAM NAME=FlashVars VALUE="' + FlashVars + '">');
	document.write('<PARAM NAME=wmode VALUE=transparent>');
	document.write('<EMBED name="axflash" src="' + movie + '?' + FlashVars + '"'); 
	document.write('quality=high  WIDTH=' + width + ' HEIGHT=' + height); 
	document.write('swLiveConnect=true TYPE="application/x-shockwave-flash"'); 
					document.write('PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
	document.write('</EMBED></OBJECT>'); 
}
