// Button Rollover Code
function rollOver(imgID, imgName) {
  if (navigator.appName== "Netscape" && parseInt(navigator.appVersion) >= 3)
    document.images[imgID].src = imgName;
  else if (navigator.appName != "Netscape" && parseInt(navigator.appVersion) >= 4) 
    document.images[imgID].src = imgName;
}

function isBlank(val){
  if(val==null) {return true;}
  for(var i=0;i<val.length;i++) {
    if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
  }
  return true;
}

function isEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.lastIndexOf("@") != email.indexOf("@")) {  // @ can't appear more than once
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-/=?^_{|}~.@";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

 
function Left(str, n){
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else
    return String(str).substring(0,n);
}

function Right(str, n){
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else {
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}

function Len(str){  
  return String(str).length;  
}

function showElement(ele) {
  obj = document.getElementById(ele).style;
  obj.display='block';
}

function hideElement(ele) {
  obj = document.getElementById(ele).style;
  obj.display='none';
}

function popUpWindow(URL,W,H) 
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + W + ',height=' + H + ',left=487.5,top=350');");
}

function popupCenter(winname, url, winwidth, winheight, scrollbars, toolbars){

  var top   = (screen.availHeight - winheight - 29) / 2;
  var left  = (screen.availWidth - winwidth - 10) / 2;

  var urlPrefix = "";
  var winurl    = url;

  if (toolbars == "1")
	tbars = 1;
  else
	tbars = 0;

  var winopt    = "toolbar=" + tbars + ",location=0,directories=0,status=0,menubar=0,scrollbars=" + scrollbars + ",copyhistory=0,resizable=0,width="+winwidth+",height="+winheight+",left="+left+",top="+top;
  //alert(winopt);
  newwin = window.open(winurl,winname,winopt);

}

function noSpaces(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if (((" ").indexOf(keychar) > -1))
   return false;

else
   return true;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    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;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

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 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = field.value.length;
}



function toggleObjects(hideObj, showObj) {
 
  if (document.getElementById) {
    document.getElementById(hideObj).style.display = 'none';
    document.getElementById(showObj).style.display = 'block';
  }
}


function goThere(){
  var list = document.chooseState.selectState;
  location = list.options[list.selectedIndex].value;
}


var hawaiiCurDivId = 1, floridaCurDivId = 1, caribbeanCurDivId = 1, vegasCurDivId = 1, mexicoCurDivId = 1;
var hawaiiResortCnt = 10, floridaResortCnt = 10, caribbeanResortCnt = 5, vegasResortCnt = 5, mexicoResortCnt = 10;

function toggleResort(label, inc) {
  var newDivId = eval(label + 'CurDivId') + inc;

  if (newDivId > eval(label + 'ResortCnt')) {
    newDivId = 1;
  } else if (newDivId < 1) {
    newDivId = eval(label + 'ResortCnt');
  }

  document.getElementById(label + '_' + eval(label + 'CurDivId')).style.display = 'none';
  document.getElementById(label + '_' + newDivId).style.display = 'block';

  if (label == 'hawaii') {
    hawaiiCurDivId = newDivId;
  } else if (label == 'florida') {
    floridaCurDivId = newDivId;
  } else if (label == 'caribbean') {
    caribbeanCurDivId = newDivId;
  } else if (label == 'vegas') {
    vegasCurDivId = newDivId;
  } else if (label == 'mexico') {
    mexicoCurDivId = newDivId;
  }
//  label + 'CurDivId' = newDivId;
}