var SET_EMPTY_FIELD  = 0;
var ADD_CHILD        = false;
var ADD_FROM_PROFILE = false;

function showGameStat( gameid, e ){

var divname       = 'gameblock';
var gamestatpanel = document.getElementById( divname ).style;

//alert(arrGameCaption[gameid]+' and id_game = '+gameid+' and arrGameDescription = '+arrGameDescription[gameid]);
//return false;

 if( gamestatpanel ){
  $("#gameCaption").html(arrGameCaption[gameid]);
  $("#imgGameImage").html('<img src="'+arrGameImage[gameid]+'" alt="">');
  $("#gmsDescription").html('<p align="right"><font size="2">'+arrGameDescription[gameid]+'</font>');

  var detailGame    = new String('');
  var gmsMedalsFlag = false;
  var countPlayGame = 0;
  var COL_RECOMENDATION = '<b><font size="3">מילים שנלמדו</font></b>';
  var COL_RAITING       = '<b><font size="3">מספר <br>משחקים</font></b>';
  var COL_IMAGE         = '<b><font size="3">המלצה</font></b>';
  var table             = '';
 $("#gamesDetail").html(table);

 table = '<table border="0" cellpadding="2" cellspacing="5" width="100%"><tr class="childs_table_color2"><td style="white-space:nowrap;" valign="bottom" width="23%">'+COL_RECOMENDATION+'</td><td style="white-space:nowrap;" valign="bottom">'+COL_RAITING+'</td><td style="white-space:nowrap;" valign="bottom" width="69%">'+COL_IMAGE+'</td></tr>';
 if (!(arrGames == '')) {
   for (var i=0; i<arrGames[gameid].length; i++){
    if (!(arrGames[gameid][i] === undefined)) {

	 countGame      = parseInt(arrGamesPlay[gameid][i]);
	 countPlayGame  = parseInt(countPlayGame)+parseInt(countGame);

     var Stars = '';

	 for (var k=0;k<countGame;k++){
      Stars += '<img border="0" src="images/fullstar.jpg" width="16" height="16" style="display:inline;">';
      if (k == 4) {
       Stars +='<br />';
      }
	 }
     var last_start_pos = k;

	 for (var k=0;k<(10-countGame);k++){
      Stars += '<img border="0" src="images/emptystar.jpg" width="16" height="16" style="display:inline;">';
      if (k == (4 - last_start_pos)) {
       Stars +='<br />';
      }
     }

     if (!(userIdentif > 0)) {
      Stars ='<center>0<br /></center>';
     }
	 var recomed = _getRecomandationByNumPlayedGame(countGame);
         table   += '<tr class="childs_table_color1"><td style="white-space:nowrap; background-color:#FFFFFF" width="23%"><img border="0" src="images/'+arrGamesImages[gameid][i]+'" width="163" height="32" alt="'+arrGames[gameid][i]+'" title="'+arrGames[gameid][i]+'"></td><td style="white-space:nowrap; background-color:#FFFFFF">'+Stars+'</td><td style="white-space:nowrap;text-align:right; background-color:#FFFFFF">&nbsp;&nbsp;'+recomed+'</td></tr>';
   }
  }
 }else{
  return 0;
 }


  table   += '</table>';
  $(table).appendTo('#gamesDetail');

  if (i > 0) {countPlayGame = countPlayGame / i;}
  else countPlayGame = 0;

  recomed = _getRecomandationByNumPlayedGame(countPlayGame);
  if (countPlayGame >= 6) gmsMedalsFlag = true;
  else gmsMedalsFlag = false;

  if (!gmsMedalsFlag)$('#gmsMedals').css("display","none");
  else $('#gmsMedals').css("display","block");

  $('#generalRecomandation').html('<font size="2" color="#99CF17">המלצתינו:'+recomed+'</font>');

  gamestatpanel.display    = 'block';
  gamestatpanel.visibility = 'visible';

  if (window.navigator.userAgent.indexOf ("Gecko") >= 0){
   gamestatpanel.top  = ( e.clientY +20 ) + 'px';
   gamestatpanel.left = e.clientX+'px';
  } else {
   gamestatpanel.top  = window.event.y;
   gamestatpanel.left = window.event.x;
  }
  //gamestatpanel.top  = 240;
  //gamestatpanel.left = 360;
 }

}

