function getXmlDocumentElement(text)
{
    var doc;
    if (window.ActiveXObject)
    {
        doc=new ActiveXObject("Microsoft.XMLDOM");
        doc.async="false";
        doc.loadXML(text);        
    }
    else
    {
        var parser=new DOMParser();
        doc=parser.parseFromString(text,"text/xml");    
    }    
    return doc.documentElement;
}
function _$(_el) 
{
   return document.getElementById(_el);
}
function CreateXmlHttp()
{
    var XmlHttp;
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
	return XmlHttp;
}
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}
function GetInnerHTML(node)
{
    if(CheckForValidObject(node))
    {
        if(CheckForValidObject(node.textContent))
            return node.textContent;
        else if(CheckForValidObject(node.innerHTML))
            return node.innerHTML;
        else if(CheckForValidObject(node.text))
            return node.text;
        else 
            return "";
    }
    else 
        return "";
}
function CheckForValidObject(obj)
{
    if(obj==null || typeof obj=='undefined')
        return false; 
    else
        return true;
}    
function _cObj(obj)
{
    if(obj==null || typeof obj=='undefined')
        return false; 
    else
        return true;
}
String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }
function ReplaceAll(text, strA, strB) 
{
    while ( text.indexOf(strA) != -1)
    {
        text = text.replace(strA,strB);
    }
    return text;
}
function closeWindow()
{
    window.opener='X'; 
    window.open('','_parent',''); 
    window.close();
    return true;
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char; 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}
function RepSpecialChar(sText)
{
   if(sText!=null)
   {
       var str=sText;   
       var rText =str.replace(/&amp;/g,'&');  
       rText =rText.replace(/&apos;/g,"'");  
       rText =rText.replace(/&gt;/g,">");
       rText =rText.replace(/&lt;/g,"<");          
       rText =ReplaceAll(rText, '*', '');    
       rText =rText.replace(/&quot;/g,"\"");  
       rText =rText.replace(/quot;/g,"\""); 
       rText =rText.replace(/apos;/g,"\'");      
       rText =rText.replace(/&pound;/g,"£");        
       return rText; 
   }
}
function QueryString(qText)
{
   var qText=qText.replace(/&/g,'amp;');
    return qText;
}
function SetChildAge()
{
    try
    {
        var childAge=_$("ctl00_plhBody_rInf").value;   
        childAge=childAge.split(':');
        if(_$("ctl00_plhBody_ddlAdult")!=null)
        _$("ctl00_plhBody_ddlAdult").value = childAge[1];
        if(_$("ctl00_plhBody_children_room_1")!=null)
        _$("ctl00_plhBody_children_room_1").value = childAge[2];
        childAge=childAge[3];    
        var childDdl=childAge.split('!');    
        childDdl=childDdl[0].split('-');          
        if(childDdl.length>0)
        {                      
            for(var _ch=0;_ch<childDdl.length;_ch++)
             {
                if(_ch==0)
                {
                    _$('ctl00_plhBody_childage').value=childDdl[_ch];
                    _$('child_row_1').style.display='block';
                }
                else
                {
                    if(_$('ctl00_plhBody_childage' + _ch)!=null)
                    _$('ctl00_plhBody_childage' + _ch).value=childDdl[_ch];
                    var chRow=_ch+1;
                    _$('child_row_'+chRow).style.display='block';
                }
            }
        }
        update_rooms_rows(); 
        update_children();
    }
    catch(e)
    {
       _$('ctl00_plhBody_ddlAdult').value="2";
       _$('ctl00_plhBody_children_room_1').value="0";
       if(_$('hdlpPrice')!=null){_$('hdlpPrice').style.display='none';}
       if(_$('arrival_details')!=null){_$('arrival_details').style.display='none';}       
    }
}
function ConfirmationPage()
{
    var content = _$("ctl00_plhBody_hdnConfmPage").value;
    content = content.replace("SFC/Insurance Cover","Insurance Cover");
    var contentDiv = _$("fullwidth_content_new");    
    contentDiv.innerHTML = content;    
    var beach_tab = _$("beach_tab_link");
    var city_tab =  _$('city_tab_link');
    //var ski_tab= _$('ski_tab_link');    
    var TabValue = _$("ctl00_plhBody_hdnTabValue").value;    
     if(TabValue=='0')
     {
        beach_tab.className="active_tab";
        //ski_tab.className="inactive_tab_right";
        city_tab.className="inactive_tab_right";
     }
     if(TabValue=='1')
     {
        beach_tab.className="inactive_tab";
        //ski_tab.className="inactive_tab_right";
        city_tab.className="active_tab";
     }
     if(TabValue=='2')
     {
        beach_tab.className="inactive_tab_right";
        //ski_tab.className="active_tab";
        city_tab.className="inactive_tab";
     }       
}
    
