// adds right trim function to javascript string object e.g: txtName.value.Rtrim()
String.prototype.Rtrim = function(){return RTrim(this);}
// adds left trim function to javascript string object e.g: txtName.value.Ltrim()
String.prototype.Ltrim = function(){return LTrim(this);}
// adds trim function to javascript string object e.g: txtName.value.trim()
String.prototype.trim = function(){return Trim(this);}

function BrowserInfo() { 
    var agent = navigator.userAgent.toLowerCase(); 
    this.major = parseInt(navigator.appVersion); 
    this.minor = parseFloat(navigator.appVersion); 
    this.op = (agent.indexOf("opera")!= -1); 
} 
var is = new BrowserInfo(); 

/*--------------------------------------------------------------
Common
---------------------------------------------------------------*/

function SetBGColorObj(ctr, c)
{
    if (ctr && ctr.value.length>0)
    {ctr.style.background=c;}
}
function SetBGColor(controlID,color)
{
	//alert(controlID);
	var ctr=document.getElementById(controlID)	;
	if(ctr && ctr.value.length>0)
	{		
		ctr.style.background=color;
	}	
}

/*--------------------------------------------------------------
Dimension
---------------------------------------------------------------*/

function GetBodyWidth(){
    var fWidth;    
    if(document.all) 
    {         
        fWidth = document.body.clientWidth; 
    } 
    else if(document.getElementById) 
    {       
        fWidth = document.width;        
    } 
    else if (is.op) 
    { 
        fWidth = innerWidth; 
    } 
    else if (document.layers) 
    { 
        fWidth = window.innerWidth; 
    }
    return fWidth;
}

function GetBodyHeight(){
    var fHeight; 

    if(document.body.clientHeight) 
    { 		                        
        fHeight = document.body.clientHeight;                      
    } 
    else if(document.getElementById) 
    { 
        fHeight = document.height; 
    } 
    else if (is.op) 
    { 
        fHeight = innerHeight; 
    } 
    else if (document.layers) 
    { 
        fHeight = window.innerHeight; 
    }
    return fHeight;	
}

function GetFrameWidth(){
    var frameWidth = 800;
    if (self.innerWidth)
    {	
	    frameWidth = self.innerWidth;
    }else if (document.documentElement && document.documentElement.clientWidth)
    {
    	frameWidth = document.documentElement.clientWidth;
    }
    else if (document.body)
    {
        frameWidth = document.body.clientWidth;
    }   
    return (frameWidth-16);
}

function GetFrameHeight(){
	    var frameHeight = 600;
	    if (self.innerHeight)
	    {
	        frameHeight = self.innerHeight;
	    }
	    else if (document.documentElement && document.documentElement.clientHeight)
	    {
	        frameHeight = document.documentElement.clientHeight;
	    }
	    else if (document.body)
	    {
	        frameHeight = document.body.clientHeight;
	    }
	    //alert(frameHeight-16);
	    return (frameHeight-16);
}

/*--------------------------------------------------------------
Funzioni ClientServerVisibilityDiv
---------------------------------------------------------------*/

function SwapVisibility(control){
    var element = document.getElementById(control);

    if (element != null &&
        element != undefined){
        if (element.style.display != 'block')
            element.style.display = 'block';
        else
            element.style.display = 'none';
    }
    
    return false;
}

function ShowHideElement(control, visible) {
    var element = document.getElementById(control);
    if (element && element.style)
    {
        element.style.display = visible ? "block" : "none";
    }
}

function IsVisible(control){
    var element = document.getElementById(control);
    if (element != null &&
        element != undefined){
        if (element.style.display== '' || element.style.display == 'block')
            return true;
    }
    return false;
}

/*--------------------------------------------------------------
CruiseFinder
---------------------------------------------------------------*/

