// JScript File
var CityID=1;
var ShowCalenderOrder=false;
if (!window.XMLHttpRequest)
{
  window.XMLHttpRequest = function() 
  {
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
}
function SearchMovies(CinemaID,GenreID,MovieID)
{
var MovieValue= document.getElementById(MovieID).value;
var CinemaValue= document.getElementById(CinemaID).value;
var GenreValue= document.getElementById(GenreID).value;
var GenreText= document.getElementById(GenreID).options[document.getElementById(GenreID).selectedIndex].text;

if(MovieValue!="0")
    window.location='/Movies/MovieInfo.aspx?MID='+MovieValue+'&CityId='+CityID;
 else if (CinemaValue != "0")
 {
       if (GenreValue != "0")
          window.location='/Movies/CinemaInfo.aspx?CID=' + CinemaValue + '&GID=' +GenreValue + '&GN=' +GenreText+'&CityId='+CityID;
       else
          window.location='/Movies/CinemaInfo.aspx?CID=' + CinemaValue +'&CityId='+CityID;
 }
 else
    window.location='/Movies/SearchResult.aspx?GID=' + GenreValue+ "&GN=" + GenreText+'&CityId='+CityID;

}
function SearchOutings(AreaID,VarID,NameID,TypID)
{
var AreaValue= document.getElementById(AreaID).value;
var AreaText= document.getElementById(AreaID).options[document.getElementById(AreaID).selectedIndex].text;
if(VarID!='null')
{
var VarValue= document.getElementById(VarID).value;
var VarText= document.getElementById(VarID).options[document.getElementById(VarID).selectedIndex].text;
}
else
{
var VarValue= '0';
var VarText= 'Area';
}
var NameValue= validateText(document.getElementById(NameID).value);
if(TypID!=2)
    window.location='/Outing/OutingSearchResult.aspx?CHID=0&CHN=&AID=' + AreaValue + '&Vname=' + (NameValue == 'Name' ? '=' : NameValue) + '&FID=' + VarValue + '&Typ='+TypID+'&AN=' + AreaText + '&FN=' +VarText+'&CityId='+CityID;
else
    window.location='/Outing/RestaurantSearchResult.aspx?CHID=0&CHN=&AID=' + AreaValue + '&Vname=' + (NameValue == 'Name' ? '=' : NameValue) + '&CID=' + VarValue + '&Typ='+TypID+'&AN=' + AreaText + '&CN=' +VarText+'&CityId='+CityID;
}
function SearchEvents(VenueID,EventTypeID,NameID,CatID)
{
var VenueValue= document.getElementById(VenueID).value;
var VenueText= document.getElementById(VenueID).options[document.getElementById(VenueID).selectedIndex].text;
var EventTypeValue= document.getElementById(EventTypeID).value;
var EventTypeText= document.getElementById(EventTypeID).options[document.getElementById(EventTypeID).selectedIndex].text;
var NameValue= document.getElementById(NameID).value;
if (VenueValue != "0" )
    window.location='/Events/EventsInSameVenue.aspx?T='+ CatID +'&VID=' + VenueValue+'&CityId='+CityID;
else
    window.location='/Events/EventSearch.aspx?T='+ CatID +'&VID=' + VenueValue + '&Ename=' + (NameValue== 'Name' ? '=' :NameValue) + '&TID='+ EventTypeValue + '&VN=' + VenueText + '&TN=' + EventTypeText+'&CityId='+CityID;

}
function validateText(str){
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	str = str.replace(/\n/g, "<br />");
	str = str.replace(/\|/g, " ");
	return str;
}

function getCookie(name) 
 {
 
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1)
   {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
   }
   else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
 return unescape(dc.substring(begin + prefix.length, end));
}

