﻿/**
 * Copyright (c) 2009, Omnia FZ LLC
 * All rights reserved.
 * @version 0.1.x
 *  Javascript library
 */
	
	/* Index
	
	No     Function                                                                                          Purpose
	====================================================================================================================================================================================================
	1        AssignCSSSelectors()                                                                  This function dynamically attaches FirstChild,LastChild  css classes to elements in IE 6. 
	2       AssignLinks()							                                                                This function will attach "target='_blank' to all links which has "rel='external' tag. Fix to aviod w3c validation error for target "_blank"
	3       search()                                                                                       This function shows/ hides caption texts in a textbox, used for Search, Newsletter etc. call it as  $("#SearchText").search();  #SearchText =  id of the textbox
	4       InitializeMenu(ParentId)                                                              Initialize Drop down navigation , Accepts Parent id of the Navigation list. 
	5       OnUpdating(ElementID),OnUpdated(ElementId)                         Displaying loading animation for a process. Just to call it with the client if of the div where you want to show the loading animation, (Requires Jquery Block UI plugin)
	6       Rollout(Image), Rollover(Image)																			 Changes Image on hover, Just to give hover effect to image links
	7       Scroll()																																			Scroll the content up/down on keyboard shotcuts, Needs Scroll,Shortcut jquery plugins
	8       FileUpload()                                                                                     A flash based file upload function, requires its handlers, swf files, aspx files.
	9       Accordion ()                                                                                    *Need to find a best accordion script and create a function *
	10  	 NumericFilter ()                                                                              This function doesn't allow user to fill alphanumeric charecters in a textbox.	
	11     AjaxRequest(TargetURL,TargetDivId)                                          This is a generic ajax call function which gets the data as html format and appened to the target div
	12     CreateCookie(Name,Value,Days), ReadCookie(Name),                Cookie Functions, Creates, reads and delete cookies
	         EraseCookie(Name)
	13    SendToFriendPopup(),AddRecipient(),ClosePopup()                    These functions are used to create send to friend popup 
	14    AjxSendToFriend()                                                                           Posting send to friend data for processing. Ajax call function
	15    AutoFit()                                                                                             If the content page width exceeds 1024px , we have to use this fn for avoid  horizontal scrolling
	16   setFeedbackWindow() 							These functions are used to create Feedback popup
	*/
	
// <summary>
// Global function calls,
// </summary>
var AppPath="/";
function ExecuteHandler(){
 if (window.location.href.toLowerCase().indexOf("cmspagemode=edit")>0){  // exiting if in the sitefinity edit mode
  return false;
 }
 $(document).ready(function(){
	 AssignCSSSelectors();
	 AssignLinks();
	$(".SearchText").search();
	HandlePopup();
 });
}

// <summary>
//  This function to attach non-ie css selectors to the html elements
// </summary>
function AssignCSSSelectors()
{
if(jQuery.browser.msie){
 $("li:first-child").addClass("FirstChild");
 $("li:last-child").addClass("LastChild");
 $("td:last").addClass("LastChild");
 $("tr:first").addClass("FirstChild");
}
}


//For google tracking the Each download LInks
function trackDownloadLink(){
var downloadabsolutePath;
$(".photoList li p.imgSize a").click(function(){
//below function is it avoiding to putting the id attrbute to all download link
     var downloadPath=$(this).attr("href");
     //downloadPath.substring(3); == removing "../" from the string
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     downloadabsolutePath ="http://www.samsungsoccer.com/ar/"+downloadPath.substring(3);
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
     downloadabsolutePath ="http://www.samsungsoccer.com/fr/"+downloadPath.substring(3);
     }
     else{
     downloadabsolutePath ="http://www.samsungsoccer.com/en/"+downloadPath.substring(3);
     }
     
     //alert(downloadabsolutePath);
trackLink(downloadabsolutePath);
});
}
function trackLink(link)
{
var pageTracker = _gat._getTracker("UA-333687-51");
pageTracker._trackPageview(link);
}
// <summary>
//  These functions handle events generated by an Input Text box
// </summary>
$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});	
};