function FromArrayToDate(dateArray){
    var retDate = null;
    try {
        if (dateArray && dateArray.length && dateArray.length >= 3) {
            var testDate = new Date(dateArray[0], dateArray[1]-1, dateArray[2], 0, 0, 0);
            if (testDate.constructor==Date && 
		dateArray[0] == testDate.getFullYear() &&
		dateArray[1] == (testDate.getMonth() + 1) &&
		dateArray[2] == testDate.getDate()) {
		retDate = testDate;
	    }
	}
    } catch (e) { retDate = null; }
    return retDate;
}

function isDate(dateArray, min, max){
	if (!min && !max )
    		return (FromArrayToDate(dateArray) != null);
	else {
		var current = FromArrayToDate(dateArray);
		var minDate = FromArrayToDate(min); 
		var maxDate = FromArrayToDate(max);             
		return (current && minDate && maxDate && current >= minDate && current <= maxDate);
	}
		
}

/*--------------------------------------------------------------
WindowManager
---------------------------------------------------------------*/

function UseWindowManager(windowName, url, width, height)
{
    //alert(url);
    //Getting rad window manager
    var oManager = GetRadWindowManager();
    //Success. Getting existing window DialogWindow using GetWindowByName
    var oWnd = oManager.GetWindowByName(windowName);
    

    //Success. Setting a size and a Url to the window using its client API before showing
    oWnd.SetSize(width, height);    
    oWnd.SetUrl(url);
    //Success. Opening window
    oWnd.Show();
    oWnd.Center();

    //Success. Calling window RadWindowManager.GetActiveWindow (should return reference to current window
    var oActive = oManager.GetActiveWindow();
    //Success. Is current visible window the active one? " + (oActive != null && oActive == oWnd)    
}

function UseStandardWindowManagerPopUpParams( url, popUpParams)
{
    var width = 200
    var height = 200
    if (popUpParams != '')
    {        
        var arrParams = popUpParams.split(',')       
        if (arrParams != null && arrParams.length >0)
        {
            for (x in arrParams)
            {
               var nameValueParam = arrParams[x].split('=');
               if (nameValueParam != null && nameValueParam.length >0)
               {
                    if (nameValueParam[0].toLowerCase()  == 'height')
                    {
                        height = nameValueParam[1];
                    }
                    else if (nameValueParam[0].toLowerCase()  == 'width')
                    {
                        width = nameValueParam[1];
                    }
               }
            }
        }
    }    
    UseWindowManager('rwstd', url, width, height);
}

function UseStandardWindowManager( url, width, height)
{
    UseWindowManager('rwstd', url, width, height);
}

/*--------------------------------------------------------------
Funzioni modalWindow modale
---------------------------------------------------------------*/

var modalWindowArray=new Array();
var modalDivArray=new Array();

function ModalWindowArrayItem(modalWindow)
{
    this.id = modalWindow.id;
    this.modalWindow = modalWindow;
}

function ModalDivArrayItem(modalDiv, heightModalDiv, widthModalDiv)
{
    this.id = modalDiv.id;
    this.modalDiv = modalDiv;
    this.heightModalDiv = heightModalDiv;
    this.widthModalDiv = widthModalDiv;
}

function ShowModal(modalWindowId, modalDivId, excludeHidePrefix, grayed, zIndexModalWindow, zIndexModalDiv, centerModalWindow, centerModalWindowOnScroll, heightModalDiv, widthModalDiv, posModalWindowOnModal)
{ 

    //modalWindow, modalDiv
    var modalWindow = document.getElementById(modalWindowId);
    var modalDiv = document.getElementById(modalDivId);  
    
    //add to array 
    var modalWindowArrayItem = new ModalWindowArrayItem(modalWindow);
    AddToArray(modalWindowArrayItem, modalWindowArray);                           
    var modalDivArrayItem = new ModalDivArrayItem(modalDiv, heightModalDiv, widthModalDiv);
    AddToArray(modalDivArrayItem, modalDivArray);                           

    //centerModalWindow
    if(centerModalWindow==true || centerModalWindowOnScroll==true)
    {
        CenterModalWindow(modalWindow);
    }
    if(centerModalWindowOnScroll==true)
    {
        //SetOnScrollEvent
        SetOnScrollEvent(modalWindow);
    }

    //modalWindow
    if(modalWindow)
    {
        modalWindow.style.position = posModalWindowOnModal;
        modalWindow.style.zIndex = zIndexModalWindow; 
    }

    //modalDiv  
    ResizeModalDiv(modalDiv, heightModalDiv, widthModalDiv);
    if(modalDiv)
    {
        modalDiv.style.display = 'block';
        modalDiv.style.zIndex = zIndexModalDiv;
    }
    if(grayed)
    {
        modalDiv.style.background = 'gray';
        SetOpacity(modalDiv,50);
    }
    HideControls(excludeHidePrefix);
    
    //window.onresize
    window.onresize = ResizeModalDivOnWindowResize;  
    
}

