$(document).ready(
    function(){
      
       
       $('#storeSelector').change(function(){
    
            updateStoreDetails($('#storeSelector').val());

            });
            
            
            $('#offers_select').change(function(){
            
            updateOffers($('#offers_select').val());

            });
      
      
      
       $('#emailCheck').click(function(){
    
            surveyCheck($('#emailCheckValue').val());

            });
             $('#start_survey').hide();
             $('#survey_error').hide();
             
             
$('#language_ar').click(function(){

$('#disclaimer_english').hide();
$('#disclaimer_arabic').show();



});

$('#language_en').click(function(){

$('#disclaimer_arabic').hide();
$('#disclaimer_english').show();

});

$("#loading").ajaxStart( function() { $(this).show(); } );
$("#loading").ajaxStop( function() { $(this).hide(); } );
            
});

function SetupAjaxForm()
{

$("#email_check_load").ajaxStart( function() { $(this).show(); } );
$("#email_check_load").ajaxStop( function() { $(this).hide(); } );


}


function SendToFriend()
{


efrom_name=$('input[name=sf_from_name]').val();
efrom_email=$('input[name=sf_from_email]').val();
eto_name=$('input[name=sf_to_name]').val();
eto_email=$('input[name=sf_to_email]').val();

	
$.get('/DataCheck.asmx/SendToFriend', {
    from_name: efrom_name,
    from_email: efrom_email,
    to_name: eto_name,
    to_email: eto_email
}, function() {
    $('#s2f_confirmation').html('<p>Thank you, your email has been sent to ' + eto_name +'</p>');
});


}

function updateOffers(offer_id)
{

switch(offer_id) {

  case "1":
  $('div.First').load('mmi_bs.html?decache='+Math.random()*999);
  break;
  
  case "2":
  $('div.First').load('mmi_wine.html?decache='+Math.random()*999);
  break;
  
  case "3":
  $('div.First').load('cellsaver.html?decache='+Math.random()*999);
  break;
  
  case "4":
  $('div.First').load('cs_wine.html?decache='+Math.random()*999);
  break;

  default:
  $('div.First').load('mmi_beer.html?decache='+Math.random()*999);
  break;

}


}

function ChangeVoucher(voucher)
{
switch (voucher) {

case 1:
    $('div#voucher').html('<img src="../common/image/content/taste_vip.gif" width="320" height="282" alt="Offer" />');
    break;
case 2:
    $('div#voucher').html('<img src="../common/image/content/taste_2for1.gif" width="320" height="282" alt="Offer" />');
    break;
case 3:
    $('div#voucher').html('<img src="../common/image/content/taste_10percent.gif" width="320" height="282" alt="Offer" />');
    break;
   
}


}


function CheckDiplomat()
{

uname=$('#uname').val();
pass=$('#pass').val();

if (uname=="diplomatic@mmidubai.com" && pass=="d1pl0m4tmmi")

{
$('div#link').html("<p>Thank you, please <a href='portfolio/DiplomaticPortfolio.pdf'>click here</a> to download the Diplomatic Portfolio (PDF).</p>");
$('div#link').show();
}

else
{
$('div#link').html("<p style='color:red;font-weight:bold;'>Sorry, please check your username and password</p>");
$('div#link').show();
}

}

function updateStoreDetails(store_id)
{


$.get('../DataCheck.asmx/getStoreByID',{id: store_id}, function(data) {

var $result = $result=$(data).find('Store');
var _name;
var _location;
var _location_description;
var _telephone;
var _opening_hours;
var _map;

_location = $(data).find('location').text();
_location_description = $(data).find('location_description').text();
_telephone = $(data).find('telephone').text();
_opening_hours = $(data).find('opening_hours').text();
_map = "../common/image/maps/" + $(data).find('map').text();

$('#storeLocation').html("<strong>"+_location+"</strong>");
$('#storeLocationDescription').html(_location_description);
$('#storeTelephoneNumber').html(_telephone);
$('#storeOpeningHours').html(_opening_hours);
$('#storeMap').html("<img src='" + _map + ".jpg' alt='Location Map' />");
$('#large_map').html("<a href='" + _map + ".html' target='_blank'><img src='../Common/Image/Button/zoom.gif' alt='Print' /></a>");

});


}


function surveyCheck(email_to_check)
{
 $.get('../DataCheck.asmx/surveyEntered',{email: email_to_check}, function(data) {
  
  var $result=$(data).find('boolean');
  var result = $result.text();
  
  if (result=='true') {$('#survey_error').show('fast');}
  else {$('#start_survey').show('slow');}
 
 });
}


function AssignExternals()
 {
  $("a[rel='external']").click(function(){this.target="_blank";});
 }


