﻿// JScript File



// auto complete

var isOpera = navigator.userAgent.indexOf('Opera') > -1; 
var isIE = navigator.userAgent.indexOf('MSIE') > 1 && !isOpera; 
var isMoz = navigator.userAgent.indexOf('Mozilla/5.') == 0 && !isOpera; 
var arrValues = ["red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown"]; 

function textboxSelect (oTextbox, iStart, iEnd) { 

   switch(arguments.length) { 
       case 1: 
           oTextbox.select(); 
           break; 

       case 2: 
           iEnd = oTextbox.value.length; 
           /* falls through */ 
            
       case 3:          
           if (isIE) { 
               var oRange = oTextbox.createTextRange(); 
               oRange.moveStart("character", iStart); 
               oRange.moveEnd("character", -oTextbox.value.length + iEnd);      
               oRange.select();                                              
           } else if (isMoz){ 
               oTextbox.setSelectionRange(iStart, iEnd); 
           }                     
   } 

   oTextbox.focus(); 
} 

function textboxReplaceSelect (oTextbox, sText) { 

   if (isIE) { 
       var oRange = document.selection.createRange(); 
       oRange.text = sText; 
       oRange.collapse(true); 
       oRange.select();                                 
   } else if (isMoz) { 
       var iStart = oTextbox.selectionStart; 
       oTextbox.value = oTextbox.value.substring(0, iStart) + sText + oTextbox.value.substring(oTextbox.selectionEnd, oTextbox.value.length); 
       oTextbox.setSelectionRange(iStart + sText.length, iStart + sText.length); 
   } 

   oTextbox.focus(); 
} 

function autocompleteMatch (sText, arrValues) { 

   
   for (var i=0; i < arrValues.length; i++) { 
        
       if (arrValues[i].toLowerCase().indexOf(sText.toLowerCase()) == 0) { 
            return arrValues[i]; 
           
       } 
   } 

   return null; 

} 
function autocomplete(oTextbox, oEvent, arrValues) { 

   switch (oEvent.keyCode) { 
       case 38: //up arrow  
       case 40: //down arrow 
       case 37: //left arrow 
       case 39: //right arrow 
       case 33: //page up  
       case 34: //page down  
       case 36: //home  
       case 35: //end                  
       case 13: //enter  
       case 9: //tab  
       case 27: //esc  
       case 16: //shift  
       case 17: //ctrl  
       case 18: //alt  
       case 20: //caps lock 
       case 8: //backspace  
       case 46: //delete 
           return true; 
           break; 

       default: 
           textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode)); 
           var iLen = oTextbox.value.length; 

           var sMatch = autocompleteMatch(oTextbox.value, arrValues); 

           if (sMatch != null) { 
               oTextbox.value = sMatch; 
               textboxSelect(oTextbox, iLen, oTextbox.value.length); 
           }  
           
           return false; 
   } 
} 

function autocompletePostcode(oTextbox, oEvent, arrValues) { 
   
   switch (oEvent.keyCode) { 
       case 38: //up arrow  
       case 40: //down arrow 
       case 37: //left arrow 
       case 39: //right arrow 
       case 33: //page up  
       case 34: //page down  
       case 36: //home  
       case 35: //end                  
       case 13: //enter  
       case 9: //tab  
       case 27: //esc  
       case 16: //shift  
       case 17: //ctrl  
       case 18: //alt  
       case 20: //caps lock 
       case 8: //backspace  
       case 46: //delete 
           return true; 
           break; 

       default: 
           textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode)); 
           var iLen = oTextbox.value.length; 

           var sMatch = autocompleteMatch(oTextbox.value, arrValues); 
                      
           if (sMatch != null) { 
               var a1 = new Array();
               a1=sMatch.split("#");

               oTextbox.value = a1[0];//sMatch;
               document.getElementById('uxtxtCity').value = a1[1];
               textboxSelect(oTextbox, iLen, oTextbox.value.length); 
           }  
           
           return false; 
   } 
} 