function HideModalSynch()
{  
    var modalWindowArrayTmp=new Array();
    var modalDivArrayTmp=new Array();
    
    //copy
    var i=0;
    for(i=(modalWindowArray.length-1);i>=0;i--)
    {
        modalWindowArrayTmp.push(modalWindowArray[i]);
        modalDivArrayTmp.push(modalDivArray[i]);
    }
    
    //HideModal
    var modalDivTmp;
    for(i=(modalDivArrayTmp.length-1);i>=0;i--)
    {
        modalDivTmp = document.getElementById(modalDivArrayTmp[i].id);
        if(!modalDivTmp || modalDivTmp.style.display == 'none')
        {
            HideModal(modalWindowArrayTmp[i].id, modalDivArrayTmp[i].id);
        }
    }
    
}

function HideModal(modalWindowId, modalDivId)
{  

    //se l'ho già rimosso, niente
    if(!FindInArrayById(modalDivId,modalDivArray))
    {
        //alert(modalWindowId);
        return;
    }
    
    //modalWindow, modalDiv
    //alert(modalWindowId);     
    var modalWindow = document.getElementById(modalWindowId);   
    //alert(modalWindow);  
    //alert(modalDivId);                             
    var modalDiv = document.getElementById(modalDivId);
    //alert(modalDiv);
    
    //remove from array
//    if(modalWindow)
//    {
        RemoveFromArrayById(modalWindowId, modalWindowArray); 
//    }
//    if(modalDiv)
//    {      
        RemoveFromArrayById(modalDivId, modalDivArray);  
//    }

    //rimuovo scroll event
    RemoveOnScrollEvent(modalWindow);

    //modalWindow
    if(modalWindow)
    {
        modalWindow.style.zIndex = '1'; 
        modalWindow.style.position = 'static';
    }
                            
    //modaldiv
    if(modalDiv)
    {
        modalDiv.style.display = 'none';
    }
    ShowControls();

}

function ResizeModalDivOnWindowResize()
{
    //alert('ResizeModalDivOnWindowResize');
    var i;
    for (i in modalDivArray)
    {
        ResizeModalDiv(modalDivArray[i].modalDiv,modalDivArray[i].heightModalDiv,modalDivArray[i].widthModalDiv)
    }
}

function ResizeModalDiv(modalDiv, heightModalDiv, widthModalDiv)
{
    if(modalDiv)
    {
        //alert(modalDiv.id + ' ' + GetBodyHeight() + ' ' + GetBodyWidth())
        
        //height
        if(heightModalDiv=='body')
        {
            //alert(GetBodyHeight());
            modalDiv.style.height = GetBodyHeight() + 'px'; 
        }
        else if(heightModalDiv=='client')
        {
            modalDiv.style.height = GetFrameHeight() + 'px'; 
        }
        
        //width
        if(widthModalDiv=='body')
        {
            modalDiv.style.width = GetBodyWidth() + 'px'; 
        }
        else if(widthModalDiv=='client')
        {
            modalDiv.style.width = GetFrameWidth() + 'px'; 
        }
        
    }
}

