var joinus_loaded   = 0;
var joinrules_loaded   = 0;

function joinrules_pop() {
	var not_loaded_yet = 0;
	document.getElementById("joinus").style.display = 'none';

	if (use_enhanced_js) {
		try {
			xml_joinrules_init();
			not_loaded_yet = 1;
		} catch(e) {
			//alert(e);
			not_loaded_yet = 0;
		}
	}
}

function joinus_pop() {
	var not_loaded_yet = 0;

	if (use_enhanced_js) {
		try {
			xml_joinus_init();
			not_loaded_yet = 1;
		} catch(e) {
			//alert(e);
			not_loaded_yet = 0;
		}
	}
}

function xml_joinrules_init( tab ) {
	joinrules_main    = document.getElementById('joinrules');
	joinrules_drag    = document.getElementById('joinrules-drag');
	joinrules_content = document.getElementById('joinrules-content');

  joinrules_main.style.position = 'absolute';
	joinrules_main.style.display = 'block';
	joinrules_main.style.zIndex = 99;

	if (!joinrules_loaded) {
		var my_width  = 0;
		var my_height = 0;
		
		if (typeof( window.innerWidth) == 'number') {
			my_width  = window.innerWidth;
			my_height = window.innerHeight;
		} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			my_width  = document.documentElement.clientWidth;
			my_height = document.documentElement.clientHeight;
		} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
			my_width  = document.body.clientWidth;
			my_height = document.body.clientHeight;
		}

		var divheight = parseInt( joinrules_main.style.Height );
		var divwidth  = parseInt( joinrules_main.style.Width );
		
		divheight = divheight ? divheight : 400;
		divwidth  = divwidth  ? divwidth  : 400;

		var divxy = my_getcookie( 'ipb-joinrules-div' );
		var co_ords;
		
		if (divxy && divxy != null) {
			co_ords = divxy.split( ',' );

			if (co_ords.length) {
				var final_width  = co_ords[0];
				var final_height = co_ords[1];

				if (co_ords[0] > my_width)
					final_width = my_width - divwidth;

				if (co_ords[1] > my_height)
					final_height = my_height - divheight;

				joinrules_main.style.left = final_width  + 'px';
				joinrules_main.style.top  = final_height + 'px';
			}
		} else {
			joinrules_main.style.left = my_width  / 2  - (divwidth / 2)  + 'px';
			joinrules_main.style.top  = my_height / 2 - (divheight / 2 ) + 'px';
		}

		Drag.cookiename = 'ipb-joinrules-div';
		Drag.init( joinrules_drag, joinrules_main );
		joinrules_loaded = 1;
	}
};

function xml_joinus_init( tab ) {
	joinus_main    = document.getElementById('joinus');
	joinus_drag    = document.getElementById('joinus-drag');
	joinus_content = document.getElementById('joinus-content');

  joinus_main.style.position = 'absolute';
	joinus_main.style.display = 'block';
	joinus_main.style.zIndex = 99;

	if (!joinus_loaded) {
		var my_width  = 0;
		var my_height = 0;
		
		if (typeof( window.innerWidth) == 'number') {
			my_width  = window.innerWidth;
			my_height = window.innerHeight;
		} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			my_width  = document.documentElement.clientWidth;
			my_height = document.documentElement.clientHeight;
		} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
			my_width  = document.body.clientWidth;
			my_height = document.body.clientHeight;
		}

		var divheight = parseInt( joinus_main.style.Height );
		var divwidth  = parseInt( joinus_main.style.Width );
		
		divheight = divheight ? divheight : 400;
		divwidth  = divwidth  ? divwidth  : 400;

		var divxy = my_getcookie( 'ipb-joinus-div' );
		var co_ords;
		
		if (divxy && divxy != null) {
			co_ords = divxy.split( ',' );

			if (co_ords.length) {
				var final_width  = co_ords[0];
				var final_height = co_ords[1];

				if (co_ords[0] > my_width)
					final_width = my_width - divwidth;

				if (co_ords[1] > my_height)
					final_height = my_height - divheight;

				joinus_main.style.left = final_width  + 'px';
				joinus_main.style.top  = final_height + 'px';
			}
		} else {
			joinus_main.style.left = my_width  / 2  - (divwidth / 2)  + 'px';
			joinus_main.style.top  = my_height / 2 - (divheight / 2 ) + 'px';
		}

		Drag.cookiename = 'ipb-joinus-div';
		Drag.init( joinus_drag, joinus_main );
		joinus_loaded = 1;
	}
};

function submit_joinrules() {
	var chk = document.getElementById('joinrules-check').checked;

	if (chk) {
		document.getElementById("joinrules").style.display = 'none';
		joinus_pop();
	} else {
		document.getElementById('diverrorjoinrules').style.display = 'block';
		document.getElementById('diverrorjoinrules').style.color = 'Yellow';
		document.getElementById('diverrorjoinrules').innerHTML = 'Please agree our rules!!!';
	}
}

function submit_joinus() {
	var url = '/joinus.php';

	do_request_function = function() {
		if ( ! xmlobj_joinus.readystate_ready_and_ok() )
			return;
		var html = xmlobj_joinus.xmlhandler.responseText;

		if (html == 'email') {
			document.getElementById('divokeejoinus').style.display = 'none';
			document.getElementById('diverrorjoinus').innerHTML = 'Email address is not valid';
			document.getElementById('diverrorjoinus').style.display = 'block';
		} else if (html == 'name') {
			document.getElementById('divokeejoinus').style.display = 'none';
			document.getElementById('diverrorjoinus').innerHTML = 'Player name field is left blank';
			document.getElementById('diverrorjoinus').style.display = 'block';
		} else if (html == 'age') {
			document.getElementById('divokeejoinus').style.display = 'none';
			document.getElementById('diverrorjoinus').innerHTML = 'Age field is left blank';
			document.getElementById('diverrorjoinus').style.display = 'block';
		} else if (html == 'from') {
			document.getElementById('divokeejoinus').style.display = 'none';
			document.getElementById('diverrorjoinus').innerHTML = 'From field is left blank';
			document.getElementById('diverrorjoinus').style.display = 'block';
		} else if (html == 'content') {
			document.getElementById('divokeejoinus').style.display = 'none';
			document.getElementById('diverrorjoinus').innerHTML = 'Content field is left blank';
			document.getElementById('diverrorjoinus').style.display = 'block';
		} else if (html == 'okee') {
			document.getElementById('diverrorjoinus').style.display = 'none';
			document.getElementById('divokeejoinus').style.display = 'block';
			document.getElementById('joinus-submit').disabled = true;
			setTimeout('document.getElementById("joinus").style.display="none"', 5000);
		}
	};

	var fields = new Array();
	fields['joinus-emailaddress'] = document.getElementById('joinus-emailaddress').value;
	fields['joinus-name'] = document.getElementById('joinus-name').value;
	fields['joinus-age'] = document.getElementById('joinus-age').value;
	fields['joinus-from'] = document.getElementById('joinus-from').value;
	fields['joinus-contentblock'] = document.getElementById('joinus-contentblock').value;

	xmlobj_joinus = new ajax_request();
	xmlobj_joinus.onreadystatechange( do_request_function );
	xmlobj_joinus.process( url, 'POST', xmlobj_joinus.format_for_post(fields) );
}