﻿var AppPath="/";
function executeHandler(){
 if (window.location.href.toLowerCase().indexOf("cmspagemode=edit")>0){  // exiting if in the sitefinity edit mode
 $("body").addClass("editMode");
  return false;
 }
 $(document).ready(function(){
	  try{
    AssignCSSSelectors();
    AssignLinks();
    navigationHover();
    setDimensions();
    accordianTab();
    initializePopup();
    $(".searchText").handleTextBlur();
    animationText();
    if (window.location.href.toLowerCase().indexOf("/en/")>0){ 
    Fixfont();
     }
    // if (window.location.href.toLowerCase().indexOf("/ar/")>0){ 
    // AdOverlay();
    // }
 }
	catch(obj)
	{
 }
 });
}

// <summary>
//  These functions handle events generated by an Input Text box
// </summary>


$.fn.handleTextBlur = function() {
try{
    return this.focus(function() {
        if( this.value == this.defaultValue ) {
            this.value = "";
        }
    }).blur(function() {
        if( !this.value.length ) {
            this.value = this.defaultValue;
        }
    });   
}catch(obj){
alert(obj.message)
}

}


// <summary>
//  This function to attach non-ie css selectors to the html elements
// </summary> //TradeGothic_b, TradeGothic_l (additional fonts)
function Fixfont(){
 try {
   Cufon.replace('#navigation > ul > li > a', {hover: false,fontFamily: 'TradeGothic-Med',textShadow: '#b4b3b4 1px 1px'});
			Cufon.replace('#navigation > ul > li.Highlight > a', {hover: false,fontFamily: 'TradeGothic-Med',textShadow: '#666 1px 1px'});
   Cufon.replace('#navigation > ul > li.hoverList > a', {hover: false,fontFamily: 'TradeGothic-Med',textShadow: '#575757 0px 0px'});
			Cufon.replace('h2', {fontFamily: 'TradeGothic-Med',textShadow: '#5f80a1 0px 1px'});
			Cufon.replace('.columnRight h2', {fontFamily: 'TradeGothic-Med'});
			Cufon.replace('.columnRight .LandingList h2', {fontFamily: 'TradeGothic-Med',textShadow: '#cfd9e3 -1px 1px'});
   Cufon.replace('.mediaLinks h2', {textShadow: '#fff 0px 0px',fontFamily: 'TradeGothic-Med'});
   Cufon.replace('.nav2 > li > a', {hover: true, fontFamily: 'TradeGothic-Med'});
   Cufon.replace('.mediaLinks>ul > li > a', {    
   hover: true,
   fontFamily: 'TradeGothic-Med',
   textShadow: '#cbd1d8 0px 0px'
  });
   Cufon.replace('#innerMediaspace h2,#innerMediaspace h3', {
   fontFamily: 'TFarrow'
  });
    Cufon.replace('#output h3,#output h2', {
    fontFamily: 'TFarrow'
//    textShadow: '#fff 0px 0px'
    });
 } 
 catch (obj) {
 }
}

function navigationHover(){
$("#navigation>ul>li").hover(function(){
//if($(this).find("ul").length==0) return false;
$(this).addClass("hoverList");
if (window.location.href.toLowerCase().indexOf("/en/")>0){ 
Cufon.replace('#navigation > ul > li.hoverList > a', {hover: false,fontFamily: 'TradeGothic-Med',textShadow: '#e0e1e1 0px 0px'});
}
},function()
{
$(this).removeClass("hoverList");
if (window.location.href.toLowerCase().indexOf("/en/")>0){ 
Cufon.replace('#navigation > ul > li > a', {hover: false,fontFamily: 'TradeGothic-Med',textShadow: '#b4b3b4 1px 1px'});
Cufon.replace('#navigation > ul > li.Highlight > a', {hover: false,fontFamily: 'TradeGothic-Med',textShadow: '#666 1px 1px'});
}
});
}

// var childNo=$(this).find(".subnavWrap > ul > li").length;
//alert(childNo);
// if(childNo%2 != 0){
// alert(childNo);
// $(this).find(".subnavWrap > ul > li:eq("+childNo-1+")").addClass("no_border");
// $(this).find(".subnavWrap > ul > li:eq("+childNo-2+")").addClass("no_border");
// }



