var whitespace = " \t\n\r";

function isEmail (s)
{   if (isEmpty(s))
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);

    // is s whitespace?
    if (isWhitespace(s)) return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function isWhitespace (s)
{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


function getRadioValue(rb)
{
var L=rb.length;var ret="";
for (var i = 0 ; i< L ; i++)
 { if(rb[i].checked) { ret=rb[i].value; break; } }
return(ret);
}


function email(strAddress, strLink, strTitle, strSubject)
{
  var arrAddress     = strAddress.split(",");
  var arrLink        = strLink.split(",");
  var arrTitle       = strTitle.split(",");
  var encodedAddress = "";
  var encodedLink    = "";
  var encodedTitle   = "";
  var result         = "";
  if (isEmpty(strSubject))
        {
        strSubject = "";
        }
  else
        {
        strSubject = "?subject=" + strSubject;
        }
  for (i=0;i<arrAddress.length;i++) encodedAddress = encodedAddress + "&#" + arrAddress[i];
  for (i=0;i<arrLink.length;i++) encodedLink = encodedLink + "&#" + arrLink[i];
  for (i=0;i<arrTitle.length;i++) encodedTitle = encodedTitle + "&#" + arrTitle[i];
  result = "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;" + encodedAddress + strSubject + "\" title=\"" + encodedTitle + "\">" + encodedLink + "<\/a>";
  document.write(result);
  return result; // not necessarily needed, but nice to have just in case
}


function chooseRegion(form)
{
var arrRegionList;
var i;

form.hotel_region1.selectedIndex = 0;
form.hotel_region2.selectedIndex = 0;
form.hotel_region1.options.length = 1;
form.hotel_region2.options.length = 1;


if (form.hotel_country.selectedIndex >= 1)
        {
        if (arrRegions1[form.hotel_country.options[form.hotel_country.selectedIndex].value] != null)
                {
                arrRegionList1 = (arrRegions1[form.hotel_country.options[form.hotel_country.selectedIndex].value]).split(';');
                for (i = 0; i < arrRegionList1.length; i++)
                        {
                        form.hotel_region1.options.length = i + 2;
                        form.hotel_region1.options[i+1].value = (arrRegionList1[i]).split(',')[0];
                        form.hotel_region1.options[i+1].text = (arrRegionList1[i]).split(',')[1];
                        }
                }

        if (arrRegions2[form.hotel_country.options[form.hotel_country.selectedIndex].value] != null)
                {
                arrRegionList2 = (arrRegions2[form.hotel_country.options[form.hotel_country.selectedIndex].value]).split(';');
                       for (i = 0; i < arrRegionList2.length; i++)
                        {
                        form.hotel_region2.options.length = i + 2;
                        form.hotel_region2.options[i+1].value = (arrRegionList2[i]).split(',')[0];
                        form.hotel_region2.options[i+1].text = (arrRegionList2[i]).split(',')[1];
                        }
                }
        }
} // chooseRegion

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 mysqldate(str)
    {
    if (str.length != 10)
        return str;
    else
        return right(str, 4) + "-" + str.substring(3, 5) + "-" + left(str, 2);
    }


/**
 * 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 strDay=dtStr.substring(0, pos1)
        var strMonth=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 (pos1!=2 || pos2!=5){
//                alert("The date format should be : mm/dd/yyyy")
                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 (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 (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
//                alert("Please enter a valid date")
                return false
        }
return true
}


function trim(argvalue)
    {
    var argvalue = ltrim(argvalue);
    var argvalue = rtrim(argvalue);
    return argvalue;
    }

function rtrim(argvalue)
    {
    if (undefined == argvalue)
        {
        var argvalue = "";
        }
    while (1)
        {
        if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
            break;
        argvalue = argvalue.substring(0, argvalue.length - 1);
        }
    return argvalue;
    }

function ltrim(argvalue)
    {
    if (undefined == argvalue)
        {
        var argvalue = "";
        }
    while (1)
        {
        if (argvalue.substring(0, 1) != " ")
            break;
        argvalue = argvalue.substring(1, argvalue.length);
        }
    return argvalue;
    }


function occurs(arg_str, arg_chr)
    {
    if (undefined == arg_str)
        {
        var arg_str = "";
        }
    var i = 0;
    var anzahl = 0;
    var sLength = arg_str.length;
    while (i < sLength)
        {
        i++;
        if(arg_str.charAt(i) == arg_chr)
            {
            anzahl++;
            }
        }
    return anzahl;
    }


function feld(arg_str, arg_chr, arg_no)
    {
    var string_array = arg_str.split(arg_chr);
    return string_array[arg_no - 1];
    }

function padl(arg_str, arg_chr, arg_no)
    {
    i = 0;
    pad_str = "";
    while (i < 100)
        {
        pad_str = pad_str + arg_chr;
        i++;
        }
    arg_str = ltrim("" + arg_str);
    arg_str = right(pad_str + arg_str, arg_no);
    return arg_str;
    }
	
function TextualZoomControl()
    {
    }


