var ChildWindow;

function Popup(){
	var LeftPosition = (screen.width/2) - 200;
	var TopPosition = (screen.height/2) - 60;
	window.open("popup.html", "popup", "width=400,height=120,toolbar=no,header=no,location=no,resizable=0,"+"left="+LeftPosition +",top="+TopPosition+",scrollbars=0");
}

function password(){
  	window.open("forgottenpassword.aspx", "", "width=300,height=350,scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
}
	
function changeImage(image){	
	document.getElementById("imageHolder").src = "hostelimages/" + image;	
}

function openWin(){
 	window.open("warning_help.html", "Help", "width=250,height=250,scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
}

function openWinRoomTypes(){
 	window.open("help_roomtypes.htm", "Help", "width=720,height=200,scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
}

function showreceipt(invoice, hostel, base){
    var url=base+'/receipt.aspx?iid='+invoice+'&hid='+hostel;
    window.open(url, "receipt", "width=690,height=600,toolbar=no,header=no,location=no,resizable=0,scrollbars=yes");	
}

function showMap(hostel){
    var url='/map.aspx?hid='+hostel;
    window.open(url, "map", "width=690,height=460,toolbar=no,header=no,location=no,resizable=0,scrollbars=yes");	
}

function showterms(invoice, base){
    var url=base+'/terms.aspx?iid='+invoice;
    window.open(url, "", "width=690,height=600,toolbar=no,header=no,location=no,resizable=0,scrollbars=yes");	
}

function GetDate(CtrlName)
{
    var w_top = 350;
    var w_left = 5;
    var date_in = "";
    var date_out = "";

    date_in = document.frm_booking.be_date_in.value;
    date_out = document.frm_booking.be_date_out.value;

    ChildWindow = window.open('/Calendar.aspx?FormName=frm_booking&CtrlName=' + CtrlName + "&DateIn=" + date_in + "&DateOut=" + date_out, "PopUpCalendar", "width=220,height=280,top=" + w_top + ",left=" + w_left + ",menubar=no,scrollbars=no,status=no,titlebar=no,resizable=no,toolbar=no");
}

function CheckWindow()
{
    if (ChildWindow != null)
    {
        ChildWindow.close();
    }
}


var globalKeyCode;    
var currentFieldid, currentFieldMaxLength, nextFieldid;

var TAB_KEY = 9;
var BACK_TAB_KEY = 16;
var ONE_MILLISECOND = 1;

function registerTemporaryFocusControl( ctrlid ) {
    TemporaryFocusControl = ctrlid;
}         

function fieldAdvance( ctrl, ctrlToFocusid ) {
    var ctrlToFocus = getControl( ctrlToFocusid ); 

    this.currentFieldid         = ctrl.id;
    this.currentFieldMaxLength  = ctrl.maxLength;
    this.nextFieldid            = ctrlToFocusid;        

    if ( ( globalKeyCode != TAB_KEY ) && ( globalKeyCode != BACK_TAB_KEY ) ) {
        document.getElementById( 'autotab' ).focus();
        setTimeout( 'checkFieldLength()', ONE_MILLISECOND );
    }            
}         

function checkFieldLength() {
    var x = document.getElementById( currentFieldid ).value.length;
    var y = currentFieldMaxLength;

    if ( document.getElementById( this.currentFieldid ).value.length ==
                                            this.currentFieldMaxLength ) {
        document.getElementById( this.nextFieldid ).focus();
        document.getElementById( this.nextFieldid ).select();
    }    
    else {
        document.getElementById( this.currentFieldid ).focus();            
    }    
}    

function getControl( ctrlid ) {
    var ctrl = document.getElementById( ctrlid );

    if ( ! ctrl ) {
        alert( "Fatal JavaScript error: " + ctrlid + " was not found!" );
    }
    return ctrl 
}         

function catchGlobalKeyStroke( e ) {
    globalKeyCode  = e.keyCode;  
}  
function initialSetUp(){
    setTimeout('createMapFrame()', 100); 
}

function createMapFrame() { 
    
    var mapFrame = document.getElementById('map_frame'); 
   
    mapFrame.src = "/google_map_frame.aspx"; 
    showTab('tab_displays', 'area_div', document.getElementById('area_tab')) 
    setTimeout(function(){window.location='#'},100);
   
    
}
var mapActive=false;
function showTab(holder, toShow, clicked, fromChild){

showDiv(holder,toShow);
var tabs = document.getElementById(clicked.parentNode.id).getElementsByTagName(clicked.tagName);
 for (var i = 0; i < tabs.length; i++) {
    if(tabs[i] == clicked){
            tabs[i].className='tab_open';
            if(!fromChild){
                if(tabs[i].id=='map_tab'){
                    mapActive=true;
                }else if(tabs[i].id=='area_tab'){
                    mapActive=false;
                }
            }
    }else{
        if(tabs[i].parentNode == clicked.parentNode){
            tabs[i].className='tab_closed';
        }        
    }
 }
}

function showDiv(holderDiv,divToShow){
 	var divs=document.getElementById(holderDiv).getElementsByTagName('div');
 	 for (var i = 0; i < divs.length; i++) {
		if(divs[i].id==divToShow){			
			divs[i].style.display = '';
			 divs[i].style.top = divs[i].style.height * -1;
		}else{
			if(divs[i].parentNode.id == holderDiv){
			    divs[i].style.display = 'none';
			   
			}
		}
	}
}