//-------------------------------------------------------------------------------
//                           menu initialization 
//-------------------------------------------------------------------------------		
var urlBase= '/etisalat/templates/129';
ddsmoothmenu.init({
	    mainmenuid: "smoothmenu1", //menu DIV id
	    orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	    classname: 'ddsmoothmenu', //class added to menu's outer DIV
	    //customtheme: ["#1c5a80", "#18374a"],
	    contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
    })
//-------------------------------------------------------------------------------
//                            menu focus setter	
//-------------------------------------------------------------------------------	
function menu_selection(level_1){
document.getElementById(level_1).style.background="url('+urlBase+'/topnav_active.gif)"
}

$(document).ready(function(){ 
if($('.wahmyyya2 div').length > 0){                                                                                                
var level_3 =$('.wahmyyya2 div').text();                
$( 'ul.product_menu_items li a:contains(' + level_3 + ')' ).parent().addClass('product_menu_selected');
}
if($('.wahmyyya div').length > 0){
var level_2 =$('.wahmyyya div').text();  
$( 'ul.bcrumb li div:contains(' + level_2 + ')' ).parent().addClass('bcrumb_selected_item');
}
//-------------------------------------------------------------------------------
//                           Home gallery
//-------------------------------------------------------------------------------		
if($('#images_container').is('.flash_content'))
{
$("#images_container #pikame").PikaChoose({show_captions:false, slide_enabled:true, show_prev_next:false,thumb_width:15, thumb_height:15,auto_play:true});
$("#images_container #pikame").fadeTo(0, 0.00);
$("#images_container #pikame").fadeTo(1000, 0.01);
$("#images_container #pikame").fadeTo(1000, 1);
$("#images_container .pika_play").fadeTo(0, 0.00);
$("#images_container .pika_play").fadeTo(1000, 0.01);
$("#images_container .pika_play").fadeTo(1000, 1);
	$("#some-element").simpletooltip();
	$(".with-tooltip").simpletooltip();
}
//-------------------------------------------------------------------------------
//                           Mobile gallery 
//-------------------------------------------------------------------------------	
if($('#mobile_phones').is('.mobile_slideshow'))
{

	$("#mobile_phones #pikame").PikaChoose({show_captions:false, slide_enabled:false, show_prev_next:true,thumb_width:61, thumb_height:61,auto_play:false});	
}
//-------------------------------------------------------------------------------
//                          Blackbery Carousel  gallery 
//-------------------------------------------------------------------------------	
if($('#carousel').is('.blackbery'))
{
    $(".blackbery").jCarouselLite({
        btnNext: ".prev1",
        btnPrev: ".next1"
    });
}
//-------------------------------------------------------------------------------
//                          Brands Carousel  gallery 
//-------------------------------------------------------------------------------	
if($('#carousel2').is('.brands'))
{
var carousel2 = document.getElementById("carousel2");
items = carousel2.getElementsByTagName("li");
var li_num = items.length;
if(li_num>6){
    $(".brands").jCarouselLite({
        btnNext: ".prev2",
        btnPrev: ".next2",
		visible: 6
  });
}
else{$(".next_prev_carousel").hide()}
}	
//-------------------------------------------------------------------------------
//                           Medals and flags fade
//-------------------------------------------------------------------------------		
							   
	$('.opacity').hover(
		function () {
		  $(this).fadeTo("fast", 0.99);
		}, 
		function () {
		  $(this).fadeTo("fast", 0.4);			
		}
	);				   	
//-------------------------------------------------------------------------------
//                            field text keeber 	
//-------------------------------------------------------------------------------											
	$('.field-clear').show();
	$('.field-field').hide();
	$('.field-clear').focus(function() {
		$(this).hide();
		$(this).next('.field-field').show();
		$(this).next('.field-field').focus();
	});
	$('.field-field').blur(function() {
		if($(this).val() == '') {
			$(this).hide();
			$(this).prev('.field-clear').show();
			
		}
	});
//-------------------------------------------------------------------------------
//                            field text keeber with popup 	
//-------------------------------------------------------------------------------		
	
	$("#looking_for_button_2").show();
	$("#looking_for_button").hide();
	$('#looking_for_input').blur(function() {
		var length = $("#looking_for_input").val().length; 
		if(length > 0)  {
		$("#looking_for_button").show();
			$("#looking_for_button_2").hide();
		}else{
	$("#looking_for_button_2").show();
	$("#looking_for_button").hide()	
		}
	});
//-------------------------------------------------------------------------------
//                            Tabs	
//-------------------------------------------------------------------------------									   			 
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();			
	$('div.tabs ul.tabNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabs ul.tabNavigation a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();			
//-------------------------------------------------------------------------------
//                            Trigger slide
//-------------------------------------------------------------------------------													
	$('#slideshow').slideshow({
		  timeout: 2000,
		  fadetime: 2000,
		  type: 'sequence',
		  pauselink: 'pause'
	});	   
	$(".toggle_container").hide();

	$(".trigger").toggle(function(){
		  $(this).contents(".plus_button").css('background', 'url('+urlBase+'/minus_button.gif)');
		  }, function () {
		  $(this).contents(".plus_button").css('background', 'url('+urlBase+'/plus_button.gif)');
	});			
	$(".trigger").click(function(){
		  $(this).parent().next(".toggle_container").slideToggle("slow");
	});
//-------------------------------------------------------------------------------
//                           features slide show
//-------------------------------------------------------------------------------	
	var feature=1;		
	$(".first_feature").hover(function(){ 
		if(feature==1)
 		{
	  	feature=0;
		$(this).parent().parent().next(".price_view").slideDown(250);
		$(this).parent().parent().next().next(".enroll_view").hide();
		$(this).parent().parent().next().next().next(".terms_view").hide();
		}
		else{
		$(this).parent().parent().next(".price_view").show();
		$(this).parent().parent().next().next(".enroll_view").hide();
		$(this).parent().parent().next().next().next(".terms_view").hide();			
		}		
	});		   		
	$(".second_feature").hover(function(){
		 if(feature==1)
 		{
		feature=0;
		$(this).parent().next().next(".enroll_view").slideDown(250);
		$(this).parent().next(".price_view").hide();
		$(this).parent().next().next().next(".terms_view").hide();
		}
		else{
		$(this).parent().next().next(".enroll_view").show();
		$(this).parent().next(".price_view").hide();
		$(this).parent().next().next().next(".terms_view").hide();
			
		}
	});
	$(".third_feature").hover(function(){
		if(feature==1)
 		{
		feature=0;						 
		$(this).parent().next().next().next(".terms_view").slideDown(250);
		$(this).parent().next(".price_view").hide();
		$(this).parent().next().next(".enroll_view").hide();
		}
		else{
		$(this).parent().next().next().next(".terms_view").show();	
		$(this).parent().next(".price_view").hide();
		$(this).parent().next().next(".enroll_view").hide();	
		}
	});	
	
//-------------------------------------------------------------------------------
//                           Send success or fail
//-------------------------------------------------------------------------------							
   var sent_success=2;
   $('.popup_form_container').show();
	$('.send_success').hide();
	$('.send_faild').hide();
	$('.loading').hide();
	
	$(".send_form_data").click(function(){
		
		if(sent_success==0)
		{
	    $('.popup_form_container').hide();
		$('.send_faild').hide();
		$('.send_success').hide();
		$('.loading').fadeIn("slow");
		}								
		if(sent_success==1)
		{
	    $('.popup_form_container').hide();
		$('.send_faild').hide();
		$('.loading').hide();
		$('.send_success').fadeIn("slow");
		}								
		if(sent_success==2)
		{
	    $('.popup_form_container').hide();
		$('.send_success').hide();
		$('.loading').hide();
		$('.send_faild').fadeIn("slow");
		}								
    });
	
		$(".reset_popup").click(function(){
		$('.send_success').hide();
		$('.send_faild').hide();
		$('.loading').hide();		
		$('.popup_form_container').show();
		$('#form_holder .field-clear').show();
		$('#form_holder .field-field').hide();
		$('#form_holder .field-field').val("");
    });
//-------------------------------------------------------------------------------
//                           menu reset
//-------------------------------------------------------------------------------		
		$('#smoothmenu1').hover(
		function () {$(".level_1").css('background', 'url('+urlBase+'/topnav_stretch.gif)')}, 
		function () {}
		);						
//-------------------------------------------------------------------------------
//                           Font setter
//-------------------------------------------------------------------------------							
var x = $.cookie('fontsize');
var fontsize=x;
if(fontsize==1){resetFont()}						   
if(fontsize==2){Increase_Font_Size_2X()}
if(fontsize==3){Increase_Font_Size_4X()}

     function resetFont()
	{	
	
$('#content div,#content td,#content span,#content li,#content th,#content td').css('font-size', '12px');
$('#content div,#content td,#content span,#content li,#content th,#content td').css('line-height', '18px'); 

$('.row2_personal_header ,.tapnotselected ,.alternatrow2 ,.row3,.row2,.tapselected,.row2_personal,.alternatrow2_personal').css('font-size', '8px');
$('.securenote,.darkgreen,.divlayer,.txt_box80,.shoplocations,.greenframed span,.router_desc td,.txt_box130,.greenframed,.titlesmall_personal,.flatinput').css('font-size', '11px');	
$('.scname').css('font-size', '14px');
$('.combo_box75,.combo_box130,.alternatrow').css('font-size', '10px'); 


		$('.resetFont').attr('src', urlBase+'/text_size_3_selected.gif');
		$('.increaseFont').attr('src', urlBase+'/text_size_2.gif');
		$('.increaseFont2').attr('src', urlBase+'/text_size_1.gif');
		$.cookie('fontsize', '1');
	} 
	
	    function Increase_Font_Size_2X()
	{
		
$('#content div,#content td,#content span,#content li,#content th,#content td').css('font-size', '15px');
$('#content div,#content td,#content span,#content li,#content th,#content td').css('line-height', '20px'); 

$('.row2_personal_header ,.tapnotselected ,.alternatrow2 ,.row3,.row2,.tapselected,.row2_personal,.alternatrow2_personal').css('font-size', '10px');
$('.securenote,.darkgreen,.divlayer,.txt_box80,.shoplocations,.greenframed span,.router_desc td,.txt_box130,.greenframed,.titlesmall_personal,.flatinput').css('font-size', '14px');
$('.scname').css('font-size', '17px');
$('.combo_box75,.combo_box130,.alternatrow').css('font-size', '13px'); 



		$('.resetFont').attr('src', urlBase+'/text_size_3.gif');
		$('.increaseFont').attr('src', urlBase+'/text_size_2_selected.gif');
		$('.increaseFont2').attr('src', urlBase+'/text_size_1.gif');
		$.cookie('fontsize', '2');
		return false;
	}
	
    function Increase_Font_Size_4X()
	{

		var newFontSize = 20;
		
$('#content div,#content td,#content span,#content li,#content th,#content td').css('font-size', '17px');
$('#content div,#content td,#content span,#content li,#content th,#content td').css('line-height', '22px'); 

$('.row2_personal_header ,.tapnotselected ,.alternatrow2 ,.row3,.row2,.tapselected,.row2_personal,.alternatrow2_personal').css('font-size', '12px');
$('.securenote,.darkgreen,.divlayer,.txt_box80,.shoplocations,.greenframed span,.router_desc td,.txt_box130,.greenframed,.titlesmall_personal,.flatinput').css('font-size', '16px');
$('.scname').css('font-size', '19px');
$('.combo_box75,.combo_box130,.alternatrow').css('font-size', '15px'); 

		$('.resetFont').attr('src', urlBase+'/text_size_3.gif');
		$('.increaseFont').attr('src', urlBase+'/text_size_2.gif');
		$('.increaseFont2').attr('src', urlBase+'/text_size_1_selected.gif');
		$.cookie('fontsize', '3');
		return false;
	}
	// Reset Font Size
    var originalFontSize = $('#content').css('font-size');
    $(".resetFont").click(function(){
		resetFont();
    });
	
  	// Increase Font Size 2X
    $(".increaseFont").click(function(){
	Increase_Font_Size_2X();
    });
	
 	 // Increase Font Size 4X
    $(".increaseFont2").click(function(){
	Increase_Font_Size_4X();
    });
//	onload functions goes here **********************************************	
		try
		{
			loadLoginCookie();	// load the login coockie if exists
		}
		catch(e)
		{
			//	load login cookie failed
		}
		
		try
		{
			load_relatedContent();	// load the related content JSP
		}
		catch(e)
		{
			// the page does not have the related content area
		}
//	*************************************************************************	
});

//-------------------------------------------------------------------------------
//                           Home products show
//-------------------------------------------------------------------------------	
function show_product1()
{	
	document.getElementById("product1").className="control_area_selected";
	document.getElementById("product2").className="control_area";
	document.getElementById("product3").className="control_area control_area_3_row";
	document.getElementById("offfer_3").style.zIndex="-3";
	document.getElementById("offfer_2").style.zIndex="-2";
	document.getElementById("offfer_1").style.zIndex="1";$("#offfer_1").fadeIn("slow");
	$("#offfer_2").fadeOut("normal");
	$("#offfer_3").fadeOut("normal");
}
function show_product2()
{	
	document.getElementById("product2").className="control_area_selected";
	document.getElementById("product1").className="control_area";
	document.getElementById("product3").className="control_area control_area_3_row";
	document.getElementById("offfer_1").style.zIndex="-3";
	document.getElementById("offfer_3").style.zIndex="-2";
	document.getElementById("offfer_2").style.zIndex="1";$("#offfer_2").fadeIn("slow");
	$("#offfer_1").fadeOut("normal");
	$("#offfer_3").fadeOut("normal");
}
function show_product3()
{	
	document.getElementById("product3").className="control_area_selected control_area_3_row";
	document.getElementById("product1").className="control_area";
	document.getElementById("product2").className="control_area ";
	document.getElementById("offfer_1").style.zIndex="-3";
	document.getElementById("offfer_2").style.zIndex="-2";
	document.getElementById("offfer_3").style.zIndex="1";$("#offfer_3").fadeIn("slow");
	$("#offfer_2").fadeOut("normal");
	$("#offfer_1").fadeOut("normal");
}
//-------------------------------------------------------------------------------
//                           add to bookmark
//-------------------------------------------------------------------------------	
function bookmarksite(title,url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print)
	{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
//-------------------------------------------------------------------------------
//                           Textbox limiter
//-------------------------------------------------------------------------------	
 
	function limitbox(textboxId,outputId,max){
	  this.textboxId = textboxId;
	  this.outputId = outputId;
	  this.max = max;
	  this.remainingText = "";
	  this.init();
	}
	 
	limitbox.prototype = {
	
	  init : function(){
	 
		var elem = document.getElementById(this.textboxId);
		var ref = this;
	 
		elem.onkeyup = function(){ref.keypress();}  
		elem.onkeydown = function(){ref.keypress();}  
		elem.onkeypress = function(){ref.keypress();}  
		elem.onchange = function(){ref.keypress();}  //catches paste events
	 
		this.keypress();
		elem = null;
	  },
	
	  keypress : function(){
		var elem = document.getElementById(this.textboxId);
		if(elem.value.length >= this.max) elem.value = elem.value.substr(0,this.max);
		document.getElementById(this.outputId).innerHTML = this.remainingText + (this.max - elem.value.length);    
		elem = null;
	  }
	}				
//------------------------------------------------------------------------------------------------------------------------------------------------------
// implementation scripts

	function ajaxpage(url, containerid){
	    var page_request = false;
	    if (window.XMLHttpRequest) // if Mozilla, Safari etc
	            page_request = new XMLHttpRequest();
	    else if (window.ActiveXObject){ // if IE
			try {
				page_request = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					page_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){}
			}
		}
		else
			return false;
	    
	    document.getElementById(containerid).innerHTML = "<p align='center'><br/><br/><img src='/webapp/jtags/jsps/18-1.gif' /><br /><b> Please wait </b><br><b>&#1575;&#1604;&#1585;&#1580;&#1575;&#1569; &#1575;&#1604;&#1575;&#1606;&#1578;&#1592;&#1575;&#1585; </b></p><br/><br/>";
	    page_request.onreadystatechange=function(){
	            loadpage(page_request, containerid);
	    }
	    page_request.open('GET', url, true);
	    page_request.send(null);
	}
	
	function loadpage(page_request, containerid){
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
			 document.getElementById(containerid).innerHTML=page_request.responseText;
		}
	}

	function getPageMetaData(){
		var metaTags = document.getElementsByTagName('meta');
		var metaData = "";
		for(i=0;i<metaTags.length;i++){
		if( metaTags[i].name == 'metaData')
			metaData = metaTags[i].content;
		}
		return metaData;
	}
	
	function load_relatedContent(){
		var metaData = getPageMetaData();
		var url="/webapp/jtags/jsps/sub_related_content_ar.jsp?metaData=" + metaData;
		ajaxpage(url, 'relatedContentDiv');
	}
	