function sendemail()
{
    var email = _$("txt_Email").value;
    var hnref = _$("ctl00_plhBody_hdnHnRef").value;
    var _sendParam = email+"|"+hnref;
    if(email == "" || email==null)
    {
        alert("Please provide emailID");
        return false;
    }
      var _requestUrl = "/Search/AjaxImpl.aspx?Bookpage=SendConfMail&parameter="+_sendParam;
      var XmlHttp = CreateXmlHttp();
    if(XmlHttp)
    {            
        XmlHttp.open("GET", _requestUrl,  true);    		
        XmlHttp.send(null);		
    }
    alert("Confirmation mail sent successfully");
}       
function ReviewWindow(cusRating,cusReviews)
 {
    var a=document.createElement('A');  
    a.href = "javascript:void(0);";
    a.onclick=function(){Reviews(parseInt(cusRating),cusReviews);};//open a new window for cr    common-util.js                         
    return a;
 }   
function SecurityCode(url)
{
    if(_$("ctl00_plhBody_hdndomain")!=null)
        url=_$("ctl00_plhBody_hdndomain").value + url ;
    window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,letf=0,resizable=no,top=0,width=600,height=300,scrollbars=no');    	
    return false;  
}    
function DisableEnter(event)
{
    if (event.keyCode == 13) { event.returnValue=false; event.cancel = true; return false;}
}
function AllowAlphabet(obj)
{
  var ptn = /^[a-zA-Z\s\.]+$/;
  var chkString = obj.value;
  var chkLength = chkString.length;
  
   if( chkLength > 0 )
	{	
		if (isValid(ptn,chkString))
		 {
			return true;
		 }
		 else
		 {	
			if(chkString.length==1)$(obj).value=chkString.substring(0,chkString.length-1);
			else
			{
			    while(isValid(ptn,chkString)!=true)
                {
                    $(obj).value = chkString.substring(0,chkString.length-1);
                    chkString = $(obj).value;
			        if(chkString.length==0){$(obj).value=chkString.substring(0,chkString.length-1);break;}
                }
            }
			return false;
		 }
	 }
	else
     {
		return true;
     }	
}
function isValid(pattern, str)
{
	return pattern.test(str);
}
function isAlphaNumeric(obj)
{   
    var ptn = /^[A-Za-z0-9\s\.\ \-\_]+$/;
    var chkString = obj.value;
    var chkLength = chkString.length;
    if( chkLength > 0 )
    {
        if (isValid(ptn,chkString))
        {
            return true;
        }
        else
        {
			if(chkString.length==1)obj.value = chkString.substring(0,chkString.length-1);
			else
			{
			    while(isValid(ptn,chkString)!=true)
                {
                    obj.value = chkString.substring(0,chkString.length-1);
                    chkString = obj.value;
			        if(chkString.length==0){obj.value = chkString.substring(0,chkString.length-1);break;}
                }
            }
			return false;
        }
    }
    else
    {
        return true;
    }	
}
function ValidPhone(obj)
{
    var ptn = /^[0-9\s\+\ \-\(\)]+$/;
    var chkString = obj.value;
    var chkLength = chkString.length;  
    if( chkLength > 0 )
    {
        if (isValid(ptn,chkString))
        {
            return true;
        }
        else
        {
			if(chkString.length==1)obj.value = chkString.substring(0,chkString.length-1);
			else
			{
			    while(isValid(ptn,chkString)!=true)
                {
                    obj.value = chkString.substring(0,chkString.length-1);
                    chkString = obj.value;
			        if(chkString.length==0){obj.value = chkString.substring(0,chkString.length-1);break;}
                }
            }
			return false;
        }
    }
    else
    {
        return true;
    }
}
function Reviews(cusRating,cusReviews)
{
    var finalReviewdiv=document.getElementById("reviewBox"); 
    finalReviewdiv.innerHTML="";           
    var tr,td;
    var  table= document.createElement('table');   
    var tbody=document.createElement('tbody')
    tbody.align="left";
    tr = document.createElement('tr');
    td= document.createElement('td'); 
    td.colSpan="3";	   
    var img = document.createElement('img');
    img.src= '/Search/Images/reviews/hn2_logo.gif';
    td.appendChild(img);
    tr.appendChild(td);
    tbody.appendChild(tr); 
    tr = document.createElement('tr');
    td= document.createElement('td');
    var itbl=document.createElement('table');
    var itbody=document.createElement('tbody')
    var itr = document.createElement('tr');
    var itd= document.createElement('td');
    var img = document.createElement('img');
    img.src= '/Search/Images/reviews/dotted_arrow.gif';
    itd.appendChild(img);
    itr.appendChild(itd);
    itd= document.createElement('td');
    itd.style.paddingLeft = "20px";
    rvDiv=document.createElement('DIV');
    rvDiv.className="rating_blue_box";
    rvDiv.innerHTML="<p>Average customer rating</p><p><span>" + cusRating + "%</span> " + cusReviews + " reviews</p>";
    itd.appendChild(rvDiv);
    itr.appendChild(itd);
    itbody.appendChild(itr);
    itbl.appendChild(itbody);
    td.appendChild(itbl);
    tr.appendChild(td);
    tbody.appendChild(tr);
    tr = document.createElement('tr');
    td= document.createElement('td');
    td.colSpan="5";
    var p = document.createElement('p');
    p.innerHTML ='We have <strong>aggregated</strong> over <strong>1 million</strong> user reviews from the internet to give you an accurate hotel quality measure as defined by your fellow travellers and not just out dated star ratings.';
    td.appendChild(p);
    tr.appendChild(td);
    tbody.appendChild(tr); 
    tr = document.createElement('tr');
    td= document.createElement('td');
    td.colSpan="5";
    td.align="right";        
    td.innerHTML = "<a href=javascript:void(0) onclick=hideReview()>Close window [x]</a>";
    tr.appendChild(td);
    tbody.appendChild(tr);
    table.appendChild(tbody);
    finalReviewdiv.appendChild(table);   
    openModalWindow("reviewBox","modalBackgroundDiv");      
}
function hideReview()
{
    document.getElementById("modalBackgroundDiv").style.display="none";
    document.getElementById("reviewBox").style.display="none";
    document.getElementById("frame").style.display="none";
} 
function DisableSClick()
{ 
    var browser=navigator.appName;
    var shiftPressed=0;
    function mouseDown() 
    {            
       if (event.shiftKey) 
       {
         alert ('Shift-click is disabled.');
         return false;
       }
       else
       {            
            var evt=window.event||arguments.callee.caller.arguments[0];
            var eobj=window.event?evt.srcElement:evt.target;
            if(eobj.id == "destDiv")
            {
                if(_$('destDiv').style.display != "none")
                {
                    _$('destDiv').style.display = "block";
                    _$("destIFrame").style.display = "block";                    
                }
            }
            else if(_$('destDiv')!=null && _$('destDiv') != 'undefined')
            {
                if(_$('destDiv').style.display != "none")
                {
                    _$('destDivContainer').style.display = "none";                    
                }   
            }
            
       }
       return true;
     }   
    
    if(browser == "Microsoft Internet Explorer")
    {
        if(_$('destDiv')!=null && _$('destDiv') != 'undefined')
        {
           _$('ctl00_plhBody_txtDestination').onblur = 'javascript:void(0)';
        }
        document.onmousedown = mouseDown;
    }
    else
    {
        //document.addEventListener("mousedown", function (event){mouseDown1(event, 'window')}, true);        
    }    
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}