﻿function ValidateArrivalDate(date, controlName, buttonName)
{
    if (isDate(date))
    {
        var dateString = date;
        var searchDate = new Date(dateString);
        var today = new Date();
        if (searchDate < today)
        {
            document.getElementById(buttonName).disabled = true;
            document.getElementById(buttonName).value = "Incorrect date!";
            return false;
        }
        else
        {
            document.getElementById(buttonName).disabled = false;
            document.getElementById(buttonName).value = "Check Availability";
            return true;
        }
    }
    else
    {
        document.getElementById(buttonName).disabled = true;
        document.getElementById(buttonName).value = "Incorrect date!";
        return false;
    }
}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "";
}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = ""; }
else { document.getElementById(d).style.display = "none"; }
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=440,height=400');");
}

function clearAltText()
{
    if(document.all){
    var arImg=document.getElementsByTagName("img");
    var len=arImg.length;
    for(var i=0; i<len; i++)
    arImg[i].alt="";
    }
}
clearAltText();

function PrepareForInput(sender, defaultText)
{
    sender.style.backgroundColor = "#FFFFAA";
    if (sender.value == defaultText)
    {
        sender.value = "";
    }
}
function OnInputBlur(sender, defaultText)
{
    sender.style.backgroundColor = "#FFFFCC";
    if (sender.value == "")
    {
        sender.value = defaultText;
    }
}

function FixColumns(id1, id2)
{
    if (document.getElementById(id1) != null && document.getElementById(id2) != null)
    {
        var w1 = document.getElementById(id1).offsetHeight;
        var w2 = document.getElementById(id2).offsetHeight;
        var diff = w1 - w2;

        if (diff > 0)
        {
            document.getElementById(id2).style.minHeight = w2 + 250 + diff + "px";
        }
        else if (diff < 0)
        {
            document.getElementById(id2).style.minHeigh = w1 - diff + "px";
        }
    }
}

function ResetTabElements()
{
    var i = 1;
    var count = 0;
    for(j = 1; j <= 5; j++)
    {
        if (document.getElementById('tb_a' + j) != null)
            count++;
    }
    while(i <= count)
    {
        if (document.getElementById('tb_a' + i) != null)
            document.getElementById('tb_a' + i).className = '';
        if (document.getElementById('tc_a' + i) != null)
            document.getElementById('tc_a' + i).style.display = 'none';
        i++;
    }
}
function ToggleTabElement(sender, id)
{
    var thisTab = document.getElementById(id);
    ResetTabElements();
    thisTab.style.display = 'block';
    sender.parentNode.className = 'current';
}

//Generating Pop-up Print Preview page
function getPrintPlainDiv(print_area)
{ 
    //Creating new page
    var pp = window.open();
    //Adding HTML opening tag with <HEAD> … </HEAD> portion 
    pp.document.writeln('<HTML><HEAD><title>Print Preview</title>');
    pp.document.writeln('<LINK href=../css/formating.css type="text/css" rel="stylesheet">');
    pp.document.writeln('<LINK href=../css/printing.css type="text/css" rel="stylesheet" media="print">');
    pp.document.writeln('<base target="_self"></HEAD>');
    //Adding Body Tag
    pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
    pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
    //Adding form Tag
    //Creating two buttons Print and Close within a HTML table
    pp.document.writeln('<div aling="center" id="PrintExclusion"><br /><br />');
    pp.document.writeln('<center><INPUT type="button" value="Print" ');
    pp.document.writeln('onclick="javascript:location.reload(true);window.print();">');
    pp.document.writeln('<INPUT type="button" value="Close" onclick="window.close();">');
    pp.document.writeln('</center><br /><br /></center><hr width="500px" /></div>');
    pp.document.writeln('<center>');
    //Writing print area of the calling page
    formating = new String(document.getElementById(print_area).innerHTML);
    formating = formating.replace(/<TABLE/g, "<TABLE CLASS=PlainText");
    pp.document.writeln(formating);
    //alert(innerRender);
    //Ending Tag of </form>, </body> and </HTML>
    pp.document.writeln('</center></body></HTML>');
} 

// Checks if a given date string is in    
// one of the valid formats:   
// a) M/D/YYYY format   
// b) M-D-YYYY format   
// c) M.D.YYYY format   
// d) M_D_YYYY format   
function isDate(s)   
{      
    // make sure it is in the expected format   
    if (s.search(/^\d{1,2}[\/|\-|\.|_]\d{1,2}[\/|\-|\.|_]\d{4}/g) != 0)   
        return false;   
  
    // remove other separators that are not valid with the Date class              
    s = s.replace(/[\-|\.|_]/g, "/");   
               
    // convert it into a date instance   
    var dt = new Date(Date.parse(s));          
  
    // check the components of the date   
    // since Date instance automatically rolls over each component   
    var arrDateParts = s.split("/");   
    return (   
        dt.getMonth() == arrDateParts[0]-1 &&   
        dt.getDate() == arrDateParts[1] &&   
        dt.getFullYear() == arrDateParts[2]   
    );             
} 

function roundNumber(rnum, rlength) 
{
  return Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
}