//handles the AJAX requests - this method is compatible with all versions of IE
var objreportxml;

var report_content;

var domainpath = '';

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  objreportxml=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  objreportxml=new ActiveXObject("Microsoft.XMLHTTP");
}

function sendReport(content) {
	//alert(this);
	objreportxml.open("POST", ''+domainpath+'/external/send_report.php?content='+ content +'',true);
		
	objreportxml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	var form = $('#report_form');
	objreportxml.send(form.serialize());
	objreportxml.onreadystatechange=reportHandler;
}

//Handle the callbacks from the script
reportHandler=function(data) {
	
	if (objreportxml.readyState==4 && objreportxml.status==200) {
				
		$('.report_form_status').html(objreportxml.responseText);
		$('.report_preloader_login').hide();
		
	}
	
}


jQuery(document).ready(function() {
	
	//declare all variables
	var rollovers = [];
	var images = [];
	
	var gameSearch = 'search games or classic arcade titles';
	
	//execute code
	$("[name=game_searchfield_live]").val(gameSearch)
		.focus(function() { 
			if($(this).val() == $(this).attr("title")) $(this).val("");  
			})  
		.blur(function() {  
			if($.trim($(this).val()) == "") $(this).val($(this).attr("title"));
	});

	
	//POP-UP Module
	$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size
	report_content = $(this).attr('name');//Get the itemID assigned to the popup

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="/images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
	});
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  //fade them both out
		});
		return false;
	});
	//POP-UP Module end

	
	$('.form_preloader').hide();
	$('.form_preloader_login').hide();
	$("#registration_form").submit(function(){
		$('.form_preloader').show();
	});
	
	
	$('.form_preloader_email_confirm').hide();
	$("#email_confirm_form").submit(function(){
		$('.form_preloader_email_confirm').show();
	});
	
	
	$('.report_preloader_login').hide();
	$('#report_form').submit(function() {
		
		$('.report_preloader_login').show();
			sendReport(report_content);
	});
	
	// validate signup form on keyup and submit
	/*$("#registration_form").validate({
		rules: {
			username: {
				required: true,
				minlength: 2
			},
			password: {
				required: true,
				minlength: 8
			},
			password_confirm: {
				required: true,
				minlength: 8,
				equalTo: "#post_password"
			},
			email_address: {
				required: true,
				email: true
			},
		},
		messages: {
			username: {
				required: "Please enter a username",
				minlength: "Your username must consist of at least 2 characters"
			},
			password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 8 characters long"
			},
			confirm_password: {
				required: "Please provide a password",
				minlength: "Your password must be at least 8 characters long",
				equalTo: "Please enter the same password as above"
			},
		}
	});*/
	
});

