﻿/*
  this function initiates the html overlay 
  Section -  this is the current section of  to be triggered
  Type -  The type of content ( it can be html or xml)
*/

var global_user_id = "";

var global_section = "";

var IsPopupShown = false;
var FromEventPlanner = false;

// - - - - - - - - - - LANG - - - - - - - - - - 
// TODO on startup: read cookie or query string
// Update the global_lang variable
// set the correct flashvar

function toggleLang()
{
 if (IsPopupShown) return false;
 if (global_lang == "EN"){ 
  global_lang = "AR"
  $("body").addClass("ArabiCss");
 }
 else{ 
  $("body").removeClass("ArabiCss");
  global_lang = "EN"
 }
 
  // update the cookie
 createCookie("Language",global_lang,365);
 
 // change the image
 $('#langBtn').html('<img src="/images/generic/lang_'+ global_lang + '.jpg" width="57" height="22" border="0"  />');
 
 // notify flash
 getElement("flashevents").changeLang(global_lang); 
}


// - - - - - - - - - - JS / Flash AS3 communication - - - - - - - - - - 
// get the flash movie 
function getElement(movieName) {
 var isIE = navigator.appName.indexOf("Microsoft") != -1;
 return (isIE) ? window[movieName] : document[movieName];
}


function getPopupState()
{
	return IsPopupShown;
}


function callToActionscript() {
 try{
 $("embed").css({visibility: "visible"});
 $("#PagingLeft,#PagingRight").hide();
 $('.Layer1').hide(); 
 $('#MainVideo').empty(); // make sure the youtube video stops playing on the gallery page
 getElement("flashevents").sendToActionscript('close'); 
 IsPopupShown = false;
 $("#langBtn").css("cursor", "pointer"); 
}
catch(obj){}
}

// Opens the login form and redirect to the section when User is logged in
function loginAndRedirect(Section) {
 $('.Layer1').hide();
 getElement("flashevents").loginAndRedirect(Section, global_section);
}

// forwards the xml response to flash
function SendRegistration(XmlString) {
 if (jQuery.browser.msie) {
  var string = XmlString.xml;
 } else {
  var string = (new XMLSerializer()).serializeToString(XmlString);
 }
 //alert($("#Password").val());
 getElement("flashevents").sendRegistration(string, $("#Password").val() );
}

// Triggering function : - Executed from flash
function sendToJavaScript(str) {

 createCookie("Referor","flash",365);
 //console.log(str);
 var Item = "";
 var Param = str.split("#"); //Spliting the parameters
 // Update the global_user_id from flash
 if (Param.length > 1) {
   if (Param[1] != "NOID") global_user_id = Param[1];
 }
 // Get the item
 if (Param.length > 2) {
   Item = Param[2];
 }
 
 switch (Param[0]) {
 	case "register":
 	 PopulateContent("Register", "html", global_user_id);
 	 break;
 	case "ContactForm":
 	 PopulateContent("ContactUs", "html", Item);
 	 //PopulateContent("EventPlanner", "html", "");
 	 break;
 	case "Update":
 	 PopulateContent("Register", "html", global_user_id);
 	 break;
 	case "Register":
 	 PopulateContent("Register", "html", global_user_id);
 	 break;
 	case "NextEvent":
 	 PopulateContent("RegisterInfo", "html", Item);
 	 break;
 	default:
 	 PopulateContent(Param[0], "html", Item);
 }
 
}