function autocompleteCity(oTextbox, oEvent, arrValues) { 
   
   switch (oEvent.keyCode) { 
       case 38: //up arrow  
       case 40: //down arrow 
       case 37: //left arrow 
       case 39: //right arrow 
       case 33: //page up  
       case 34: //page down  
       case 36: //home  
       case 35: //end                  
       case 13: //enter  
       case 9: //tab  
       case 27: //esc  
       case 16: //shift  
       case 17: //ctrl  
       case 18: //alt  
       case 20: //caps lock 
       case 8: //backspace  
       case 46: //delete 
           return true; 
           break; 

       default: 
           textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode)); 
           var iLen = oTextbox.value.length; 

           var sMatch = autocompleteMatch(oTextbox.value, arrValues); 
                      
           if (sMatch != null) { 
               var a1 = new Array();
               a1=sMatch.split("#");

               oTextbox.value = a1[0];//sMatch;
               document.getElementById('uxtxtPostCode').value = a1[1];
               textboxSelect(oTextbox, iLen, oTextbox.value.length); 
           }  
           
           return false; 
   } 
}


//Other


// Portal Functions

function Postback(title){

        document.getElementById('uxhfStartProcedure').value = title;
        document.forms["PortalForm"].submit();
}

function PortalFrame2GoTo(url, Name, ImgSource){
    
    var MyFrame2 = top.document.getElementById("myFrame2");
    MyFrame2.src = url;
    MyFrame2.style.height = (MyFrame2.contentWindow.document.body.scrollHeight + 80) + 'px';
    top.document.getElementById('uxlblMenuName').innerHTML = Name;
    var newStr = ImgSource.substring(3, ImgSource.length);
    top.document.getElementById('uximgMenu').src = newStr;

}

function ResizeFrame2(type, msg){

    var MyFrame2 = top.document.getElementById("myFrame2");
    if (MyFrame2 != null) { MyFrame2.style.height = (MyFrame2.contentWindow.document.body.scrollHeight + 80) + 'px'; }
    
    if (type > 0 ) { 
        SetMessage(type, msg);
        }

}

function SetMessage(msgtype, msgtext){
    
    var Message = top.document.getElementById("uxtopMenuOther");
    if (Message != null) {
        if (msgtype == 1) {
            Message.className = 'TopMenuOtherInfoError';
        }
        else if (msgtype == 3) {
            Message.className = 'TopMenuOtherInfoHelp';
        }
        else if (msgtype == 2) {
            Message.className = 'TopMenuOtherInfoOK';
        }
        else if (msgtype == 99) {
        ReSetMessage();
        return;
        }
        Message.innerHTML = msgtext;
    }
}

function ReSetMessage(){
    
    var Message = top.document.getElementById("uxtopMenuOther");
    if (Message != null) {
        Message.className = 'TopMenuOtherInfo';
        Message.innerHTML = '';
    }
}

function ShowSortHelp(Element, DivName) {
    
    var obj = document.getElementById(Element);

    var posx = findPosX(obj); //left
    var posy = findPosY(obj); //top

    if (document.getElementById(DivName).style.visibility == 'hidden') {
        document.getElementById(DivName).style.left = obj.offsetLeft + "px";
        document.getElementById(DivName).style.top = obj.offsetTop + "px";
        document.getElementById(DivName).style.visibility = 'visible';
    }
    else {
        document.getElementById(DivName).style.visibility = 'hidden';
    }
    var MyFrame2 = top.document.getElementById("myFrame2");
    MyFrame2.style.height = (MyFrame2.contentWindow.document.body.scrollHeight + 80) + 'px';
} 

// Menu Creation Functions
function ShowMenu(id){
    
    var Picske = document.getElementById('uximg' + id);
    var Divke = document.getElementById('uxdiv' + id);
    if (Divke.className == 'OptionsDiv') {
        Divke.className = 'OptionsDivShow'
        Picske.src = '../Pictures/PORTAL/Other/navigate_open.png'
        }
    else {
        Divke.className = 'OptionsDiv'
        Picske.src = '../Pictures/PORTAL/Other/navigate_close.png'
                }
    var MyFrame2 = top.document.getElementById("myFrame");
    MyFrame2.style.height = (MyFrame2.contentWindow.document.body.scrollHeight + 80) + 'px';
    
    var MyFrame1 = top.document.getElementById("myFrame2");
    MyFrame1.style.height = (MyFrame1.contentWindow.document.body.scrollHeight + 80) + 'px';
  
}