function hideGameStat( gameid )
{
var divname       = 'gameblock';
var gamestatpanel = document.getElementById( divname ).style;

	if( gamestatpanel )	{
		gamestatpanel.display = 'none';
		gamestatpanel.visibility = 'hidden';
		gamestatpanel.top = -1000;
		gamestatpanel.left = -1000;
	}
}

function _getRecomandationByNumPlayedGame(numPlayedGame){

 var result = 'עדיין לא שיחקת.';
 if (userIdentif > 0) {
   if (numPlayedGame > 0 && numPlayedGame <= 3) {
    result = 'צריך לשחק עוד.';
   }else if (numPlayedGame >= 4 && numPlayedGame <= 5) {
    result = 'צריך לשחק עוד קצת.';
   }else if (numPlayedGame >= 6) {
    result = 'כל הכבוד, שיחקת מספיק!';
   }

 }else{
  result = 'עליך להתחבר לחשבון ילד.';
 }
 return result;
}

function entsub(myform) {
  if (window.event && window.event.keyCode == 13)
    myform.submit();
  else
    return true;
}

function entsubclick(mybtn) {
  if (window.event && window.event.keyCode == 13)
    mybtn.click();
  else
    return true;
}


function openFS(file) {
    window.open(file,
                  'player',
                  'top=0,left=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,fullscreen=yes,width=' + screen.availWidth + ',height=' + screen.availHeight );
}

function openFS2(file) {
    window.open(file,
                  'forum',
                  'top=0,left=0,toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,fullscreen=no,width=' + screen.availWidth + ',height=' + screen.availHeight );
}

function checkAvailable(id){


    var login = $("#"+id).val();

    if(login.length > 0) {
     loadingPage();

    	$.ajax({
    		type: "POST",
    		url:  "/user/checkname/",
    		data: "login=" + login,
    		async: true,
    		dataType: "json",
    		success: function(data) {
    		    if(data.code == 1){
    		        $("#"+id).css("color", "#f00");
    		    } else {
    		        $("#"+id).css("color", "#0F0");
    		    }
    		},
    		error: function(data) {
    			$("#"+id).html("שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.");
    		}
	});
	 $('#guiIdLoadingBlock').hide();
    }

}

var current_line = 1;
var counter = 0;
var arrUsers = {};
var selectedSex = '';

var returnval;

function editchild( id_child ){
 parent_username =  $('#guiStrParentUserName').val();
 var firstname   = $('#guiStrChildFirstNameEdit').val();
 var lastname    = $('#guiStrChildLastNameEdit').val();
 var date_year   = $('#guiIntChildYearOfBirthEdit').val();
 var date_month  = $('#guiIntChildMonthOfBirthEdit').val();
 var date_day    = $('#guiIntChildDayOfBirthEdit').val();
 var sex         = $(":radio[name=guiIntChildGenderEdit]").filter(":checked").val();//selectedSex;

 var child = {};

 child['firstname']  = firstname;
 child['lastname']   = lastname;
 child['date_year']  = date_year;
 child['date_month'] = date_month;
 child['date_day']   = date_day;
 child['sex']        = sex;
 child['user_id']    = id_child;

 var errorContainer = "";


 if (!firstname.length) {errorContainer += "נא להזין את שם הילד<br/>";}
 if (!lastname.length ) {errorContainer += "נא להזין את שם המשפחה של הילד<br/>"; }
 if (sex === undefined) {
  errorContainer += "נא לבחור את מין הילד<br/>";
 }else if (!sex.length) {errorContainer += "נא לבחור את מין הילד<br/>";}


 if (errorContainer.length > 0) {
   $("#errorContainer").html(errorContainer);
   returnval = false;
   return false;
 }

 loadingPage();

 $.ajax({
         type: "POST",
         url:  "/user/modifychild/",
         data: child,
         async: true,
         dataType: "json",
         success: function(data) {

          $("#errorContainer").html('');
          if(data.code == 1){
           $('#childRow'+id_child).html('');
           $("#childrenTable").html(data.childrenTable);

           var childArr = data.childArray;
           for (var i = 0; i < childArr.length; i++){
             arrChildFirstName[childArr[i]['user_id']]  = childArr[i]['user_firstname'];
             arrChildLastName[childArr[i]['user_id']]   = childArr[i]['user_lastname'];
             arrChildBirthDay[childArr[i]['user_id']]   = childArr[i]['d'];
             arrChildBirthMonth[childArr[i]['user_id']] = childArr[i]['m'];
             arrChildBirthYear[childArr[i]['user_id']]  = childArr[i]['y'];
             arrChildSex[childArr[i]['user_id']]        = childArr[i]['user_sex'];
		   }

		   returnval = true;
         }else {
                $('#errorContainer').html(data.message);
				returnval = false;
         }
         $('#guiIdLoadingBlock').css("display", "none");
       	},
       	error: function(data) {
			$('#errorContainer').html("שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.");
			returnval = false;
			$('#guiIdLoadingBlock').css("display", "none");
         }
      });

}