// - - - - - - - - - - #END JS / Flash AS3 communication - - - - - - - - - - 
function PopulateContent(Section, Type, SelectedItem) {
  global_section = Section;
  if (Type == "html") {
    var XmlFile = "/Html_" + global_lang +"/"  + Section + ".html?554654"; // getting the ARABIC file
  }
 /*
  else {
    
  }
 */
 var HTMLText;
 $.ajax({ //initiates ajax request
  type: "GET",
  url: XmlFile,
  dataType: Type,
  success: function(xml) {
  $(".Layer1").css({
   display: "block"
  });
  var xml = xml;
  xml = xml.replace('<script type="text/javascript" src="/Js/jquery.js"></script>','');
  xml = xml.replace('<script type="text/javascript" src="/Js/InnerPage.js"></script>','');
  $("#langBtn").css("cursor", "default");
  IsPopupShown = true;     
  $(".Layer1").removeClass("Timeline");
  $("#PagingLeft,#PagingRight").hide();
  switch (Section) {
   case "AboutUs":
    //About us section
    HTMLText = "<div class=\"LeftColumn\"><h1><img src='/Images/Caption/" + $(xml).find("heading").text() + "' /></h1><h2>" + $(xml).find("subheading").text() + "</h2><div class='Scroll'><p>" + $(xml).find("content").text() + "</p></div></div>";
    $("#layout").html(HTMLText);
    $(document).pngFix();
    $('.Scroll').jScrollPane({
     scrollbarWidth: 7
    });
    break;
   case "Partners":
    //Partners Section
    $(".Layer1").addClass("Generic");
    $(".Layer1").removeClass("WhoWeAre");
    $(".Layer1").removeClass("GenericSmall");
    $("#layout").html(xml);
    $("#Content").html("");
    $("#" + SelectedItem).addClass("active");
    $("#Content").append($(".active").find(".HiddenContent").html());
    
    //$("#Content").html($(".Logo").parent().find(".HiddenContent").html());          
    $('#Content .Scroll').jScrollPane({
     scrollbarWidth: 7
    })
    $(document).pngFix();
    $(".Logo").click(function() { //function for each item click
     $("#Content").html("");
     $("#Content").append($(this).parent().find(".HiddenContent").html());
     $(".Thumb").removeClass("active");
     $(".RightLink").css({
      background: "none"
     });
     $(this).parent().addClass("active");
     $('#Content .Scroll').jScrollPane({
      scrollbarWidth: 7
     })
    });
    break;
   case "Careers":
    $(".Layer1").addClass("Generic");
    $(".Layer1").removeClass("WhoWeAre");
    $(".Layer1").removeClass("GenericSmall");
    $("#layout").html(xml);
    $(document).pngFix();
    $('.HalfColumnRight .Scroll').jScrollPane({
     scrollbarWidth:7
    })
    $(".CareersList td a").click(function() {
     $("#CareerDetails").html($(this).parent().find(".HiddenContent").html());
    });
    break;
   case "MessageBoard":
    $(".Layer1").addClass("Generic");
    $(".Layer1").removeClass("WhoWeAre");
    $(".Layer1").removeClass("GenericSmall");
    $("#layout").html(xml);
    $('#MessageBoard .Scroll').jScrollPane({
     scrollbarWidth:7
    })
    var AjaxUrl = "/API.svc/GetComments/?lang=en&Category=1";
    var HtmlText = "";
    $(document).pngFix();
    $.ajax({
     cache: false,
     dataType: 'json',
     url: AjaxUrl,
     success: function(result) {
      for (var i = 0; i < result.length; i++) {
       HtmlText = "<li><p class=\"Title\"><span>by</span> <strong>" + result[i].UserName + "</strong> <em>" + result[i].DateAdded + "</em></p><p>" + result[i].Comment + "</p></li>"
      }
      $(".MessageBoard").html(HtmlText);
      $(".MessageBoard li:even").addClass("Alternate");
     }
    });
    $(".PostComments .Button").click(function() {
     if (!Validate("PostComments")) {
      $(".ErrorInfo").css({
       display: "block"
      });
      return false;
     }
     AjaxUrl = "/API.svc/SendComments/?lang=en&name=" + $("#FullName").val() + "&Comment=" + $("#Comments").val();
     onUpdating(".PostComments");
     $.ajax({
      type: "GET",
      url: AjaxUrl,
      success: function(msg) {
       $("#AddComments table").remove();
       $("#AddComments").append("<p>Thank you! Your comment has been successfully posted.</p>");
       onUpdated(".PostComments");
       }
      });
    });
    break;
   case "WhatWeDo":
    $("#layout").html(xml);
    $(".Layer1").removeClass("WhoWeAre");
    $(".Layer1").removeClass("Generic");
    $(".Layer1").addClass("GenericSmall");
    $('.HalfColumnLeft .Scroll').jScrollPane({
    	scrollbarWidth:7
    });
    $(document).pngFix();
    $("#Servics ul li a").each(function() {
    $(this).hover(function() {
    	$(this).parent().find(".HiddenContent").css({
    	 display:"block"
    	});
    },
    function() {
     $(this).parent().find(".HiddenContent").css({
      display: "none"
      });
     });
    });
    break;
   case "Ourawards":
    $("#layout").html(xml);
    $(".Layer1").removeClass("WhoWeAre");
    $(".Layer1").removeClass("GenericSmall");
    $(".Layer1").addClass("Generic");
    //$("#Content").html($(".Logo").parent().find(".HiddenContent").html());          
    $('.MusicHome .Scroll').jScrollPane({
     scrollbarWidth:7
    })
    
    $(document).pngFix();
    BacktoPage("WhatWeDo");
    break;
   case "RegisterInfo":
    $(".Layer1").addClass("Generic");
    $(".Layer1").removeClass("WhoWeAre");
    $(".Layer1").removeClass("GenericSmall");
    $("#layout").html(xml);
    $("#Content").html("");
    $('.HalfColumnLeft .Scroll').jScrollPane({
     scrollbarWidth:7
    });
    $(document).pngFix();
    $(".RegisterLink").click(function(event) {
     if (global_user_id != "") {
      PopulateContent("RegisterForm2", "html", "");
     }
     else {
      PopulateContent("Register", "html", global_user_id);
     }
    });
    break;
   case "RegisterForm2":
    $(".Layer1").addClass("Generic");
    $(".Layer1").removeClass("WhoWeAre");
    $(".Layer1").removeClass("GenericSmall");
    $("#Content").html("");
    $("#layout").html(xml);
    $('.HalfColumnLeft .Scroll').jScrollPane({
     scrollbarWidth: 7
    });
    $(document).pngFix();

    //to enable"other"  text box when check the "Other" check box
    $("#CheckotherEvents").click(function(){
     if ($("#CheckotherEvents").is(':checked')){
     $("#OtherEvents").removeAttr('disabled'); 
     }
     else{
      $("#OtherEvents").attr('disabled', 'disabled');
      $("#OtherEvents").attr("value","");
     }
     });
    $("#CheckOtherNews").click(function(){
     if ($("#CheckOtherNews").is(':checked')) {
     $("#OtherNews").removeAttr('disabled'); 
     }
     else{
      $("#OtherNews").attr('disabled', 'disabled');
      $("#OtherNews").attr("value","");
     }
     });
     
    $("#CheckOtherMagazine").click(function(){
     if ($("#CheckOtherMagazine").is(':checked')) {
     $("#OtherMagazine").removeAttr('disabled'); 
     }
     else{
      $("#OtherMagazine").attr('disabled', 'disabled');
      $("#OtherMagazine").attr("value","");
     }
     });
     $("#LinkEnter").click(function() {
     if (!Validate("RegisterForm2")) {
      return;
     }
     var eventTicket="";
     var eventsAttend = "";
     var Magazines ="";
     var NewsPapers ="";
     var FindOutFlash="";
     $('Input.RadioGroup2').each(function() {
      if ($(this).is(':checked')) { //alert($(this).val())
       eventTicket = $(this).val();
      }
     });

     $('Input.RadioGroup1').each(function() {
      if ($(this).is(':checked')) {
       eventsAttend = $(this).val();
      
      }
     });         
     $('Input.CheckGroup1').each(function() {
      if ($(this).is(':checked')) {
       Magazines += $(this).val() + " ,";
      }
     });
      // if there is no value in the text fiels remove the comma at the end other wise append the text field value
     if ($('#OtherMagazine').val() == ""){
      Magazines = Magazines.substring(0, Magazines.length - 1); 
     }
     else{
      Magazines += $('#OtherMagazine').val();
     }
              
     $('Input.CheckGroup2').each(function() {
      if ($(this).is(':checked')) {
       NewsPapers += $(this).val() + " ,";     
      }
     });
      // if there is no value in the text fiels remove the comma at the end other wise append the text field value
     if($('#OtherNews').val() == ""){
      NewsPapers = NewsPapers.substring(0, NewsPapers.length - 1);
     }
     else{
      NewsPapers += $('#OtherNews').val();
     }

     $('Input.CheckGroup3').each(function() {
      if ($(this).is(':checked')) {                  
       FindOutFlash += $(this).val() + ","
      }
     });
               // if there is no value in the text fiels remove the comma at the end other wise append the text field value
     if($('#OtherEvents').val() == ""){
      FindOutFlash = FindOutFlash.substring(0, FindOutFlash.length - 1);
     }
     else{
      FindOutFlash += $('#OtherEvents').val();
     }
              
      //alert(SelectedItem);var AjaxUrl = "/API.svc/user/?UniqueId="+SelectedItem+"&FullName="+$("#FullName").val()+
      var AjaxUrl = "/API.svc/submitsurvey/?uniqueid=" + global_user_id + "&favoritemusic=" + $("#MusicGenre").val() + "&favoriteartist=" + " " + "&mostlikemusician=" + $("#Musicians").val() + "&favoritesport=" + " " + "&favoriteeventAttend=" + $("#Favoriteevent").val() + "&eventsattend=" + eventsAttend + "&eventticket=" + eventTicket + "&magazinesread=" + Magazines + "&newspaperread=" + NewsPapers + "&websiteVisitaboutevents=" + $("#Website").val() + "&findflashevents=" + FindOutFlash + "&hearwebsite=" + $("#Aboutwebsite").val();

      //alert(AjaxUrl);
      $.ajax({
       type: "GET",
       url: AjaxUrl,
       success: function(msg) {
        // send to flash
        SendRegistration(msg);

        //if (msg == "success") {
        // if user exists -> success
        if (msg.getElementsByTagName("User")) {           
         $(".Layer1").removeClass("WhoWeAre");
         $(".Layer1").removeClass("Generic");
         $(".Layer1").removeClass("GenericSmall");
         $('.FourColRegForm').hide();
         $('.BottomLinks').hide();
         $('#Copy h3').html("<span style='font-weight:normal'>Thank you for taking the time to<br /> fill out the questionnaire!<br /><br />We will be announcing the winners <br />by September 1st.</span>");
           //$(".HalfColumnRight").html("<p>Thank you! Your feedback has been successfully sent.<br /> We will get back to you.</p>");   
           //onUpdated(".HalfColumnRight");
           //alert('success');               
         if (global_lang == "AR"){  
          $("#Copy").addClass("FixCaption")
          $('#Copy h3').html("<span style='font-weight:normal'>نشكر لك الوقت الذي أمضيته في ملء هذا الاستبيان!<br /><br />سيتم الإعلان عن الفائزين بحلول الأول من سبتمبر</span>");
          //$(".HalfColumnRight").html("<p>Thank you! Your feedback has been successfully sent.<br /> We will get back to you.</p>");   
          //onUpdated(".HalfColumnRight");
          //alert('success');                      
         }
        }
        else {
         if (global_lang == "AR"){                                              
         alert('حدث خطأ. نأسف للإزعاج. يرجى المحاولة مرة أخرى في وقت لاحق');
          }
          else{
           alert('An error has occurred. We are sorry for the inconvenience.\r\nPlease try again later.');
          }
        }
                                    }
       });
      });
      $("#LinkClose").click(function() {});
      break;

     case "Downloads": case "Merchandise": case "Bookmarks": case "ComingSoon":
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("Generic");
      $(".Layer1").addClass("GenericSmall");
      $("#layout").html(xml);
      $('.LeftColumn .Scroll').jScrollPane({
        scrollbarWidth:
        7
      });
      $(document).pngFix();
      break;
     case "PressReleases":
      $(".Layer1").addClass("Generic");
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $("#layout").html(xml);
      $("#Content").html("");
      $("#" + SelectedItem).addClass("active");
      $("#Content").append($(".active").find(".HiddenContent").html());
      
      //$("#Content").html($(".Logo").parent().find(".HiddenContent").html());          
      $('#Content .Scroll').jScrollPane({
              scrollbarWidth: 7
      })
      $(document).pngFix();
      $("#Content").append($(".Pressrelease a.First").parent().find(".HiddenContent").html());
       $("a.First").parent().addClass('Active');
      $(".Pressrelease").each(function() {
   
       $(this).find("a").click(function() {
        $(".Pressrelease div").removeClass('Active');
        $("#Content").html("");
        $("#Content").append($(this).parent().find(".HiddenContent").html());
      
        if (!$(this).parent().hasClass('Active')) {
         $(this).parent().addClass('Active');
         //$(this).parent().addClass("Active");
        }
        else {
         $(this).parent().removeClass('Active');
        }
      
        $(".Thumb").removeClass("active");
        $(".RightLink").css({
         background: "none"
        });
        //$(this).parent().addClass("active");
        $('#Content .Scroll').jScrollPane({
         scrollbarWidth: 7
        })
       });
      });
      break;
     case "WhoWeAre":
      $(".Layer1").addClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $(".Layer1").removeClass("Generic");
      $("#layout").html(xml);
      $('.HalfColumnLeft .Scroll').jScrollPane({
              scrollbarWidth:
              7
      });
      $(document).pngFix();
      $(".VideoOverlay").click(function(event) {
              var str2 = "WhoWeAreVideo";
              // alert(str2);
              var Item = "";
              var Param = str2.split("#"); //Spliting the parameters
              if (Param.length > 1) {
                      Item = Param[1];
              }
              switch (Param[0]) {
              case "WhoWeAreVideo":
                      //About Us section
                      PopulateContent("WhoWeAreVideo", "html", Item);
                      break;
              }
      });
      
      break;
     case "Flashforward":
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $(".Layer1").removeClass("Generic");
      $("#layout").html(xml);
      $(document).pngFix();
      $('.LeftColumn .Scroll').jScrollPane({
              scrollbarWidth:
              7
      });
      $(".RegisterLink").click(function(event) {
              var str2 = $(this).attr("id");
              // alert(str2);
              var Item = "";
              var Param = str2.split("#"); //Spliting the parameters
              if (Param.length > 1) {
                      Item = Param[1];
              }
              switch (Param[0]) {
              case "Register":
                      //About Us section
                      PopulateContent("Register", "html", global_user_id);
                      break;
              }
      });
      break;
     case "AbuDhabiLive":
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $(".Layer1").removeClass("Generic");
      $("#layout").html(xml);
      $(document).pngFix();
      $('.HalfColumnLeft .Scroll').jScrollPane({
              scrollbarWidth:
              7
      });
      break;
     case "Feedback":
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $(".Layer1").addClass("Generic");
      $("#layout").html(xml);
      $(".HalfColumnRight").css({
              overflow:
              "hidden"
      });
      $(document).pngFix();
     
      var mytext = document.getElementById("FullName"); //to positioning the cursor on page load
      mytext.focus();
      mytext.select();
     
      $(".Action a").click(function() {
              if (!Validate("Feedback")) {
                      $(".ErrorInfo").css({
                              display: "block"
                      });
                      return false;
              }
              onUpdating(".HalfColumnRight");
              var AjaxUrl = "/API.svc/sendfeedback/?lang=en&user=" + $("#FullName").val() + "&useremail=" + $("#Email").val() + "&feedback=" + $("#Comments").val() + "&typeoffeedback=" + $("#Feedbacktype").val();
              $.ajax({
                      type: "GET",
                      url: AjaxUrl,
                      success: function(msg) {                     
                              $(".HalfColumnRight").html("<p>Thank you! Your feedback has been successfully sent.<br /> We will get back to you.</p>");
        if (global_lang == "AR"){  
        $(".HalfColumnRight").html("<p>شكرا لك! تم ارسال ملاحظاتك بنجاح. سنقوم بالاتصال بك قريبا</p>");
        }
       onUpdated(".HalfColumnRight");
                      }
              });
      });
      break;
     case "ContactUs":
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $(".Layer1").addClass("Generic");
      $("#layout").html(xml);
      $(".HalfColumnRight").css({
              overflow:
              "hidden"
      });
      $(document).pngFix();
      var mytext = document.getElementById("FullName"); //to positioning the cursor on page load
      mytext.focus();
      mytext.select();
      $(".Action a").click(function() {
              if (!Validate("ContactUs")) {
                      $(".ErrorInfo").css({
                              display: "block"
                      });
                      return false;
              }
              onUpdating(".HalfColumnRight");
              var AjaxUrl = "/API.svc/contact/?lang=en&user=" + $("#FullName").val() + "&useremail=" + $("#Email").val() + "&message=" + $("#Comments").val() + "&subject=" + $("#Subject").val() + "&company=" + $("#Company").val() + "&Country=" + $("#Company").text() + "&City=" + $("#City").val() + "&phone=" + $("#Mobile").val() + "&Pobox=" + $("#POBox").val();
              $.ajax({
                      type: "GET",
                      url: AjaxUrl,
                      success: function(msg) {
      $(".HalfColumnRight").html("<p>Thank you! Your information has been successfully sent. We will get in touch with you shortly.</p>");
       if (global_lang == "AR"){                                              
          $(".HalfColumnRight").html("<p>شكرا لك! تم ارسال معلوماتك بنجاح. سنقوم بالاتصال بك قريبا</p>");                                   
        }
       onUpdated(".HalfColumnRight");
                      }
              });
      });
      //HandleInputElements2();
      break;
     
     case "Music":
      //Partners Section
      $(".Layer1").addClass("Generic");
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $("#layout").html(xml);
      $("#Content").html("");
      //$("#Content").html($(".Logo").parent().find(".HiddenContent").html());          
      $('.MusicHome .Scroll').jScrollPane({
              scrollbarWidth:
              7
      })
      $(document).pngFix();
      $(".Logo").click(function(event) {
              var str2 = $(this).attr("id");
              //alert(str2);
              var Item = "";
              var Param = str2.split("#"); //Spliting the parameters
              if (Param.length > 1) {
                      Item = Param[1];
              }
              PopulateContent(Param[0], "html", Item);
      });
      break;
     case "MusicEvent1": case "MusicEvent2": case "MusicEvent3": case "MusicEvent4": case "MusicEvent5": case "MusicEvent6": case "MusicEvent7": case "MusicEvent8": case "MusicEvent9": case "MusicEvent10":
      LoadEvents(xml);
      BacktoPage("Music");
      DisablePrivateSection(); //Disable Image Gallery links if the user is not loged in
      break;
     case "Sport": case "Film":
      LoadEvents(xml);
      DisablePrivateSection(); //Disable Image Gallery links if the user is not loged in
      break;
                    
     case "Register":
      $(".Layer1").removeClass("WhoWeAre");
      $(".Layer1").removeClass("GenericSmall");
      $(".Layer1").addClass("Generic");
      $("#layout").html(xml);
      $(".HalfColumnRight").css({overflow:"hidden"});
      $(document).pngFix();
     
     $(".Terms").click(function(event) {
      var str2 = "RegisterInfo";
      // alert(str2);
      var Item = "";
      var Param = str2.split("#"); //Spliting the parameters
      if (Param.length > 1) {
       Item = Param[1];
      }
      switch (Param[0]) {
      case "RegisterInfo":
       //About Us section
       PopulateContent("RegisterInfo", "html", Item);
       break;
      }
      return false;
     });
     
     $('#date1').datepicker({
      showOn: 'both',
      showOtherMonths: true,
      showWeeks: true,
      firstDay: 1,
      changeFirstDay: false,
      buttonImageOnly: true,
      buttonImage: '../Images/Generic/calendar.gif'
     }); //date picker fn
             //fousing the cursor first text box
     var mytext = document.getElementById("FullName"); //to positioning the cursor on page load
     mytext.focus();
     mytext.select();
     var ToDate =  new Date();
     
             if (SelectedItem != "") { //Edit mode and populate fields from databas
                     onUpdating(".HalfColumnRight");
     
                     var AjaxUrl = "/API.svc/GetUserProfile/?UniqueUserId=" + SelectedItem + "&" + ToDate.getMilliseconds();
                     $.ajax({
                             type: "GET",
                             url: AjaxUrl,
                             success: function(msg) {
     
                                     $("#FullName").val($(msg).find("User").attr("Name"));
                                     $("#Email").val($(msg).find("User").attr("Email"));
                                     $(".date-pick").val($(msg).find("User").attr("DOB"));
                                     if ($(msg).find("User").attr("Gender") == "Male") {
                                             $("#GenderMale").attr("checked", "checked");
                                     }
                                     else {
                                             $("#GenderFemale").attr("checked", "checked");
                                     }
                                     //alert( $(msg).find("Question[@Text='Favorite Sports Personality']").val());
                                     $("#Nationality").val($(msg).find("User").attr("Nationality"));
                                     $("#City").val($(msg).find("User").attr("City"));
                                     $("#Password").val($(msg).find("User").attr("Password"));
                                     $("#Mobile").val($(msg).find("User").attr("MobileNo"));
                                     $(msg).find("question").each(function() { // Getting all questions and answers for edit
                                             switch ($(this).find("id").text()) {
                                             case "1":
                                                     //Question 1
                                                     $("#FavSport").val($(this).find("answer").text());
                                                     break;
                                             case "2":
                                                     //Question 1
                                                     $("#FavArtist").val($(this).find("answer").text());
                                                     break;
                                             case "10":
                                                     //Question 1
                                                     //$("#Newsletter").attr('checked','checked');
                                                     //$('#Updates').attr('checked','checked');
                                                     if ($(this).find("answer").text().indexOf("True") >= 0) {
                                                             $("#Newsletter").attr('checked', 'checked');
                                                     }
                                                     else {
                                                             $("#Newsletter").removeAttr('checked');
                                                     }
                                                     break;
                                             case "12":
                                                     //Question 1
                                                     if ($(this).find("answer").text().indexOf("True") >= 0) {
                                                             $('#Updates').attr('checked', 'checked');
                                                     }
                                                     else {
                                                             $('#Updates').removeAttr('checked');
                                                     }
                                                     break;
                                             }
                                     });
     
                                     onUpdated(".HalfColumnRight");
                             },
                             error: function() {}
                     });
     
             }
             $(".Action a").click(function() {
                     if (!Validate("Register")) {
                             $(".ErrorInfo").css({
                                     display: "block"
                             });
                             return false;
                     }
                     var Gender = $("input[@name='Gender']:checked").val();
                     var Subscribe = false;
                     var UpdateSubscribe = false;
                     if ($("#Newsletter").attr("checked")) {
                             Subscribe = true;
                     }
                     if ($("#Updates").attr("checked")) {
                             UpdateSubscribe = true;
                     }
                     var QuestionAnswer = [];
                     QuestionAnswer.push({
                             QuestionId: "1",
                             Answer: $("#FavSport").val()
                     });
                     QuestionAnswer.push({
                             QuestionId: "2",
                             Answer: $("#FavArtist").val()
                     });
                     QuestionAnswer.push({
                             QuestionId: "10",
                             Answer: Subscribe
                     });
                     QuestionAnswer.push({
                             QuestionId: "12",
                             Answer: UpdateSubscribe
                     });
                     onUpdating(".HalfColumnRight");
                     var AjaxUrl = "/API.svc/user/?Lang="+global_lang+"&UniqueId=" + SelectedItem + "&FullName=" + $("#FullName").val() + "&DOB=" + $(".date-pick").val() + "&gender=" + Gender + "&city=" + $("#City").val() + "&email=" + $("#Email").val() + "&nationality=" + $("#Nationality").val() + "&country=UAE&mobileno=" + $("#Mobile").val() + "&password=" + $("#Password").val() + "&QuestionsAndAnswers=" + $.toJSON(QuestionAnswer) + "&_" + ((new Date()).getTime());
                     //alert(AjaxUrl);
                     $.ajax({
                             type: "GET",
                             url: AjaxUrl,
                             success: function(msg) {
     
                                     // Inform Flash
                                     SendRegistration(msg);
     
                                     //console.log("test = ",msg);
                                     var usrObj = msg.getElementsByTagName("User");
     
                                     var errorMsg = msg.getElementsByTagName("string");
     
                                     //console.log("usrObj = ", usrObj);
                                     //console.log("errorMsg = ", errorMsg);
                                     if (usrObj == null || errorMsg[0] != undefined) {
              
                                             $(".HalfColumnRight").html("<div class=\"InfoMessage\"><p>Error! Your registration has been cancelled</p>" + errorMsg[0].childNodes[0].nodeValue +"</div>");
                    if (global_lang == "AR"){  
                       $(".HalfColumnRight").html("<div class=\"InfoMessage\">خطأ! تم الغاء التسجيل " +"<br />"+ errorMsg[0].childNodes[0].nodeValue + "</div>");
                    }
                                     }
                                     else {
                                             // store the user id in the page
                                             global_user_id = usrObj[0].getAttribute("Id");
     
                                             if (SelectedItem == "") {
                                                     PopulateContent("RegisterForm2", "html", "");
                                                     return false;
                                             }
                                             $(".HalfColumnRight").html("<p>Thank you! Your registration has been successfull</p>");
                   if (global_lang == "AR"){  
                     $(".HalfColumnRight").html("<p>شكرا لك! تم التسجيل بنجاح</p>");
                   }
                                             //console.log("global_user_id = ", global_user_id);
                                     }
                                     //console.log("test = ",usrObj);
                                     //console.log("test = ",usrObj[0].getAttribute("Id"));
                                     //usrObj[0].getAttribute("id")
                                     onUpdated(".HalfColumnRight");
     
                                     return;
     
                             },
                             error: function(XMLHttpRequest, textStatus, errorThrown) {
                                     $(".ErrorInfo").css({
                                             display: "block"
                                     });
                                    
                                     if (global_lang == "AR"){                                              
                                     $(".ErrorInfo").html(" للأسف هناك مشكلة. التسجيل لم يكتمل ، يرجى المحاولة مرة أخرى في وقت لاحق");
                                          }
                                          else{
                                          $(".ErrorInfo").html("Unfortunately there was a problem. Your registration is not complete, please try again later.");
                                          }
                                     onUpdated(".HalfColumnRight");
                             }
                     });
             });
             break;
            case "Team":
                    //Team section
                    $(".Layer1").addClass("Generic");
                    $(".Layer1").removeClass("WhoWeAre");
                    $(".Layer1").removeClass("GenericSmall");
                    $("#layout").html(xml);
                    $(document).pngFix();
                    $("#Content").html("");
                    $("#" + SelectedItem).addClass("active");
                    $("#Content").append($(".active").find(".HiddenContent").html());
                    //$("#Content").append($(".Logo").parent().find(".HiddenContent").html());
                    //$("#Content").html($(".Logo").parent().find(".HiddenContent").html());          
                    $("div.scrollable").scrollable({
                      size: 12,
                      items: '#thumbs',
                      hoverClass: 'hover'
                    });
                    $('#Content .Scroll').jScrollPane({
                      scrollbarWidth: 7
                    })
                    $(".Logo").click(function() { //function for each item click
                      $("#Content").html("");
                      $("#Content").append($(this).parent().find(".HiddenContent").html());
                      $(".Thumb").removeClass("active");
                      $(this).parent().addClass("active");
                      $('#Content .Scroll').jScrollPane({
                        scrollbarWidth: 7
                      })
                    });
                    break;
                    case "Board":
                    //Team section
                    $(".Layer1").addClass("Generic");
                    $(".Layer1").removeClass("WhoWeAre");
                    $(".Layer1").removeClass("GenericSmall");
                    $("#layout").html(xml);
                    $(document).pngFix();
                    $("#Content").html("");
                    $("#" + SelectedItem).addClass("active");
                    $("#Content").append($(".active").find(".HiddenContent").html());
                    //$("#Content").append($(".Logo").parent().find(".HiddenContent").html());
                    //$("#Content").html($(".Logo").parent().find(".HiddenContent").html());          
                    $("div.scrollable").scrollable({
                      size: 12,
                      items: '#thumbs',
                      hoverClass: 'hover'
                    });
                    $('#Content .Scroll_1').jScrollPane({
                      scrollbarWidth: 7
                    })
                    $(".Logo").click(function() { //function for each item click
                      $("#Content").html("");
                      $("#Content").append($(this).parent().find(".HiddenContent").html());
                      $(".Thumb1").removeClass("active");
                      $(this).parent().addClass("active");
                      $('#Content .Scroll_1').jScrollPane({
                        scrollbarWidth: 7
                      })
                    });
                    break;
                    case "Gallery1": case "Gallery2": case "Gallery3": case "Gallery4": case "Gallery5": case "Gallery6": case "Gallery7": case "Gallery8": case "Gallery9": case "Gallery10":case "Gallery11":case "Gallery12":case "Gallery13":case "Gallery14":case "Gallery15":case "YasVideo":case "ChristinaVideo":case "KillersVideo":case "CreamVideo":case "Gallery16":
                    LoadGalleryThumbs(xml); //Loading thumbnails
                    break;
                    case "MainGallery": case "Gallery17":
                    //Team section
                    $(".Layer1").addClass("Generic");
                    $(".Layer1").removeClass("WhoWeAre");
                    $(".Layer1").removeClass("GenericSmall");
                    $("#layout").html(xml);
                    $(document).pngFix();
                    $("#Content").html("");
                    $("#mike").addClass("active");
                    $("#Content").append($(".active").find(".HiddenContent").html());
                    $("div.scrollable").scrollable({
                      size:5,
                      items: '#thumbs',
                      hoverClass: 'hover'
                    });
                    $('#Content .Scroll').jScrollPane({scrollbarWidth: 7});
                    $(".Logo").click(function() { //function for each item click
                      var str2 = $(this).attr("id");
                      var Item = "";
                      var Param = str2.split("#"); //Spliting the parameters
                      if (Param.length > 1) {
                        Item = Param[1];
                      }
                      PopulateContent(Param[0], "html", Item);
                      return false;
                    });
                    break;
            case "VideoMain":
                    //Team section
                    $(".Layer1").addClass("Generic");
                    $(".Layer1").removeClass("WhoWeAre");
                    $(".Layer1").removeClass("GenericSmall");
                    $("#layout").html(xml);
                    $(document).pngFix();
                    $("#Content").html("");
                    $("#mike").addClass("active");
                    $("#Content").append($(".active").find(".HiddenContent").html());
                    $("div.scrollable").scrollable({
                      size:5,
                      items: '#thumbs',
                      hoverClass: 'hover'
                    });
                    $('#Content .Scroll').jScrollPane({scrollbarWidth: 7});
                    $(".Logo").click(function(event) {
                      var str2 = $(this).attr("id");
                      var Item = "";
                      var Param = str2.split("#"); //Spliting the parameters
                      if (Param.length > 1) {
                        Item = Param[1];
                      }
                      PopulateContent(Param[0], "html", Item);
                    });
                    break;
            case "Video1": case "Video2": case "Video3":
                    LoadVideo(xml);
                    BacktoPage("VideoMain");
                    break;
            case "WhoWeAreVideo":
                    LoadVideo(xml);
                    BacktoPage("WhoWeAre");
                    break;
            case "Wake1": case "Wake2": case "Wake3": case "Wake4":
            				FromEventPlanner= false;
                    LoadVideo(xml);
                    BacktoPage("Gallery17");
                    break;                    
                    
                    
            case "EventPlanner":
            onUpdating(".Copy");
                    $(".Layer1").addClass("Timeline");
                    $(".Layer1").removeClass("Generic");
                    $(".Layer1").removeClass("WhoWeAre");
                    $(".Layer1").removeClass("GenericSmall");
                    //$("embed").css({visibility: "hidden"});
                   $("#layout").load(XmlFile,function(){
                    onLoad();
                    $("#PagingLeft,#PagingRight").show();
                    });
                    break;
            }
        }
    });
}

