var digits = "0123456789";
// reformat (TARGETSTRING, STRING, INTEGER, STRING, INTEGER ... )       
//
// Inserts formatting characters or delimiters within TARGETSTRING.
//
function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}
// Returns true if all characters in string s are numbers.
//
function isInteger (s)
{   var i;
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!((c >= "0") && (c <= "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
// Removes all characters which do NOT appear in string bag 
// from string s.
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
} 
// This function will replace all occurences of string X with string Y in the argument
function ReplaceString(argvalue, x, y) {
	var leading, trailing, i;

	if (argvalue == "") return argvalue;
	i = argvalue.indexOf(x);
	while (i != -1) {
//	while ((i = argvalue.indexOf(x)) != -1) {
		leading = argvalue.substring(0, i);
		trailing = argvalue.substring(i + x.length, argvalue.length);
		argvalue = leading + y + trailing;
		i = argvalue.indexOf(x, i + y.length);
	}
	return argvalue;
}

// Added by kent 7/25/2001
function Rtrim(thestr){
	var cont = true;
	while (cont){
		trailing = thestr.substring(thestr.length-1,thestr.length);
		// if last char is a space, strip it off and continue testing the last space 
		if(trailing==" "){
			thestr = thestr.substring(0,thestr.length-1);
		}
		else{
			cont = false;
		}
	}
	return thestr;
}
// Added by kpb 11/26/2002
function Ltrim(thestr){
	var cont = true;
	while (cont){
		leading = thestr.substring(0,1);
		// if first char is a space, strip it off and continue testing the first space 
		if(leading==" "){
			thestr = thestr.substring(1,thestr.length);
		}
		else{
			cont = false;
		}
	}
	return thestr;
}
// Added by kpb 11/26/2002
function Trim(thestr){
	trimstr = thestr;
	trimstr = Rtrim(trimstr);
	trimstr = Ltrim(trimstr);
	
	return trimstr;
}
// Added by kent 2/22/2002
function writeoutput(div,msg){
	// for ie
	if (document.all) {
		var thediv = eval(div);
		thediv.innerHTML=msg;
	}
	// for netscape
	if (document.layers) {
		var thediv = eval("document."+div);
		thediv.document.write(msg);
		thediv.document.close();
	}
}
// Added by kent 3/11/2002
//CASE SENSITIVE Returns the first index of an occurrence of a substring in a string
function Find(substr, str) {
	i = str.indexOf(substr);
	return i;
}
// Added by kent 3/11/2002
//CASE IN-SENSITIVE Returns the first index of an occurrence of a substring in a string
function FindNoCase(substr, str) {
	str = str.toLowerCase();
	i = str.indexOf(substr);
	return i;
}

// Added by kent 3/11/2002
// This will tell us how many occurences of substr within a string
function OccursNoCase(substr, str){
	var i = 0;
	var x = 0;	// counter 
	if ((str == "")||(substr == "")) return x;
	tempstr = str.toLowerCase();
	i = tempstr.indexOf(substr);
	while (i != -1) {
		x = x + 1;
		leading_str = tempstr.substring(0, i);
		trailing_str = tempstr.substring(i + substr.length, tempstr.length);
		tempstr = leading_str + trailing_str;
		i = tempstr.indexOf(substr, i);
		//alert("tempstr: "+tempstr+"\ni: "+i);
	}
	return x;
}
// Added by kent 3/11/2002
//returns length of list 
function ListLen(inList,delim){
	var len = 0;
	if (inList.length){
		var myarray = inList.split(delim);
		len = myarray.length;
	}
	return len;
}


/* This disables the button and reset tag on a page */
function submitonce(theform)
	{
		//if IE 4+ or NS 6+
		if (document.all||document.getElementById)
			{
				//screen thru every element in the form, and hunt down "submit" and "reset"
				for (i=0;i<theform.length;i++)
					{
						var tempobj=theform.elements[i]
						if(tempobj.type.toLowerCase()=="button"||tempobj.type.toLowerCase()=="reset")
						//disable em
						tempobj.disabled=true
					}
			}
	}


//confirm user wants to cancel
function confirmCancel(theURL)
	{
		cancelPopUp = "Note: By cancelling this process any information you have entered will not be saved.\n If you would still like to cancel, click the 'OK' button.\n If you would like to continue this process, click the 'Cancel' button.";		
		if (confirm(cancelPopUp))		
		{	
			location.href = theURL;
			return true;		
		}	
		else
			return false;
	}
	

//cancellation for cruise section
function confirmCruiseCancel()
	{
		cancelPopUp = "Note: Cancelling this process will return you to the main cruise section.\n IAny information you may have entered on this page will not be saved.\n If you would still like to cancel, click the 'OK' button.\n If you would like to continue this process, click the 'Cancel' button.";		if (confirm(cancelPopUp))		
		{	
			location.href = "?action=displayCruises";
			//return true;		
		}	
		else
			return false;
	}
//********************************************************************** js ErrNumeric.cfm file *******************************************************************************
// check field for numeric, alert them or return error, round
function errNumeric(formField,fieldLabel, min, max, len, noBlank, round, showalert) {
// numeric field check
    var errorStr = ""
    var numcomma = 0;

    // no blanks & if length is 0, then just return
    if (formField.value.length == 0) {
	if (noBlank == true) {
        errorStr += fieldLabel + " cannot be blank.\n"
        if (showalert == true) 
		alert(errorStr);
	  return errorStr
	}
	else {
		return errorStr;
	}
    }
    // if field ends in period, truncate
    var vlength = formField.value.length;
    if (formField.value.substring(vlength-1,vlength) == '.') {
        formField.value = formField.value.substring(0,vlength-1);
    }
    // field must be numeric or comma or period
    for (var i = 0; i < formField.value.length; i++) {
        var ch = formField.value.substring(i, i + 1)
        if (ch == ",")
           numcomma++

        if ((ch < "0" || ch > "9") && (ch != ",") && (ch != ".") && (ch != "-")) {
           errorStr += fieldLabel + " must be numeric.\n"
           if (showalert == true) 
		   alert(errorStr);
           return errorStr
        }
    }
    // add rounding back to number
    if (round == true) {
	    // Check for decimal and round value past decimal
	    var decindex = formField.value.lastIndexOf(".");
	    var dec=0;
          var left = '0';
	    if (decindex > -1) {
	      // if number in front of decimal
            if (decindex > 0) { 
 	         left = formField.value.substring(0,decindex);
            }
	      dec = 0 + Math.round(formField.value.substring(decindex,formField.value.length));
    	    }
    	    else
    	      left = formField.value;
          // get string with only digits and store string + round back
	    var numwoutcomma = "";
	    for (var i = 0; i < left.length; i++) {
	        var ch = left.substring(i, i + 1)
	        if (ch != ",")
	           numwoutcomma += ch;
	    }
              if (parseInt(numwoutcomma) >= 0)
  	            formField.value = parseInt(numwoutcomma,10) + dec;
              else
  	            formField.value = parseInt(numwoutcomma,10) - dec;
    }

    // max/min
    if ((min != 0 || max != 0) && len > -1) {
        if ((formField.value < min) || (formField.value > max)) {
            errorStr += fieldLabel + " must be between " + min + " and " + max + ".\n";
            if (showalert == true) 
	  	    alert(errorStr);
            return errorStr
        }
    }
    // max/min when only warning for negatives
    // only alert if -1, -2 means do not alert (used in CheckAndSubmit)
    if ((min != 0 || max != 0) && len < 0) {
        if ((((parseInt(formField.value) < 0) && (Math.abs(parseInt(formField.value))) > Math.abs(min)) && ((parseInt(formField.value) > 0) && (Math.abs(parseInt(formField.value))) < Math.abs(min))) || (Math.abs(parseInt(formField.value)) < Math.abs(max))) {
            // within bounds so check if need to warn (do not return since not error)
            if ((len != -2) && ((formField.value < min) || (formField.value > max))) {
                errorStr += fieldLabel + " is typically between between " + min + " and " + max + ".\n";
                if (showalert == true) 
    	    	        alert(errorStr);
            }
        }
	  else {
		// outside bounds
            if ((formField.value < min) || (formField.value > max)) {
				if (len == -1)
	                errorStr += fieldLabel + " is typically between between " + min + " and " + max + ".\n";
				else
				     errorStr += fieldLabel + " must be between " + min + " and " + max + ".\n";
                if (showalert == true) 
		      	    alert(errorStr);
                return errorStr
            }
        }
    }
    // length
    if (len > 0 && formField.value.length != len-numcomma && formField.value.length > 0) {
        errorStr += fieldLabel + " must be " + len + " characters long.\n"
	    if (showalert == true)
	        alert(errorStr);
    }
    return errorStr
}

//
// Checks a field for numbers and punctuation.
// allows user to specify the punctuation and required length
function errNumPunc(formField,fieldLabel,delims,numdigits,showalert) {
    var errorStr = ""
    var testStr = "";

    testStr = stripCharsNotInBag(formField.value,delims+'0123456789');
	if (testStr.length != formField.value.length) {
		errorStr += fieldLabel + " contains invalid characters.\n"
		if (showalert == true)
			alert(errorStr);
    }
	else {
		testStr = stripCharsNotInBag(formField.value,'0123456789');
		// normal check is length vs number of digits
		if (numdigits != 0) {
			if (formField.value.length != numdigits) {
				// but if created by system will include single alpha
				//if ((numdigits < 0) && (testStr.length < (Math.abs(numdigits)-1))) {
					errorStr += fieldLabel + " must be " + Math.abs(numdigits) + " digits.\n"
					if (showalert == true)
						alert(errorStr);
				//}
			} 
		}
	}
	return errorStr
}
// added by kent 6/16/2000
function dollarFormat(expr){
	return "$" + decimalFormat(expr, 2);
}
function decimalFormat(expr, decplaces){
	// raise by power of 10 times the decplaces; round to an int; convert to str
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces));
	// pad with zeros 
	while (str.length <= decplaces){
		str = "0" + str	;
	}
	// get location of decimal point
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

//********************************************************************** jsscripts.cfm file *******************************************************************************
function rollover(imagename)
{
	document.images[imagename].src = "images/" + imagename + "_roll.gif";
}

function rollout(imagename)
{
	document.images[imagename].src = "images/" + imagename + ".gif";
}

bttn_home_roll = new Image(); bttn_home_roll.src = "images/bttn_home_roll.gif";
bttn_home = new Image(); bttn_home.src = "images/bttn_home.gif";
bttn_newsroom_roll = new Image(); bttn_newsroom_roll.src = "images/bttn_newsroom_roll.gif";
bttn_newsroom = new Image(); bttn_newsroom.src = "images/bttn_newsroom.gif";
bttn_contactus_roll = new Image(); bttn_contactus_roll.src = "images/bttn_contactus_roll.gif";
bttn_contactus = new Image(); bttn_contactus.src = "images/bttn_contactus.gif";

function keySort(dropdownlist,caseSensitive) {
  // check the keypressBuffer attribute is defined on the dropdownlist 
  var undefined; 
  if (dropdownlist.keypressBuffer == undefined) { 
    dropdownlist.keypressBuffer = ''; 
  } 
  // get the key that was pressed 
  var key = String.fromCharCode(window.event.keyCode); 
  dropdownlist.keypressBuffer += key;
  if (!caseSensitive) {
    // convert buffer to lowercase
    dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
  }
  // find if it is the start of any of the options 
  var optionsLength = dropdownlist.options.length; 
  for (var n=0; n < optionsLength; n++) { 
    var optionText = dropdownlist.options[n].text; 
    if (!caseSensitive) {
      optionText = optionText.toLowerCase();
    }
    if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
      dropdownlist.selectedIndex = n; 
      return false; // cancel the default behavior since 
                    // we have selected our own value 
    } 
  } 
  // reset initial key to be inline with default behavior 
  dropdownlist.keypressBuffer = key; 
  return true; // give default behavior 
} 