function Hide(id) {
    var divke = document.getElementById(id);
    if (divke.style.display == 'none') 
        {
            divke.style.display = 'block';
        }
    else 
        {
            divke.style.display = 'none';
        }
    var MyFrame2 = top.document.getElementById("myFrame");
    if (MyFrame2 != null) { MyFrame2.style.height = (MyFrame2.contentWindow.document.body.scrollHeight + 80) + 'px'; }

    var MyFrame1 = top.document.getElementById("myFrame2");
    if (MyFrame1 != null) { MyFrame1.style.height = (MyFrame1.contentWindow.document.body.scrollHeight + 80) + 'px'; }
    

}



function InfoFocus(infoField, infotext, focusfield){

document.getElementById(infoField).innerHTML = infotext;
document.getElementById(focusfield).focus();
}


function ShowTranslation(Counter, FieldName)
        {
            var url = "../Management/Management_Editor.aspx?Counter=" + Counter + "&FieldName=" + FieldName;
            var leftsize = (screen.width-860)/2;
            var topsize = (screen.height-520)/2;
            var options = "width=860,height=520,scrollbars=no,left=" + leftsize + ",top=" + topsize;
            my_window=window.open(url,'my_window',options);
            //my_window.moveTo((screen.width-560)/2,(screen.height-850)/2); 
            my_window.focus();
        }

function ShowTranslationSimpleMultiLine(Counter, FieldName) {
            var url = "../Management/Translations_Simple.aspx?Multi=1&Counter=" + Counter + "&FieldName=" + FieldName;
            var leftsize = (screen.width - 800) / 2;
            var topsize = (screen.height - 290) / 2;
            var options = "width=800,height=290,scrollbars=no,left=" + leftsize + ",top=" + topsize;
            my_window = window.open(url, 'my_window', options);
            //my_window.moveTo((screen.width-560)/2,(screen.height-850)/2); 
            my_window.focus();
        }

function ShowImages(Counter, FieldName)
        {
            var url = "../Management/Management_Images.aspx?Counter=" + Counter + "&FieldName=" + FieldName;
            var leftsize = (screen.width-860)/2;
            var topsize = (screen.height-520)/2;
            var options = "width=860,height=520,scrollbars=no,left=" + leftsize + ",top=" + topsize;
            my_window=window.open(url,'my_window',options);
            //my_window.moveTo((screen.width-560)/2,(screen.height-850)/2); 
            my_window.focus();
        }
function ShowPrintOut(url)
        {
            var wscreen = 720;
            var hscreen = 650;
                        var leftsize = (screen.width-wscreen)/2;
            var topsize = (screen.height-hscreen)/2;
            var options = "width=" + wscreen + ",height=" + hscreen + ",left=" + leftsize + ",top=" + topsize;
            my_window=window.open(url,'my_window',options);
            my_window.focus();
        }

 function ShowOther(url) {
            var wscreen = 720;
            var hscreen = 650;
            var leftsize = (screen.width - wscreen) / 2;
            var topsize = (screen.height - hscreen) / 2;
            var options = "width=" + wscreen + ",height=" + hscreen + ",left=" + leftsize + ",top=" + topsize;
            window.open(url);

        }

function ShowWWH(url) {
            var wscreen = 980;
            var hscreen = 680;
            var leftsize = (screen.width - wscreen) / 2;
            var topsize = (screen.height - hscreen) / 2;
            var options = "width=" + wscreen + ",resizable=1, scrollbars=1, height=" + hscreen + ",left=" + leftsize + ",top=" + topsize;
            var options = "width=" + wscreen + ",height=" + hscreen + ",left=" + leftsize + ",scrollbars=1,resizable=1, top=" + topsize;
            window.open(url, 'WWH', options);

        } 
        
        
