validateBigpointRegistration = function() {
  uname_class = 'bp_register_uname';
  patnerid = $('#bp_patner_gameid').val();
  uid = $('#bp_uid').val();
  uname = $('#'+uname_class).val();
  cuname = $('#bp_register_newuname').val();
  if(cuname != 'null'){
  	uname = cuname;
  	uname_class = 'bp_register_newuname';
  }
  pword = $('#bp_register_password').val();
  emails = $('#bp_email').val();
  dob = $('#bp_dob').val().split("-");
  gid = $('#bp_gameid').val();
  pgid = $('#bp_patner_gameid').val();
  gname = $('#bp_gamename').val();
  gurl = $('#bp_gameurl').val();
	if(uname.length < 6) {
  	$('#'+uname_class+'_error').html('Invalid Username').fadeIn();
    return false;
  }
  else if(pword.length < 6) {
  	$('#bp_register_password_error').html('Invalid Password').fadeIn();
    return false;
  }
  else {
    tb_show('','#TB_inline?height=0&width=0','');
    $('#bp_register_form').hide();
    $('#bp_loading_form').show();
    var queryString = "uid="+uid+"&patnerid="+patnerid+"&name="+escape(uname)+"&pass="+escape(pword)+"&email="+escape(emails)+"&dob="+escape(dob)+"&game="+gid+"&pgame="+pgid+"&gname="+escape(gname)+"&gurl="+escape(gurl);

    $.ajax({
      type: 'POST',
      url: '?q=games/bigpoint_register',
      data: queryString,
      success: function(response) {
        arResponse = response.split("<==>");
        $('#bp_loading_form').hide();
        tb_remove();
        if(arResponse[0] == 113) {
        	$('#bp_register_title_txt').html('The user name <span class="fluorescent_blue_txt">'+uname+'</span> is<br>already in use on '+gname+' please<br>choose another one.');
        	$('#bp_register_uname_layer').hide();
        	$('#bp_register_password_layer').hide();
        	$('#bp_register_tc_layer').hide();
        	$('#bp_register_newuname').val('');
        	$('#bp_register_unamechange_layer').show();
        	$('#bp_register_submit').removeClass('yes_continue_bt');
        	$('#bp_register_submit').addClass('confirm_bt');
        	$('#bp_register_form').show();
        }
        else if(arResponse[0] == 0) {
          window.location.href = arResponse[1];
        }
        else {
          alert(response);
        }
      }
    });
  }
}

validateBigpointLogin = function() {
  uname = $('#bp_login_uname').val();
  pword = $('#bp_login_password').val();
  gid = $('#bp_gameid').val();
  pgid = $('#bp_patner_gameid').val();

  if(uname.length < 6) {
    $('#bp_login_uname_error').html('Invalid Username').fadeIn();
    return false;
  }
  else if(pword.length < 6) {
    $('#bp_login_password_error').html('Invalid Password').fadeIn();
    return false;
  }
  else {
	$('#bp_login_form').hide();
    bp_startGame();
  }
}

removeErrorMessage = function(id) {
  if(document.getElementById(id).style.display == 'block' || document.getElementById(id).style.display == '') {
    $('#'+id).hide();
  }
}

hideAllErrors = function() {
  if(document.getElementById('bigpoint_registration_uname_error').style.display == 'block') {
    $('#bigpoint_registration_uname_error').hide('slow');
  }
  if(document.getElementById('bigpoint_registration_password_error').style.display == 'block') {
    $('#bigpoint_registration_password_error').hide('slow');
  }
  if(document.getElementById('bigpoint_registration_email_error').style.display == 'block') {
    $('#bigpoint_registration_email_error').hide('slow');
  }
  if(document.getElementById('bigpoint_registration_terms_error').style.display == 'block') {
    $('#bigpoint_registration_terms_error').hide('slow');
  }
}



submitForm = function(e, frm) {
  if(e.keyCode == 13) {
    switch(frm) {
      case 1:
        validateBigpointLogin();
        break;
      case 2:
        validateBigpointRegistration();
        break;
    }
  }
}



/* new bigpoint registration integration starts */
bp_registerShowForm = function() {
	
	$('#bp_register_form').show();
}

bp_registerHideForm = function() {
	
	$('#bp_register_form').hide();
}

bp_loginShowForm = function() {
	
	$('#bp_login_form').show();
}

bp_loginHideForm = function() {
	
	$('#bp_login_form').hide();
}

bp_startGame = function() {
	tb_show('','#TB_inline?height=0&width=0','');
    $('#bp_loading_form').show();
	uname = $('#bp_login_uname').val();
	pword = $('#bp_login_password').val();
	gid = $('#bp_gameid').val();
	pgid = $('#bp_patner_gameid').val();
	gname = $('#bp_gamename').val();
	gurl = $('#bp_gameurl').val();

	var queryString = "name="+escape(uname)+"&pass="+escape(pword)+"&game="+gid+"&pgame="+pgid+"&gname="+escape(gname)+"&gurl="+escape(gurl);

	$.ajax({
		url: "?q=games/bigpoint_login",
		type: "POST",
		data: queryString,
		success: function(response) {
			arResponse = response.split("<==>");
			$('#bp_loading_form').hide();
		    tb_remove();
			if(arResponse[0] == 0) {
				window.location.href = arResponse[1];
			}
			else {
				 $('#bp_login_form').show();
				 $('#bp_login_form_error').fadeIn();
			}
		}
	});
}

bp_hideLayer = function(layer) {
	if(document.getElementById(layer).style.display == 'block') {
		$('#'+layer).hide();
	}
}

setWidthAlignment = function() {
/*	if(navigator.appName != 'Microsoft Internet Explorer') {
		switch(screen.width) {
			case 1024:
				$('#bp_register_form').attr('style','left:250px');
				$('#bp_login_form').attr('style','left:250px');
				$('#bp_loading_form').attr('style','left:250px');
				break;
			case 1152:
				$('#bp_register_form').attr('style','left:350px');
				$('#bp_login_form').attr('style','left:350px');
				$('#bp_loading_form').attr('style','left:350px');
				break;
			case 1280:
				$('#bp_register_form').attr('style','left:375px');
				$('#bp_login_form').attr('style','left:375px');
				$('#bp_loading_form').attr('style','left:375px');
				break;
		}
	}
*/
	var boxWidth = 520;
	var screenWidth = screen.width;
	var boxWidthSize = boxWidth / 2;
	if(navigator.appName == 'Microsoft Internet Explorer') {
		var boxWidthSize = boxWidth
	}
	var position = (screenWidth / 2) - boxWidthSize;
//	alert(boxWidth+'\n'+screenWidth+'\n'+boxWidthSize+'\n'+position);
	$('#bp_register_form').attr('style','left:'+position+'px');
	$('#bp_login_form').attr('style','left:'+position+'px');
	$('#bp_loading_form').attr('style','left:'+position+'px');
}

/* new bigpoint registration integration starts */