//function for loading the gallery thumbnails
function LoadGalleryThumbs(Content){
  $(".Layer1").addClass("Generic");
  $(".Layer1").removeClass("WhoWeAre");
  $(".Layer1").removeClass("GenericSmall");
  $("#layout").html(Content);
  $(document).pngFix();
  $("#Content").html("");
  $("#mike").addClass("active");
  $("#Content").append($(".active").find(".HiddenContent").html());
  $("div.scrollable").scrollable({
    size:8,
    items: '#thumbs',
    hoverClass: 'hover'
  });
  $('#Content .Scroll').jScrollPane({
    scrollbarWidth: 7
  })
  BacktoPage("MainGallery");
}

//Function to load single video on click of the thumb nail from the main page
function LoadVideo(Content){
  //Team section
  $(".Layer1").addClass("Generic");
  $(".Layer1").removeClass("WhoWeAre");
  $(".Layer1").removeClass("GenericSmall");
  $("#layout").html(Content);
  $(document).pngFix();
  $("#Content").html("");
  $("#mike").addClass("active");
  $("#Content").append($(".active").find(".HiddenContent").html());
  $("div.scrollable").scrollable({
  size: 8,
  items: '#thumbs',
  hoverClass: 'hover'
  });
  $('#Content .Scroll').jScrollPane({scrollbarWidth: 7});
}