function CenterModalWindow(modalWindow) 
{
    //height, width
    if (modalWindow) {
        modalWindow.style.height = GetFrameHeight() + "px";
        modalWindow.style.width = GetFrameWidth() + "px";
        modalWindow.style.top = GetTopOffset() + "px";
    }
}

//var divToScroll;
var modalWindowToScrollArray=new Array();
function SetOnScrollEvent(modalWindow)
{
    if(modalWindow)
    {
        var modalWindowArrayItem = new ModalWindowArrayItem(modalWindow);
        AddToArray(modalWindowArrayItem, modalWindowToScrollArray); 
    }
    window.onscroll = CenterModalWindowOnScroll;
}
function RemoveOnScrollEvent(modalWindow)
{
    if(modalWindow)
    {
        RemoveFromArrayById(modalWindow.id, modalWindowToScrollArray);
    }
    if(modalWindowToScrollArray.length==0)
    {
        window.onscroll = null;
    }
}
function CenterModalWindowOnScroll() {

      //alert('CenterModalWindowOnScroll');
      if(modalWindowToScrollArray.length==0 || modalWindowArray.length==0)
      {
        return;
      }
      
      var lastModalWindow = modalWindowArray[modalWindowArray.length-1].modalWindow;
      //alert(lastModalWindow);
      if(!lastModalWindow)
      {
        return;
      }      
      var lastModalWindowToScroll = modalWindowToScrollArray[modalWindowToScrollArray.length-1].modalWindow;
      //alert(lastModalWindowToScroll);  
      if(!lastModalWindowToScroll)
      {
        return;
      }
      
      //faccio scrollo solo se è l'ultima finestra modale aggiunta
      //alert(modalWindowArray.length);
      //alert(modalWindowToScrollArray.length);
      //alert(lastModalWindow.id);
      //alert(lastModalWindowToScroll.id);
      if(lastModalWindow.id.indexOf(lastModalWindowToScroll.id)==-1
         && lastModalWindowToScroll.id.indexOf(lastModalWindow.id)==-1)
      {
        return;
      }

      var onScrollFunctionTmp = window.onscroll;
      window.onscroll = null;
      lastModalWindowToScroll.style.top = GetTopOffset() + "px";
      window.onscroll = onScrollFunctionTmp;
     
}

function GetTopOffset()
{
      //currentOffset
      var currentOffset;
      if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
            var oBody = document.body;   
            var oDoc = document.documentElement;   
            currentOffset = oBody.scrollTop > oDoc.scrollTop ? oBody.scrollTop  : oDoc.scrollTop;   
      }
      else {
            currentOffset = window.pageYOffset;
      }
      return currentOffset;
}

function HideControls(excludeHidePrefix)
{ 
    //alert('HideControls');
    for (var i=0; i<document.forms[0].elements.length; i++)
    { 
        var obj = document.forms[0].elements[i];
        if (obj && obj.type && obj.type.indexOf('select')>-1)
        {   
            if(excludeHidePrefix==null || obj.id.indexOf(excludeHidePrefix)==-1)
            {
                if(obj.style)
                {
                    obj.style.visibility = 'hidden';
                }
                else
                {
                    obj.visibility = 'hide';
                }
            }
        }
    }    
}

function ShowControls()
{
    for (var i=0; i<document.forms[0].elements.length; i++)
    {            
        var obj = document.forms[0].elements[i]; 
        if (obj && obj.type && obj.type.indexOf('select')>-1)
        {
            if(obj.style){
                obj.style.visibility = 'visible';
            }
            else
            {
                obj.visibility = 'show';
            }
        }
    } 
}

/*
function SetOpacity(n,v){
    var ie = (document.all) ? 1 : 0;
    var p = (ie) ? 'filter' : 'MozOpacity';

    // n is the element node
    //   v is the opacity value, from 0 to 100.
    v = (ie) ? 'alpha(opacity='+v+')' : v/100;
    n.style[p] = v;
}*/