var type_form_child='add';

function addchild( showmessage ){

	ADD_CHILD       = false;
    parent_username =  $('#guiStrParentUserName').val();
    var username    =  $('#guiStrChildUserName').val();
    var firstname   =  $('#guiStrChildFirstName').val();
    var lastname    =  $('#guiStrChildLastName').val();
    var date_year   =  $('#guiIntChildYearOfBirth').val();
    var date_month  =  $('#guiIntChildMonthOfBirth').val();
    var date_day    =  $('#guiIntChildDayOfBirth').val();
    var sex         =  selectedSex;

    var child = {};

    child['username']   = username;
    child['firstname']  = firstname;
    child['lastname']   = lastname;
    child['date_year']  = date_year;
    child['date_month'] = date_month;
    child['date_day']   = date_day;
    child['sex']        = sex;
    child['form']       = type_form_child;

    var errorContainer = "";

    if (!username.length || username.length < 4) {errorContainer += "כינוי השחקן ריק או קטן מ- 4 תוים<br/>";}
    if (!firstname.length) {errorContainer += "נא למלא שם פרטי של הילד<br/>";}
    if (!lastname.length ) {errorContainer += "נא למלא שם משפחה של הילד<br/>"; }
    if (sex === undefined) {errorContainer += "נא לסמן בן או בת<br/>";}
    else if (!sex.length) {errorContainer += "לא נבחר מין הילד<br/>";}

   if(username == parent_username){
    $('#guiStrChildUserName').css("color", "#f00");
    $('#guiStrParentUserName').css("color", "#f00");
    errorContainer += "לא ניתן להשתמש בכינוי זהה עבור ילד והורה, אנא בחרו כינויים שונים";
   }

   if (errorContainer.length > 0) {
    if (showmessage != false) {
      $("#errorContainer").html(errorContainer);
      returnval = false;
	  return false;
    }else{
     alert(errorContainer);
     returnval = false;
	 return false;
	}
   }


    if(username.length && firstname.length && lastname.length){
        returnval = true;
        loadingPage();
        $.ajax({
        	type: "POST",
        	url:  "/user/addchild/",
        	data: child,
        	async: true,
        	dataType: "json",
        	success: function(data) {
        	    if(data.code == 1){
					isNotFromSubmit = ( showmessage === undefined );
                    $("#childrenTable").html(data.childrenTable);

                    $('#guiStrChildUserName').val("");
                    $('#guiStrChildFirstName').val("");
                    $('#guiStrChildLastName').val("");
                    $('#guiStrChildSecondName').val("");
                    $('#guiIntChildYearOfBirth').val("1");
                    $('#guiIntChildMonthOfBirth').val("1");
                    $('#guiIntChildDayOfBirth').val("1995");

                    if (type_form_child == 'edit') {
                     var childArr = data.arrayChild;
                     for (var i = 0; i < childArr.length; i++){
                       arrChildFirstName[childArr[i]['user_id']] = childArr[i]['user_firstname'];
                       arrChildLastName[childArr[i]['user_id']]  = childArr[i]['user_lastname'];
                       arrChildBirthDay[childArr[i]['user_id']]  = childArr[i]['d'];
                       arrChildBirthMonth[childArr[i]['user_id']]= childArr[i]['m'];
                       arrChildBirthYear[childArr[i]['user_id']] = childArr[i]['y'];
                       arrChildSex[childArr[i]['user_id']]       = childArr[i]['user_sex'];
				     }
                    }

                  ADD_CHILD = true;
                  returnval = true;
        	    } else {
        	        $('#errorContainer').html(data.message);
        	        ADD_CHILD = false;
					returnval = false;
        	  }
              $('#guiIdLoadingBlock').hide();
        	},
        	error: function(data) {
        	   if (!ADD_FROM_PROFILE) {
        	   	$('#errorContainer').html("1247:שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.");
        	   }
			   $('#guiIdLoadingBlock').hide();
			   returnval = false;
        	}
        });

      }else{
       if (showmessage) {
        $("#errorContainer").html('שגיאה בפרטי הילד');
         $('#guiIdLoadingBlock').hide();
       }
	  }
 return returnval;
 ADD_CHILD = returnval;
}

