// JavaScript Document

var xmlHttp;
var g_defClass = "-1";

function COM_IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}

COM_IncludeJavaScript('../custom/config.js');

// Add left trim, right trim, and trim functions
function trim(str) {
  return str.replace(/^s+|s+$/g,"");
}

function trimw(str){
  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}

function messageWindow(title, msg)
{

  var width="550", height="500";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title></head>';
  var body = '<body bgcolor="#aaaaaa"><left>'+msg+'<p><form><input type="button" value="   Close   " onclick="self.close()"></form></body>';
  msgWindow.document.write(head + body);
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; 
  if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function prepPage_simple()
{
	var cs = " 8px";
	$("#header").corner("top" + cs);
	//setPageLen();
	popDown("msgbox");
}

function prepPage_asLoad()
{
	var cs = " 8px";
	//$("#sponsors").corner("top" + cs);
	$("#header").corner("top" + cs);
	//$("#header_title").corner("bottom" + cs);
	//$("#main_menu").corner("top" + cs);
	//$("#main").corner("top" + cs);
	//$("div.story").corner();
	setPageLen();
	//$("#main").corner("bottom" + cs);
	//$("#sponsors").corner("bottom" + cs);
	//$("#main_menu").corner("bottom" + cs);
	$("#main_menu").css("z-index", 100001);
	//$(".widget").corner("all" + cs);
	$(".widget").css("border", "1px solid #333333");
	
}

function prepPage_onLoad()
{		
	MM_preloadImages(CFG_SWSHOME + '/custom/images/ma_small.JPG',CFG_SWSHOME + '/custom/images/msa.jpg');	
}


function setPageLen()
{
	var bWrap = document.getElementById("bodywrapper");
	var mWrap = document.getElementById("main");
	var sWrap = document.getElementById("sponsors");
	
	
	// use offsetheight because when using auto setting ie does not store height value
	var bh = bWrap.offsetHeight;
	var sh = sWrap.offsetHeight;
	var mh = mWrap.offsetHeight;
	var hh;
	
	if (mh > sh) {
		hh = mh;
	} else {
		hh = sh;				
	}
	bWrap.style.height = hh + 10 + "px";
	mWrap.style.height = hh + "px";
	sWrap.style.height = hh + "px";


	//alert (bWrap.style.height + ":" + sh + ":" + ":" + mh + ":" + hh);

}

function COM_OpenPhotoWindow(series){
	var nw;
    // series = jun for juniors, sen for seniors
 	nw = open(CFG_SWSHOME + "gallery/photoshow.php?cf="+series, "_blank", "status=yes,scrollbars=no,width=600px,height=650px");
    				
	   
};

function showCalenderDetails(evNum, trow, event){
	//var cd = $("#caldetails");
	//cd.style.visibility="visible";
	var cd = document.getElementById("caldetails");
	var det = document.getElementById("evdetails");
	
	//alert(trow.innerHTML);
	//alert(event.clientX);
	
	//cd.innerHTML = "<strong>Event Details for Round " + rnd + "</p>";
	cd.innerHTML = det.childNodes[evNum-1].innerHTML;

	cd.style.zIndex = "9000";
	cd.style.top = event.clientY + 140 + "px";
	cd.style.left = event.clientX + "px";
	var cdwidth = 350 + "px";
	//cd.style.width = cdwidth;
	//cd.style.height = "auto";	
	
	//alert(cd.style.left + ":" + screen.width/2);
	//cd.style.left = (screen.width/2) - (cd.style.width/2);
	//cd.style.left = "10px";
	
	cd.innerHTML = cd.innerHTML + '<img src="' + CFG_IMGHOME + '/close_btn.PNG" onclick="hideCalenderDetails()" style="border:1px solid #666;position:absolute;top: 0px;left:' + (cdwidth-22) + 'px;"></img>';
	//cd.innerHTML = cd.innerHTML + '<button style="left=5px;" align="center" onclick="hideCalenderDetails()">Close</button>';
	
	cd.style.visibility="visible";
	
}

function hideCalenderDetails(){
	
	//$("#caldetails").style.visibility="hidden";
	document.getElementById("caldetails").style.visibility="hidden";
}

function popDown(divname){
	document.getElementById(divname).style.visibility="hidden";
}

function popUp(popup, x, y){
	popup.style.zIndex = "9000";
	popup.style.visibility="visible";
	popup.style.top = y + "px";
	popup.style.left = x + "px";
}

function popUp_ByDivName(divname, x, y, w, h){
	div = document.getElementById(divname);
	div.style.width = w;
	div.style.height = h;
	//div.innerHTML = div.innerHTML + '<button align="center" onclick="popDown(\''+divname+'\')">Close</button>';
	
	popUp(div, x, y);
	
}

function msgBox(msg){
	COM_MsgBox(msg);
}

function COM_MsgBox(msg){	
	var m = document.getElementById("msgbox");
	m.innerHTML="<p>"+ msg + "</p>";
	popUp(m, 400, 300);
}

function COM_ShowHelp(id){
	window.open("../notice/notice.php?id="+id);
}

function get_sid(win){
	var form = win.document.round_select;
	var sid = form.series.options[form.series.selectedIndex].value;
	return sid;
}

function get_eid(win){		
	var form = win.document.round_select;
	var eid = form.event.options[form.event.selectedIndex].value;
	return eid;
}

function COM_DownloadStart(url){
	if (url.indexOf("ERROR") < 0) {	
		alert("IE users: Please note that you may see a note at the top of your screen. \n\nIf you see the note please select option to allow download from this site.\n\nYou will need to click the download button a second time to complete the download.");
		window.open(url, "_self");
	} else {
		alert("Error: File unable to be downloaded. Contact Web admin.");
	}
}

function COM_StripHTML(field){
	var re = /(<([^>]+)>)/gi;
	return field.replace(re, "")	
}

function COM_GoHome(){
		window.location.href="http://www." + g_domain;
}

function COM_SetWindowTitle(windowName){	
		document.title = g_webSiteName + " " + windowName;
}

function COM_XMLDocToString(doc){
	var xmlText="";
	if (window.DOMParser){ // non-IE
		xmlText = (new XMLSerializer()).serializeToString(doc);
	} else { // IE
		xmlText = doc.xml;
	}
	return xmlText;
}