//********************************************************************** js date.cfm file *******************************************************************************
// define number of days for month - except february which is checked
var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
// isYear returns true if string s is a valid 
// Year number.  Must be 4 digits only.
function isYear (s)
{
	if (!isIntegerInRange (s, 1900, 9999)) return false;
    return (s.length == 4);

}
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
function isIntegerInRange (s, a, b)
{
    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;
	// check if leading 0 and remove
	if ((s.substring(0,1) == "0") && (s.length > 1))
		s = s.substring(1,s.length);
	
    // Now, explicitly change the type to integer via parseInt
    // for JS 1.1/1.2 compatability
	var num = parseInt (s);
    return ((num >= a) && (num <= b));
}
// isMonth returns true if string s is a valid 
// month number between 1 and 12.
//
function isMonth (s)
{
   return isIntegerInRange (s, 1, 12);
}
// isDay returns true if string s is a valid 
// day number between 1 and 31.
// 
function isDay (s)
{
    return isIntegerInRange (s, 1, 31);
}
// daysInFebruary (INTEGER year)
// 
// returns number of days in February of that year.
function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}
// isDate checks if string arguments year, month, and day 
// form a valid date.  Error string returned with/out data.
// 
function isDate (year, month, day, fieldLabel, noBlank, showalert)
{
    var errorStr="";
	// check for missing values & exit
    if ((year.length == 0) || (month.length== 0) || (day.length == 0)) {
    	if (noBlank == true) {
        errorStr += fieldLabel + " cannot be blank.\n";
        if (showalert == true)
		alert(errorStr);
	}
	  return errorStr;
    }
    // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/2000.\n";
        if (showalert == true)
		alert(errorStr);
	  return errorStr
    }
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);
    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/2000.\n";
        if (showalert == true)
		alert(errorStr);
	  return errorStr
    }
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/2000.\n";
        if (showalert == true)
		alert(errorStr);
	  return errorStr
    }
    return errorStr;
}
function errDate(thefield, fieldLabel, noBlank, showalert) {
	var errorStr="";
	var isplit=0;
	var sMonth="";
	var sDay="";
	var sYear="";
			
	if (thefield.value.length == 0) {
	if (noBlank == true) {
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/2000.\n";
        if (showalert == true)
		alert(errorStr);
      }
	  return errorStr;
	}
	//Returns true if value is a date in the mm/dd/yyyy format
	isplit = thefield.value.indexOf('/');

	if (isplit == -1 || isplit == thefield.value.length){
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/2000.\n";
        if (showalert == true)
		alert(errorStr);
        return errorStr;
	}

	sMonth = thefield.value.substring(0, isplit);
	isplit = thefield.value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == thefield.value.length){
        errorStr += "Please enter " + fieldLabel + " in mm/dd/yyyy format.\nFor example, 08/01/2000.\n";
        if (showalert == true)
		alert(errorStr);
        return errorStr;
	}
	sDay = thefield.value.substring((sMonth.length + 1), isplit);
	sYear = thefield.value.substring(isplit + 1);
	return isDate (sYear, sMonth, sDay, fieldLabel, noBlank, showalert)
    }
