//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getLinkOptionPage(Option)
{
var RetLink = ""; 
//----------------------------------------------------------------------------------------------------------------------------------------------------
	switch(Option)
	{
		case "Alexandria, VA.":
			RetLink = "support/Williams.php";
			break;
			
		case "Amsterdam, NY.":
			RetLink = "support/Rymaruk.php";
			break;

		case "Boulder, CO.":
			RetLink = "support/Bennett.php";
			break;			
			
		case "Collegeville, PA.":
			RetLink = "support/Drehobl.php";
			break;
			
		case "E-Mail Message":
			RetLink = "support/MailPage.htm";
			break;

		case "Gladstone, MI.":
			RetLink = "support/Bunno.php";
			break;
						
		case "Kalamazoo, MI.":
			RetLink = "support/Thompson.php";
			break;
			
		case "Kyoshi Thompson":
			RetLink = "support/Thompson.php";
			break;

		case "Philadelphia, PA.":
			RetLink = "support/Sumpter.php";
			break;

		case "Roanoke, VA.":
			RetLink = "support/Bleecker.php";
			break;
			
		case "Uechi-Ryu Karate":
			RetLink = "support/UechiRyu.php";
			break;
			
	}

return(RetLink);	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isOutsideTheDiv(e, ObjX)
{
var x1 = 00; 
var x2 = 00
var y1 = 00; 
var y2 = 00;
var RetFlag = false; 
//----------------------------------------------------------------------------------------------------------------------------------------------------
	//Determine the browser and the event handler
	if ($.browser.mozilla == true)
	{
		posX = e.clientX;
		posY = e.clientY;
	}
	else 
	{
		posX = window.event.clientX; 
		posY = window.event.clientY; 		
	}		
	
	//Determine the 4 corners of the plane
	x1 = ObjX.offset().left; 
		x1 = Math.ceil(x1);
	y1 = ObjX.offset().top;
		y1 = Math.ceil(y1);
	x2 = x1 + ObjX.outerWidth();
	y2 = y1 + ObjX.outerHeight();
	
	//alert(posX + "  |  " + posY + "\n" + x1 + "  |  " + y1 + "\n" + x2 + "  |  " + y2 + "\n");
	if ( (posX > x1 && posX < x2) && (posY > y1 && posY < y2) )
	{
		RetFlag = true; 
	}

return (RetFlag);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function PageLayout()
{
var CURR_HEIGHT = 00;
var MARGIN_LEFT = 00; 
var TMP_HEIGHT = 00; 
var TMP_WIDTH = 00; 
var TMP_LEFT = 00; 
var TMP_TOP = 00; 
var WINDOW_HEIGHT = $(window).height() - 100;
var WINDOW_WIDTH = $(window).width();
//----------------------------------------------------------------------------------------------------------------------------------------------------
//PURPOSE: When the page is initially loaded, or if it is resized, the page specific elements will 
//         be positioned accordingly.
//----------------------------------------------------------------------------------------------------------------------------------------------------
	$("#mainHeaderDiv").css("margin-left", "00");
	$("#mainMenuTable").css("margin-left", "00");
	if (WINDOW_WIDTH > 800)
	{
		MARGIN_LEFT = WINDOW_WIDTH - 800; 
		MARGIN_LEFT = MARGIN_LEFT / 2; 
		MARGIN_LEFT = Math.ceil(MARGIN_LEFT); 
		MARGIN_LEFT = MARGIN_LEFT + "px";

		$("#mainHeaderDiv").css("left", MARGIN_LEFT);
		//$("#mainMenuTable").css("left", MARGIN_LEFT);
	}
	
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	//xx MAIN LOGIN DIV
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	if (WINDOW_WIDTH <= 800)
		TMP_WIDTH = 200;	
	else 
		TMP_WIDTH = WINDOW_WIDTH * .20
		TMP_WIDTH = Math.ceil(TMP_WIDTH);
	
	if (WINDOW_HEIGHT <= 600)
		TMP_HEIGHT = 200;
	else 
		TMP_HEIGHT = WINDOW_HEIGHT * .40
	TMP_HEIGHT = Math.ceil(TMP_HEIGHT);

	TMP_HEIGHT = Math.ceil(TMP_HEIGHT);
	TMP_HEIGHT -= 10;
	CURR_HEIGHT += TMP_HEIGHT;
	//alert("#1.) CURRENT HEIGHT: " + CURR_HEIGHT);
	
	$("#mainLoginDiv").css("height", TMP_HEIGHT);
	$("#mainLoginDiv").css("width", TMP_WIDTH);
	$("#mainLoginDiv").css("top", "100px");
	$("#mainLoginDiv").css("left", "10px");
	$("#mainLoginDiv").load("support/LoginPage.php");
	
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	//xx MAIN UPDATES DIV
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx	
	if (WINDOW_WIDTH <= 800)
		TMP_WIDTH = 200;	
	else 
		TMP_WIDTH = WINDOW_WIDTH * .20;	
	TMP_WIDTH = Math.ceil(TMP_WIDTH);
	
	if (WINDOW_HEIGHT <= 600)
		TMP_HEIGHT = 350;
	else 
	{
		TMP_HEIGHT = WINDOW_HEIGHT * .60
		TMP_HEIGHT = Math.ceil(TMP_HEIGHT);
		TMP_HEIGHT = TMP_HEIGHT-150;		
	}
	
	TMP_HEIGHT = Math.ceil(TMP_HEIGHT);
	CURR_HEIGHT +=TMP_HEIGHT;
	//alert("#2.) CURRENT HEIGHT: " + CURR_HEIGHT);
	$("#mainUpdatesDiv").css("height", TMP_HEIGHT);
	$("#mainUpdatesDiv").css("width", TMP_WIDTH);
		
	TMP_TOP = 00; 
	TMP_TOP = 100 + $("#mainLoginDiv").outerHeight() + 5;

	$("#mainUpdatesDiv").css("top", TMP_TOP);
	$("#mainUpdatesDiv").css("left", "10px");
	//$("#mainUpdatesDiv").load("support/WhatsNewPage.php");	
	$("#mainUpdatesDiv").load("whatsnew/status.php");
	
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	//xx MAIN CONTENT DIV & Glass Plate
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx	
	if (WINDOW_WIDTH <= 800)
		TMP_WIDTH = 600;	
	else 
	{
		TMP_WIDTH = WINDOW_WIDTH - $("#mainLoginDiv").outerWidth();
		TMP_WIDTH = TMP_WIDTH - 30;
	}
	
	if (WINDOW_HEIGHT <= 600)
		TMP_HEIGHT = 547;
	else 
	{
		//TMP_HEIGHT = WINDOW_HEIGHT * .60
		//TMP_HEIGHT = Math.ceil(TMP_HEIGHT);
		//TMP_HEIGHT = TMP_HEIGHT-150;		
		TMP_HEIGHT = CURR_HEIGHT;
	}
	
	TMP_HEIGHT = Math.ceil(TMP_HEIGHT);
	$("#mainContentDiv").css("height", TMP_HEIGHT);
	$("#mainContentDiv").css("width", TMP_WIDTH);
	$("#mainPlateDiv").css("height", TMP_HEIGHT);
	$("#mainPlateDiv").css("width", TMP_WIDTH);	
		
	TMP_LEFT = 00; 
	TMP_LEFT = $("#mainLoginDiv").outerWidth() + 15;
	
	$("#mainContentDiv").css("top", "100px");
	$("#mainPlateDiv").css("top", "100px");	
	
	$("#mainContentDiv").css("left", TMP_LEFT);
	$("#mainPlateDiv").css("left", TMP_LEFT);
	//$("#mainContentDiv").load("support/ContentView.php");	
	
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	//xx Manipulating mainContentDiv's background image
	//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx	
	//       Height: 600px   |   Width: 650px
	//--------------------------------------------------		
	if (TMP_HEIGHT >= 600)
	{
		TMP_HEIGHT = 600
	}
	else 
	{
		TMP_HEIGHT = TMP_HEIGHT / 600; 
		TMP_HEIGHT = 600 * TMP_HEIGHT; 
		TMP_HEIGHT = Math.ceil(TMP_HEIGHT)
	}

	
	if (TMP_WIDTH >= 650)
	{
		TMP_WIDTH = 650
	}
	else 
	{
		TMP_WIDTH = TMP_WIDTH / 650; 
		TMP_WIDTH = 650 * TMP_WIDTH; 
		TMP_WIDTH = Math.ceil(TMP_WIDTH)
	}
	
	$("#contentBkground").height(TMP_HEIGHT);
	$("#contentBkground").width(TMP_WIDTH);

return(0);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function subMenuDisplay(flag)
{
//----------------------------------------------------------------------------------------------------------------------------------------------------
	if (flag == 00)
	{
		$("#subNomenTxt").attr("value", "");
		$("#subNomenTxt").attr("value", "void");
				
		$("#subMenuDiv").hide();
	}
	else 
	{
		$("#subMenuDiv").show();
	}
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function subMenuLoadOut(Option)
{
var Options = ""; 
//----------------------------------------------------------------------------------------------------------------------------------------------------
	$("#subMenuDiv").html("");
	
	switch(Option)
	{
		case 'About Us': 
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Kyoshi Thompson</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Uechi-Ryu Karate</p>';
			break;

		case 'Contact Us': 
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;E-Mail Message</p>';
			break;
			
		case 'Kokusai Dojos':
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Boulder, CO.</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Gladstone, MI.</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Kalamazoo, MI.</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Amsterdam, NY.</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Collegeville, PA.</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Philadelphia, PA.</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Alexandria, VA.</p>';
			Options += '<p class="MenuOpt">&nbsp;&bull;&nbsp;Roanoke, VA.</p>';
			break;		
	}
	
	Options += '<input type="hidden" id="subNomenTxt" name="subNomenTxt" value="' + Option + '"/>';
	
	$("#subMenuDiv").html(Options);
	
return(0);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function subMenuOptionLoader(Option)
{
var View_Link = getLinkOptionPage(Option);
//----------------------------------------------------------------------------------------------------------------------------------------------------
	$("#mainPlateDiv").load(View_Link);

return(0);	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidEmail()
{
var errMsg = "";
var MailFromTxt = $("#MailFromTxt").val();
var MailSubjTxt = $("#MailSubjTxt").val();
var MailBodyTxt = $("#MailBodyTxt").val();
var RetVal; 
//----------------------------------------------------------------------------------------------------------------------------------------------------
	
	if ( MailFromTxt.length == 00 )
		errMsg += '* The "FROM" section of the message is incomplete.\n\n';
		
	if ( validEmailAddress(MailFromTxt) != true)
		errMsg += '* The "FROM" section of the message is incorrect.\n\n';
	
	if ( MailSubjTxt.length == 00 )
		errMsg += '* The "SUBJECT" section of the message is incomplete.\n\n';
		
	if ( MailBodyTxt.length == 00 )
		errMsg += '* The "BODY" of the message is incomplete.\n\n';
	
	if (errMsg.length > 00)
	{
		errMsg = "E-MAIL MESSAGE ERROR...\n\n" + errMsg;
		alert(errMsg);
		RetVal = false; 
	}
	else 
	{
		RetVal = true; 
	}
	
return(RetVal);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validEmailAddress(email) 
{ 
/*http://stackoverflow.com/questions/46155/validate-email-address-in-javascript*/
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
//----------------------------------------------------------------------------------------------------------------------------------------------------
return re.test(email);
} 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function()
{
	PageLayout();

	$(window).resize(function()
	{
		PageLayout(); 
	});
	
	
	$("#HomeCell").click(function()
	{
	//------------------------------------------------------------------------------------------------------------------------------------------------
		window.location.reload()
		
		return(0);
	});
	
	$(".KokMsg").live("click", function()
	{
	var MsgId = $(this).attr("id");
	var MsgInfoMtx = MsgId.split("_");	
	var Id = MsgInfoMtx[1]; 
	var RetMsg = ""; 
	//------------------------------------------------------------------------------------------------------------------------------------------------

		switch( parseInt(Id) )
		{
			case 1: 
				RetMsg += '<br/><br/>';
				RetMsg += '<h3 style=text-align:center;><u>Uechi-Ryu Kokusai: Under Construction</u></h3>';
				RetMsg += '<br/><br/>';
				RetMsg += '<font size="3">';
				RetMsg += 'The <i>Uechi-Kokusai</i> is currently under construction.  This particular website has not had a major ';
				RetMsg += 'since its inception.  Some of the options currently displayed may be expanded, or they might be removed ';
				RetMsg += 'altogether.  Either way, it is my hope to create a better web experience for those that visit our site.  ';
				RetMsg += 'In the event that you have an idea or a thought you believe could make this site better, I would be more ';
				RetMsg += 'than happy to listen.<br/><br/><br/>';
				RetMsg += 'Thank you for being patient,<br/>';
				RetMsg += 'Site Webmaster';
				RetMsg += '</font>';
				break;

			case 2: 
				RetMsg += '<br/><br/>';
				RetMsg += '<h3 style=text-align:center;><u>Uechi-Ryu Kokusai: Web Presence</u></h3>';
				RetMsg += '<br/><br/>';
				RetMsg += '<font size="3">';
				RetMsg += 'The <i>Uechi-Kokusai</i> is comprised of several dojos across the United States of America, and abroad.  ';
				RetMsg += 'Some of these dojos are listed here, while many of them are not.  As an association, we should strive to ';
				RetMsg += 'improve our presence on the Internet.<br/><br/>';
				RetMsg += 'At this time, I would like to ask any <i>Uechi-Kokusai</i> dojo that is not displayed on this site to ';
				RetMsg += 'contact us so that they can be displayed online as well as to promote a sense of <i>Uechi-Kokusai</i> unity.';
				RetMsg += 'In the event that you do not have a website that represents your dojo on the Internet, contact us anyway - ';
				RetMsg += 'Perhaps we could be able to provide you and your dojo with representation on this website.<br/><br/>';
				RetMsg += 'I thank you for taking the time to read this, and I sincerely hope that some of the dojos that have lost their ';
				RetMsg += 'website will take the time to contact us.  I wish you well both on and off the dojo floor, and I look forward ';
				RetMsg += 'to hearing from fellow karate-ka soon.';				
				RetMsg += '<br/><br/><br/>';
				RetMsg += 'Thank you for being patient,<br/>';
				RetMsg += 'Site Webmaster';
				RetMsg += '</font>';
				break;				
		}
				
		$("#mainPlateDiv").html("");
		$("#mainPlateDiv").html(RetMsg);
	return(0);

	});
	
	
	$("#MailClearCmnd").live("click", function()
	{
	//------------------------------------------------------------------------------------------------------------------------------------------------
		$("#MailFromTxt").attr("value", "");
		$("#MailSubjTxt").attr("value", "");
		$("#MailBodyTxt").attr("value", "");
	
	return(0);
	});
	

	$("#MailCloseCmnd").live("click", function()
	{
	//------------------------------------------------------------------------------------------------------------------------------------------------
		window.location.reload();
		
	return(0);
	});

	
	$("#MailSendCmnd").live("click", function()
	{
	var MailToTxt = encodeURIComponent( "UechiKokusai@GMail.com" ); 
	var MailFromTxt = encodeURIComponent( $("#MailFromTxt").val() );
	var MailSubjTxt = encodeURIComponent( $("#MailSubjTxt").val() );
	var MailBodyTxt = encodeURIComponent( $("#MailBodyTxt").val() );
	//------------------------------------------------------------------------------------------------------------------------------------------------
		//if ( ValidEmail() )			
		$("#MailBoxDiv").load("support/Mail2Kok.php?MailToTxt="+MailToTxt+"&MailFromTxt="+MailFromTxt+"&MailSubjTxt="+MailSubjTxt+"&MailBodyTxt="+MailBodyTxt);

		return(0);
	});
	
	
	$("#mainMenuTable td").mouseenter(function()
	{
	var divLeft = $(this).offset().left;
	var divTop = $(this).offset().top + $(this).outerHeight() - 3.5;
	var nomen = $(this).text();
	//------------------------------------------------------------------------------------------------------------------------------------------------
		
		if ( $("#subNomenTxt").attr("value")  == 'void' )
		{			
			$("#subMenuDiv").css("display", "");
			$("#subMenuDiv").css("top", divTop);
			$("#subMenuDiv").css("left", divLeft);		
			
			subMenuLoadOut(nomen);

			subMenuDisplay(1); 
			
			$("#subNomenTxt").attr("value", nomen);
			//alert( $("#subNomenTxt").attr("value") );
		}
	});
	
	$("#mainMenuTable td").mouseleave(function(e)
	{
	var Menu_Div = $("#subMenuDiv");
	//------------------------------------------------------------------------------------------------------------------------------------------------
		if (!isOutsideTheDiv(e, Menu_Div) )
		{
			subMenuDisplay(0); 
		}
	});	

	$(".MenuOpt").live("click", function()
	{
	var Option = $(this).text().substring(3,99); 
	//------------------------------------------------------------------------------------------------------------------------------------------------
		subMenuOptionLoader(Option);
	
	return(0);
	});
	
		
	$(".MenuOpt").live("mouseenter", function()
	{
	var Option = $(this).text().substring(3,99); 
	//------------------------------------------------------------------------------------------------------------------------------------------------
		$(".MenuOpt").each(function()		
		{
			$(this).css("background-color", "#000000");
			$(this).css("color", "#FFFFFF");
		});

		$(this).css("background-color", "#FFFFFF");
		$(this).css("color", "#000000");
	});

	$(".MenuOpt").live("mouseleave", function()
	{
		$(".MenuOpt").each(function()
		{
			$(this).css("background-color", "#000000");
			$(this).css("color", "#FFFFFF");
		});
	});
	
	
	$("#subMenuDiv").mouseleave(function()
	{
	var Menu = $("#mainMenuTable");
	var Option = $("#subNomenTxt").attr("value");
	//------------------------------------------------------------------------------------------------------------------------------------------------
		subMenuDisplay(0); 
	/*
		$("#mainMenuTable td").each(function()
		{
			if ( $(this).text() == Option )
			{
				//alert(77);
			}
			
		});
	*/
	});
});

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
