// <summary>
// Global function calls
// </summary>
function executeHandler(){
 if (window.location.href.toLowerCase().indexOf("cmspagemode=edit")>0){
 return false;
 }
AssignCSSSelectors();
AssignLinks();
InitializeMenu();
toggleListItem();
handleHover();
fixFonts();
fixSitemap();
handleBranches();
setFeedbackWindow();
$("#nonflashText").show(5000);
// <summary>
// safari fix for top box heading
// </summary>
if ($.browser.safari) {
 $("div.copy").css({filter:"alpha(opacity=1)",opacity:"1"});
}
}

// <summary>
// this function toggles the list item being used for faqs
// </summary>
function toggleListItem()
{
 $(".toggle").find("p").hide();
 $(".toggle").find("table").hide();
 $(".toggle").find("ul").hide();
 $(".toggle").find("span").hide();
 $(".toggle").find("ol").hide();
 $(".toggle").children().each(function(){
  $(this).find("a").click(function(){
  if ($(this).parent().hasClass("clicked"))
  {
   $(this).parent().find("p").slideUp({duration: 500, easing: "easeInQuad"});
   $(this).parent().find("table").hide();
   $(this).parent().find("ul").hide();
   $(this).parent().find("span").hide();
   $(this).parent().find("ol").hide();
  }
  else
  {
   $(this).parent().find("p").slideDown({duration: 500, easing: "easeInQuad"});
   $(this).parent().find("table").show();
   $(this).parent().find("ul").show();
   $(this).parent().find("span").show();
   $(this).parent().find("ol").show();
  }
  $(this).parent().toggleClass("clicked");
 });
 });
}

// <summary>
//  Dropdown Navigation initialize function
// </summary>

function InitializeMenu(){
try{
  $("#navigation").children().each(function(){
   $(this).hover(
    function(){
    try
    {
     if ($(this).children(".slide").length > 0)
     {
      $("#navBg").show();
      $(this).addClass("active");
      var offset = $("#header").offset();
      var rightPos = offset.left + $("#header").width();
      $(this).find("ul").css({left: $(this).offset().left-offset.left});
      var ulwidth = $(this).find("ul").find("li").width() * $(this).find("ul").children("li").length + 40;
      $(this).find("ul").width(ulwidth);
       var curRightPos = $(this).find("ul").offset().left - offset.left + ulwidth;
       if (curRightPos > rightPos)
       { 
        var ErrVal =curRightPos - rightPos +15;
        $(this).find("ul").css({marginLeft: "-" + ErrVal + "px"});
       }
       else
       {
        $(this).find("ul").css({marginLeft: "-15px"});
       }       
      }
     }
     catch(obj)
     {
     }
      
    },
    function(){
     $(this).removeClass("active");
     $(this).find("ul").css({marginLeft: "0px"});
     $("#navBg").hide();
    });
   });
 }
 catch(obj)
 {
 }
}

function hideNav()
{
 $(".horizontal").children().children(".slide").css({display: "none"});
}

// <summary>
//  Function to attach css class to dropdown element on hover
// </summary>
$.fn.hoverClass = function(c) {
 return this.each(function(){
  $(this).hover( 
   function() { $(this).addClass(c);  },
   function() { $(this).removeClass(c); }
  );
 });
};    

// <summary>
//  This function to assign target blank to the external link. html target blank is not a standard w3c validated code. insted of using target="_blank" we use rel="external" and replace the rel with javascript.
// </summary>
function AssignLinks() 
{
	$("a[rel='external']").attr("target","_blank");
	$("a[href='#']").click(function(){
		return false;
	});
}

// <summary>
//  This function to attach non-ie css selectors to the html elements
// </summary>
function AssignCSSSelectors()
{
	if(jQuery.browser.msie)
	{
		$("li:first-child").addClass("FirstChild");
		$("li:last-child").addClass("LastChild");
		$("td:last").addClass("LastChild");
	}
  $("tr:first").addClass("First");
  $(".thumbnails").find("li.LastChild").css({paddingRight: "0"});
}

// <summary>
//  Setting up the interface according to the screen resolution
// </summary>
function fixScreen(){
 var masterOffset = $("#navBlock").offset();
 $("h1").css({left: masterOffset.left+723 + "px"});
 $(".press>li:odd").addClass("second");
}