// <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;
 });
}
// Initialise Cufon Font
function  FixFont(){
Cufon.replace('h2',{fontFamily: 'SamsungCondensedBold'});
//Cufon.replace('h2 a', {hover: true, fontFamily: 'SamsungCondensedBold'});
//Cufon.replace('h3',{fontFamily: 'SamsungCondensedBold'});
//Cufon.replace('h3 a', {hover: true, fontFamily: 'SamsungCondensedBold'});
//Cufon.replace('h4',{fontFamily: 'SamsungCondensedBold'});
//Cufon.replace('h4 a', {hover: true, fontFamily: 'SamsungCondensedBold'});
Cufon.replace('.newFont', {fontFamily: 'Samsung'});
Cufon.replace('.cufonFont', {fontFamily: 'SamsungCondensedBold'});
Cufon.replace('.cufonFont a', {hover: true, fontFamily: 'SamsungCondensedBold'});
Cufon.replace('.cufonFont', {hover: true, fontFamily: 'SamsungCondensedBold'});
Cufon.replace('.langSwitch label', {fontFamily: 'SamsungCondensedBold'});
Cufon.replace('ul#navigation li a',{hover: true, fontFamily: 'SamsungCondensedBold'});
Cufon.replace('ul.subNav li',{hover: true, fontFamily: 'SamsungCondensedBold'});
}
//light box function

function SetlightBox()
{
$('.lightBox').lightBox();
}
// <summary>
//  Update panel loading animation functions
// </summary>
function onUpdating(elementId) {
    $.extend($.blockUI.defaults.overlayCSS, {
        backgroundColor: '#ddd'
    });
    $(elementId).block('<img src="../Images/Generic/ajax-loader.gif" border="0" style="margin:auto;" />', {
        background: 'transparent',
        border: '0'
    });
}

function onUpdated(elementId) {
    $(elementId).unblock();
}


// <summary>
//  Scroll the page by using up/down arrows
// </summary>
function Scroll() {
var start = 0;
	shortcut.add("down",function() {
	$.scrollTo( '+=300px', 200 );
	 return false;
 });
 
	shortcut.add("up",function() {
 	$.scrollTo( '-=300px', 200 );
	 return false;
	});
}


//slide show function
function SlideImage(){
$('#s5').cycle({
    fx:     'fade',
    timeout: 4000,
    before:  onBefore,
    after:   onAfter,
    next:   '#next2',
    prev:   '#prev2'
      });
      
      $('#s6').cycle({
    fx:     'fade',
    timeout: 4000,
    before:  onBefore,
    after:   onAfter,
    next:   '#next2',
    prev:   '#prev2'
      });
}

function onBefore() {

}
function onAfter(){

}