function deleteChild(ida){

    $.ajax({
    	type: "POST",
    	url:  "/user/deletechild/",
    	data: "child_id=" + ida,
    	async: false,
    	dataType: "json",
    	success: function(data) {
    	    if(data.code == 1){
    	        $("#tr"+ida).remove();
    	        $('#errorContainer').html(data.message);
    	    } else {

    	    }
    	},
    	error: function(data) {
            $('#errorContainer').html("שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.");
    	}
    });

}

function validateAndSaveProfileData(){
 var login = $('#guiStrChildUserName').val();

 if (login.length) {
  res =	addchild(false);
 }else res = true;

 if (res) {
  $('#profile').submit();
  return false;
 };
}

function validateAndSave(){
  returnval = null;
  var childUsername = $('#guiStrChildUserName').val();

  if (childUsername.length) {
   var resultAddChild = addchild( true );

   if (!resultAddChild) {
    $('#guiIdLoadingBlock').hide();
    return false;
   }

   var i = 0;
   while(!ADD_CHILD){
	i++;
	if (i > 5000) {break;}
   }
  }

  $.ajax({
    	type: "POST",
    	url:  "/user/getchcount/",
    	data: "",
    	async: false,
    	dataType: "json",
    	success: function(data) {

    	    if(data > 0){
    	        document.forms.signup_form.submit();
    	    } else {
    	        $('#errorContainer').html("Could you please add information about your children before confirmation of registation");
    	    }
    	    $('#guiIdLoadingBlock').hide();
    	},
    	error: function(data) {
          $('#errorContainer').html("שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.");
          $('#guiIdLoadingBlock').hide();
    	}
    });

}

var count_of_childrens = {};



function discardChild(child_id){
    if (!confirm('בחרת למחוק ילד מהרשימה, האם אתה בטוח?')) {return false;}
    loadingPage();
    $.ajax({
    	type: "POST",
    	url:  "/billing/discard-child/",
    	data: "child_id=" + child_id,
    	async: true,
    	dataType: "json",
    	success: function(data) {
    	  if(data.childrenTable == "empty"){
    	     $("#childrenTable").html("רשימת הילדים ריקה");
    	  } else {
    	      $("#childrenTable").html(data.childrenTable);
    	      cntChield = cntChield - 1;
    	      var selected_subs_type = $(":radio[name=guiEnumSubscriptionType]").filter(":checked");
              if(!(selected_subs_type.val() === undefined) && selected_subs_type.val() > 0){
               setSubscriptionTypes(selected_subs_type.val());
	          }
    	  }

          $('#guiIdLoadingBlock').hide();
          return false;
    	},
    	error: function(data) {
    	   $('#guiIdLoadingBlock').hide();
          $('#errorContainer').html("שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.");
    	  return false;
		}
    });

/*
  var selected_subs_type = $(":radio[name=guiEnumSubscriptionType]").filter(":checked");
  if(selected_subs_type.val() != 'undefined') {
   setSubscriptionTypes(selected_subs_type.val());
  }*/
}

var DISCOUNT_FOR_SECOND_CHILD = 50;
var DISCOUNT_FOR_FIRST_CHILD  = 0;
var VALIDATE_ST_ID            = 0;
var ONSEND_REQUEST            = true;