function SetCookie( name, value, expires, path, domain, secure ) 
{
var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function ChangeCity(id)
{
SetCookie("YallabinaCity",id,60,'/','','');
CityID=id;
 //window.location='/default.aspx?CityId='+CityID;
if (location.href.lastIndexOf('/') !=-1)
{
        firstpos=location.href.lastIndexOf('/')+1;
        lastpos=location.href.lastIndexOf('?');
        Channel=location.href.substring(firstpos-7,firstpos-1);
        Namer=location.href.substring(firstpos,lastpos);
        var CityIdLoc=document.location.href.indexOf("CityId=");
        if(Channel.toLowerCase()=="summer")
            window.location='/default.aspx?CityId='+CityID;
        if(Channel.toLowerCase()=="travel" && CityID==7)
            window.location='/default.aspx?CityId='+CityID;
        if(Channel.toLowerCase()=="movies" && CityID==11)
            window.location='/default.aspx?CityId='+CityID;
        if(Channel.toLowerCase()=="events" && CityID==11)
        {
            var EventCatgoryLoc=document.location.href.indexOf("T=");
            var EventCatgory=document.location.href.substring(EventCatgoryLoc+2,EventCatgoryLoc+3)
            if(EventCatgory=="2")
            {
                window.location='/default.aspx?CityId='+CityID;
            }
        }
        if(Namer.toLowerCase()== "movieinfo.aspx" || Namer.toLowerCase()== "starprofile.aspx" || Namer.toLowerCase()== "eventinfo.aspx" || Namer.toLowerCase()== "restaurantinfo.aspx" || Namer.toLowerCase()== "cinemainfo.aspx")
            window.location='/default.aspx?CityId='+CityID;
        else if(Namer.toLowerCase()== "outinglisting.aspx" )
            window.location='/Outing/default.aspx?CityId='+CityID;
        else
        {
             if(CityIdLoc==-1)
             {
                 CityIdLoc=document.location.href.length-1;
                 window.location=document.location.href.substring(0,CityIdLoc)+'?CityId='+CityID;
             }
             else
             {
                  window.location=document.location.href.substring(0,document.location.href.indexOf("CityId=")+7)+CityID;
             }
        }
    }
else
{
     if(CityIdLoc==-1)
     {
          CityIdLoc=document.location.href.length-1;
          window.location=document.location.href.substring(0,CityIdLoc)+'?CityId='+CityID;
     }
     else
          window.location=document.location.href.substring(0,document.location.href.indexOf("CityId=")+7)+CityID;
}
}
function Load()
{
    if(getCookie("YallabinaCity")!=null)
        CityID=getCookie("YallabinaCity");
    CheckReservationRedirection();
}

function Click()
{
    if(ShowCalenderOrder==false)
    {
        if(calStart!=null && document.getElementById(calStart.DivName ).className!="hide")
        {
            document.getElementById(calStart.DivName ).className="hide";
        }
        if(calEnd!=null && document.getElementById(calEnd.DivName ).className!="hide")
        {
             document.getElementById(calEnd.DivName ).className="hide";
        }
    }
    ShowCalenderOrder=false;
}

function CheckReservationRedirection()
{
  lastpos=document.referrer.indexOf('m');
  if(document.referrer.substring(0,lastpos+1) =="http://sso.linkonlineworld.com" && document.referrer.substring(0,lastpos+1) !=" ")
  {
    if (location.href.lastIndexOf('/') !=-1)
    {
            firstpos=location.href.lastIndexOf('/')+1;
            lastpos=location.href.lastIndexOf('?');
            Namer=location.href.substring(firstpos,lastpos);
//            if(Namer.toLowerCase()== "eventinfo.aspx" )
//            {
//                ShowTab('DivEvent','TabEvent',3,2,'linkhover');
//            }
//            else if  (Namer.toLowerCase()== "restaurantinfo.aspx" )
//            {
//                ShowTab('DivRest','LinkRest',3,2,'linkhover');
//            }
     }
  }
}
function ShowHideDiv(divid,chk)
{
var elmnt = document.getElementById(divid);
if(!chk)
    elmnt.className='hide';
else
    elmnt.className='show2';
}
function ShowTab(div,link,count,id,style)
{
    for(var i=0;i<count;i++)
    {
        document.getElementById(div+i).className="hide";
        document.getElementById(link+i).className="";
    }
    document.getElementById(div+id).className="show2";
    document.getElementById(link+id).className=style;
}
function GetEventDesc(EventID)
{
if(document.getElementById("_EventDesc"+EventID).className=="show")
  {
    document.getElementById("_EventDesc"+EventID).className="hide";
    document.getElementById("_EventImg"+EventID).title="Expand";
  }
else
  {
    document.getElementById("_EventDesc"+EventID).className="show";
    document.getElementById("_EventImg"+EventID).title="Collapse";
  }
}

function validateSearchText(fld,oldvalue)
{
     var value=fld.value.replace(" ","");
    if(value=='' && fld.id.indexOf("Arabic")==-1)
       fld.value='Name';
    else if(value=='' && fld.id.indexOf("Arabic")!=-1)
       fld.value=oldvalue;
}
function ValidateMobile(source, arguments)
{
      var txtMob = document.getElementById(source.controltovalidate);
      if (null != txtMob)
      {
           if(txtMob.value.length<10)
           arguments.IsValid = false;
      }
      else
      {
            arguments.IsValid = true;
       }
}
function validateDate(fld) 
{
    var value=fld.value.replace(" ","");
    if(value!='')
    {
        var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
        var errorMessage = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen or period to separate the values.\nThe date must be a real date. 2-30-2000 would not be accepted.\nFormay mm/dd/yyyy.';
        if ((fld.value.match(RegExPattern)) && (fld.value!='') )
        {
            if(fld.id=='To')
            {
                var fromvalue= document.getElementById('From').value;
                if(value.replace(" ","")!='')
                {
                    datefrom=new Date();
                    dateTo=new Date();
                    datefrom=fromvalue;
                    dateTo=fld.value;
                    if(dateTo<datefrom)
                        document.getElementById('ErrorDate').innerHTML='To cannot be less than From';
                    else
                        document.getElementById('ErrorDate').innerHTML='';
                }
            }
         } 
         else 
         {
             document.getElementById('ErrorDate').innerHTML='Invalid Date Format';
             fld.value='dd/mm/yyyy';
         }
   }
   else
   {
       document.getElementById('ErrorDate').innerHTML='';
       fld.value='dd/mm/yyyy';
   }
}
function DaySearchCalendar(date,DaySearch)
{      
    if(DaySearch==true)
    {
         var xr = new XMLHttpRequest();  
         var res = document.getElementById("_ResultEventSearch");
         xr.open("GET", "../Handlers/DaySearch.ashx?Date=" + date+"&CityId="+CityID, true);
         xr.onreadystatechange = function() 
         {
            if (xr.readyState == 4) 
            {
               if (xr.status == 200) // request succeeded   
               {         
                 res.innerHTML = xr.responseText;
               }
               else
                  res.innerHTML = "No Result";
            }
        }
        xr.send(null);
    }
    else
    {
        window.location='/Events/DaySearch.aspx?Date='+date+'&CityId='+CityID;
    }
}

function DaySearchFromTo(DaySearch)
{      
  var datefrom= document.getElementById(SelectedDateStartsValueID).value;
  var dateto= document.getElementById(SelectedDateEndsValueID).value;
 
  if(dateto!='' && datefrom!='')
  if(DaySearch==true)
  {
      var xr2 = new XMLHttpRequest();  
      var res2 = document.getElementById("_ResultEventSearch");
      xr2.open("GET", "../Handlers/DaySearch.ashx?DateFrom=" + datefrom+"&DateTo="+dateto+"&CityId="+CityID, true);
      xr2.onreadystatechange = function() 
      {
        if (xr2.readyState == 4) 
        {
          if (xr2.status == 200) // request succeeded   
          {         
            res2.innerHTML = xr2.responseText;
          }
          else
            res2.innerHTML = "No Result";
        }
      }
      xr2.send(null);
   }
   else
   {
       window.location='/Events/DaySearch.aspx?DateFrom='+datefrom+"&DateTo="+dateto+'&CityId='+CityID;
   }
   else
   {
        document.getElementById('ErrorDate').innerHTML='Please Insert Date';
   }
}
function validateAddEvent()
{
    var value=document.getElementById(txtEventNameID).value.replace(" ","");
    if(value=='')
    {
        document.getElementById("EventError").innerHTML='Please insert event name.';
        return false;
    }
    if( document.getElementById(VenueKindID).value==0)
    {
         value=document.getElementById(txtVenueNameID).value.replace(" ","");
         if(value=='')
         {
              document.getElementById("EventError").innerHTML='Please insert venue name.';
              return false;
         }
        if( document.getElementById(AreaID).value==0)
        {
            document.getElementById("EventError").innerHTML='Please select area.';
            return false;
        }
    }
    
}

function AddEventTicket(Tickets)
{
    if( document.getElementById('txtTicketPrice').value.replace(" ","")=='')
    {
        document.getElementById('TicketPriceError').innerHTML="*";
        return false;
    }
    else
    {
       document.getElementById('TicketPriceError').innerHTML="";
       var txtTickets=document.getElementById(Tickets);
       var ddlTicketTypeID=document.getElementById(TicketTypeID);
       var addedTicket=ddlTicketTypeID.value+"-"+ddlTicketTypeID.options[ddlTicketTypeID.selectedIndex].text+"-"+document.getElementById('txtTicketPrice').value+"-";
       if(txtTickets.value.indexOf(addedTicket)!=-1)
       {
            document.getElementById('ExistError').innerHTML="This Ticket already exists";
            return false;
       }
       else
       {
           document.getElementById('ExistError').innerHTML="";
           txtTickets.value=txtTickets.value+addedTicket;
           var Result = "<div id='WhatOn'> <table id='TableEvents'>";
           Result += " <tr> <th scope='col'>Ticket Type</th><th scope='col'>Value</th><th scope='col'></th></tr>";
           var TicketsValue = txtTickets.value.split("-");
           var NoOfTicket=(TicketsValue.length-1)/3;
           for(var No=0;No< NoOfTicket;No++)
           {
               if (No%2)
                   Result += "<tr class='dark' id='_tdEventTicket" + No + "'>";
              else
                  Result += "<tr id='_tdEventTicket" + No + "'>";
              Result += "<td scope='row'>" + TicketsValue[(No*3)+1] + "</td>";
              Result += "<td scope='row'>" + TicketsValue[(No*3)+2] + "</td>";
             Result += "<td scope='row'><a href='";
             Result += "javascript:CloseRow(\"_tdEventTicket" + No + "\",\""+Tickets+"\",\""+TicketsValue[(No*3)]+"-"+TicketsValue[(No*3)+1]+"-"+ TicketsValue[(No*3)+2]+"-\",\"_AddedTickets\",\"TableEvents\")'>";
             Result += "<img src='../images/close_blue.gif' title='Close' width='14' height='19' border='0' ></img></a></td>";
           }
           document.getElementById("_AddedTickets").innerHTML=Result;
        }
    }
}
function validateAddVenue()
{
    
   value=document.getElementById(txtVenueNameID).value.replace(" ","");
    if(value=='')
    {
        document.getElementById("VenueError").innerHTML='Please insert venue name.';
        return false;
    }
    if( document.getElementById(AreaID).value==0)
    {
        document.getElementById("VenueError").innerHTML='Please select area.';
        return false;
    }
     if(document.getElementById(PhoneID).value.replace(" ","")=='')
    {
        document.getElementById("VenueError").innerHTML='Please insert phone number.';
        return false;
    }
    var ulCuisines=document.getElementById('ulCuisines');
	var liCuisines = ulCuisines.getElementsByTagName("li");
	for( var c=0; c<liCuisines.length;c++)
	{
		var chkCuisines = liCuisines[c].getElementsByTagName("input");
		if(chkCuisines[0].checked==true)
		 {
		    return true;
		 }
	}
	document.getElementById("VenueError").innerHTML='Please select cuisine.';
	return false;
}
function CloseRow(args,Tickets,DeletedTicket,ContainedDiv,Table)
{
    document.getElementById('ExistError').innerHTML="";
    var txtTickets=document.getElementById(Tickets);
    var RestTickets=txtTickets.value.replace(DeletedTicket,"");
    txtTickets.value=RestTickets;
    if(txtTickets.value.length==0)
        document.getElementById(ContainedDiv).innerHTML='';
    else
    {
        var parentTable = document.getElementById(Table);
        var row = document.getElementById(args);
        parentTable.deleteRow(row.rowIndex);
    }
}


function TellAFriend()
{
   window.location='/TellAFriend.aspx?URL='+window.location;
}
function GoBack(pageno)
{
history.go(pageno);
}

function SwitchFeatured(id,Title)
{
eval("featured"+Title + " = " + id);
FillUIFeatured(Title,id);
}
function FillUIFeatured(Title,id)
{
var items = new Array();
eval( "items" + " = " + "itemsFeatured"+Title);
document.getElementById("TitleLinkFeatured"+Title).innerHTML = items[id].title;
document.getElementById("ThumbFeatured"+Title).src = items[id].thumb;
document.getElementById("SummaryFeatured"+Title).innerHTML = items[id].summary;
document.getElementById("TitleLinkFeatured"+Title).href = items[id].url;
document.getElementById("LinkUrlFeatured"+Title).href =items[id].url;
document.getElementById("ThumbFeatured"+Title).title = items[id].title;
document.getElementById("LinkUrlFeaturedMore"+Title).href = items[id].url;
for(var i=0;i< items.length;i++)
   document.getElementById("LinksFeatured"+Title+i).className="";
document.getElementById("LinksFeatured"+Title+id).className="linkhover";
}
function ClientCallback(result,context)
{

        if(navigator.appName == "Microsoft Internet Explorer")
        {
            document.getElementById(context).outerHTML = result;
        }
        else
        {
          if(result.substring(0,7).toLowerCase()=="<select")
            {
                firstpos=result.indexOf(">");
                result=result.substring(firstpos+1,result.length);
                result=result.replace("</select>","");
            }
            document.getElementById(context).innerHTML = result;
        }
}
function ClientCallbackSearch(result,context)
{
    document.getElementById(context).innerHTML = result;
}
function ShowCalender(DName,DOther)
{
    document.getElementById(DName).className="";
    document.getElementById(DOther).className="hide";
    ShowCalenderOrder=true;    
}


function printPage()
 {
 var printsitemap = document.getElementById("sitemape");
 var printReadyElem = document.getElementById("mainContent");
 var printFooter = document.getElementById("footer");
 var printWin = window.open("","PrintSpecial");
 printWin.document.open();
 printWin.document.write('<link type="text/css" rel="stylesheet" href="../css/style.css" /><img src="../images/Logo.jpg" dir="rtl" align="right" >' + printsitemap.innerHTML +printReadyElem.innerHTML  + printFooter.innerHTML);
 printWin.document.close();
 printWin.print();
// printWin.close();
 }

//Change City script
    function _changeCity(elm, id) {
		SetCookie("YallabinaCity",id,60,'/','','');
    	var parent = elm.parentNode;
		var links = parent.getElementsByTagName("a");
		for(var i=0; i<links.length; i++) {
			links[i].className = "";
		}
		elm.className = "linkhover";
	}     
	
//id = <%=this.UniqueID %>
//param = what is sent to server
//callback = method after getting back from server and have response
function doCallbackHtml(id, param, callback)
{
			var postData = "__CALLBACKID=" + escape(id) +
			"&__CALLBACKPARAM=" +
			escape(param) +
			"&__VIEWSTATE=&";
			PostCallback(document.URL, postData,callback);
}
		
function PostCallback(URL,postData,CompleteMethod) 
{
    var xmlHttp;
    try 
    {
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("This sample only works in browsers with AJAX support"); 
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState == 4)
        {
              CompleteMethod(xmlHttp.responseText);
        }
    }
    xmlHttp.open("POST", URL, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(postData);
}
function startLoader(divName)
{
    var loader = $("#loader"+divName)[0];
    var div = $("#"+divName);
    if(!loader) {
        loader = document.createElement("div");
        loader.id = "loader"+divName;
        loader.className = "loader";
        loader.innerHTML = "<img src='../images/loading1.gif' class='imgloader' />";
        div.before(loader);
    }
    loader.style.width = div[0].offsetWidth+"px";
    loader.style.height = parseInt(div[0].offsetHeight)+"px";
    $(loader).show();
}