function RssFeed(Path,pagename)
{	
 $.get(Path, function(data) {
  var offerlist='';
  var i=0;
  var j=0;
  var $category=$(data).find('category');
  
  $category.each(function() {
   if(i<3)
   {
   $offer=$(this).find('offer');
   $offer.each(function() {    
     if(j<1)
     {
     if(i==2)
      if(pagename=='Homepage')
       offerlist +='<li class="Last"><img src=Common/Image/FeedIcons/'+$(this).find('thumb').text()+' /><strong>'+$(this).find('offertitle').text()+'</strong>'+$(this).find('offerdetail').text()+'</li>';
      else
       offerlist +='<li class="Last"><img src=/Common/Image/FeedIcons/'+$(this).find('thumb').text()+' /><strong>'+$(this).find('offertitle').text()+'</strong>'+$(this).find('offerdetail').text()+'</li>';
     else
      if(pagename=='Homepage')     
       offerlist +='<li><img src=Common/Image/FeedIcons/'+$(this).find('thumb').text()+' /><strong>'+$(this).find('offertitle').text()+'</strong>'+$(this).find('offerdetail').text()+'</li>';
      else
       offerlist +='<li><img src=/Common/Image/FeedIcons/'+$(this).find('thumb').text()+' /><strong>'+$(this).find('offertitle').text()+'</strong>'+$(this).find('offerdetail').text()+'</li>';
     }
     else
     {
     j=0;
     return;
     }
     j++;
   });
  }
  else
  return;
  i++;
  });
  $("#OffersRss").empty();
  $("#OffersRss").append(offerlist);
 
 });  
}


function XmlPlacer(Cat,PlacerId)
{
 $.get('../october_offers.xml?decache='+Math.random()*999, function(data) {
  var offerlist='';
  
  var $category=$(data).find('category');
  
  $category.each(function() {
   if($(this).attr('cat')==Cat)                     
   {
    $offer=$(this).find('offer');
    offerlist="<p>";
    $offer.each(function() {
    offerlist += '<strong>'+$(this).find('offertitle').text()+'</strong><br />';
    offerlist +=$(this).find('offerdetail').text()+'<br /><br />';
    });
    offerlist+="</p>";
   }
  });
  $(PlacerId).empty();
  $(PlacerId).append(offerlist);
 
 });
}


function AssignRollOvers(NavId)
{
 Menu=document.getElementById(NavId);
 IsActive=0;
 
 RollOvers=Menu.getElementsByTagName('IMG');
 ClassIsActive=0;
 $("#"+NavId+" li li").mouseover(function(){
 	if($(this).hasClass("Active"))
 	ClassIsActive=1;
 	else
 	$(this).addClass("Active");
 	});
 $("#"+NavId+" li li").mouseout(function(){if(ClassIsActive==0)$(this).removeClass();else ClassIsActive=0;});  
 $("#"+NavId+" li li a").click(function(){
 	$(this).parent().parent().find("li").removeClass();
 	$(this).parent().parent().find("img").each(function(){
 		if($(this).attr("src").indexOf("Active")>=1)
 		{
 			a=$(this).attr("src");
 			a=a.replace("Active_en","_en");
 			$(this).attr("src",a);
 		}
		});
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("_en","Active_en"));
		if(!$(this).parent().hasClass("Active"));
		$(this).parent().addClass("Active");
 		ClassIsActive=1;
 		IsActive=1;

 	});  
 for(i=0;i<RollOvers.length;i++)
  {
   RollOvers[i].onmouseover=function()
    {
     if(this.src.indexOf("Active")<=-1)
     this.src=this.src.replace("_en","Active_en");
     else
     IsActive=1;
    }
   RollOvers[i].onmouseout=function()
    {
     if(IsActive==1)
     IsActive=0;
     else
     this.src=this.src.replace("Active_en","_en");
    }
  }
}


var Shown=1; 
function TogglePane()
{
 if(Shown==1)
 {
  $("div#Offers").animate({left:"210px",opacity:"0"}, 1500 ); 
  $("#OffersToggle").animate({opacity:"1"},1500);
	 Shown=0;
 }
 else
 {
  $("div#Offers").animate({left:"0",opacity:"1"}, 1500 ); 
  $("#OffersToggle").animate({opacity:"0"},1500);
  Shown=1;
 }  	
 return false;
}

function AssignActive(Menu)
{
    $(Menu + " a").click(function() {
        $(this).parent().parent().find("li.Active").removeClass("Active");
        $(this).parent().addClass("Active");
        $(this).parent().parent().find("img").each(function() { $(this).attr("src", $(this).attr("src").replace("Active_en", "_en")); });
        $(this).find("img").attr("src", $(this).find("img").attr("src").replace("_en", "Active_en"));

      if ($(this).attr("href") == "#") return false;

    }
  );
  
  RolloverEffect(Menu);  //calling function for rollover image change
 }  
 