function setSubscriptionTypes(idSubTypes){

 if (SET_EMPTY_FIELD > 0) {
  $('#guiStrCoupon').val('');
  $('#guiStrCoupon').focus();
  var curr = $(":radio[name=guiEnumSubscriptionType]").filter(":checked");

  SET_EMPTY_FIELD = 0;
  setSubscriptionTypes(curr.val());
  return;
 }

	
 if (!(idSubTypes > 0)) {idSubTypes = 0;}
 var captionST       = arrSubScriptionTypes[idSubTypes];     /* caption of the subscription type*/
 var costST          = arrSubScriptionTypesCost[idSubTypes]; /* cost of the subscription type*/
 var countChild      = cntChield;                            /* count child */
 var couponObj       = $('#guiStrCoupon');
 var couponVal       = couponObj.val();
 var couponStrLength = couponVal.length;
 var strUserTable    = ""; /* Users table*/
 var strUserTotal    = ""; /* Users total row of table*/
 var fltTotalSumm    = 0;

// $('#guiIdLoadingBlock').hide();

 if (couponStrLength > 0 && ONSEND_REQUEST) {
   couponChange = false;
   checkCoupon();

   if (DISCOUNT_FOR_FIRST_CHILD > 0) {
   	VALIDATE_ST_ID = idSubTypes;
   }
 }

 for (var k = 1; k <= countChild; k++ ){
   if (k == 1 && DISCOUNT_FOR_FIRST_CHILD > 0 && VALIDATE_ST_ID == idSubTypes) {
    Total         = costST - ( ( costST * DISCOUNT_FOR_FIRST_CHILD ) / 100 );
    strUserTable += "<tr><td>מנוי ל- " + captionST + " עם שובר הנחה של " + DISCOUNT_FOR_FIRST_CHILD + "%</td><td>" +Total+ " ש&quot;ח</td></tr>";
   }else{
    if(k % 2 == 0) {
     Total         = costST - ( ( costST * DISCOUNT_FOR_SECOND_CHILD ) / 100 );
     strUserTable += "<tr><td>מנוי ל- " +captionST+" עם הנחה של " +DISCOUNT_FOR_SECOND_CHILD+ "% עבור רישום כל ילד שני</td><td>" +Total+ " ש&quot;ח </td></tr>";
    }else{
     Total         = costST;
     strUserTable += "<tr><td>" + "מנוי ל- "+captionST+"</td><td>" + Total + " ש&quot;ח</td></tr>";
	}
   }
   fltTotalSumm += eval(parseFloat(Total));
 }

/*
 if (VALIDATE_ST_ID != idSubTypes ) {
  $("#guiStrCoupon").css("color", "#000000");
  $("#guiStrCoupon_comment").html("<b>ללא שובר הנחה בתוקף</b>");
 }else{
   $("#guiStrCoupon").css("color", "#0F0");
   $("#guiStrCoupon_comment").html("&nbsp;");
 }
*/

 strUserTotal  =  strUserTable;
 strUserTotal += "<tr><td><b>סה&quot;כ</b></td><td><b>"+fltTotalSumm.toString()+" ש&quot;ח</b></td></tr>";
 $("#totals").html(strUserTotal);

}


function changeCouponDesciption(){
 var selected_subs_type = $(":radio[name=guiEnumSubscriptionType]").filter(":checked");
 $("#guiStrCoupon").css("color", "#000000");

 if(!(selected_subs_type.val() === undefined)) {
  DISCOUNT_FOR_FIRST_CHILD = 0;
  ONSEND_REQUEST = false;
  setSubscriptionTypes(selected_subs_type.val());
  ONSEND_REQUEST = true;
 }
}

function checkValidCouponBySubscriptionType(){
/*
 var selected_subs_type = $(":radio[name=guiEnumSubscriptionType]").filter(":checked");
 var couponObj          = $('#guiStrCoupon');
 var couponVal          = couponObj.val();
 var couponStrLength    = couponVal.length;
 ONEXIT_STATUS          = true;

 if(selected_subs_type.val() != 'undefined' && couponStrLength > 0){
 // if (VALIDATE_ST_ID == selected_subs_type.val() ) {return;}
  checkCoupon();
 }else{
  alert('Check Subscription Type!');
 }*/

}