// Compares two dates in format 01/01/1999 and returns -1 if first one less, 0 if same, 
// and 1 if second greater.  Assumes that dates have already been validated
// if firstDate < secondDate function returns the number of years as negative
function CompareDates(firstDate, secondDate)
{
	var isplit=0;
	var s1Month="";
	var s1Day="";
	var s1Year="";
	var s2Month="";
	var s2Day="";
	var s2Year="";

	isplit = firstDate.value.indexOf('/');
	s1Month = firstDate.value.substring(0, isplit);
	isplit = firstDate.value.indexOf('/', isplit + 1);
	s1Day = firstDate.value.substring((s1Month.length + 1), isplit);
	s1Year = firstDate.value.substring(isplit + 1);
	
	isplit = secondDate.value.indexOf('/');
	s2Month = secondDate.value.substring(0, isplit);
	isplit = secondDate.value.indexOf('/', isplit + 1);
	s2Day = secondDate.value.substring((s2Month.length + 1), isplit);
	s2Year = secondDate.value.substring(isplit + 1);
	
	date1 = new Date(s1Year,s1Month-1,s1Day);
	date2 = new Date(s2Year,s2Month-1,s2Day);
	
	if (date1 < date2) 
		return 	-1*Math.round(.51+(date2-date1)/31536000000);

	if (date1 > date2)
		return 1;
	else
		return 0;
}
// Compares two dates in format 01/01/1999 and returns -1 if first one less, 0 if same, 
// and 1 if second greater.  Returns -999 if firstDate has error, +999 if second has error
// if firstDate < secondDate function returns the number of years as negative
function errCompareDates(firstDate, secondDate)
{
	if (firstDate.value.length > 0) {
		isplit = firstDate.value.indexOf('/');
		if (isplit == -1 || isplit == firstDate.value.length)
			return -999;
		s1Month = firstDate.value.substring(0, isplit);
		isplit = firstDate.value.indexOf('/', isplit + 1);
		if (isplit == -1 || (isplit + 1 ) == firstDate.value.length)
			return -999;
		s1Day = firstDate.value.substring((s1Month.length + 1), isplit);
		s1Year = firstDate.value.substring(isplit + 1);
	    if (! (isYear(s1Year, false) && isMonth(s1Month, false) && isDay(s1Day, false)))
			return -999;
	    var intYear = parseInt(s1Year);
    	var intMonth = parseInt(s1Month);
    	var intDay = parseInt(s1Day);
  		if (intDay > daysInMonth[intMonth])
			return -999;
		if ((intMonth == 2) && (intDay > daysInFebruary(intYear)))
			return -999;
		date1 = new Date(s1Year,s1Month-1,s1Day);
	}	
	if (secondDate.value.length > 0) {
		isplit = secondDate.value.indexOf('/');
		if (isplit == -1 || isplit == secondDate.value.length)
			return 999;
		s2Month = secondDate.value.substring(0, isplit);
		isplit = secondDate.value.indexOf('/', isplit + 1);
		if (isplit == -1 || isplit == secondDate.value.length)
			return 999;
		s2Day = secondDate.value.substring((s2Month.length + 1), isplit);
		s2Year = secondDate.value.substring(isplit + 1);
	    if (! (isYear(s2Year, false) && isMonth(s2Month, false) && isDay(s2Day, false)))
			return -999;
	    var intYear = parseInt(s2Year);
    	var intMonth = parseInt(s2Month);
    	var intDay = parseInt(s2Day);
  		if (intDay > daysInMonth[intMonth])
			return -999;
		if ((intMonth == 2) && (intDay > daysInFebruary(intYear)))
			return -999;
		date2 = new Date(s2Year,s2Month-1,s2Day);
	}
	if ((firstDate.value.length > 2) && (secondDate.value.length > 2)) {
		if (date1 < date2) 
			return 	-1*Math.round(.51+(date2-date1)/31536000000);
		if (date1 > date2)
			return 1;
	}
	return 0;
}