function ConfirmReservationCheck() {
    
       var chkbox1 = document.getElementById("ctl00$ContentPlaceHolder1$uxcbAgreeConditions"); 
       var chkbox2 = document.getElementById("ctl00$ContentPlaceHolder1$uxcbAgreeCancellation"); 
       var button = document.getElementById("ctl00$ContentPlaceHolder1$uxbtnConfirmReservation"); 
        
       if (chkbox1 && chkbox2) 
       { 
          if (chkbox1.checked && chkbox2.checked)
          button.disabled = false; 
          else
          button.disabled = true;
       } 
 
    }
    
function ShowMsg(Text) {

    var DivName = "MessageBox"
    if (document.getElementById(DivName).style.visibility == 'hidden') 
                            {
                                    var lbl = document.getElementById("ctl00_uxlblMsg");
                                    lbl.innerHTML = Text;
                                    document.getElementById(DivName).style.visibility = 'visible';
                            }
                else
                            {
                            document.getElementById(DivName).style.visibility = 'hidden';
                            }

}

function CheckKeyCode()
                            //onkeydown="return CheckKeyCode()"
{
    if (((event.keyCode == 190)|| (event.keyCode == 110)) && (field.value.indexOf('.')!==-1)) {
        
        return false;
        
        }
   if ( 
        
        (event.keyCode == 190) || 
        (event.keyCode == 110) ||
        (event.keyCode >= 48 && event.keyCode <= 57) || 
        (event.keyCode >= 96 && event.keyCode <= 105)  ||
        (event.keyCode == 8) ||
        (event.keyCode == 46) ||
        (event.keyCode >= 37 && event.keyCode <= 40) 
     )
      {
            return true; 
      }
  else 
      {
            return false;
      }
}

// ################################################
// Only Numeric FUNCTION
// ################################################

function OnlyNumeric(textbox, val){
val = val.replace(/[^0-9.-]/g, ''); // strip non-digit chars
val = stripDuplicateChars(val, '.', 1, 0); // strip excess decimals
val = stripDuplicateChars(val, '-', 0, 1); // strip excess minus signs
textbox.value = val; // replace textbox value
}
function stripDuplicateChars(str, strip, n, s){
var count=0; var stripped=str.substring(0, s); var chr;
for (var i=s; i<str.length; i++){ chr = str.substring(i, i+1);
if (chr == strip){ count++; if (count<n+1){ stripped = stripped +
chr;}}
else {stripped = stripped + chr;}} return stripped;
}


// ################################################
// Availability Table FUNCTIONS
// ################################################

function SetSelection(SelDate, SelRate, SelComments, SelProp, SelRT, SelNrRooms) {

    var SelDateDiv = document.getElementById(("uxdivSelectedDate" + SelProp));
    var SelRateDiv = document.getElementById(("uxdivSelectedRate" + SelProp));
    var SelCommentsDiv = document.getElementById(("uxdivSelectedComments" + SelProp));
    var SelRTDiv = document.getElementById(("uxdivSelectedRT" + SelProp));
    var SelRoomsDiv = document.getElementById(("uxdivSelectedRooms" + SelProp));
    var button1 = document.getElementById(("uxbtnReserveIT" + SelProp));
    
    SelDateDiv.innerHTML = SelDate;
    SelRateDiv.innerHTML = SelRate;
    SelCommentsDiv.innerHTML = SelComments;
    SelRTDiv.innerHTML = SelRT;
    SelRoomsDiv.innerHTML = SelNrRooms;
    button1.disabled = false;
       
}

function GoToReservations(SelProp) {

    var SelDateDiv = document.getElementById(("uxdivSelectedDate" + SelProp));
    var SelNrOfNightsDiv = document.getElementById(("uxdivSelectedNrOfNights" + SelProp));
    var SelAllotment = document.getElementById(("ctl00_ContentPlaceHolder1_uxcbViewAllotment"));
    var Str = '0';
    if (SelAllotment != null) {if (SelAllotment.checked) { Str = '1'; } }
    window.location = "be_availability.aspx?status=3&Prop=" + SelProp + "&date=" + SelDateDiv.innerHTML + "&Allot=" + Str + "&nights=" + SelNrOfNightsDiv.options[SelNrOfNightsDiv.selectedIndex].text;

}