// <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 HandlePopup()
{
var windowRegister;
  $(".popUpinfo").click(function(){
  $(".Forgotpass").show();
  var ScrollPos = getPageScroll();
  var PageSizes = getPageSize();
  var TopMargin;
  var contentHeight=$("#wrap2").height()+30;
  var PageHeight =  $(document).height();
  var PagewindoHeight =  $(window).height();
  var overlayheight;

  if(PagewindoHeight>contentHeight){
  overlayheight = PagewindoHeight;
  }
  else{
   overlayheight = contentHeight;
  }
  var PopupHTML = '<div class="Fade" style="height:'+overlayheight +'px" ></div><div class="Popup">' +
  '<div class="popupWrap1">' +
   '<div class="popupWrap2">' +
    '<div class="popupWrap3">' +
     '<div class="ClosePopup" onclick="ClosePopup();">' +
      '<img src="../Images/Generic/ClosePopup.png" alt="Close window" /></div> ' +
      '<div class="PopupContent">';
       PopupHTML = PopupHTML + $(this).parent().find(".HiddenText").html();
       PopupHTML = PopupHTML + '</div>' +
     '</div>' +
    '</div>' +
   '</div>' +
  '</div>';
 if($(this).parent().find(".HiddenText").html() ==null) return false;
 $("body").append(PopupHTML);
  $(".Popup .forgotPass .textWrap").show(); 
  $(".Popup .forgotPass label").show();
  $(".popupRegister").hide();
  $(".popupLogin").show();
  $(".Forgotpass").show();
 //light box only for some particular class
  if($(this).parent().parent().hasClass("countries")){
  SetlightBox();
 }
  if (window.location.href.toLowerCase().indexOf("/en/")>0 || window.location.href.toLowerCase().indexOf("/fr/")>0){ 
  Cufon.replace('.PopupContent h2.popupHead',{fontFamily: 'SamsungCondensedBold'});
  Cufon.replace('.PopupContent h3.popupHead',{fontFamily: 'SamsungCondensedBold'});
  Cufon.replace('.PopupContent .registerLink', {hover: true,fontFamily: 'SamsungCondensedBold'});
  Cufon.replace('.PopupContent .Forgotpass', {hover: true,fontFamily: 'SamsungCondensedBold'});
  Cufon.replace('.PopupContent .backtoLogin', {hover: true,fontFamily: 'SamsungCondensedBold'});
  }
  postRegisterForm();
  $(".PopupContent label.registerLink").click(function(){
$(".popupLogin").hide();
$(".popupRegister").show();
  $(".Popup .changeHead1").show();
  $(".Popup .changeHead2").hide();
  $(".Popup .backtoLogin").hide();
$(".Popup .changeHead").html("Login");
 $(".Popup").css({top: $(".Popup").offset().top+-50});  /*To center align the new register pop up*/
  });
 $(".Fade").css({opacity:0});
 //$(".Popup").hide();
 $(".Popup").css({top: -600});
 $(".Fade").animate({opacity: 0.25},{queue:false,duration:200,complete:function(){
  $(".Popup").animate({top:	ScrollPos[1] + (PageSizes[3] / 2) - ($(".Popup").height()/2)},{queue:false,duration:400,easing: "easeOutQuad"});
 }});
 return false;
});
}

function ClosePopup(){
 $(".Popup").animate({top:	-600},{queue:false,duration:400,easing: "easeOutQuad",complete:function(){
   $(".Fade").animate({opacity: 0},{queue:false,duration:200,easing: "easeOutQuad",complete:function(){
  $(".forgotPass .textWrap").hide(); 
  $(".forgotPass label").hide();
   $(".btnLogin").show();
   $(".sendPass").hide();
    $(".Popup").remove();
    $(".Fade").remove();

  }});
 }});
}

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;
}
// chck that current charecter is string

function containsAlphabets(checkString) {
        var tempString="";
        if (window.location.href.indexOf("/en/")<0) return true;
        var regExp = /^[A-Za-z]$/;
        if(checkString != null && checkString != "")
        {
          for(var i = 0; i < checkString.length; i++)
          {
            if (!checkString.charAt(i).match(regExp))
            {
              return false;
            }
          }
        }
        
        return true;
}

