var NS6=document.getElementById && !document.all;
var IE=document.all;

document.onmousemove = setCursorPos; // for showing image popup ... see setCursorPos() function


function topMenu() {
	document.write(
	"<table class='topmenu' cellpadding=0 cellspacing=5 style='' align='center' border=0>"
	+"<tr><td style='height:4px'></td></tr>"
	+ "	<tr> "
	+ "		<td align='center' width=45> "
	+ "			<a href='/index.php' class='topmenu' >HOME</a> "
	+ "		</td> "
	+ "		<td align='center' valign='top' width=7> | </td> "
	+ "		<td align='center' width=40> "
	+ "			<a href='/news.php' class='topmenu'>NEWS</a> "
	+ "		</td> "
	+ "		<td align='center' valign='top' width=7> | </td> "
	+ "		<td align='center' width=50> "
	+ "			<a href='/links.php' class='topmenu'>MEMBERS</a> "
	+ "		</td> "
	+ "		<td align='center' valign='top' width=7> | </td> "
	+ "		<td align='center' > "
	+ "			<a href='/events.php' class='topmenu'>EVENT CALENDAR</a> "
	+ "		</td> "
	+ "		<td align='center' valign='top' width=7> | </td> "
	+ "		<td align='center' > "
	+ "			<a href='/points.php' class='topmenu'>COMPETITOR RECORDS</a> "
	+ "		</td> "
	+ "		<td align='center' valign='top' width=7> | </td> "
	+ "		<td align='center' > "
	+ "			<a href='/contact.php' class='topmenu'>CONTACT</a> "
	+ "		</td> "
	+ "		<td align='center' valign='top' width=7> | </td> "
	+ "		<td align='center' > "
	+ "			<a href='/registration.html' class='topmenu'>REGISTRATION</a> "
	+ "		</td> "
	+ "		<td align='center' valign='top' width=7> | </td> "
	+ "		<td align='center' > "
	+ "			<a href='/gb/index.php' class='topmenu'>GUEST BOOK</a> "
	+ "		</td> "
	+ "	</tr> "
	+ "	</table> "
	// Nantional Martial Arts Circuit
	+ "	<img src='/img/nmac.png'border='0' alt=''>");
}

function mainBanner(classBanner) {
	if(!classBanner)
		classBanner = 'banner1';

	document.write(
	  "<br>"
	+ "<table cellpadding=0 cellspacing=0 align='center' >"
	+ "	<tr> "
	+ "	<td> "
	+ "		<table class='"+classBanner+"' cellpadding=20 cellspacing=0 align='center' border=0> "
	+ "		<tr> "
	+ "			<td valign=top  class='bannerLeft'> "
	+ "				<h4>Welcome to the National Martial Arts Circuit!</h4><br> "
	+ "				We are open to all schools, all styles, all belts and all ages.<br><br>  "
	+ "				The NMAC is open to <font size='+1' color=''>everyone</font>, <font size='+1' color=''>everywhere</font>. "
	+ "			</td> "
	+ "			<td width=252>&nbsp;</td> "
	+ "		</tr> "
	+ "		</table> "
	+ "	</td> "
	+ "	</tr> "
	+ "	<tr><td height=8></td></tr> ");

}

function mainBannerWushu(classBanner) {
	if(!classBanner)
		classBanner = 'banner1';

	document.write(
	  "<br>"
	+ "<table cellpadding=0 cellspacing=0 align='center' >"
	+ "	<tr> "
	+ "	<td> "
	+ "		<table class='"+classBanner+"' cellpadding=2 cellspacing=0 align='center' border=0> "
	+ "		<tr> "
	+ "			<td valign=top  class='bannerLeft'> "
	+ "				<br><a href='/img/Sanshou_Poster_2.jpg' target='_blank' title='CLICK TO VIEW DETAIL'>"
	+ "				<img src='/img/Banners_10thwwc.jpg' style='border: solid 0px none; width: 440px;'><br><br>"
	+ "				<img src='/img/Banners_Sanshou.jpg'  style='border: solid 0px none; width: 440px;'>"
	+ "				</a>"
	+ "			</td> "
	+ "			<td width=252>&nbsp;</td> "
	+ "		</tr> "
	+ "		</table> "
	+ "	</td> "
	+ "	</tr> "
	+ "	<tr><td height=8></td></tr> ");

}


function footer() {
	
	document.write(
	"<tr><td height=8></td></tr>"
	+ "		<tr>"
	+ "			<td align='center' valign='center' >"
	+ "			<table width=100%>"
	+ "			<tr>"
	+ "				<td style='border: solid 2px #FFCC00; '>&nbsp;</td>"
	+ "				<td style='font-family: arial; font-size: 12px; color: #868686; padding-left: 5px;'>"
	+ "					For advertisement and affiliates on the NMAC's Web site,"
	+ "						please <a href='contact.php' class='link0'>contact us</a>.<br>"
	+ "						<b>President of National Martial Arts Circuit: <a href='http://www.northtorontokarate.com/sensei.php' target='_blank' class='link0'>Michael Palitti</a></b>."
	+ "				<br>&copy; Designed & maintained by <a href='/Thang_Nguyen.php' class='link0'>Thang Nguyen</a>. "
	+ "				</td>"
	+ "			</tr>"
	+ "			</table>"
	+ "			</td>"
	+ "		</tr>"
	+ "	<tr><td><br><br></td></tr>"
	+ "	</table>	"
	);
}