function homeSubnavhover(){
var posX=0;
var posX2=100;

$(".mediaLinks > ul > li > a").mouseover(function(){
var posY = $(this).offset().top - 133;// 143 is the top offset of  "div.subnavHold" .The position change should reflect here
//if($(this).find("div.subnavHold").length==0) return false;
$(this).parent().addClass("hoverList");
 if (window.location.href.toLowerCase().indexOf("/ar/")>0){
 $("div.subnavHold").css({'backgroundPosition': + posX2 + '% ' + posY + 'px'});
 }
  if (window.location.href.toLowerCase().indexOf("/en/")>0){
 $("div.subnavHold").css({'backgroundPosition': + posX + 'px ' + posY + 'px'});
 }
});


$(".mediaLinks > ul > li").mouseleave(function(){
$(this).removeClass("hoverList");
});

}

// function for home page media space animation

function homeMediaspace(){
  $("#slideshow").cycle({
      fx:'fade',
      timeout: 7000,
      speed:   3000,
      pager:  '#imageNav',
      before:   onBefore,
      cleartype:  false
  });
}

function onBefore() { 
var Caption;
var CaptionArray;
    Caption = this.alt;
    CaptionArray = Caption.split("#");
    $('#output').html('<h3>' + CaptionArray[0] + '</h3><h2 id="caption'+CaptionArray[2]+'">' +CaptionArray[1]+'</h2>');
    // setting text fade effect in all browsers except ie - in ie there is bug in fade text.
        if (!$.browser.msie ) {
        $("#output h2").css("display", "none");
        $("#output h2").fadeIn(4000);
        }
    if (window.location.href.toLowerCase().indexOf("/en/")>0){
        Cufon.replace('#output h3,#output h2', {
        fontFamily: 'TFarrow'
        //textShadow: '#003469 1px 1px' 
        });
    }
}

//this is for the animation text for inner media space
function animationText(){
   $('.slideText').cycle({
    fx:     'fade',
    timeout: 4000,
    speedIn:  3500, 
    speedOut: 400, 
    after:   onAfterinner
      });
}
function onAfterinner() { 
   //   $('.slideText h3').css('filter','');
    if (window.location.href.toLowerCase().indexOf("/en/")>0)
    {
        Cufon.replace('.slideText h3', {
        fontFamily: 'TFarrow'
        });
    }
}

function AssignCSSSelectors()
{
 $("li:first-child").addClass("firstChild");
 $("li:last-child").addClass("lastChild");
 $("ul.LandingList li:nth-child(2n)").addClass("second");
 $(".shuaaTable2 tr,.stockChart tr").each(function(){
 //$(this).find("td:first").addClass("firstTd");
 $(this).find("td:last").addClass("lastTd");
  $(this).find("tr:last").addClass("lastRaw");
  $(this).find("td:first").addClass("firstTd");
 });
  $("table").each(function(){
  $(this).find("tr:last").addClass("lastRaw");
  $(this).find("tr:first").addClass("firstRaw");
 });
}



// <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;
 });
}


//function for accordian tabs
 
 function accordianTab(){
 $(".toggleList").children().each(function(){
  $(this).find(".toggleLink").click(function(){
   if ($(this).parent().hasClass("clicked")){
    $(this).parent().find("div.slideContent").slideUp(500);
    $(this).parent().removeClass("clicked")
   }
   else{
    CloseAllDivs();  
    $(this).parent().find("div.slideContent").slideDown(500);
    $(this).parent().addClass("clicked");  
   }
  });
 });
 }
 
function CloseAllDivs(){
$(".toggleList div.slideContent").slideUp(500);
$(".toggleList li").each(function(){$(this).removeClass("clicked")});
}

 
 // function for handling the check boxes - Manage Publication page under career section
 
 function checkboxControl()
 {
$('span.checkPub').click(function(){
if($(this).find("input").is(':checked')){
$(this).parent().parent().find("span.chkEnglish input").attr("checked","checked");
$(this).parent().parent().find("span.chkArabic input").removeAttr("checked");
}
else{
$(this).parent().parent().find("span.chkEnglish input").removeAttr("checked")   ;
$(this).parent().parent().find("span.chkArabic input").removeAttr("checked");
}
});
 }
 
 