function postRegisterForm(){
 var isValidate = false;
 //validation for login form
 
 $(".Popup #loginBtn").click(function()
 {
 if ($(".Popup input#txtEmail").val() =="")
 {
  $(".Popup input#txtEmail").addClass("Error");
  $(".Popup #errorIncorrect").text("");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     $(".Popup #errorLuser").text("أدخل بريدك الالكتروني ");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
     $(".Popup #errorLuser").text("S'il vous plaît entrer votre e-mail");
     }
     else{
     $(".Popup #errorLuser").text("Please enter your email");
     }
   isValidate = false;
 }  
 else
 {   
    if (!CheckMail($(".Popup input#txtEmail").val()))
    {
    isValidate = false;
    $(".Popup input#txtEmail").addClass("Error");   
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     $(".Popup #errorLuser").text(" الرجاء إدخال عنوان بريد إلكتروني صالح");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
     $(".Popup #errorLuser").text("S'il vous plaît entrer une adresse électronique valide");
     }
     else{
    $(".Popup #errorLuser").text("Please enter a valid email");
     }
    }
    else
    {
     isValidate = true;
     $(".Popup input#txtEmail").removeClass("Error");
     $(".Popup #errorLuser").text("");
    }
 }
 
 if ($(".Popup input#txttPassword").val() =="")

 {
 isValidate = false;
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
      $(".Popup #errorLpass").text("الرجاء إدخال كلمة السر");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
      $(".Popup #errorLpass").text(" S'il vous plaît entrer le mot de passe");
     }
     else{
     $(".Popup #errorLpass").text("Please enter the password");
     }
  $(".Popup input#txttPassword").addClass("Error");
 } 
 
 else
 {
 // isValidate = true;
  $(".Popup input#txttPassword").removeClass("Error");
  $(".Popup #errorLpass").text("");
 }
 
  if(isValidate == true){
         onUpdating(".Popup");
         var Login = {};
        Login.Email = $(".Popup #txtEmail").val();
        Login.Password = $(".Popup #txttPassword").val();
        
        var jsonvalue = $.toJSON(Login);
        //alert(jsonvalue);
        

        $.ajax({ 
        type: "POST", 
        url: "../Service/Login.aspx/Login", 
        contentType: "application/json; charset=utf-8",
        
        data: jsonvalue, 
        dataType: "json", 
        success: function(result){
    if((result.d.indexOf("success")>=0)){
    
        if(window.location.href.toLowerCase().indexOf("/ar/")>0)
        {
        window.location.href ="../ar/game.aspx";
        onUpdated(".Popup");
        ClosePopup();
        }
        else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
        {
        window.location.href ="../fr/game.aspx";
         onUpdated(".Popup");
         ClosePopup();
        }
        else{
        window.location.href ="../en/game.aspx";
         onUpdated(".Popup");
         ClosePopup();
        }
    }
    else if($(".Popup .popupLogin input.textRegister").val()=="")
    
    {
      $(".Popup #errorIncorrect").text("");
        onUpdated(".Popup");
    }
    else if($(".Popup #errorLuser").text().indexOf("valid email")>=0){ 
    $(".Popup #errorIncorrect").text("");
      onUpdated(".Popup");
    }
    else{
          if(window.location.href.toLowerCase().indexOf("/ar/")>0){
          $(".Popup #errorIncorrect").text("الإسم المستخدم و كلمة السر غير صحيحين");
           onUpdated(".Popup");
          }
          else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
          $(".Popup #errorIncorrect").text("Nom d'utilisateur et mot de passe incorrect");
           onUpdated(".Popup");
          }
          else{
          $(".Popup #errorIncorrect").text("Incorrect user name and password");
          onUpdated(".Popup");
          // $(".Popup #errorLpass").text("");
          }
       }
        }, 
        error: AjaxFailed 
        });    
  }
 });
 
 
 //validation for forgot password field
  $(".Popup .Forgotpass span").click(function(){
  $(".Popup .changeHead1").hide();
  $(".Popup .changeHead2").show();
  $(".Popup .backtoLogin").show();
   if (window.location.href.toLowerCase().indexOf("/en/")>0 || window.location.href.toLowerCase().indexOf("/fr/")>0){ 
 Cufon.replace('.Popup .changeHead2' , {fontFamily: 'SamsungCondensedBold'});
 }
  $(".Popup .forgotPass .textWrap").hide(); 
  $(".Popup .forgotPass label").hide();
  $(".btnLogin").hide();
  $(".sendPass").show();
  $(".Forgotpass").hide();
    $(".Popup #errorLpass").text("");
    $(".Popup #errorIncorrect").text("");
    $(".Popup #txttPassword").val("");
 return false;
  });
 
 // going back to login form agin after clicking the login button
 
   $(".Popup .backtoLogin").click(function(){
     $(".Popup .changeHead2").hide();
       $(".Popup .changeHead1").show();
  $(".Popup .forgotPass .textWrap").show(); 
  $(".Popup .forgotPass label").show();
  $(".Popup .forgotPass label").show();
  $(".btnLogin").show();
  $(".sendPass").hide();
  $(".Forgotpass").show();
  $(this).hide();
   });
 
 // validation for registration form