function loadLoginCookie()
	{
		var username = $.cookie('etisalat_username');
		var password = $.cookie('etisalat_password');
		
		if( username != null  && username.trim().length > 0 )
		{
			document.getElementById('txt_username').value = username;
			document.getElementById('txt_username').style.display="block";
			document.getElementById('txt_username_clear').style.display="none";
		}
		
		if( password != null &&  password.trim().length > 0 )
		{
			document.getElementById('txt_password').value = password;
			document.getElementById('txt_password').style.display="block";
			document.getElementById('txt_password_clear').style.display="none";
		}
	}
	
	function onLogin()
	{
		if( document.getElementById('chk_rememberme').checked )
		{
			var username = document.getElementById('txt_username').value;
			var password = document.getElementById('txt_password').value;
			
			if( username != null  && password != null && username.trim().length > 0 && password.trim().length > 0 )
			{		
				$.cookie('etisalat_username', username);
				$.cookie('etisalat_password', password);
			}
			else
			{
				alert("please enter valid username/password for login!");
			}
		}
	}

	function DecodeURL(inputString) { 
		if(inputString!=null && inputString!=""){
			while(inputString.indexOf("%2B")>=0) { inputString=inputString.replace("%2B","+"); } 
			while(inputString.indexOf("%21")>=0) { inputString=inputString.replace("%21","!"); } 
			while(inputString.indexOf('%22')>=0) { inputString=inputString.replace("%22",'"'); } 
			while(inputString.indexOf("%23")>=0) { inputString=inputString.replace("%23","#"); } 
			while(inputString.indexOf("%24")>=0) { inputString=inputString.replace("%24","$"); } 
			while(inputString.indexOf("%26")>=0) { inputString=inputString.replace("%26","&"); } 
			while(inputString.indexOf("%27")>=0) { inputString=inputString.replace("%27","'"); } 
			while(inputString.indexOf("%28")>=0) { inputString=inputString.replace("%28","("); } 
			while(inputString.indexOf("%29")>=0) { inputString=inputString.replace("%29",")"); } 
			while(inputString.indexOf("%2C")>=0) { inputString=inputString.replace("%2C",","); } 
			while(inputString.indexOf("%3A")>=0) { inputString=inputString.replace("%3A",":"); } 
			while(inputString.indexOf("%3B")>=0) { inputString=inputString.replace("%3B",";"); } 
			while(inputString.indexOf("%3C")>=0) { inputString=inputString.replace("%3C","<"); } 
			while(inputString.indexOf("%3D")>=0) { inputString=inputString.replace("%3D","="); } 
			while(inputString.indexOf("%3E")>=0) { inputString=inputString.replace("%3E",">"); } 
			while(inputString.indexOf("%3F")>=0) { inputString=inputString.replace("%3F","?"); } 
			while(inputString.indexOf("%5B")>=0) { inputString=inputString.replace("%5B","["); } 
			while(inputString.indexOf('%5C')>=0) { inputString=inputString.replace('%5C','\\');} 
			while(inputString.indexOf("%5D")>=0) { inputString=inputString.replace("%5D","]"); } 
			while(inputString.indexOf("%5E")>=0) { inputString=inputString.replace("%5E","^"); } 
			while(inputString.indexOf("%7B")>=0) { inputString=inputString.replace("%7B","{"); } 
			while(inputString.indexOf("%7C")>=0) { inputString=inputString.replace("%7C","|"); } 
			while(inputString.indexOf("%7D")>=0) { inputString=inputString.replace("%7D","}"); } 
			while(inputString.indexOf("%7E")>=0) { inputString=inputString.replace("%7E","~"); } 
			while(inputString.indexOf("%40")>=0) { inputString=inputString.replace("%40","@"); }
			while(inputString.indexOf("%")>=0) { inputString=inputString.replace("%"," "); }
		}
		return inputString; 
	}
	
	// public method for url encoding
	function encode(string) {
		return escape(this._utf8_encode(string));
	}
	// public method for url decoding
	function decode(string) {
		return this._utf8_decode(unescape(string));
	}
	// private method for UTF-8 encoding
	function  _utf8_encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	}

	// private method for UTF-8 decoding
	function  _utf8_decode(utftext){
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ){
			c = utftext.charCodeAt(i);
			if (c < 128){
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)){
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else{
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
	
	function postpaidAjaxFunctionCallings(){
	}
	
	function prepaidAjaxFunctionCallings(){
	}
	
	function randomizeimages(l)
	{
	}