// <summary>
//  Update panel loading animation functions
// </summary>
function OnUpdating(elementId){
	$.extend($.blockUI.defaults.overlayCSS, { backgroundColor: '#ffffff' });
 $('#' + elementId).block('<img src="/Images/Generic/Bigrotation.gif" border="0" />',{ background: 'transparent', border: '0' });
}

function OnUpdated(elementId){
 $('#' + elementId).unblock();
}

// Sliding news

function newsSlide(){
    $('#newsScroll').cycle({
		fx:         'scrollLeft',
        timeout:     3000,
        pager:      '#slideNav',
        pagerEvent: 'mouseover',
        fastOnEvent: true
    });
}


// Sliding news with NO - autosliding(without pluguin)

function newsSlide2(){
    $("div#newsScroll div").hide();
    var slideNo=$("#newsScroll div").length;
	var navMarkup="";
	for (i = 0; i <slideNo; i++) {
	navMarkup+='<a href="#" id="'+i+'">'+i+'</a>';
	}
	$("div#slideNav").append(navMarkup);
    $("div#slideNav a:first").addClass("activeSlide");
    $("div#newsScroll div:eq(0)").show();
	//$("div #slideNav a"+"#"+currentPage).addClass("activeSlide");
    $("div#slideNav a").each(function(){
    $(this).click(function(){
    $("div#newsScroll div").hide();
    $("div#slideNav a").removeClass("activeSlide");
    $("div#newsScroll div:eq("+$(this).attr("id")+")").show();
    $("div #slideNav a"+"#"+$(this).attr("id")).addClass("activeSlide");
    });
    });
}

//set dimensions for some particular elements

function setDimensions(){
$(".shuaaTable, .shuaaTable2").each(function(){
//$(this).width($(this).find("table").width());
//$(this).width($(this).find("table").width());
});

//alert($(".shuaaTable table").width());
}



// <summary>
// Numeric field filter functions
// </summary>
 function NumericFilter(event)
 {
  var keycode;

  if (document.all)
  {
   keycode=event.keyCode;
  }

  else
  {
   keycode=event.which;
  }
  if((keycode==8) || (keycode==127) || (keycode==9)  || (keycode==0))
  {
   return(true);
  }
  if ( ((keycode>47)&&(keycode<58)) )
  {
   return(true);
  }
  else
  {
   return(false);
  }
 }


/*Cookie functions */
 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 googleMapInitialize()
{
 if (GBrowserIsCompatible()) {
  $("#GoogleMap").css({display: "block"});
  var map = new GMap2(document.getElementById("GoogleMap"));
  var point;
  map.setCenter(new GLatLng(25.217261,55.28311), 14);
  point = new GLatLng(25.217261,55.28311);
  var raktext =(window.location.href.toLowerCase().indexOf("/en/")> 0 ? "<div class='GooglemapLogo'><p><strong>SHUAA Capital</strong> <br />Level 28, Emirates Towers<br />Sheikh Zayed Road ,P.O. Box 31045<br />Dubai, United Arab Emirates<br />Switchboard:      +971 4 330 3600<br />UAE Toll-Free:     800 SHUAA (74822)<br />Fax:                  +971 4 330 3550</p></div>" : "<div class='GooglemapLogo'><p>أبراج الإمارات، الطابق 28 <br />شارع الشيخ زايد <br />صندوق البريد: 31045 <br />دبي، دولة الإمارات العربية المتحدة<br />بريد إلكتروني: <a href='mailto:info@shuaacapital.com'>info@shuaacapital.com</a><br /><br />بدالة :  <span class='engText'>+971 4 330 3600</span> <br />فاكس : <span class='engText'>+971 4 330 3550</span></p></div>");
  map.openInfoWindow(map.getCenter(), raktext);
     map.setMapType(G_NORMAL_MAP);
    //map.setMapType(G_HYBRID_MAP);
    //map.setUIToDefault();
    var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
    map.addControl(new GMapTypeControl(),bottomRight);
  var bottomLeft = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10,10));
  map.addControl(new GLargeMapControl3D,bottomLeft);
  map.addOverlay(new GMarker(point));
  //GEvent.addListener(map, "tilesloaded", printPage());
 }
}