//********************************************************************** js checkemail.cfm file *******************************************************************************
	function checkEmail(myForm) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.value)){
			return (true)
		}
		return (false)
	}

// Check email.. for @ and .
	function validEmail(email,showalert){
		var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@._-"
		invalidChars =" /:,;"
		var str =  "";
		var errmsg = "";
		var bademail = false;
		if (email == ""){
			errmsg = "Email is missing";
			bademail = true;
		}
		else
		{
			for (i = 0;i<email.length; i++){
				testChar = email.charAt(i);
				if (validChars.indexOf(testChar,0) == -1){
					if(testChar == " "){
						testChar = "A space";
						if (i+1 == email.length)
							testChar = "A space at the end";
					}
					errmsg = testChar+" is an invalid email character";
					bademail = true;
					i=email.length+1;
				}
			} 
			if (errmsg == ""){
				atPos = email.indexOf("@", 0)
				firstperiodPos = email.indexOf(".", 0);
				afterperiodPos = email.indexOf(".",atPos);
				beforeperiodPos = email.lastIndexOf(".", atPos);
				lastperiodPos = email.lastIndexOf(".", email.length);
				// no @ sign
				if (atPos == -1){
					errmsg = "@ sign is missing in email";
					bademail = true;
				}
				// @ signs as first character
				else if (atPos == 0) {
					errmsg = "@ signs as first character in email are invalid";
					bademail = true;
				}
				// multiple @ signs
				else if (email.indexOf("@", atPos+1) > -1) {
					errmsg = "Multiple @ signs in email are invalid";
					bademail = true;
				}
				// no Period
				else if (firstperiodPos == -1){
					errmsg = "Period in email is missing";
					bademail = true;
				}
				// Period at beginning
				else if (firstperiodPos == 0){
					errmsg = "First character as period in email is invalid";
					bademail = true;
				}
				// period at end
				else if (lastperiodPos+1 == email.length){
					errmsg = "Last character as period in email is invalid";
					bademail = true;
				}
				// period after @ sign
				else if (afterperiodPos == atPos+1){
					errmsg = "Period following the @ sign in email is invalid";
					bademail = true;
				}
				// period before @ sign
				else if (beforeperiodPos == atPos-1){
					errmsg = "Period preceeding the @ sign in email is invalid";
					bademail = true;
				}
				// Period next to period
				else if ((email.indexOf(".", firstperiodPos+1) == firstperiodPos+1) || (email.indexOf(".", beforeperiodPos-1) == beforeperiodPos-1) || (email.indexOf(".", afterperiodPos+1) == afterperiodPos+1) || (email.indexOf(".", lastperiodPos-1) == lastperiodPos-1)){
					errmsg = "Period following period is invalid";
					bademail = true;
				}
				// more than 3 characters after last period
				else if (email.length - lastperiodPos > 4){
					errmsg = "Max characters after last period of email is 3\n     Including spaces";
					bademail = true;
				}
			}
			if (bademail == true){
				if (showalert == true){
					alert(errmsg);
					return false;
				}
			}
		}
		return errmsg
	}
	