$(".Popup .btnRegister").click(function(){
 if ($(".Popup input#firstName").val() =="" )
 {
 isValidate = false;
 

  $(".Popup input#firstName").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
      $(".Popup #errorFname").text("الأول الرجاء إدخال الإسم");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
      $(".Popup #errorFname").text("S'il vous plaît entrer votre prénom");
     }
     else{
     $(".Popup #errorFname").text("Please enter your first name");
     }
 } 
 else
 {
   if (!containsAlphabets($(".Popup input#firstName").val())) 
   {
    isValidate = false;
    if(window.location.href.toLowerCase().indexOf("/ar/")>0){
    $(".Popup #errorFname").text("الرجاء استخدام الحروف الهجائية فقط");
    }
    else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
     $(".Popup #errorFname").text("Veuillez n’utiliser que des lettres");
    }
    else{
    $(".Popup #errorFname").text(" Please use alphabets only");
    }
   }
   else{
   isValidate = true;
   $(".Popup input#firstName").removeClass("Error");
   $(".Popup #errorFname").text("");
   }
 }
  
  if ($(".Popup input#lastName").val() =="" )
  {
   isValidate = false;
   $(".Popup input#lastName").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
    $(".Popup #errorLname").text("الرجاء إدخال الإسم الثاني");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
    $(".Popup #errorLname").text("S'il vous plaît entrez votre nom de famille");
     }
     else{
   $(".Popup #errorLname").text("Please enter your last name");
     }
   
 } 
 
 else{
   if (!containsAlphabets($(".Popup input#firstName").val())) 
   {
     isValidate = false;
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     $(".Popup #errorLname").text("الرجاء استخدام الحروف الهجائية فقط");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
     $(".Popup #errorLname").text(" Please use alphabets only");
     }
     else{
     $(".Popup #errorLname").text(" Please use alphabets only");
     }
   }
   else{
   $(".Popup input#lastName").removeClass("Error");
   $(".Popup #errorLname").text("");
   }
 }
 
 
  if ($(".Popup input#email").val() =="" )
  {
 isValidate = false;
  $(".Popup input#email").addClass("Error");
      if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     $(".Popup #errorEmail").text("أدخل بريدك الالكتروني ");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
     $(".Popup #errorEmail").text("S'il vous plaît entrer votre e-mail");
     }
     else{
    $(".Popup #errorEmail").text("Please enter your email");
     }
 } 
 
 else 
 {
    if (!CheckMail($(".Popup input#email").val())) 
    {
    isValidate = false;
    $(".Popup input#email").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     $(".Popup #errorEmail").text(" الرجاء إدخال عنوان بريد إلكتروني صالح");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
     $(".Popup #errorEmail").text("S'il vous plaît entrer une adresse électronique valide");
     }
     else{
     $(".Popup #errorEmail").text("Please enter a valid email");
     }
    

    }
    else
    {
    $(".Popup input#email").removeClass("Error");
    $(".Popup #errorEmail").text("");
    }
 }
  
 if ($(".Popup input#phone").val() =="" )
  {
    isValidate = false;
    $(".Popup input#phone").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     $(".Popup #errorPhone").text("الرجاء إدخال رقم هاتفك");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
     $(".Popup #errorPhone").text("S'il vous plaît entrer votre numéro de téléphone");
     }
     else{
    $(".Popup #errorPhone").text("Please enter your phone number");
     }
  } 
 
else 
 {
   if (!isInteger($(".Popup input#phone").val())) 
   {
      isValidate = false;
      $(".Popup input#phone").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
      $(".Popup #errorPhone").text(" الرجاء استخدام الأرقام فقط");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
      $(".Popup #errorPhone").text("S'il vous plaît n'utilisez que des chiffres");
     }
     else{
      $(".Popup #errorPhone").text("Please use numbers only");
     }

      //$("span.UseNumbers").text("Please use numbers only");

   }
   else
   {
      $(".Popup input#phone").removeClass("Error");
      $(".Popup #errorPhone").text("");
    }
 }
  