//Function load single event when clicking the event thumbs
function LoadEvents(Content){
  $("#layout").html(Content);
  $(".Layer1").addClass("Generic");
  $('.EventDetailes .Scroll').jScrollPane({
    scrollbarWidth: 7
  });
  $(document).pngFix();
}

//Going back to the previous page
function BacktoPage(Section) {
	
 if (FromEventPlanner){
  $(".BacklinkHidden").show();
 }
 $(".BackLink").click(function(event) {
  if (!FromEventPlanner){
   PopulateContent(Section, "html", "");
  }else
  {
   FromEventPlanner= false;
   PopulateContent("EventPlanner", "html", "");
   
   }
 });
}




function CheckMail(email) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email)) {
        return true;
    }
    return false;
}

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);

        if (((c < "0") || (c > "9")) && !((c == '+') || (c == '-') || (c == ' '))) return false;

    }
    // All characters are numbers.
    return true;
}

function Validate(FormName) {
    var isValidate = true;
    $(".Textbox").removeClass("Error");
    $("select").removeClass("Error");
    $(".ErrorInfo").css({
        display: "none"
    });
    switch (FormName) {
    case "Feedback":
        //Feedback form
        if ($("#FullName").val() == "") {
            isValidate = false;
            $("#FullName").addClass("Error");
        }
        if ($("#Email").val() == "") {
            isValidate = false;
            $("#Email").addClass("Error");
        }
        if (!CheckMail($("#Email").val())) {
            isValidate = false;
            $("#Email").addClass("Error");
        }
        if ($("#Comments").val() == "") {
            isValidate = false;
            $("#Comments").addClass("Error");
        }

        if ($("#Feedbacktype").val() == "[Select Type]") {
            isValidate = false;
            $("#Feedbacktype").addClass("Error");
        }
        break;
    case "Register":
        //Feedback form
        if ($("#FullName").val() == "") {
            isValidate = false;
            $("#FullName").addClass("Error");
        }
        if ($("#Email").val() == "") {
            isValidate = false;
            $("#Email").addClass("Error");
        }
        if (!CheckMail($("#Email").val())) {
            isValidate = false;
            $("#Email").addClass("Error");
        }
        if ($("#Mobile").val() == "") {
            isValidate = false;
            $("#Mobile").addClass("Error");
            $("span.UseNumbers").text("Please enter phone number");
           if (global_lang == "AR"){                                              
            $("span.UseNumbers").text("يرجى إدخال رقم الهاتف");
            }
        }
        if (!isInteger($("#Mobile").val())) {
            isValidate = false;
            $("#Mobile").addClass("Error");
            $("span.UseNumbers").text("Please use numbers only");
            if (global_lang == "AR"){                                              
            $("span.UseNumbers").text("الرجاء استخدام الأرقام فقط");
             }
        }
        if ($("#Nationality").val() == "[Select Country]") {
            isValidate = false;
            $("#Nationality").addClass("Error");
        }
        if ($("#City").val() == "") {
            isValidate = false;
            $("#City").addClass("Error");
        }
        if ($("#Password").val() == "") {
            isValidate = false;
            $("#Password").addClass("Error");
        }
        if ($("#Password2").val() == "") {
            isValidate = false;
            $("#Password2").addClass("Error");
        }
        var x = $("#Password").val();
        if ($("#Password2").val() != x) {
            isValidate = false;
            $("#Password2").addClass("Error");
        }

        if ($("#FavArtist").val() == "") {
            isValidate = false;
            $("#FavArtist").addClass("Error");
        }
        if ($("#FavSport").val() == "") {
            isValidate = false;
            $("#FavSport").addClass("Error");
        }
        if ($("#date1").val() == "") {
            isValidate = false;
            $("#date1").addClass("Error");
        }
        if ($("#date1").val() != "") {
            $("#date1").removeClass("Error");
        }

        break;
    case "ContactUs":
        //Feedback form
        if ($("#FullName").val() == "") {
            isValidate = false;
            $("#FullName").addClass("Error");
        }
        if ($("#Email").val() == "") {
            isValidate = false;
            $("#Email").addClass("Error");
        }
        if (!CheckMail($("#Email").val())) {
            isValidate = false;
            $("#Email").addClass("Error");
        }
        if ($("#Subject").val() == "") {
            isValidate = false;
            $("#Subject").addClass("Error");
        }
        if ($("#Company").val() == "") {
            isValidate = false;
            $("#Company").addClass("Error");
        }
        if ($("#Country").val() == "[Select Country]") {
            isValidate = false;
            $("#Country").addClass("Error");
        }
        if ($("#City").val() == "") {
            isValidate = false;
            $("#City").addClass("Error");
        }
        if ($("#Mobile").val() == "") {
            isValidate = false;
            $("#Mobile").addClass("Error");
        }

        if (!isInteger($("#Mobile").val())) {
            isValidate = false;
            $("#Mobile").addClass("Error");
        }

        if ($("#Comments").val() == "") {
            isValidate = false;
            $("#Comments").addClass("Error");
        }
        break;

    case "PostComments":
        //Feedback form
        if ($("#FullName").val() == "") {
            isValidate = false;
            $("#FullName").addClass("Error");
        }
        if ($("#Comments").val() == "") {
            isValidate = false;
            $("#Comments").addClass("Error");
        }
        break;
    case "RegisterForm2":
        //Feedback form
        if ($("#MusicGenre").val() == "") {
            isValidate = false;
            $("#MusicGenre").addClass("Error");
        } 
        if ($("#Musicians").val() == "") {
            isValidate = false;
            $("#Musicians").addClass("Error");
        }
        if ($("#Favoriteevent").val() == "") {
            isValidate = false;
            $("#Favoriteevent").addClass("Error");
        }

        if ($("#Website").val() == "") {
            isValidate = false;
            $("#Website").addClass("Error");
        }
        if ($("#Aboutwebsite").val() == "") {
            isValidate = false;
            $("#Aboutwebsite").addClass("Error");
        }
       if ($('input[name=FavEvent]:checked').val() == undefined) {
        isValidate = false;       
        if (global_lang == "AR"){                                              
       alert(' الرجاء اختيار عدد الأحداث التي حضرتها شهريا ');
        }
        else{
         alert('Please select a number of events you attend per month');
        }
       break;
        }
        if ($('input[name=Willingtopay]:checked').val() == undefined) {
        isValidate = false;       
        if (global_lang == "AR"){                                              
        alert('الرجاء اختيار ما هو المبلغ الذي أنت على استعداد لدفعه ثمن للتذاكر');
        }
        else{
         alert('Please select how much you are willing to pay for tickets');
        }
         break;
        }
        
        if($("#OtherMagazine").val() == ""){
        if ($('input[name=frequentlyReadMagazin]:checked').val() == undefined) {
        isValidate = false;       
        if (global_lang == "AR"){                                              
        alert(' الرجاء تحديد ما هي المجلات التي كثيرا ما تقرأ');
        }
        else{
         alert('Please select which magazines do you frequently read');
        }
         break;
        }
        }
        if($("#OtherNews").val() == ""){
        if ($('input[name=frequentlyReadNews]:checked').val() == undefined) {
        isValidate = false;        
        if (global_lang == "AR"){                                              
        alert(' الرجاء تحديد ما هي الصحف التي كثيرا ما تقرأ');
        }
        else{
        alert('Please select which newspapers do you frequently read');
        }
        break;
        }  
        }
        
        if($("#OtherEvents").val() == ""){
        if ($('input[name=findout]:checked').val() == undefined) {
        isValidate = false;
        if (global_lang == "AR"){                                              
        alert('الرجاء اختيار كيف عرفت عن أحداث فلاش');  
        }
        else{
        alert('Please select how did you find out about Flash events');  
        }
        break;        
        }
        }        
        
        break;
    }
    return isValidate;
}