////////////////////////////////////////////////////////////////////////////////////// BEGIN credit card validation //////////////////////////////////////////
function isValidCreditCard(type, ccnum) 
	{
  		 if (type == "VISA") 
		 	{
    		    // Visa: length 16, prefix 4, dashes optional.
      			var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   			} 
		else if (type == "MC") 
			{
      			// Mastercard: length 16, prefix 51-55, dashes optional.
      			var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
   			} 
		else if (type == "DISC") 
			{
     			 // Discover: length 16, prefix 6011, dashes optional.
     			var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   			} 
		else if (type == "AMEX")
			{
      			// American Express: length 15, prefix 34 or 37.
      			var re = /^3[4,7]\d{13}$/;
 			} 
		else if (type == "DINERS") 
			{
     			 // Diners: length 14, prefix 30, 36, or 38.
      			var re = /^3[0,6,8]\d{12}$/;
   			}
		else if (type == "") 
			{
				var re = /^3[0,6,8]\d{12}$/;
			}
  
   if (!re.test(ccnum))
   	{
		return false;
	}
   
   	 
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) 
   	{
      	checksum += parseInt(ccnum.charAt(i-1));
   	}
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0) return true; else return false;
}
////////////////////////////////////////////////////////////////////////////////////// END credit card validation //////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////// BEGIN TABS //////////////////////////////////////////
function tabview_aux(TabViewId, id)
{
  var TabView = document.getElementById(TabViewId);

  // ----- Tabs -----
  var Tabs = TabView.firstChild;
  while (Tabs.className != "Tabs" ) Tabs = Tabs.nextSibling;

  var Tab = Tabs.firstChild;
  var i   = 0;
		
  do
  {
    if (Tab.tagName == "A")
    {
      i++;
      Tab.href      = "javascript:tabview_switch('"+TabViewId+"', "+i+");";
      Tab.className = (i == id) ? "Active" : "";
      Tab.blur();
    }
  }
  while (Tab = Tab.nextSibling);

  // ----- Pages -----

  var Pages = TabView.firstChild;
  while (Pages.className != 'Pages') Pages = Pages.nextSibling;

  var Page = Pages.firstChild;
  var i    = 0;

  do
  {
    if (Page.className == 'Page')
    {
      i++;
      if (Pages.offsetHeight) Page.style.height = (Pages.offsetHeight-2)+"px";
      Page.style.display  = (i == id) ? 'block' : 'none';
    }
  }
  while (Page = Page.nextSibling);
}