if ($(".Popup input#password").val() =="" )
 {
  isValidate = false;
   $(".Popup input#password").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
    $(".Popup #errorpassword").text(" الرجاء إدخال كلمة السر");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
    $(".Popup #errorpassword").text("S'il vous plaît entrer le mot de passé");
     }
     else{
    $(".Popup #errorpassword").text("Please enter the password");
     }
  } 
 else 
 {
   $(".Popup input#password").removeClass("Error");
   $(".Popup #errorpassword").text("");
 }
 
 if ($(".Popup input#confirmPasswod").val() =="" )
 {
  isValidate = false;
  $(".Popup input#confirmPasswod").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
    $(".Popup #errorConfirm").text("يرجى تأكيد كلمة السر");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
    $(".Popup #errorConfirm").text("S'il vous plaît confirmer le mot de passé");
     }
     else{
   $(".Popup #errorConfirm").text("Please confirm the password");
     }
  
 } 
  else
  {
    if ($(".Popup input#confirmPasswod").val() != ($(".Popup input#password").val()) )
    {
    isValidate = false;
    $(".Popup input#confirmPasswod").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
     $(".Popup #errorConfirm").text("الرجاء إعادة كتابة كلمة السر الصحيحة");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
    $(".Popup #errorConfirm").text("Retapez le mot de passe correct");
     }
     else{
    $(".Popup #errorConfirm").text("Retype the correct pasword");
     }
    

    } 
    else
    {
    $(".Popup input#confirmPasswod").removeClass("Error");
    $(".Popup #errorConfirm").text("");
    }
 } 
  if ($(".Popup #selectCountry").val() =="Select country")
  {
  isValidate = false;
  $(".Popup input#selectCountry").addClass("Error");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
      $(".Popup #errorCntry").text("يرجى تحديد بلدك");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
      $(".Popup #errorCntry").text("S'il vous plaît sélectionner votre pays");
     }
     else{
     $(".Popup #errorCntry").text("Please select your country");
     }
  } 
  else
  {
  $(".Popup input#selectCountry").removeClass("Error");
  $(".Popup #errorCntry").text("");

}