function mainBanner2() {

	document.write(
	  "<br>"
	+ "<table cellpadding=0 cellspacing=0 align='center' >"
	+ "	<tr> "
	+ "	<td> ");

	adTourney();

	document.write(
	"	</td> "
	+ "	</tr> "
	+ "	<tr><td height=8></td></tr> ");

}

function adTourney() {
	
	document.write
	("			<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='750' height='144' id='adtrophies2' align='middle'>"
	+ "			<param name='allowScriptAccess' value='sameDomain' />"
	+ "			<param name='movie' value='/img/adtrophies2.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#000000' /><embed src='img/adtrophies2.swf' quality='high' bgcolor='#000000' width='750' height='144' name='adtrophies2' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"
	+ "			</object>"
	
	);	
}

function adTourney2() {
	document.write(
	"<tr><td height=8></td></tr>"
	+ "	<tr> "
	+ "	<td> ");
	adTourney();
	document.write(
	"	</td> "
	+ "	</tr> ");
}

function adWushu() {
	// opening
	document.write(
	"<tr><td height=8></td></tr>"
	+ "	<tr> "
	+ "	<td> ");

	// content
	document.writeln("<a href='/img/Sanshou_Poster_2.jpg' target='_blank' title='CLICK TO VIEW DETAIL'>");
	document.writeln("<img src='/img/Banners_10thwwc.jpg' style='border: solid 0px none'> <br><br>");
	document.writeln("<img src='/img/Banners_Sanshou.jpg'  style='border: solid 0px none'> <br>");
	document.writeln("</a>");
	// closing 
	document.write(
	"	</td> "
	+ "	</tr> ");
}


function ContainsNS6(mainwin, subwin) { 
  //check if subwin is contained by mainwin
	while (subwin.parentNode)
	if ((subwin = subwin.parentNode) == mainwin)
		return true;
	return false;
}

function hl(event, bgc){   
	
	source=IE? event.srcElement : event.target;

	if (source.tagName=="TABLE") {
		return; 
	}
	
	while(source.tagName!="TR"&&source.tagName!="HTML") {
		source=NS6? source.parentNode : source.parentElement;
	}		
	if(source.id=="ignore") 
		return;

	source.style.backgroundColor = bgc;
}

function uhl(event, bgc){
    
	if(IE&&(event.fromElement.contains(event.toElement)
		||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE") {
		 return;
	}    

	if(source.id=="ignore") 
		return;

    if (IE&&event.toElement!=source||NS6&&event.relatedTarget!=source) {
      source.style.backgroundColor = bgc;
	}
}

function validateEmailMessage(form, pageName) {
	if(!form) {
		return false;
	}

	if(pageName == "CONTACT_PAGE") {
		if (form.message.value == "" || form.captcha_contact.value == "") {
			alert("(*) fields are required. Please complete the form and send again.");	
			return false;
		}
	}
	else if (form.message.value == "")	{	
		alert("Perhaps you forgot to type in a message?");	
		return false;	
	}
	
	return true;
}


var CURSOR_POS = null;

function goi(id) {
	return document.getElementById(id);
}

function showImg(divId) {
	var div = goi(divId);
	
	if (div && CURSOR_POS){
		div.style.left = CURSOR_POS.x + 10;
		div.style.top = CURSOR_POS.y;
		div.style.display = 'block';
	}
}

function hideImg(divId) {
	goi(divId).style.display = 'none';
	window.status = "";
}

function setCursorPos(e) {
	CURSOR_POS = getCursorPos(e);
}

function getCursorPos(e) {
  var x1 = 0;
  var y1 = 0;

	if (document.layers||NS6) {
		x1 = parseInt(e.pageX);
		y1 = parseInt(e.pageY);
	} else {
		x1 = (parseInt(event.clientX) + parseInt(document.body.scrollLeft));
		y1 = (parseInt(event.clientY) + parseInt(document.body.scrollTop));
	}
	return {x:x1,y:y1};
}


function abspos(el) {
	var offsetLeft = 0;
	var offsetTop = 0;
	while (el) {
		offsetLeft += el.offsetLeft;
		offsetTop += el.offsetTop;
		el = el.offsetParent;
	}
	return {x:offsetLeft, y:offsetTop};
}

function expandRows(textarea) {  
	 // trim trailing return char if exists  
	 var text = textarea.value;//.replace(/\s+$/g,"") ;
	 var split = text.split("\n");  
	 var totalRows = split.length;
	
	// start expand rows when there are 3 space lines
	 if(totalRows > (textarea.rows - 3)) {
		textarea.rows = totalRows + 3;
	 } else if(textarea.rows > (totalRows + 3)) {
		var n = totalRows + 3; // shrink it
		if(n < 10) {
			n = 10;
		}
		textarea.rows = n;
	 }

	 window.status = totalRows + ", " + textarea.rows;	 
}  