//printPage(){
//setTimeout ("setToBlack()", 2000 );
//}



// add class to the body of inner pages


function addbodyClass(){
 var urlpath=window.location.href;
 var urlArray = urlpath.split("/");
 if(urlArray[5].indexOf(".aspx")>0){
 urlarray2 = urlArray[5].split(".");
 $("body").addClass(urlarray2[0]);
 }
 else{
 $("body").addClass(urlArray[5]);
 }
}

function closePopup(){
 $(".popup").animate({top:	-800},{queue:false,duration:400,complete:function(){
   $(".fade").animate({opacity: 0},{queue:false,duration:200,complete:function(){
    $(".popup").remove();
    $(".fade").remove();
  }});
 }});
}



// <summary>
// E-support popup script
// </summary>
function openModelWindow(targetid)
{
  var ScrollPos = getPageScroll();
  var PageSizes = getPageSize();
  var TopMargin;
  var PageHeight =  $(document).height();
  var PopupHTML = '<div class="fade" style="height:'+ PageHeight +'px" ></div><div class="popup">' +
    '<div class="wrap1">' +
     '<div class="popup-close" onclick="closePopup();"></div>' +
      '<div class="PopupContent clearfix">';
       PopupHTML = PopupHTML + $(targetid).html();
       PopupHTML = PopupHTML + '</div>' +
     '</div>' +
  '</div>';
 $("body").append(PopupHTML);
 $(".fade").css({opacity:0});
 $(".popup").css({top: -600});
 $(".fade").animate({opacity: 0.25},{queue:false,duration:200,complete:function(){
  $(".popup").animate({top:ScrollPos[1]+30},{queue:false,duration:400});
 }});
 return false;
}

function initializePopup(){
 $(".model-popup").click(function(){
  var targetId= "#" + $(this).attr("rel");
  openModelWindow(targetId);
 });
}


//Array Return an array with x,y page scroll values.
		function getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;
			}
			arrayPageScroll = new Array(xScroll,yScroll)
			return arrayPageScroll;
		}

// <summary>
// @return Array Return an array with page width, height and window width, height
// </summary>
		function getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth;
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else {
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){
				pageWidth = xScroll;
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
			return arrayPageSize;
		};

  
  
function Popup (URL, Width, Height, Scrollable, Resizable)
{
	try
	{
		var Popup;
		if ((typeof(Width) == "number") && (typeof(Height) == "number"))
		{
			Popup = window.open(URL, "Popup", "width = " + Width + ", height = " + Height + ", top = " + ((screen.height - Height) / 2) + ", left = " + ((screen.width - Width) / 2) + ", resizable = " + (Resizable ? "yes" : "no") + ", scrollbars = " + (Scrollable ? "yes" : "no") + ", status = no");
		}
		else
		{
			Popup = window.open(URL, "Popup");
		}
	}
	catch (ExceptionObject)
	{
		alert("Your browser or a piece of software installed on your\ncomputer appears to be blocking popups on this page.\n\nPlease enable popups and refresh this page to continue.");
	}
	
	try
	{
		Popup.window.focus();
	}
	catch (ExceptionObject)
	{
	}
}
  
  
  
function AdOverlay(){
    var PageHeight =  $(window).height();
    var BackgroundOverlay='<div class="Overlay" style="height:'+ PageHeight +'px" ><table cellpadding="0" cellspacing="0" height="100%" width="100%"><tr><td width="100%" height="100%" align="center" valign="top"><table cellpadding="0" cellspacing="0" width="100%"><tr><td align="center" valign="top" class="overlayTopspace"><h1>UNDER CONSTRUCTION</h1><p><a href="#" class="overlayLink">Go to English website </a></p></td></tr></table></td></tr></table></div>';
    $("#wrap1").hide();
    $("body").append(BackgroundOverlay);
    $(".overlayLink").attr('href',window.location.href.replace('/ar/', '/en/'));
}