if ($(".Popup #selectCountry").val() == "Others" && $(".Popup input#countryOther").val() == "") {
    isValidate = false;
    $(".Popup input#selectCountry").addClass("Error");
    if (window.location.href.toLowerCase().indexOf("/ar/") > 0) {
        $(".Popup #errorCntry").text("يرجى تحديد بلدك");
    }
    else if (window.location.href.toLowerCase().indexOf("/fr/") > 0) {
        $(".Popup #errorCntry").text("S'il vous plaît sélectionner votre pays");
    }
    else {
        $(".Popup #errorCntry").text("Please enter your country");
    }
}
else {
    $(".Popup input#selectCountry").removeClass("Error");
    $(".Popup #errorCntry").text("");

}
  
 if(isValidate == true){
        onUpdating(".Popup");
         var Registration = {};
        Registration.FirstName = $(".Popup #firstName").val();
        Registration.LastName = $(".Popup #lastName").val();
        Registration.Email = $(".Popup #email").val();
        Registration.Phone = $(".Popup #phone").val();
        Registration.Password = $(".Popup #password").val();     
        if ($(".Popup #selectCountry").val() =="Others"){
        Registration.Country = $(".Popup input#countryOther").val();
        }
       else{
        Registration.Country = $(".Popup #selectCountry").val();
        }
        var jsonvalue = $.toJSON(Registration);
        //alert(jsonvalue);
        

        $.ajax({ 
        type: "POST", 
        url: "../Service/Register.aspx/Register", 
        contentType: "application/json; charset=utf-8",
        data: jsonvalue, 
        dataType: "json", 
        success: function(result){
    if((result.d.indexOf("success")>=0)){
        if(window.location.href.toLowerCase().indexOf("/ar/")>0)
        {
        window.location.href ="../ar/game.aspx";
        onUpdated(".Popup");
        ClosePopup();
        }
        else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
        {
        window.location.href ="../fr/game.aspx";
         onUpdated(".Popup");
         ClosePopup();
        }
        else{
        window.location.href ="../en/game.aspx";
         onUpdated(".Popup");
         ClosePopup();
        }
    }
    else if(result.d.indexOf("already exists")>=0){
      if(window.location.href.toLowerCase().indexOf("/ar/")>0){    
      // alert("User with this email already exists, please try another");
      $(".Popup .registerMsg").css("color","#ff0000");
      $(".Popup .registerMsg").text("البريد الإلكتروني مستخدم ، يرجى المحاولة مرة أخرى");
      onUpdated(".Popup");    
      }  
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
      // alert("User with this email already exists, please try another");
      $(".Popup .registerMsg").text("L'utilisateur avec cet e-mail existe déjà, s'il vous plaît essayer un autre");
      $(".Popup .registerMsg").css("color","#ff0000");
      Cufon.replace('.PopupContent .registerMsg', {fontFamily: 'SamsungCondensedBold'});
      onUpdated(".Popup"); 
     }
     else{
      // alert("User with this email already exists, please try another");
      $(".Popup .registerMsg").text("User with this email already exists, please try another");
      $(".Popup .registerMsg").css("color","#ff0000");
      Cufon.replace('.PopupContent .registerMsg', {fontFamily: 'SamsungCondensedBold'});
      onUpdated(".Popup"); 
     }
   }
   else{
        if(window.location.href.toLowerCase().indexOf("/ar/")>0){
        // alert("Unfortunately there was a problem, please try later");
        $(".Popup .registerMsg").text("للأسف كانت هناك مشكلة ، يرجى المحاولة لاحقا");
        onUpdated(".Popup");  
        }
        else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
        // alert("Unfortunately there was a problem, please try later");
        $(".Popup .registerMsg").text("Malheureusement, il y avait un problème, s'il vous plaît essayer ultérieurement");
        $(".Popup .registerMsg").css("color","#ff0000");
        Cufon.replace('.PopupContent .registerMsg', {fontFamily: 'SamsungCondensedBold'});
        onUpdated(".Popup");  
        }
        else{
        // alert("Unfortunately there was a problem, please try later");
        $(".Popup .registerMsg").text("Unfortunately there was a problem, please try later");
        $(".Popup .registerMsg").css("color","#ff0000");
        Cufon.replace('.PopupContent .registerMsg', {fontFamily: 'SamsungCondensedBold'});
        onUpdated(".Popup");  
        }
    
   }
        
        }, 
        error: AjaxFailed 
        });       
}
});
$(".selectOther .textWrap").hide();


}
function OncoutryChange(Obj){
 if ($(Obj).val() =="Others"){
  $(".selectOther .textWrap").show();
 }
 else{
 $(".selectOther .textWrap").hide();
 }
}        


    function AjaxFailed(result) {

    alert(result.status + ' ' + result.statusText); 

    }  