// ----- Functions -------------------------------------------------------------

function tabview_switch(TabViewId, id) { tabview_aux(TabViewId, id); }

function tabview_initialize(TabViewId,thisTab) 
	{ 		
		tabview_aux(TabViewId,thisTab);
	}

function tabview_initialize2(TabViewId,thisTab) 
	{ 		
		tabview_aux(TabViewId,thisTab);
	}

////////////////////////////////////////////////////////////////////////////////////// END TABS MENU//////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////// BEGIN DROP DOWN MENUS //////////////////////////////////////////
function at_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- DropDown Control ------------------------------------------------------

var at_timeout = 50;

// ----- Show Aux -----

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p.className        = "active";

  if (c.offsetWidth <= 0)
  {
    c.style.position   = "absolute";
    c.style.visibility = "visible";
    c.style.display    = "block";
  }

  var direction = undefined;
  if (p.parentNode && p.parentNode["at_position"] == "x")
    direction = p.parentNode["at_direction"];

  var top   = (c["at_position"] == "y") ?  p.offsetHeight+2 : 0;
  var left1 = (c["at_position"] == "x") ?  p.offsetWidth +2 : 0;
  var left2 = (c["at_position"] == "x") ? -c.offsetWidth -2 : 0;
  var left3 = (c["at_position"] == "x") ?  p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    if (p.style.position != 'absolute')
    {
      left1 += p.offsetLeft;
      left2 += p.offsetLeft;
      top   += p.offsetTop;
    }
    left3 += p.offsetLeft;
  }

  if (direction)
  {
    left = (direction == 'right') ? left1 : left2;
    c['at_direction'] = direction;
  }
  else
  {
    left = (left3+c.offsetWidth < document.body.offsetWidth) ? left1 : left2;
    c['at_direction'] = (left3+c.offsetWidth < document.body.offsetWidth) ? 'right' : 'left';
  }

  c.style.position   = "absolute";
  c.style.visibility = "visible";
  c.style.display    = "block";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
}

// ----- Hide Aux -----

function at_hide_aux(parent, child)
{
  document.getElementById(parent).className        = "parent";
  document.getElementById(child ).style.visibility = "hidden";
  document.getElementById(child ).style.display    = "block";
}

// ----- Show -----

function at_show(e)
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);

  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----

function at_hide()
{
  var c = document.getElementById(this["at_child"]);

  c["at_timeout"] = setTimeout("at_hide_aux('"+this["at_parent"]+"', '"+this["at_child" ]+"')", at_timeout);
}

// ----- Attach -----

function at_attach(parent, child, position)
{
  p = document.getElementById(parent);
  c = document.getElementById(child );

  p["at_child"]    = c.id;
  c["at_child"]    = c.id;
  p["at_parent"]   = p.id;
  c["at_parent"]   = p.id;
  c["at_position"] = position;

  p.onmouseover = at_show;
  p.onmouseout  = at_hide;
  c.onmouseover = at_show;
  c.onmouseout  = at_hide;
}

// ----- DropDown Menu ---------------------------------------------------------

// ----- Build Aux -----

function dhtmlmenu_build_aux(parent, child, position)
{
  document.getElementById(parent).className = "parent";

  document.write('<div class="vert_menu" id="'+parent+'_child">');

  var n = 0;
  for (var i in child)
  {
    if (i == '-')
    {
      document.getElementById(parent).href = child[i];
      continue;
    }

    if (typeof child[i] == "object")
    {
      document.write('<a class="parent" id="'+parent+'_'+n+'">'+i+'</a>');
      dhtmlmenu_build_aux(parent+'_'+n, child[i], "x");
    }
    else document.write('<a id="'+parent+'_'+n+'" href="'+child[i]+'">'+i+'</a>');
    n++;
  }

  document.write('</div>');

  at_attach(parent, parent+"_child", position);
}

// ----- Build -----

function dhtmlmenu_build(menu)
{
  for (var i in menu) dhtmlmenu_build_aux(i, menu[i], "y");
}
////////////////////////////////////////////////////////////////////////////////////// END DROP DOWN MENUS //////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////// BEGIN POPUP WINDOWS //////////////////////////////////////////
function popitup(thisURL,thisHeight,thisWidth)
	{
	
		newwindow = window.open(thisURL,'name','height =  '+thisHeight+' , width = '+thisWidth+', scrollbars = 1, resizable = 1,menubar = 0, toolbar = 0, location = 0');
		if (window.focus) {newwindow.focus()}
		return false;
	}

	var win = null;
	function radarPopUp(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
	}
////////////////////////////////////////////////////////////////////////////////////// END POPUP WINDOWS //////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////// BEGIN TEXT COLLAPSE //////////////////////////////////////////
function showReview(n)
{
  document.getElementById(n+"_f").style.display = "block";
  document.getElementById(n+"_r").style.display = "none";
}

function hideReview(n)
{
  document.getElementById(n+"_r").style.display = "block";
  document.getElementById(n+"_f").style.display = "none";
}