function fixFonts()
{
try{
 $("h2").sifr({
			path: '/fonts/',
			offsetY: .05,
			color: '#c1a866'
		});
  
  $("h3").sifr({
			path: '/fonts/',
			//offsetY: .05,
			color: '#c1a866'
		});

  $("h3.small").sifr({
			path: '/fonts/',
			offsetY: .05,
			color: '#c1a866'
		});
  
   $(".themeCaption").sifr({
			path: '/fonts/',
			//offsetY: .05,
			color: '#003263'
		});

  $(".finder h3").sifr({
			path: '/fonts/',
			offsetY: .05,
			color: '#C1A866'
		});

  $(".box h3").sifr({
			path: '/fonts/',
			offsetY: .05,
			color: '#c1a866'
		});
  $(".ZoneName h3").unsifr();
  $(".theWrapper").find(".themeCaption").unsifr();
   $("#mediaSpace h3").unsifr();
   Cufon.replace("div.Cufon");
   Cufon.replace("#mediaSpace h3");

  }
  catch(obj)
  {
  
  }
}
  
// <summary>
//  window resize call
// </summary>
function winResize(){
 $(window).resize(function(){
  fixScreen();
 });
}

// <summary>
//  this function is to handle hover popups
// </summary>

function handleHover()
{

 $(".hoverPopup").find("a").each(function(){
 if ($(this).parent().find(".hidden").length > 0)
 {
  if ($(this).hasClass("bookmark")==false)
  {
  $(this).hover(
   function(){
   var offset = $(this).offset();
   $(".summaryBox").html("");
   $(".summaryBox").html("<div><p>"+$(this).parent().find(".hidden").html()+"</p></div>");
   $(".summaryBox").css({top:offset.top+$(this).height()+ "px"});
   $(".summaryBox").css({marginLeft:offset.left - 70+ "px"});
   if (offset.left ==$("#content").offset().left  + 15)
   {
    $(".summaryBox").css({marginLeft:offset.left + "px"});
   }
   $(".summaryBox").show();
   },
   function(){
   $(".summaryBox").hide();
   }); 
   }
  }
 });

}

// <summary>
//  These functions handle events generated by an Input Text box
// </summary>

function InputTextOnFocusHandler (InputTag, DefaultText)
{
	try
	{  		
		if (InputTag.value == DefaultText)
		{
			InputTag.value = "";
		}
	}
	catch (ExceptionObject)
	{
	}
}

function InputTextOnBlurHandler (InputTag, DefaultText)
{
	try
	{
		if (InputTag.value == "")
		{
			InputTag.value = DefaultText;	
		}
	}
	catch (ExceptionObject)
	{
	}
}

// <summary>
//  this function is to fix the sitemap layout
// </summary>
function fixSitemap()
{
$(".sitemap>li:eq(4)").css({clear:"both"});
 $(".sitemap>li:gt(3)").addClass("second");
}

// <summary>
//  setting the lightbox for image gallery
// </summary>
function setLightBox()
{
 $('.imageGallery a').lightBox();
}

// <summary>
//  setting the google map functionalities for branch network
// </summary>
function googleMapInitialize(strLocation)
{
 if (GBrowserIsCompatible()) {
  $("#googleMap").css({display: "block",height:"280px",marginTop: "-300px"});
  $("#mediaSpace").css({height:"320px"});
  $("#mediaSpace div.copy").css({marginTop: "-300px",height:"240px"});
  var map = new GMap2(document.getElementById("googleMap"));
  var point;
  if (strLocation =="sharjah")  
  {
  map.setCenter(new GLatLng(25.344996,55.385685), 13);
  point = new GLatLng(25.344996,55.385685);
  map.openInfoWindow(map.getCenter(),"<p><strong>Sharjah Corniche Road Branch</strong><br />Tel:+(9716) 575 1370<br />Fax: +(9716) 575 1371</p>");
  }
  if (strLocation =="deira")  
  {
    map.setCenter(new GLatLng(25.258941,55.33659), 13);
    point = new GLatLng(25.258941,55.33659);
    map.openInfoWindow(map.getCenter(),"<p><strong>Deira Branch</strong><br />Tel: 800 4354 (Toll Free)</p>");
  }
  if (strLocation =="ShZayedRd")  
  {
    map.setCenter(new GLatLng(25.100222,55.176258), 13);
    point = new GLatLng(25.100222,55.176258);
    map.openInfoWindow(map.getCenter(),"<p><strong>Sheikh Zayed Road Branch</strong><br />Tel: +(9714) 340 2489<br />Fax: +(9714) 340 4430</p>");
  }
  if (strLocation =="AbuDhabi")  
  {
    map.setCenter(new GLatLng(24.47551,54.323326), 13);
    point = new GLatLng(24.47551,54.323326);
    map.openInfoWindow(map.getCenter(),"<p><strong>Abu Dhabi Branch (Marina Mall)</strong><br />Tel: +(9712) 681 8252 <br />Fax:+(9716) 681 8253</p>");
  }
  map.addOverlay(new GMarker(point));
 }
}