function ShowAllotInv() {

    var date1 = document.getElementById("uxtxtDate1").value;
    var date2 = document.getElementById("uxtxtDate2").value;
    var property = document.getElementById("uxddlProperty").value;
    var GUID = document.getElementById("uxddlAllotments").value;
    
    var leftsize = (screen.width-880)/2
    var options = "width=880,height=720,scrollbars=yes,left=" + leftsize + ",top=0"
    var url = "Management_InventorySelection.aspx?date1=" + date1 + "&date2=" + date2 + "&property=" + property + "&AllotmentGUID=" + GUID
     my_window=window.open(url,'my_window',options);
    //my_window.moveTo((screen.width-560)/2,(screen.height-850)/2); 
    my_window.focus();
}

 
function toggleTB(){
                var boxke = document.getElementById("ctl00_ContentPlaceHolder1_uxcbSaveProfile");
                if(boxke.checked){
                    var Username = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtUsername");
                    Username.disabled=false;
                    Username.focus();
                    var Password = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtPassword");
                    Password.disabled=false;
                    var PasswordConf = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtPasswordConfirm");
                    PasswordConf.disabled=false;
                    }
                else{
                    var Username = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtUsername");
                    Username.disabled=true;
                    var Password = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtPassword");
                    Password.disabled=true;
                    var PasswordConf = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtPasswordConfirm");
                    PasswordConf.disabled=true;}
                
       }

      
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function ShowSortOrder(Element, DivName) {
    // capture the mouse position
    var obj = document.getElementById(Element);

    var posx = findPosX(obj); //left offsetLeft
    var posy = findPosY(obj); //top offsetTop

    if (document.getElementById(DivName).style.display == 'none') {
        document.getElementById(DivName).style.left = obj.x + "px";
        document.getElementById(DivName).style.top = obj.y + "px";
        document.getElementById(DivName).style.display = 'block';
    }
    else {
        document.getElementById(DivName).style.display = 'none';
    }
}     

function ShowDiv(Element,DivName) {
            // capture the mouse position
            var obj = document.getElementById(Element);

            var posx = findPosX(obj); //left offsetLeft
            var posy = findPosY(obj); //top offsetTop
                              
            if (document.getElementById(DivName).style.visibility == 'hidden') 
                        {
                            document.getElementById(DivName).style.left = posx + "px";
                            document.getElementById(DivName).style.top = posy + "px";  //obj.y + "px";
                            document.getElementById(DivName).style.visibility = 'visible';
                        }
            else
                        {
                        document.getElementById(DivName).style.visibility = 'hidden';
                        }
}

 

// ################################################
// DATE FUNCTIONS
// ################################################