function checkCoupon(){
    var couponObj       = $('#guiStrCoupon');
    var couponVal       = couponObj.val();
    var couponStrLength = couponVal.length;



    var selected_subs_type = $(":radio[name=guiEnumSubscriptionType]").filter(":checked");

    var params = {};

    if(!(selected_subs_type.val() === undefined) && selected_subs_type.val() > 0){

        params['coupon_name'] = couponObj.val();
        params['subscription_type'] = selected_subs_type.val();

		loadingPage();

        $.ajax({
        	    type  : "POST",
        	    url   :  "/billing/check-coupon/",
        	    data  : params,
        	    async : true,
        	    dataType : "json",
			success: function(data) {

               $('#errorBlock').html('');

        	   if(data.code == 0){
	        	 $("#guiStrCoupon").css("color", "#F00");
	        	 $("#guiStrCoupon_comment").html("<b>ללא שובר הנחה בתוקף</b><br />אם בידכם קוד קופון תקף אנא הזינו אותו בתיבה למעלה");
				 $("#totals").html(data.total);
        	   }else  if (data.code < 0) {

				if (data.code == -3) {

						 if (data.coupones.NeedleSubscriptionType > 0) {
						  $('input[@type=radio][value='+data.coupones.NeedleSubscriptionType+']').attr('checked', 'checked');
						  $('input[@type=radio][value='+data.coupones.NeedleSubscriptionType+']').click();
						  SET_EMPTY_FIELD = data.coupones.NeedleSubscriptionType;
		
						  $('#guiIdLoadingBlock').css("display", "none");
						  $("#totals").html(data.total);
						  return true;
						  ONEXIT_STATUS = false;
						 }
						 
				}else
							 SET_EMPTY_FIELD = 0;
			
							$("#guiStrCoupon").css("color", "#F00");
							$("#guiStrCoupon_comment").html("<b>ללא שובר הנחה בתוקף</b><br />אם בידכם קוד קופון תקף אנא הזינו אותו בתיבה למעלה");
							$("#totals").html(data.total);
							$('#errorBlock').html(data.coupones.Description);
        	   } else {
        	     $("#guiStrCoupon").css("color", "#0F0");
        	     $("#guiStrCoupon_comment").html("&nbsp;");
        	     DISCOUNT_FOR_FIRST_CHILD = data.coupones.c_discount;
                 $("#totals").html(data.total);
				 
				 	//Gregory 20/05/2009
				 	if(data.coupones.c_discount==100){
				  		$('#prvCartis').css("display", "none");//Gregory
						$('#flag_pay').val("1");
					}else{
				  		$('#prvCartis').css("display", "");//Gregory
						$('#flag_pay').val("0");
					}
					//End
        	   }
        	   $('#guiIdLoadingBlock').css("display", "none");
        	},
        	error: function(data) {
        	   $('#errorBlock').html('שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.');
			   $('#guiIdLoadingBlock').css("display", "none");
			   return false;
        	},
        	complete:function(data) {
					 $('#guiIdLoadingBlock').hide();
			}
        });
    }else{
      alert('Check Subscription Type!');
      return false;
	}
 return true;
 ONEXIT_STATUS = false;
}

function saveAndValidateCCForm(){
 if (checkCoupon()) {
  return true;
 }
}

function loadingPage(){
$('#guiIdLoadingBlock').css({'display':'block',
                              'background': 'transparent url(/images/loading.gif) no-repeat 50% 50%',
		                      'position': 'absolute',
		                      'left': '50%',
							  'margin-left': '-16px',
							  'top': '50%',
                              'margin-top': '-16px'
                            });
}





/* Games Map Functions */
function _getRecomendation( numPlayGame ){
 var res = '';
 if (numPlayGame > 0 && numPlayGame <= 3) {
   res = 'צריך לשחק עוד.';
 }else if (numPlayGame > 3 && numPlayGame <= 5) {
   res = 'צריך לשחק עוד קצת.';
 }else if (numPlayGame > 6) {
   res = 'כל הכבוד, שיחקת מספיק!';
  }else{
   res = 'עדיין לא שיחקת.';
  }
 return res;
}
function auPreload()
{
/*	if (!ver4) return;
	if (NS)
		auEmb = new Layer(0,window);
	else
	{
		Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
		document.body.insertAdjacentHTML("BeforeEnd",Str);
	}

	var Str = '';
	for (i=0;i<aySound.length;i++)
		Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"

	if (IE) auEmb.innerHTML = Str;
	else
	{
		auEmb.document.open();
		auEmb.document.write(Str);
		auEmb.document.close();
	}

	auCon = IE ? document.all.soundfiles : auEmb;
	auCon.control = auCtrl;*/
}