function showReview2(n)
{
  document.getElementById(n+"_f").style.display = "inline";
  document.getElementById(n+"_r").style.display = "none";
}

function hideReview2(n)
{
  document.getElementById(n+"_r").style.display = "block";
  document.getElementById(n+"_f").style.display = "none";
}
////////////////////////////////////////////////////////////////////////////////////// END TEXT COLLAPSE //////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////// BEGIN VALID DATE //////////////////////////////////////////
function isValidDate(dateStr) 
{
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) 
	{
		//alert("Date is not in a valid format.")
		missing = true;
		return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}
////////////////////////////////////////////////////////////////////////////////////// END VALID DATE //////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////// BEGIN TEXT COUNTER //////////////////////////////////////////
function textCounter(theField,theCharCounter,maxChars)
{

	var strTemp = "";
	var strLineCounter = 0;
	var strCharCounter = 0;
	
	for (var i = 0; i < theField.value.length; i++)
	{
		var strChar = theField.value.substring(i, i + 1);
		
		if (strChar == '\n')
		{
			strTemp += strChar;
			strCharCounter = 1;
			//strLineCounter += 1;
		}
		else
		{
			strTemp += strChar;
			strCharCounter ++;
		}
	}
	
	theCharCounter.value = maxChars - strTemp.length;
	//theLineCounter.value = maxLines - strLineCounter;
}
////////////////////////////////////////////////////////////////////////////////////// END TEXT COUNTER //////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////// START RESIZE & CENTER //////////////////////////////////////////
function resize()
	{ 
   		window.moveTo(10,10) 
        window.resizeTo(400,350) 
		window.scrollBar(0)
    } 
	
//center window
function centerWindow()
	{ 
		LeftPosition = (screen.width) ? (screen.width-450)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-350)/2 : 0;
		window.moveTo(LeftPosition,TopPosition)
	}
////////////////////////////////////////////////////////////////////////////////////// END RESIZE & CENTER //////////////////////////////////////////		

////////////////////////////////////////////////////////////////////////////////////// START RESIZE & CENTER //////////////////////////////////////////		
/* Script by: www.jtricks.com
 * Version: 20070703
 * Latest version:
 * www.jtricks.com/javascript/window/box_centered.html
 */
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement
    && document.documentElement.clientWidth;

// Moves the box object to be centered on current
// viewable area of the page
function center_box(box, width, height)
{
    cleft = has_inner
        ? pageXOffset + 
          (window.innerWidth - width)/2
        : has_element
          ? document.documentElement.scrollLeft + 
            (document.documentElement.clientWidth - width)/2
          : document.body.scrollLeft + 
            (document.body.clientWidth - width)/2;

    ctop = has_inner
        ? pageYOffset + (window.innerHeight - height)/2
        : has_element
          ? document.documentElement.scrollTop + 
            (document.documentElement.clientHeight - height)/2
          : document.body.scrollTop + 
            (document.body.clientHeight - height)/2;

    box.style.left = cleft > 0 ? cleft + 'px' : '0px';
    box.style.top = ctop > 0 ? ctop + 'px' : '0px';
}

// Hides other alone popup boxes that might be displayed
function hide_other_alone(obj)
{
    if (!document.getElementsByTagName)
	{
        alert("1");
		return;
	}
    var all_divs = document.body.getElementsByTagName("DIV");

    for (i = 0; i < all_divs.length; i++)
    {
        if (all_divs.item(i).style.position != 'absolute' ||
            all_divs.item(i) == obj ||
            !all_divs.item(i).alonePopupBox)
        {
            continue;
        }

        all_divs.item(i).style.display = 'none';
    }
    return;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_box(an, width, height, borderStyle)
{
    show_hide_centered_href(
        an.href, width, height, borderStyle);
    return false;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_centered_href(href, width, height, borderStyle)
{
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            hide_other_alone(boxdiv);
            // Show existing box, move it
            // if document changed layout
            center_box(boxdiv, width, height);
            boxdiv.style.display='block';

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow)
                boxdiv.contents.src = href;
        }
        else
			{
           	 // Hide currently shown box.
           	 boxdiv.style.display='none';
			 }
        return false;
    }

    hide_other_alone(null);	
	
    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    // Add object identification variable
    boxdiv.alonePopupBox = 1;
	//boxdiv.style.z-index = 500;
    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
    boxdiv.style.background = '#FFFFFF';
    document.body.appendChild(boxdiv);

    var offset = 0;

    // Remove the following code if 'Close' hyperlink
    // is not needed.
    var close_href = document.createElement('a');
    close_href.href = 'javascript:void(0);';
    close_href.onclick = function()
    {
        show_hide_centered_href(href, width, height, borderStyle);
		window.location.href=window.location.href;
    }

    close_href.appendChild(document.createTextNode('Close'));
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;
    // End of 'Close' hyperlink code.

    var contents = document.createElement('iframe');
    //contents.scrolling = 'no';
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.contents = contents;
    boxdiv.appendChild(contents);

    center_box(boxdiv, width, height);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return;
}
//-->