function SetOpacity(obj, opacity) {

  opacity = (opacity == 100)?99.999:opacity;

  // IE/Win
  obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+ opacity + ");";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function AddToArray(obj, array)
{
    if(!obj)
    {
        return;
    }
    if(!FindInArrayById(obj.id,array))
    {
        array.push(obj);
    }
}

function RemoveFromArrayById(id, array)
{
//    if(!obj)
//    {
//        return;
//    }
    var i;
    //alert(obj.id);
    for (i in array)
    {
        
        //alert(array[i].id);
        if(array[i].id==id)
        {
            array.splice(i,1);
            break;
        }
    }
}

function FindInArrayById(id, array)
{
    var obj;
    var i;
    for (i in array)
    {
        if(array[i].id==id)
        {
            obj = array[i];
            break;
        }
    }
    return obj;
}

/*--------------------------------------------------------------
Trim
---------------------------------------------------------------*/

// Left trim
function LTrim(value) {	
	var RegX = /\s*((\S+\s*)*)/;
	return value.replace(RegX, "$1");	
}
// Right trim
function RTrim(value) {
	var RegX = /((\s*\S+)*)\s*/;
	return value.replace(RegX, "$1");
}
// Left and right trim
function Trim(value) {
	return LTrim(RTrim(value));
}

/*--------------------------------------------------------------
Hotel Form
---------------------------------------------------------------*/
function HandleClientDropDownOpening(comboBoxId, phUniqueId, ajaxMgrId) 
{ 
    var comboBox = document.getElementById(comboBoxId);
    if(comboBox.options==null || comboBox.options.length==0 || 
       (comboBox.options.length==1 && comboBox.options[0].value=='load'))
    {
        eval(ajaxMgrId + ".AjaxRequestWithTarget(phUniqueId, 'LoadHotels')");
        return false;   
    }  
}

/*--------------------------------------------------------------
miscellaneous: usefull for fields custom validation

Ahmed Djobby
2007.01.17
---------------------------------------------------------------*/
// Numeric input validation
function isValidNumeric(ElementValue){        
    var pattern = '^[0-9]+$';    
   
    return ValidateInputData(ElementValue, pattern);
}
// Name input validation
function isValidName(ElementValue){        
    var pattern = "/^[a-zA-Z-À-Ü-ß-ü\s\-\']+$/";
   
    return ValidateInputData(ElementValue, pattern);
}
// Validate Input using the specified RegEx pattern
function ValidateInputData(theValue, thePattern){        
    var RegX = new RegExp(thePattern);
    var result = false;
    
    if (theValue &&
        theValue.trim().length > 0 &&
        RegX.test(theValue)){
        result = true;
    }

    return result;
}
// Validate Input minimum length
function isValidMinInputLength(ElementValue, l){
    var result = false;
    
    // l = 0 or null assumes that no control is needed
    if (l &&
        l > 0){
        if (ElementValue &&
            ElementValue.length >= l)
            result = true;
    }
    else
        result = true;
    
    return result; 
}
// Validate Input maximum length
function isValidMaxInputLength(ElementValue, l){
    var result = false;
    
    // l <= 0 or null assumes that no control is needed
    if (l &&
        l > 0){
        if (ElementValue &&
            ElementValue.length <= l)
            result = true;
    }
    else
        result = true;
        
    return result; 
}
// Validate Input length
function isValidInputLength(ElementValue, min, max){   
    return (isValidMinInputLength(ElementValue, min) && isValidMaxInputLength(ElementValue, max));        
}
function isEmpty(theElement){
    return theElement.value.length == 0;
}
/*--------------------------------------------------------------
---------------------------------------------------------------*/
// Javascript to compute elapsed time between "Start" and "Finish" button clicks
function timestamp_class(this_current_time, this_start_time, this_end_time, this_time_difference) { 
		this.this_current_time = this_current_time;
		this.this_start_time = this_start_time;
		this.this_end_time = this_end_time;
		this.this_time_difference = this_time_difference;
		this.GetCurrentTime = GetCurrentTime;
		this.StartTiming = StartTiming;
		this.EndTiming = EndTiming;
	}

	//Get current time from date timestamp
	function GetCurrentTime() {
	var my_current_timestamp;
		my_current_timestamp = new Date();		//stamp current date & time
		return my_current_timestamp.getTime();
		}

	//Stamp current time as start time and reset display textbox
	function StartTiming() {
		this.this_start_time = GetCurrentTime();	//stamp current time		
		}

	//Stamp current time as stop time, compute elapsed time difference and display in textbox
	function EndTiming() {
		this.this_end_time = GetCurrentTime();		//stamp current time
		this.this_time_difference = (this.this_end_time - this.this_start_time);	//compute elapsed time		
		}

var time_object = new timestamp_class(0, 0, 0, 0);	//create new time object and initialize it

function LDP_OnChange(txtDayID, txtMonthID, txtYearID, allowEmpty, divID, minArrayDate, maxArrayDate)
{
    var isValid = LDP_IsValid(txtDayID, txtMonthID, txtYearID, allowEmpty, divID, minArrayDate, maxArrayDate); 
    if (isValid)
    {
        ShowHideElement(divID, false); 
    }
    else
    {
        ShowHideElement(divID, true);
    }
}

function LDP_IsValid(txtDayID, txtMonthID, txtYearID, allowEmpty, divID, minArrayDate, maxArrayDate)
{
    var txtDay = document.getElementById(txtDayID);
    var txtMonth = document.getElementById(txtMonthID);
    var txtYear = document.getElementById(txtYearID);
    
    var ValidChars = "^[0-9]+$";
    var isValid = true;
    var SettingDate = false;
    
    var dateArray = new Array();
    if ((txtYear.value == null && txtMonth.value == null && txtDay.value == null) ||
            (txtYear.value.length == 0 && txtMonth.value.length == 0 && txtDay.value.length == 0))
    {
        if (allowEmpty)
        {            
            ShowHideElement(divID, false);               
            return true;
        }
        else
        {            
            ShowHideElement(divID, true);                        
            return false;
        } 
    }
    else
    {
       if ((txtYear.value == null || txtMonth.value == null || txtDay.value == null)||
                (txtYear.value.length == 0 || txtMonth.value.length == 0 || txtDay.value.length == 0))
       {
            if (allowEmpty)
            {
                ShowHideElement(divID, false);
                return true;            
            }
            else
            {                
                ShowHideElement(divID, true);
                return false; 
            }                
       }   
       if (txtYear.value.search(ValidChars)<0 || txtMonth.value.search(ValidChars)<0 || txtDay.value.search(ValidChars)<0)   
       {            
            return false;            
       }
       else
       {
            dateArray[0] = parseInt(txtYear.value);    
            dateArray[1] = parseInt(txtMonth.value, 10);            
            if (dateArray[1] < 10 &&
                txtMonth.value.length < 2)
                txtMonth.value = '0' + txtMonth.value;
            
            dateArray[2] = parseInt(txtDay.value, 10);              
            if (dateArray[2] < 10 &&
                txtDay.value.length < 2)
                txtDay.value = '0' + txtDay.value;              
            if (!isDate(dateArray, minArrayDate, maxArrayDate))
            {                
                return false;
            }           
       }
    }
    return true    
}
function GetCoords()
    {
      var scrollX, scrollY;
      d = document;
      if (d.all)
      {             
         dE = d.documentElement;
         if (!dE.scrollLeft)
            scrollX = d.body.scrollLeft;
         else
            scrollX = dE.scrollLeft;
               
         if (!dE.scrollTop)
            scrollY = d.body.scrollTop;
         else
            scrollY = dE.scrollTop;
      }   
      else
      {
         scrollX = window.pageXOffset;
         scrollY = window.pageYOffset;
      }
      if (d.getElementById('xCoordHolder'))
        d.getElementById('xCoordHolder').value = scrollX;
      if (d.getElementById('yCoordHolder'))
        d.getElementById('yCoordHolder').value = scrollY;
    }

    function Scroll(){
        d = document;                
        if (d){                   
            var x = null;
            var y = null;
            
            x = d.getElementById('xCoordHolder');
            y = d.getElementById('yCoordHolder');   

            if (x){
                x = x.value;
                if (y){
                    y = y.value;

                    if (x && y)
                        window.scrollTo(x, y);     
                }
            }
        }            
    }  
               
var AjaxIsActive = false;
function PM_RS(sender, arguments)
{   
    //alert('PM_RS');
    
    //Nella versione b5 di firefox non scatta l'evento RP_RE
    //che resetta la variabile AjaxIsActive.
    if(navigator.userAgent.indexOf("Firefox/3.0") == -1){
        if (!AjaxIsActive)
            {AjaxIsActive = true;}
         else
            {alert(AjaxRequestAlreadyInProgress);
             return false;} 
    }                                
    window.status = window.status + "Request starting";
    return true;}
function PM_S(sender, arguments)
{
     //alert('PM_S');
     GetCoords();
     aE = arguments.EventTargetElement
     window.status = window.status + ", Request sent";
     document.body.style.cursor = 'progress';
     if(aE && aE.type == "select-one")
        window.focus();            
}
function PM_RR(sender, arguments)
{
    //alert('PM_RR');
    window.status = window.status + ", Request received";            
}
function RP_RE(sender, arguments)
{
    //alert('RP_RE');
    AjaxIsActive = false;        
    if (arguments){
        aE = arguments.EventTargetElement;         
        if(aE && aE.type == "select-one")
            aE.focus();   
    }
    window.status = "";                
    document.body.style.cursor = 'default';                
    Scroll();  
}    
function RP_RequestError(sender, e)
{
    alert("Status code: " + e.Status);
    alert("ResponseText: " + e.ResponseText);
    alert("ResponseHeaders: " + e.ResponseHeaders);
//    if(e.ResponseText!=null && e.ResponseText.indexOf("SessionExp")>-1)
//    {
//        window.location.href=e.ResponseText;
//    }
}

// Focuses an anchor : Uses to give client side focus to a usercontrol if its validation has failed
function FocusErrors(anchorName){	
    var anchorsArray = null;
    
    if (anchorName &&
        anchorName.constructor == String && anchorName.length > 0)        
        anchorsArray = document.getElementsByName(anchorName);
    else
	    anchorsArray = document.getElementsByName("ErrorAnchor");
	
	
	if (anchorsArray &&
		anchorsArray.length > 0 && anchorsArray[0]){
		var anch = anchorsArray[0];
		alert(anch.id);
		anch.focus();
	}		
}
function SetFocusErrors(anchorName){
    SetFocus(anchorName);
}
function SetFocus(el){    
    if (el){
        var element = document.getElementById(el);
        
        if (element){
            var f = document.getElementById("__LASTFOCUS");
            if (f)               
                f.value = el;
            
            element.focus(); 
            ScrollToElement(el);           
        }
    }
}
// Scrolls to an html element relatively to a reference element
function ScrollToElement(ref, el){
    var shift = 0;
    
    if (el){         
        var element = document.getElementById(el);
        var refElement;
        
        if (element){       
            var xh = document.getElementById('xCoordHolder');
            var yh = document.getElementById('yCoordHolder');              
            var offset;            
            
            if (ref){
                refElement = document.getElementById(ref);

                if (refElement)
                    offset = GetYDiff(refElement, element);  
                else
                    offset = GetElementY(element);
            }
            else
                offset = GetElementY(element);
            
            if (offset)
                offset += shift;
            else
                offset = 0;
                
            if (yh)                
                yh.value = offset + shift;                                                              
            
            scrollBy(0, offset);  
        }         
    }
}
// Finds The Absolute Exact Position of an HTML Element
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
// Gets The Offset of the Element Relatively to The Current Position of the Window
function GetElementY(element){
    return GetYDiff(window, element)
}
// Gets the Y Distance Between 2 Elements
function GetYDiff(element1, element2){
    var result = 0;
    
    if (element1 && element2){
        var y1;
        var y2;
                
      	if (element1 == window)      	    
      		y1 = 0;
      	else
      		y1 = findPos(element1)[1];
      		      	
      	y2 = findPos(element2)[1]; 
      	                     	
        result = y2 - y1;
    }
    
    return result;    
}

//----------------------------------- ACTIVE CONTENT SCRIPTS
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_GenerateObjectString(objAttrs, params, embedAttrs){
    var str = '<object ';
    
    for (var i in objAttrs)
        str += i + '="' + objAttrs[i] + '" ';
        
    str += '>';
    
    for (var i in params)
        str += '<param name="' + i + '" value="' + params[i] + '" /> ';
        
    str += '<embed ';
    
    for (var i in embedAttrs)
        str += i + '="' + embedAttrs[i] + '" ';
        
    str += ' ></embed></object>';
    
    return str;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var strObj = AC_GenerateObjectString(objAttrs, params, embedAttrs);
        
    document.write(strObj);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_FL_GetContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return AC_GenerateObjectString(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        //args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
//-----------------------------------

// ----------------------------------
// Reservations JS
//
// Ahmed Djobby, 2009.06.04
// ----------------------------------
function AskForConfirmation(message){
    if (message &&
        message != ''){
        return confirm(message);
    }
    
    return true;
}

function GiveFocus(elementID){
    if (elementID){
        var element = document.getElementById(elementID);
        
        if (element){
            var scrollPositionY = document.getElementById("__SCROLLPOSITIONY");
            
            if (scrollPositionY){
                var elementCoords = findPos(element);
                
                if (elementCoords &&
                    elementCoords.constructor == Array &&
                    elementCoords.length == 2) {
                    scrollPositionY.value = elementCoords[1];
                }
            }
        }
    }
}

function SwapGuestReservationContainer(
    elementID,    
    imageID,
    sExpandImagePath, 
    sCollapseImagePath,
    hfStateID){
    ExpandCollapseGuestReservationContainer(
        elementID,
        imageID,
        !IsVisible(elementID),
        sExpandImagePath,
        sCollapseImagePath,
        hfStateID);
}

function ExpandCollapseGuestReservationContainer(
    elementID,    
    imageID,
    bExpand, 
    sExpandImagePath, 
    sCollapseImagePath,
    hfStateID){    
    if (elementID && elementID != '' &&
        imageID && imageID != '' &&
        sExpandImagePath && sExpandImagePath != '' &&
        sCollapseImagePath && sCollapseImagePath != '' &&
        hfStateID && hfStateID != ''){
        ShowHideElement(elementID, bExpand);
        
        var image = document.getElementById(imageID);
        
        if (image){
            image.src = (bExpand) ? sExpandImagePath : sCollapseImagePath;            
        }
                
        var hfState = document.getElementById(hfStateID);
        if (hfState){
            hfState.value = bExpand;
        }
    }        
}
// ----------------------------------

function aCheckEnable(el)
{
	
	//alert('tipo di el.disabled: ' + typeof(el.disabled));
	if (typeof(el.disabled)=="undefined")
	{				
		//alert('Essendo undefined lo valorizzo in base all attributo disabled '+ el.getAttribute('disabled') );
		//alert(el.hasAttribute('disabled'));
		el.disabled = el.getAttribute('disabled') && (el.getAttribute('disabled') == 'disabled' || el.getAttribute('disabled') == true );		
	}		
	
	//alert(el.id + 'el.disabled' + el.disabled);
	
	return !el.disabled;	
}

// ----------------------------------------------------------------------------------
// PNG transparency - use inside a [if lt IE 7] ... [endif] block
// ----------------------------------------------------------------------------------
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
// ----------------------------------------------------------------------------------