function onUpdating(elementId) {
    $.extend($.blockUI.defaults.overlayCSS, {
        backgroundColor: '#ddd'
    });
    $(elementId).block('<img src="/Images/Generic/Bigrotation.gif" border="0" style="margin:auto;" />', {
        background: 'transparent',
        border: '0'
    });
}

function onUpdated(elementId) {
    $(elementId).unblock();
}

function HandleInputElements2() {
    var ListControl = "";
    var DDControlHtml = "";
    var ListControlMarkup = "";
    var DDText = "";
    $(".Serach").click(function() {
        DDControlHtml = "";
        ListControlMarkup = "<ul>";
        if ($(this).parent().find("ul").length < 1) {
            $(this).parent().find("select").children().each(function() {
                DDControlHtml = DDControlHtml + "<li><a href='#'>" + $(this).html() + "</a></li>";
            });
            ListControlMarkup = ListControlMarkup + DDControlHtml + "</ul>";
            $(this).parent().append(ListControlMarkup);
        }

        ListControl = $(this).parent().find("ul");
        DDText = $(this).parent().find(".DropDownText");
        ListControl.toggle();
        //ListControl.css({top: DDText.offset().top + DDText.height()+6 + "px",left:DDText.offset().left + "px"});
        ListControl.children().each(function() {
            $(this).click(function() {
                DDText.attr("value", $(this).find("a").html());
                ListControl.hide();
                // document.getElementById("aspnetForm").submit();
            });
        });

        $(document).click(function() {
            ListControl.hide();
            $(".Dropcontainer").click(function() {
                return false;
            });

        });

    });
}
function showRadioIcon() {
    // display the correct image
  $('#langBtn').html('<img src="/images/generic/lang_'+ global_lang + '.jpg" width="57" height="22" border="0"  />');
  // show div
    $("#radioOne").css({
        visibility: "visible"
    });
}