function RolloverEffect(MenuRootNodeGroupTagId)
{
  $(MenuRootNodeGroupTagId).find("img").mouseover(function()
  {
    if ($(this).parent().parent().hasClass("Active")!= true)
    {
   	  $(this).attr("src" , $(this).attr("src").replace("_en","Active_en"));
   	 }  
  });
  
  $(MenuRootNodeGroupTagId).find("img").mouseout(function()
  {
    if ($(this).parent().parent().hasClass("Active") != true)
    {
     	$(this).attr("src" , $(this).attr("src").replace("Active_en","_en"));
    }
  });
}

   
function LoadFeed(DataLoader,Feed)
{
  $(DataLoader).load(Feed+"?decache="+Math.random()*999);
  return false;
}


function LightBoxToggle(LightBoxShow,PopUp)
 {
  if(LightBoxShow==1)
  {  
   $("#LightBox").css({height:$("#Master").height()+50});
   $("#LightBox").show();
   $(PopUp).fadeIn("slow"); 
   if(document.documentElement && document.documentElement.scrollTop)
    $(PopUp).css("top",document.documentElement.scrollTop);
   else
    $(PopUp).css("top",self.pageYOffset);
  }
  else
  {
   $("#LightBox").fadeOut("slow");
   $(PopUp).fadeOut("slow");  
  }
  return false;
} 

function Accordion()
 {
  $("#Accordion ul").hide();
  $("#Accordion h5").click(function()
   {
    $("#Accordion ul").slideUp(1000);
    $(this).next().slideDown("slow");
    return false;
   }
  ); 
 }
 
function Legal()
 {
  $("#Legal ul").hide();
  $("#Legal h5").click(function()
   {
    $("#Legal ul").slideUp(1000);
    $(this).next().slideDown("slow");
    return false;
   }
  ); 
 } 
 
function KeyAgencies(DetailId,ElementIndex,Extended,PlaceBg)
 {
  if(("#Intro:visible").length)
  {
   $("#Intro").hide();
   if(PlaceBg==1)
   $("#Content .Copy").css("backgroundImage","none");
   $(DetailId).fadeIn(1000);
  }
  $(DetailId+" div").hide();
  $(DetailId+" div").eq(ElementIndex).fadeIn(1000);
  $(DetailId+" a").removeClass();  
  if(Extended==1)
  $(DetailId+" a").eq(ElementIndex-7).addClass("Active");
  else
  $(DetailId+" a").eq(ElementIndex).addClass("Active");
  	
  $(".Back").click(function()
    {
    $("#BeerDetails").hide();
    $("#WineDetails").hide();
    $("#SpiritDetails").hide();
    $("#HRDetails").hide();
    $("#Intro").fadeIn(1000);
    if(PlaceBg==1)    
    $("#Content .Copy").css("backgroundImage","url(../Common/Image/Background/KnowAbout.jpg)");
    return false;
    }
   );
  $("#AbuDhabi").show();
  return false;
 }


function More(ClickId)
 {
  $(ClickId).parent().next().slideDown(1000);
 	
  return false;
 } 
 
  
function KnowMMI(ContentId)
 {
 	$("#Intro").show();
 	$("#HRDetails").hide();
  $("#Intro .Cell2").hide();
  $(ContentId).fadeIn(1000);
  $("#Content .Copy").css("backgroundImage","url(../Common/Image/Background/KnowAbout.jpg)");
  return false;
 }
   
   
function StateLoader(StateId,SelfId)
{
 $(SelfId).parent().find("a").removeClass();
 $(SelfId).addClass("Active");
 $("#AbuDhabi").hide();
 $("#Dubai").hide();
 $("#Sharjah").hide();
 $("#Ajman").hide();
 $("#UmmAlQuwain").hide();
 $("#RasAlKhaimah").hide();
 $("#Fujairah").hide();
 $(StateId).fadeIn(1000);
 
}


function StartSurvey()
 {
  $("div#P6").hide();
  $("#SurveyIntro").slideUp(1000);
  $("#QInfo").fadeIn(1000);
  return false;
 }
 
function ChangeQuestion(PageId,AnchorId)
 {
  $("h5.Pager a.Active").removeClass();
  $("h5.Pager a").eq(AnchorId-1).addClass("Active");
  $("div#P1").hide();
  $("div#P2").hide();
  $("div#P3").hide();
  $("div#P4").hide();
  $("div#P5").hide();
  $("div#P6").hide();
  $(PageId).fadeIn(1000);
 }  