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';}       
//    }
try
{
    if(_$("ctl00_plhBody_rInf")!=null && _$("ctl00_plhBody_rInf").value != "")
    {
        var rms=_$("ctl00_plhBody_rInf").value;
        rms = rms.split('!');
        _$("ctl00_plhBody_rooms_select_id").value = rms.length -1;
        for(var count=1;count<5;count++) { _$('roomnpass'+count).style.display == "none"; }
        for(var count=1;count<rms.length;count++)
        {
            var rmsinf = rms[count-1];
            rmsinf = rmsinf.split(':');
            _$('roomnpass'+count).style.display = "block";
            _$('ctl00_plhBody_ddlAdult'+count).value = rmsinf[1];
            _$('ctl00_plhBody_ddlChild'+count).value = rmsinf[2];
            for(var chcount=1;chcount<6;chcount++) { _$('lblchage').style.display="none"; _$('ctl00_plhBody_txtChild'+count+''+chcount).value=''; _$('ctl00_plhBody_txtChild'+count+''+chcount).style.display ="none"; }
            var chRAge = rmsinf[3].split('-');
            for(var chcount=1;chcount<chRAge.length+1;chcount++) { 
            if(_$('ctl00_plhBody_ddlChild'+count).value > 0){_$('lblchage').style.display="block"; _$('ctl00_plhBody_txtChild'+count+''+chcount).style.display ="block";
             _$('ctl00_plhBody_txtChild'+count+''+chcount).value=chRAge[chcount-1];
             }
              }
        }
    }
}
catch(e)
{
    for(var count=1;count<5;count++) { for(var chcount=1;chcount<6;chcount++) { _$('ctl00_plhBody_txtChild'+count+''+chcount).value=''; _$('ctl00_plhBody_txtChild'+count+''+chcount).style.display ="none"; } _$('roomnpass'+count).style.display == "none"; }
    _$('roomnpass1').style.display = "block";
    _$('ctl00_plhBody_ddlAdult1').value = '2';
    _$('ctl00_plhBody_ddlChild1').value = '0';
    if(_$('hdlpPrice')!=null){_$('hdlpPrice').style.display='none';}
    if(_$('arrival_details')!=null){_$('arrival_details').style.display='none';}     
}
}
function ConfirmationPage()
{
    ATTPU();
    var content = _$("ctl00_plhBody_hdnConfmPage").value;
    content = content.replace("SFC/Insurance Cover","Insurance Cover").replace("<div id='term'>","<div style='float:left;width:100%;margin-left:-10px;'><a href='http://share.holidaynights.co.uk'><img src='/Search/images/booking/confirm_banner.jpg' alt='Share and Earn banner'/></a></div><div id='term'>");
    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>collected</strong> over <strong>10 million</strong> hotel reviews from a range of review websites to give you an overall quality score as defined by your fellow travellers.';
    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(eobj.id == "destQKDiv")
            {
                if(_$('destQKDiv').style.display != "none")
                {
                    _$('destQKDiv').style.display = "block";
                    _$("destQKIFrame").style.display = "block"; 
                    _$('destQKDivContainer').style.display = "block";                   
                }
            }
            else if((_$('destDiv')!=null && _$('destDiv') != 'undefined')|| (_$('destQKDiv')!=null && _$('destQKDiv') != 'undefined'))
            {
                if(_$('destDiv')!=null && _$('destDiv') != 'undefined' && _$('destDiv').style.display != "none")
                {
                    _$('destDivContainer').style.display = "none";                    
                }  
                if(_$('destQKDiv').style.display != "none")
                {
                    _$('destQKDivContainer').style.display = "none";                    
                }  
            }          
       }
       return true;
     }   
    
    if(browser == "Microsoft Internet Explorer" || navigator.vendor=="Google Inc." || navigator.vendor.indexOf("Apple")!=-1)
    {
        if(_$('destDiv')!=null && _$('destDiv') != 'undefined')
        {
           _$('ctl00_plhBody_txtDestination').onblur = 'javascript:void(0)';
        }
        if(_$('destQKDiv')!=null && _$('destQKDiv') != 'undefined')
        {
           _$('ctl00_Header1_txtQKDestination').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"), "");
}
var trfopted=0; var insopted=0;
function ATTPU()
{
    var vardate = new Date();
    var trfinsdata = _$('ctl00_plhBody_hdnA2TData').value.split('||')
    var params = _$('ctl00_plhBody_hdnA2TData').value.split('~~');
    var sb = '';    
    sb+="|";
    sb+=params[1];
    sb+="|";
    sb+=params[2];
    sb+="|";
    sb+=ReplaceAll(params[3],'-','.');
    sb+="|";
    sb+=ReplaceAll(params[4],'-','.');
    sb+="|";
    sb+=params[5];
    sb+="|";
    sb+=params[6];
    sb+="|";
    sb+='0';
    sb+="|";
    sb+="HolidayNightsMappings";
    sb+="|";
    sb+="http://holidaynights.about2travel.com";
    if(trfinsdata[1] !=null) { trfopted = (trfinsdata[1]=='-1') ? trfopted:1; }
    if(trfinsdata[2] !=null) { insopted = (trfinsdata[2]=='-1') ? insopted:1; }
    var _requestUrl = "/Search/AjaxImpl.aspx?Bookpage=A2TPU&parameter="+sb+"&date="+vardate.getTime();
    var sbURL = "http://holidaynights.about2travel.com/search-results/all//"+params[0]+"_"+params[1]+"_"+params[2]+"/"+params[3]+"/1200_1200/"+params[4]+"/1200_1200/"+params[5]+"_"+params[6]+"_"+0+"/";
    var XmlHttp = CreateXmlHttp();
    if(XmlHttp)
    {            
        XmlHttp.onreadystatechange = function()
		{ 
            if(XmlHttp.readyState == 4)
            {
	            if(XmlHttp.status == 200)
	            {
	                PopA2t(XmlHttp.responseText,sbURL);
	            }
	        }
	    }
        XmlHttp.open("GET", _requestUrl,  true);    		
        XmlHttp.send(null);		
    }
}
function PopA2t(response,sbURL)
{
    if(response != "" && response!= "||||")
    {
        var exoptions = new Array ('Travel Insurance','Airport Parking','Airport Lounges','Airport Transfers','Car Hire');
        var exopAnchor = new Array ('i-anchor','p-anchor','l-anchor','t-anchor','c-anchor');
        var exDiv = $('pass');
        var table = document.createElement('table');
        table.style.width="100%";
        table.style.padding="10px";
        table.style.backgroundColor = "rgb(254, 246, 197)";
        table.style.border="1px solid rgb(242, 232, 174)";
        exDiv.appendChild(table);
        var tbody = document.createElement('tbody');
        table.appendChild(tbody);
        var tr = document.createElement('tr');
        var td= document.createElement('td');
        td.style.fontSize = "14px";
        td.innerHTML = "Forgotten Something?";
        tr.appendChild(td);
        tbody.appendChild(tr);
        var tr = document.createElement('tr');
        var td= document.createElement('td');
        td.innerHTML = "&nbsp;";
        tr.appendChild(td);
        tbody.appendChild(tr);
        
        var resOptions = response.split('|');
        
        for(var count=0;count<resOptions.length;count++)  
        {
            if(resOptions[count]!= null && resOptions[count]!="")
            {
                if(count==3 && trfopted == 1) {}
                else if(count==0 && insopted == 1) {}
                else
                {
                    var tr = document.createElement('tr');
                    var td= document.createElement('td');
                    td.innerHTML = "<b>"+exoptions[count]+"</b> from &pound; <a style='color:black;font-size:12px;' target='blank' href='"+sbURL+"__"+exopAnchor[count]+"/'>"+resOptions[count]+"</a>";
                    tr.appendChild(td);
                    tbody.appendChild(tr);
                }
            }
        }
    } 
    return false;
}