function memberAccess(str) {
    //console.log("memberAccess", str );
    if (global_user_id != "") {
        PopulateContent(str, "html", "");
    }
    else {
        PopulateContent("Register", "html", global_user_id);
    }
}

//this function disables all private access elements if the user is not  loged in
function DisablePrivateSection() {
    if (global_user_id == "") {
        //Events
        $(".EventPicture a:first").addClass("Disabled");
        $(".EventPicture").append('<div class="Lock"><img src="/Images/Generic/Lock.gif" alt="" /></div>');
        $(".EventPicture a").click(function() {
            return false
        });
        $(".Denied").show();
    }
    else {
        $(".Permitted").show();
    }
}

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) {
       
        if (global_lang == "AR"){                                              
         alert("متصفحك أو أحد البرامج على جهازك يبدو أنه منع النوافذ المنبثقة في هذه الصفحة من الفتح. يرجى تعديل الإعدادات لتمكين النوافذ من الفتح وتحديث هذه الصفحة لتستمر.");
       }
       else{
        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) {}
}

/*Handling Cookies*/
 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 HandleReminder(StartDate, EndDate){
 var ReminderHTML = "<div class='ReminderForm'><span class='Error'></span><a href='#' id='CloseBox' onclick='$(\".ReminderForm\").hide();$(\".ReminderForm\").remove();'>Close X</a><p>Send a reminder for this event to your calendar:</p><table cellpadding='0' cellspacing='0' border='0'><tr><td>Name : </td><td><input type='text' id='Name' maxlength='255' /></td></tr><td>Email : </td><td><input type='text' id='Email' maxlength='255' /></td></tr><tr><td colspan='2' align='right' class='Action'><input type='button' onclick=\"CallReminderAPI('"+ StartDate +"','"+ EndDate+"')\" value='Send' /></td></tr></table></div>";
 $(".simileAjax-bubble-contentContainer").append(ReminderHTML);
}