// <summary>
//  setting the google map functionalities for branch network
// </summary>
function handleBranches()
{
 if (window.location.href.toLowerCase().indexOf("branchnetwork")<0){
 return false;
 }
 $("body").unload(GUnload());
 
 $("#Branches").children().each(function(){
 $(this).find("a").click(function(){
  $("#Branches").find("a").css({fontWeight: "normal"});
  $(this).css({fontWeight: "bold"});
  var branch = $(this).html();
  if (branch =="Deira Branch")
  {
   googleMapInitialize("deira");
  }
  if (branch =="Sheikh Zayed Road Branch")
  {
   googleMapInitialize("ShZayedRd");
  }
  if (branch =="Sharjah Corniche Road Branch")
  {
   googleMapInitialize("sharjah");
  }
  if (branch =="Abu Dhabi Branch (Marina Mall)")
  {
   googleMapInitialize("AbuDhabi");
  }
 });
 });
 
 $("document").ready(function(){
  $("#Branches a:first").trigger("click");
 });
}

// <summary>
//  feedback form
// </summary>
function setFeedbackWindow()
{
 $("#feedbackLink").click(function(){
  $("#feedbackForm").show(500);  
  var feedbackOffset = $(this).offset();
  $("#feedbackForm").css({left: feedbackOffset.left-400 + "px" });
  $("#infoMessage").hide();
  $("#formContent").show();
  $("#ctl00_ucFooter_txtfeedbackText").val("Submit your feedback*");
 });
 $("#feedbackclose").find("a").click(function(){
  $("#feedbackForm").hide(500);  
 });
 
 $(".submitButton").click(function(){
  var feedbackVal = $("#ctl00_ucFooter_txtfeedbackText").val();
  var ajxURL= "/ajaxFeedBack.aspx?feedback=" + feedbackVal;
  $("#infoMessage").hide();
  $("#formContent").show();
  if ((feedbackVal=="") || (feedbackVal=="Submit your feedback*"))
  {
   alert ("Please fill in your feedback");
   return false;
  }
		$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#edece7' });
  $('#feedbackForm').block('<img src="/Images/Generic/Bigrotation.gif" border="0" />',{ background: 'transparent', border: '0' });

  $.ajax({
  type: "GET",
  url: ajxURL,
  success: function(msg){
   $("#formContent").hide();
   $("#infoMessage").html("<p>" + msg + "</p>");
   $('#feedbackForm').unblock();
   $("#infoMessage").show();
  }
  });
 });
}

// <summary>
//  call corporate structure ajax functionality
// </summary>

function getCorporateStructure()
{
 $(".portfolio").find("a").each(function(){
  $(this).click(function(){
   var contentPage = $(this).attr("href");
   var htmlData;
   $.ajax({
	   type: "GET",
	   dataType: "html",
    url: contentPage,
	   success: function(data){
    $(".ajaxPopup").find(".inner").html(data);
    $(".ajaxPopup").slideDown(500);
    }
   });
   var linkOffset = $(this).offset();
   $(".ajaxPopup").css({top: linkOffset.top - 130+ "px",left: $(".portfolio").offset().left+200 +"px"});
   $("#closeAction").click(function(){
    $(".ajaxPopup").slideUp(500);  
   });
   return false;
  });
 });
}

function onUpdatingForm(elementId)
{
		$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#ffffff' });
  $('#'+elementId).block('<img src="/Images/Generic/Bigrotation.gif" border="0" />',{ background: 'transparent', border: '0' });
}

function onUpdatedForm(elementId)
{
$('#'+elementId).unblock();
}


function HideModalPopup()
{
$(".newsletterPopup").hide();
$(".modalBackground").hide();
$(".textbox").attr("value","");
$("input:radio").attr("checked","");
}

// <summary>
//  these functions for cookie management
// </summary>

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function detectMacXFF2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}

// <summary>
//  banner close button 
// </summary>
function close48hoursBanner()
{
 $(".modalBackground").hide();
 $("#Blaster").hide();
}