function dateCheck(TextboxDate1Name, TextboxDate2Name, MayBeBeforeToday){

    var Startdate = new Date();
    var EndDate = new Date();
    var Today = new Date();
    
    if (TextboxDate1Name != 'no') 
        {
                var TxtBoxDate1 = document.getElementById(TextboxDate1Name);
                
            
                Startdate = Date.parseString(TxtBoxDate1.value, 'd/M/y');
                if (Startdate == null) {Startdate = Date.parseString(TxtBoxDate1.value, 'd.M.y');}
                if (Startdate == null) {Startdate = Date.parseString(TxtBoxDate1.value, 'dd/MM/yyyy');}
                if (Startdate == null) {Startdate = Date.parseString(TxtBoxDate1.value, 'd-M-y');}
                if (Startdate == null) {Startdate = Date.parseString(TxtBoxDate1.value, 'd/M');}
                if (Startdate == null) {Startdate = Date.parseString(TxtBoxDate1.value, 'd-M');}
                if (Startdate == null) {Startdate = Date.parseString(TxtBoxDate1.value, 'd.M');}
                if (Startdate == null) {Startdate = new Date();}
                
        }
   
    var TxtBoxDate2 = document.getElementById(TextboxDate2Name);
    if (TxtBoxDate2.value != "") 
        {
             EndDate = Date.parseString(TxtBoxDate2.value, 'd/M/y');
            if (EndDate == null) {EndDate = Date.parseString(TxtBoxDate2.value, 'd.M.y');}
            if (EndDate == null) {EndDate = Date.parseString(TxtBoxDate2.value, 'd-M-y');}
            if (EndDate == null) {EndDate = Date.parseString(TxtBoxDate2.value, 'd/M');}
            if (EndDate == null) {EndDate = Date.parseString(TxtBoxDate2.value, 'd-M');}
            if (EndDate == null) {EndDate = Date.parseString(TxtBoxDate2.value, 'd.M');}
            if (EndDate == null) 
                    {
                        var DateString = String(TxtBoxDate2.value) + "/" + String((Today.getMonth() + 1));
                        EndDate = Date.parseString(DateString, 'd/M');
                    }
                
            if (EndDate == null) 
                {
                    var PlusSign = TxtBoxDate2.value;
                    PlusSign = PlusSign.substring(0,1);

                    if (PlusSign == '+') 
                        {
                            var NumberDaysString = TxtBoxDate2.value;
                            NumberDaysString = NumberDaysString.substring(1, NumberDaysString.length);
                            var AddDays = Number(NumberDaysString);
                            EndDate = new Date();
                            
                            if (TextboxDate1Name != 'no')
                                {
                                    var x = new Date();
                                    x = Date.parseString(Startdate.format("dd/MM/yyyy"), 'dd/MM/yyyy'); 
                                    x.setDate(x.getDate()+ AddDays)
                                    EndDate = x;
                                    
                                }
                            else 
                                {
                                    EndDate.setDate(EndDate.getDate()+ AddDays);
                                }
                                
                            
                        }
                    else
                        {
                            EndDate = new Date();
                        }
                }
            
       }
       else
       {
        EndDate = new Date();
       }
   
   
        
    if (TextboxDate1Name != 'no')
        {
            if (Startdate >= EndDate)
                {
                    EndDate.setDate(Startdate.getDate()+ 1);
                }
            
            
        }
        
    
    if ((MayBeBeforeToday != 'yes') && (EndDate < Today))
        {
            EndDate.setDate(Today.getDate());
                       
        }
     
    TxtBoxDate2.value = EndDate.format("dd/MM/yyyy");
 }