//////
// Moves the box object to be directly beneath an object.
var has_inner = typeof(window.innerWidth) == 'number';
var has_element = document.documentElement
    && document.documentElement.clientWidth;
	
function move_box(an, box)
{
    var cleft = 0;
    var ctop = 0;
    var obj = an;
	
	cleft = has_inner
        ? pageXOffset + 
          (window.innerWidth)/2
        : has_element
          ? document.documentElement.scrollLeft + 
            (document.documentElement.clientWidth)/2
          : document.body.scrollLeft + 
            (document.body.clientWidth)/2;
			
    while (obj.offsetParent)
    {
        //cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }
	
	/*
	x = cleft;
	y = x - (x - 50);
	*/
	cleft = cleft + 110;
	box.style.left = cleft + 'px';
	 //box.style.left = cleft > 0 ? cleft + 'px' : '0px';
	//var cleft = 800;
    //box.style.left = cleft + 'px'
	//box.style.right = y + 'px';
    //ctop += an.offsetHeight - 100;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = '29px';
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_box(an, width, height, borderStyle)
{
    var href = an.href;
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            // Show existing box, move it
            // if document changed layout
            move_box(an, boxdiv);
            boxdiv.style.display='block';

            bringToFront(boxdiv);

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow)
                boxdiv.contents.src = href;
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    }

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    boxdiv.style.display 	= 'block';
    boxdiv.style.position 	= 'absolute';
    boxdiv.style.width 		= width + 'px';
    boxdiv.style.height 	= height + 'px';
    boxdiv.style.border 	= borderStyle;
    boxdiv.style.textAlign 	= 'right';
    boxdiv.style.padding 	= '3px';
    boxdiv.style.background = '#ffffff';
    document.body.appendChild(boxdiv);

    var offset = 0;

    // Remove the following code if 'Close' hyperlink
    // is not needed.
    var close_href = document.createElement('a');
    close_href.href = 'javascript:void(0);';
    close_href.onclick = function()
        { show_hide_box(an, width, height, borderStyle); }
    close_href.appendChild(document.createTextNode('close'));
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;
    // End of 'Close' hyperlink code.

    var contents = document.createElement('iframe');
    //contents.scrolling = 'no';
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';
	
    boxdiv.contents = contents;
    boxdiv.appendChild(contents);

    move_box(an, boxdiv);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return false;
}

function getAbsoluteDivs()
{
    var arr = new Array();
    var all_divs = document.body.getElementsByTagName("DIV");
    var j = 0;

    for (i = 0; i < all_divs.length; i++)
        if (all_divs.item(i).style.position=='absolute')
        {
            arr[j] = all_divs.item(i);
            j++;
        }

    return arr;
}

function bringToFront(obj)
{
    if (!document.getElementsByTagName)
        return;

    var divs = getAbsoluteDivs();
    var max_index = 0;
    var cur_index;

    // Compute the maximal z-index of
    // other absolute-positioned divs
    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj ||
            item.style.zIndex == '')
            continue;

        cur_index = parseInt(item.style.zIndex);
        if (max_index < cur_index)
        {
            max_index = cur_index;
        }
    }

    obj.style.zIndex = max_index + 1;
}
///////

  function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
      endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
  }

  function GetCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
    }
    return null;
  }

  function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (2 < argc) ? argv[2] : null;
    var path = (3 < argc) ? argv[3] : null;
    var domain = (4 < argc) ? argv[4] : null;
    var secure = (5 < argc) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
      ((expires == null) ? "" : ("; expires=" + 
      expires.toGMTString())) +
      ((path == null) ? "" : ("; path=" + path)) +
      ((domain == null) ? "" : ("; domain=" + domain)) +
      ((secure == true) ? "; secure" : "");
  }

  function CookieMain(){
    var expdate = new Date();
    var visits;
    if (( navigator.appName == "Microsoft Internet Explorer") 
       && (navigator.appVersion.indexOf('3.') != -1)) {
      document.write("Browsing with MSIE 3.0 does not work!");
    }else{
      // Set expiration date to a year from now.
      expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));

      if(!(visits = GetCookie("visits"))) visits = 0;
      visits++;

      SetCookie("visits", visits, expdate, null, null, false);
      document.write("Welcome!!! ");
	  //alert("ss");
      if(visits == 1) document.write("Your 1st visit");
      if(visits == 2) document.write("Your 2nd visit");
      if(visits == 3) document.write("Your 3rd visit");
      if(visits >  3) document.write("Your " + visits +"th visit");
    }
  }
////////////////////////////////////////////////////////////////////////////////////// END RESIZE & CENTER //////////////////////////////////////////		


function OpenFeaturedVideoWindow(thisURL,thisPage,w,h)
	{
	var win= null;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,toolbar=no'
	win=window.open(thisURL,thisPage,settings)
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

/// for drop down menus
	