function auCtrl(whSound,play) {
	if (IE) { this.src = play? aySound[whSound]:''; }
	else { eval("this.document.embeds[whSound]." + (play? "play();":"stop();")); }
}

function playSound(whSound)
{
//	if (window.auCon) auCon.control(whSound,true);
}

function stopSound(whSound)
{
//	if (window.auCon) auCon.control(whSound,false);
} //-->

/* Games Map Functions End */

$(document).ready(function(){
	$('input', 'form[name="signup_form"]').keypress(function(){
		$(this).css('color', '#000000');
	})
});

function testSwf()
{
	if( GetSwfVer() == '-1' )
	{
		reloadPage();
	}
}

function reloadPage()
{
	window.location.reload();
}

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try
	{
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	}
	catch (e) {	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful.

			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}

	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;

	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}
	return flashVer;
}

  function validateAndSend(){
    var user_name      = $('#guiStrParentUserName').val();
    var user_firstname = $('#guiStrParentFirstName').val();
    var user_lastname  = $('#guiStrParentLastName').val();
    var user_email     = $('#guiStrParentEmail').val();
    var user_mobile    = $('#guiStrParentMobileNumber').val();
    var user_phone     = $('#guiStrParentPhoneNumber').val();
    var user_D1        = $('#D1').val();
    var user_S1        = $('#S1').val();

    var user = {};

    user['user_name']      = user_name;
    user['user_firstname'] = user_firstname;
    user['user_lastname']  = user_lastname;
    user['user_email']     = user_email;
    user['user_mobile']    = user_mobile;
    user['user_phone']     = user_phone;
    user['user_D1']        = user_D1;
    user['user_S1']        = user_S1;


    var errorContainer = "<b>שגיאה:</b><ul>";

    if (user_name.length < 4) {errorContainer += "<li>אנא הזן שם משתמש</li>";}
    if (user_firstname.length < 4) {errorContainer += "<li>אנא הזן שם פרטי</li>";}
	if (user_lastname.length < 4) {errorContainer += "<li>אנא הזן שם משפחה</li>";}
	if (user_email.length < 4) {errorContainer += "<li>אנא הזן כתובת אימייל</li>";}
    if (user_mobile.length < 4) {errorContainer += "<li>אנא הזן טלפון סלולארי</li>";}

    if (user_D1.length < 4) {errorContainer += "<li>אנא הזן נושא להודעה</li>";}
    if (user_S1.length < 4) {errorContainer += "<li>אנא כתוב את הודעתך</li>";}

    errorContainer += "</ul>";
    if (errorContainer.length > 25) {
     $("#errorContainer").html(errorContainer);
     return false;
    }else{$("#errorContainer").html("");}

    loadingPage();

    $.ajax({
         type: "POST",
         url:  "/contact/sendmail/",
         data: user,
         async: false,
         dataType: "json",
         success: function(data) {
          $("#errorContainer").html("");

          if(data.code == 1){
             if (confirm("הודעתך נשלחה. האם ברצונך לאפס את הטופס?")) {
              $('#guiStrParentUserName').val("");
              $('#guiStrParentFirstName').val("");
              $('#guiStrParentLastName').val("");
              $('#guiStrParentEmail').val("");
              $('#guiStrParentMobileNumber').val("");
              $('#guiStrParentPhoneNumber').val("");
              $('#S1').val("");
              $('#guiStrParentUserName').focus();
             }
          }else {
            var arrErr     = data.error;
            errorContainer = "<b>Error:</b><ul>";
            for (var i = 0; i < arrErr.length; i++){
              errorContainer += "<li>" + arrErr[i] + "</li>";
            }
            errorContainer += "</ul>";
            $('#errorContainer').html(errorContainer);

         }
         $('#guiIdLoadingBlock').css("display", "none");
       	},
       	error: function(data) {
		  $('#errorContainer').html("שגיאת תקשורת, אנא נסה שנית, במידה ותקלה זאת חוזרת על עצמה אנא צור איתנו קשר ודווח, תודה.");
		  $('#guiIdLoadingBlock').css("display", "none");
		  return false;
         }
      });
  }