//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 forgotPassword(){
 
 var isValidate = true;
  if ($(".Popup input#txtEmail").val() =="" ){
 isValidate = false;
  $(".Popup input#txtEmail").addClass("Error");

     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
      $(".Popup #errorLuser").text("أدخل بريدك الالكتروني ");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
      $(".Popup #errorLuser").text("S'il vous plaît entrer votre e-mail");
     }
     else{
     $(".Popup #errorLuser").text("Please enter your email");
     }

 }  
 else if (!CheckMail($(".Popup input#txtEmail").val())) {
     isValidate = false;
     $(".Popup input#txtEmail").addClass("Error");

     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
          $(".Popup #errorLuser").text(" الرجاء إدخال عنوان بريد إلكتروني صالح");
     }
     else if(window.location.href.toLowerCase().indexOf("/fr/")>0)
     {
          $(".Popup #errorLuser").text("S'il vous plaît entrer une adresse électronique valide");
     }
     else{
         $(".Popup #errorLuser").text("Please enter a valid email");
     }
     
 }
  else{
  isValidate = true;
   $(".Popup input#txtEmail").removeClass("Error");
   $(".Popup #errorLuser").text("");
  
 }
    if(isValidate == true){
       onUpdating(".Popup");
          var forgot = {};
        forgot.Email = $(".Popup input#txtEmail").val();      
        var jsonvalue = $.toJSON(forgot);
        //alert(jsonvalue);
        $.ajax({ 
        type: "POST", 
        url: "../Service/Login.aspx/ForgotPassword", 
        contentType: "application/json; charset=utf-8",
        
        data: jsonvalue, 
        dataType: "json", 
        success: function(result){
    if((result.d.indexOf("success")>=0)){
   //alert($(result.d).html());
    
        if(window.location.href.toLowerCase().indexOf("/ar/")>0){
        $(".Popup .forgotpassMsg").css("color","#246F03");
        $(".Popup .forgotpassMsg").text(" كلمة السر الخاصة بك قد تم إرسالها إلى عنوان البريد الإلكتروني");
        onUpdated(".Popup");
        }
        else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
        $(".Popup .forgotpassMsg").text("Votre mot de passe a été envoyé à l'adresse e-mail");
        $(".Popup .forgotpassMsg").css("color","#246F03");
        Cufon.replace('.PopupContent .forgotpassMsg', {hover: true,fontFamily: 'SamsungCondensedBold'});
        onUpdated(".Popup");
        }
        else{
        $(".Popup .forgotpassMsg").text("Your password has been sent to the email address");
        $(".Popup .forgotpassMsg").css("color","#246F03");
        Cufon.replace('.PopupContent .forgotpassMsg', {hover: true,fontFamily: 'SamsungCondensedBold'});
        onUpdated(".Popup");
        }
    }
    else if(result.d.indexOf("No user exists")>=0){
   // alert($(result.d).html());
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
      $(".Popup .forgotpassMsg").css("color","#ff0000");
      $(".Popup .forgotpassMsg").text("لا يوجد مستخدم، يرجى المحاولة مرة أخرى");
      onUpdated(".Popup");  
      }
      else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
      $(".Popup .forgotpassMsg").text("Aucun utilisateur existe avec ce mail, s'il vous plaît essayez de nouveau");
      $(".Popup .forgotpassMsg").css("color","#ff0000");
      Cufon.replace('.PopupContent .forgotpassMsg', {hover: true,fontFamily: 'SamsungCondensedBold'});
      onUpdated(".Popup");  
      }
      else{
      $(".Popup .forgotpassMsg").text("No user exists with this email, please try again");
      $(".Popup .forgotpassMsg").css("color","#ff0000");
      Cufon.replace('.PopupContent .forgotpassMsg', {hover: true,fontFamily: 'SamsungCondensedBold'});
      onUpdated(".Popup");  
      }
    }
   else {
    //alert("A user with this email address does not exists");
     if(window.location.href.toLowerCase().indexOf("/ar/")>0){
       $(".Popup .forgotpassMsg").css("color","#ff0000");
       $(".Popup .forgotpassMsg").text(" كلمة السر خطأ ، الرجاء المحاولة لاحقا");
       onUpdated(".Popup");  
       }
       else if(window.location.href.toLowerCase().indexOf("/fr/")>0){
       $(".Popup .Forgotpass").text("J'ai oublié mon mot de passe d'erreur, s'il vous plaît essayer ultérieurement");
       $(".Popup .Forgotpass").css("color","#ff0000");
       Cufon.replace('.PopupContent .forgotpassMsg', {hover: true,fontFamily: 'SamsungCondensedBold'});
       onUpdated(".Popup");  
       }
       else{
       $(".Popup .forgotpassMsg").text("Forgot password error, please try later");
       $(".Popup .forgotpassMsg").css("color","#ff0000");
       Cufon.replace('.PopupContent .forgotpassMsg', {hover: true,fontFamily: 'SamsungCondensedBold'});
       onUpdated(".Popup");  
       }
    }
        }, 
        error: AjaxFailed 
        });   
  }
 }