function CallReminderAPI(StartDate, EndDate){
 $(".ReminderForm .Error").hide();
 if ($("#Name").attr("value")==""){
  $(".ReminderForm .Error").show(500);
  $(".ReminderForm .Error").html("Please fill in your Name");
  return false;
 }
 if ($("#Email").attr("value")==""){
  $(".ReminderForm .Error").show();
  $(".ReminderForm .Error").html("Please fill in your Email");
  return false;
 }
 if (!CheckMail($("#Email").val())) {
  $(".ReminderForm .Error").show();
  $(".ReminderForm .Error").html("Please fill in a valid Email");
  return false;
 }
 var UserInfo = {};
 UserInfo.Name = $("#Name").attr("value");
 UserInfo.Email = $("#Email").attr("value");
 UserInfo.StartDate = StartDate;
 UserInfo.EndDate = EndDate;
 UserInfo.Title = $(".timeline-event-bubble-title h1").html();
 UserInfo.Description = $(".timeline-event-bubble-body .Description").html();
 UserInfo.Location = $(".timeline-event-bubble-body .Venue").html();
 var PostedData = $.toJSON(UserInfo);
 onUpdating(".ReminderForm");
 $.ajax({
  type: "POST",
  contentType: "application/json; charset=utf-8",
  url: "/API.svc/eventreminder" ,
  dataType: "json",
  data: PostedData,
  success: function(Reply){
   if (Reply.indexOf("pass")>=0){
    onUpdated(".ReminderForm");
    $(".ReminderForm table").hide();
    $(".ReminderForm p").html("Thank you! A reminder for this event has been  sent!");
   }
   else{
    onUpdated("#ReminderForm");
    $(".ReminderForm p").html("Sorry, due to an unforeseen error your request could not be processed at this time. Please try again.");
   }
  },
  error: function(){
   onUpdated(".ReminderForm");
    $(".ReminderForm p").html("Sorry, due to an unforeseen error your request could not be processed at this time. Please try again.");
 }
 });     
}