Date.parseString = function(val, format) {
	// If no format is specified, try a few common formats
	if (typeof(format)=="undefined" || format==null || format=="") {
		var generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d','MMM-d','d-MMM');
		var monthFirst=new Array('M/d/y','M-d-y','M.d.y','M/d','M-d');
		var dateFirst =new Array('d/M/y','d-M-y','d.M.y','d/M','d-M');
		var checkList=new Array(generalFormats,Date.preferAmericanFormat?monthFirst:dateFirst,Date.preferAmericanFormat?dateFirst:monthFirst);
		for (var i=0; i<checkList.length; i++) {
			var l=checkList[i];
			for (var j=0; j<l.length; j++) {
				var d=Date.parseString(val,l[j]);
				if (d!=null) { 
					return d; 
				}
			}
		}
		return null;
	};

	this.isInteger = function(val) {
		for (var i=0; i < val.length; i++) {
			if ("1234567890".indexOf(val.charAt(i))==-1) { 
				return false; 
			}
		}
		return true;
	};
	this.getInt = function(str,i,minlength,maxlength) {
		for (var x=maxlength; x>=minlength; x--) {
			var token=str.substring(i,i+x);
			if (token.length < minlength) { 
				return null; 
			}
			if (this.isInteger(token)) { 
				return token; 
			}
		}
	return null;
	};
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var year=new Date().getFullYear();
	var month=1;
	var date=1;
	var hh=0;
	var mm=0;
	var ss=0;
	var ampm="";
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
		}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { 
				x=4;y=4; 
			}
			if (token=="yy") { 
				x=2;y=2; 
			}
			if (token=="y") { 
				x=2;y=4; 
			}
			year=this.getInt(val,i_val,x,y);
			if (year==null) { 
				return null; 
			}
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { 
					year=1900+(year-0); 
				}
				else { 
					year=2000+(year-0); 
				}
			}
		}
		else if (token=="MMM" || token=="NNN"){
			month=0;
			var names = (token=="MMM"?(Date.monthNames.concat(Date.monthAbbreviations)):Date.monthAbbreviations);
			for (var i=0; i<names.length; i++) {
				var month_name=names[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					month=(i%12)+1;
					i_val += month_name.length;
					break;
				}
			}
			if ((month < 1)||(month>12)){
				return null;
			}
		}
		else if (token=="EE"||token=="E"){
			var names = (token=="EE"?Date.dayNames:Date.dayAbbreviations);
			for (var i=0; i<names.length; i++) {
				var day_name=names[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
				}
			}
		}
		else if (token=="MM"||token=="M") {
			month=this.getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){
				return null;
			}
			i_val+=month.length;
		}
		else if (token=="dd"||token=="d") {
			date=this.getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){
				return null;
			}
			i_val+=date.length;
		}
		else if (token=="hh"||token=="h") {
			hh=this.getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){
				return null;
			}
			i_val+=hh.length;
		}
		else if (token=="HH"||token=="H") {
			hh=this.getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){
				return null;
			}
			i_val+=hh.length;
		}
		else if (token=="KK"||token=="K") {
			hh=this.getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){
				return null;
			}
			i_val+=hh.length;
			hh++;
		}
		else if (token=="kk"||token=="k") {
			hh=this.getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){
				return null;
			}
			i_val+=hh.length;
			hh--;
		}
		else if (token=="mm"||token=="m") {
			mm=this.getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){
				return null;
			}
			i_val+=mm.length;
		}
		else if (token=="ss"||token=="s") {
			ss=this.getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){
				return null;
			}
			i_val+=ss.length;
		}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {
				ampm="AM";
			}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {
				ampm="PM";
			}
			else {
				return null;
			}
			i_val+=2;
		}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {
				return null;
			}
			else {
				i_val+=token.length;
			}
		}
	}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { 
		return null; 
	}
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ 
				return null; 
			}
		}
		else { 
			if (date > 28) { 
				return null; 
			} 
		}
	}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { 
			return null; 
		}
	}
	// Correct hours value
	if (hh<12 && ampm=="PM") {
		hh=hh-0+12; 
	}
	else if (hh>11 && ampm=="AM") { 
		hh-=12; 
	}
	return new Date(year,month-1,date,hh,mm,ss);
};


function checkDate(sender,args)
{
 var today = new Date();
 today.setHours(0,0,0,0);
  if (sender._selectedDate < today) 
            {
                var Languages = document.getElementById("ctl00_uxddlLanguages");
                var UserLang = Languages.options[Languages.selectedIndex].value;
                if (UserLang == 1) {
                         ShowMsg("You cannot select a day earlier than today!");
                        }
                else if (UserLang == 2) {
                         ShowMsg("Vous ne pouvez pas sélectionner une date avant aujourd'hui!!");
                        }
                else if (UserLang == 3) {
                         ShowMsg("You cannot select a day earlier than today!");
                        }
                else if (UserLang == 4) {
                         ShowMsg("U kan geen datum kiezen uit het verleden!!");
                        }
                else if (UserLang == 5) {
                         ShowMsg("You cannot select a day earlier than today!!");
                        }
                else {
                         ShowMsg("You cannot select a day earlier than today!");
                        }
                
                sender._selectedDate = new Date(); 
                // set the date back to the current date
                sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            }
 else
    {
        var datestring = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtAvailDate1").value;
        var newDate = Date.parseString(datestring, "dd/M/yyyy");
        newDate.setDate(newDate.getDate()+1);
        var newValue = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtAvailDate2");
        newValue.value = newDate.format("dd/MM/yyyy");

    }
    
    onSelectedStartDate(sender, args);

}

function onSelectedStartDate(sender, args) {
    var datestring = document.getElementById("ctl00_ContentPlaceHolder1_uxtxtAvailDate1").value;
    var newDate = Date.parseString(datestring, "dd/M/yyyy");
    newDate.setDate(newDate.getDate() + 1);
    $find("endDate").set_selectedDate(newDate);
}


