// Preload Image Functions
window.onLoad = PreloadIMG;
function PreloadIMG(){MM_preloadImages("images/popdiv/close.png","images/popdiv/bottom.png","images/popdiv/bottomleft.png","images/popdiv/bottomright.png","images/popdiv/left.png","images/popdiv/right.png","images/popdiv/top.png","images/popdiv/topleft.png","images/popdiv/topright.png","images/popdiv/loading.gif","images/popdiv/loading_small.gif");}
function MM_swapImgRestore() {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() {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) {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); return x;}
function MM_swapImage() {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];}}

// Flash Functions
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function ControlVersion(){var version;var axo;var e;try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");version = axo.GetVariable("$version");} catch (e) {}if (!version){try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");version = "WIN 6,0,21,0";	axo.AllowScriptAccess = "always";version = axo.GetVariable("$version");} catch (e) {}}if (!version){try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version = axo.GetVariable("$version");} catch (e) {}}if (!version){try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");version = "WIN 3,0,18,0";} catch (e) {}}if (!version){try {axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");version = "WIN 2,0,0,11";} catch (e) {version = -1;}}return version;}
function GetSwfVer(){var flashVer = -1;if (navigator.plugins != null && navigator.plugins.length > 0) {if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;var descArray = flashDescription.split(" ");var tempArrayMajor = descArray[2].split(".");			var versionMajor = tempArrayMajor[0];var versionMinor = tempArrayMajor[1];var versionRevision = descArray[3];if (versionRevision == "") {versionRevision = descArray[4];}if (versionRevision[0] == "d") {versionRevision = versionRevision.substring(1);} else if (versionRevision[0] == "r") {versionRevision = versionRevision.substring(1);if (versionRevision.indexOf("d") > 0) {versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));}}var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;}}else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;else if ( isIE && isWin && !isOpera ) {flashVer = ControlVersion();}	return flashVer;}
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision){versionStr = GetSwfVer();if (versionStr == -1 ) {return false;} else if (versionStr != 0) {if(isIE && isWin && !isOpera) {tempArray         = versionStr.split(" ");tempString        = tempArray[1];versionArray      = tempString.split(",");} else {versionArray      = versionStr.split(".");}var versionMajor      = versionArray[0];var versionMinor      = versionArray[1];var versionRevision   = versionArray[2];if (versionMajor > parseFloat(reqMajorVer)) {return true;} else if (versionMajor == parseFloat(reqMajorVer)) {if (versionMinor > parseFloat(reqMinorVer))return true;else if (versionMinor == parseFloat(reqMinorVer)) {if (versionRevision >= parseFloat(reqRevision))return true;}}return false;}}
function AC_AddExtension(src, ext){if (src.indexOf('?') != -1){return src.replace(/\?/, ext+'?'); }else{return src + ext;}}
function AC_Generateobj(objAttrs, params, embedAttrs) { var str = '';if (isIE && isWin && !isOpera){str += '<object ';for (var i in objAttrs){str += i + '="' + objAttrs[i] + '" ';}str += '>';for (var i in params){str += '<param name="' + i + '" value="' + params[i] + '" /> ';}str += '</object>';}else{str += '<embed ';for (var i in embedAttrs){str += i + '="' + embedAttrs[i] + '" ';}str += '> </embed>';}document.write(str);}
function AC_FL_RunContent(){var ret = AC_GetArgs(  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);}
function AC_SW_RunContent(){var ret = AC_GetArgs(  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000", null);AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){var ret = new Object();ret.embedAttrs = new Object();ret.params = new Object();ret.objAttrs = new Object();for (var i=0; i < args.length; i=i+2){var currArg = args[i].toLowerCase();    switch (currArg){	case "classid":break;case "pluginspage":ret.embedAttrs[args[i]] = args[i+1];break;case "src":case "movie":	args[i+1] = AC_AddExtension(args[i+1], ext);ret.embedAttrs["src"] = args[i+1];ret.params[srcParamName] = args[i+1];break;case "onafterupdate":case "onbeforeupdate":case "onblur":case "oncellchange":case "onclick":case "ondblclick":case "ondrag":case "ondragend":case "ondragenter":case "ondragleave":case "ondragover":case "ondrop":case "onfinish":case "onfocus":case "onhelp":case "onmousedown":case "onmouseup":case "onmouseover":case "onmousemove":case "onmouseout":case "onkeypress":case "onkeydown":case "onkeyup":case "onload":case "onlosecapture":case "onpropertychange":case "onreadystatechange":case "onrowsdelete":case "onrowenter":case "onrowexit":case "onrowsinserted":case "onstart":case "onscroll":case "onbeforeeditfocus":case "onactivate":case "onbeforedeactivate":case "ondeactivate":case "type":case "codebase":case "id":ret.objAttrs[args[i]] = args[i+1];break;case "width":case "height":case "align":case "vspace": case "hspace":case "class":case "title":case "accesskey":case "name":case "tabindex":ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];break;default:ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];}}ret.objAttrs["classid"] = classid;if (mimeType) ret.embedAttrs["type"] = mimeType;return ret;}

// Div Pop-up and Default Functions
var posx;var posy;
var xmlhttp_divpopup;
window.onMouseMove = mouser;
function GetXmlHttpObject(){if (window.XMLHttpRequest){return new XMLHttpRequest();}if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;}
function mouser(event){posx = event.clientX;posy = event.clientY;}
function divpopup(themethod,theurl,qStr,divID,atclicksend,doload){if (themethod.length==0||theurl.length==0||divID.length==0){return;} else {CreatePopDiv(divID);}if(atclicksend){MoveDivToClick(divID);}xmlhttp_divpopup = GetXmlHttpObject();if (xmlhttp_divpopup == null){alert ("Your browser does not support XMLHTTP!");return;}xmlhttp_divpopup.onreadystatechange = function(){if (xmlhttp_divpopup.readyState == 1){if(doload){dispload(divID,"","w");} else {if (GetElm('popDivTtl_' + divID)){GetElm('popDivTtl_' + divID).innerHTML = '<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\"><tr><td><b>Loading...</b></td><td><img src=\"images/popdiv/loading_small.gif\" border=\"0\"/></td></tr></table>';}}}if (xmlhttp_divpopup.readyState == 4){GetElm(divID).innerHTML = xmlhttp_divpopup.responseText;}};xmlhttp_divpopup.open(themethod,theurl + '?d=' + divID + qStr,true);xmlhttp_divpopup.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');xmlhttp_divpopup.send(theurl + '?d=' + divID + qStr);}
function CreatePopDiv(divID){if(!GetElm(divID)){$("body").append("<div id=\"" + divID + "\" name=\"" + divID + "\" class=\"PopDiv\"></div>")}BringToFront(divID);}
function dispload(divID,Msg,dw){var loadingpic = "<center><div class=\"loadingpic\"></div></center>";var loadingwindow = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" onmousedown=\"javascript:BringToFront('" + divID + "');\">";loadingwindow += "<tr><td class=\"PopDivFrameTopLeft\"></td><td class=\"PopDivFrameTop\"></td><td class=\"PopDivFrameTopRight\"></td></tr>";loadingwindow += "<tr><td class=\"PopDivFrameLeft\">&nbsp;&nbsp;&nbsp;</td><td class=\"PopDivFrameBg\">";loadingwindow += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width: 100%;\">";loadingwindow += "<tr><td class=\"popDivTopBar\" onmousedown=\"return MoveDiv('" + divID + "');\" onmouseup=\"return StopDiv('" + divID + "');\">";loadingwindow += "<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" style=\"width: 100%;\">";loadingwindow += "<tr><td style=\"text-align: left; font-size: 14px; color: #ffffff;\"><b>Loading...</b></td>";loadingwindow += "<td style=\"text-align: right;\"><input type=\"button\" class=\"popDivCloseBut\" value=\" \" title=\"close\" onclick=\"javascript:ClosePopDiv('" + divID + "');\" /></td></tr>";loadingwindow += "</table>";loadingwindow += "</td></tr>";loadingwindow += "<tr><td style=\"width: 200px; height: 100px; vertical-align: middle; text-align: center;\">" + loadingpic + "</td></tr>";loadingwindow += "</table>";loadingwindow += "</td><td class=\"PopDivFrameRight\">&nbsp;&nbsp;&nbsp;</td></tr>";loadingwindow += "<tr><td class=\"PopDivFrameBottomLeft\"></td><td class=\"PopDivFrameBottom\"></td><td class=\"PopDivFrameBottomRight\"></td></tr>";loadingwindow += "</table>";if(dw=="d"){GetElm(divID).innerHTML = "<center>" + loadingpic + "<br/><b>" + Msg + "</b></center>";}else if(dw=="w"){GetElm(divID).innerHTML = loadingwindow;}}
function dispload_small(divID){var loadingpic = "<div class=\"loadingpic_small\"></div>";GetElm(divID).innerHTML = loadingpic;}
function MoveDivToClick(divID){if (!posx){posx = 150;}if (!posy){posy = 50;}var moveX = posx;var moveY = posy;GetElm(divID).style.left = moveX + "px";GetElm(divID).style.top = moveY + "px";}
function BringToFront(divID){DropDivsZIndex();GetElm(divID).style.zIndex = 2;}
function DropDivsZIndex(){var divs = document.getElementsByTagName('div');for (var i=0;i<divs.length;i++){if (divs[i].className == 'PopDiv'){var d_ID = divs[i].id;GetElm(d_ID).style.zIndex = 1;}}}
function MoveDiv(divID){dsblSlct(document.body,divID);var DivClkLft = posx - GetElm(divID).offsetLeft;var DivClkRgt = posy - GetElm(divID).offsetTop;document.onmousemove = MovemyDiv;function MovemyDiv(){var moveX = posx - DivClkLft;var moveY = posy - DivClkRgt;GetElm(divID).style.left = moveX + "px";GetElm(divID).style.top = moveY + "px";}}
function StopDiv(divID){enblSlct(document.body,divID);document.onmousemove = function(){return;};}
function ClosePopDiv(divID){$('div').remove('#' + divID);}
function ClearPopDivs(){$("div").remove(".PopDiv");}
function dsblSlct(trgt,divID){if (typeof trgt.onselectstart!="undefined"){trgt.onselectstart=function(){return false};}else if (typeof trgt.style.MozUserSelect!="undefined"){trgt.setAttribute("class","moznone");GetElm(divID).setAttribute("class","PopDivNotSelect");}else{trgt.onmousedown=function(){return false};trgt.style.cursor = "default";}}
function enblSlct(trgt,divID){if (typeof trgt.onselectstart!="undefined"){trgt.onselectstart=function(){return true};}else if (typeof trgt.style.MozUserSelect!="undefined"){trgt.setAttribute("class","moztext");GetElm(divID).setAttribute("class","PopDiv");}else{trgt.onmousedown=function(){return true};trgt.style.cursor = "select";}}
function getStyle(oElm, strCssRule){var strValue = "";if(document.defaultView && document.defaultView.getComputedStyle){strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);}else if(oElm.currentStyle){strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){return p1.toUpperCase();});strValue = oElm.currentStyle[strCssRule];}return strValue;}
function disp(div){GetElm(div).style.display="block";}
function hide(div){GetElm(div).style.display="none";}
function confirmAct(){var conf = confirm("Are you sure you want to take this action?");if(true == conf){return true;}else if(false == conf){return false;}}
function confirmDel(){var conf = confirm("Are you sure you want to delete the selected items?");if(true == conf){return true;}else if(false == conf){return false;}}
function fixForURL(val){return escape(encodeURI(val));}
function GetElm(fld){return document.getElementById(fld);}
function GetElmVal(fld){if(GetElm(fld)){return GetElm(fld).value;}}
function Trim(s) {while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')){ s = s.substring(1,s.length); }while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')){ s = s.substring(0,s.length-1); }return s;}
function Left(str, n){if (n <= 0){return "";} else if (n > String(str).length){return str;} else {return String(str).substring(0,n);}}
function Right(str, n){if (n <= 0){return "";} else if (n > String(str).length){return str;} else {var iLen = String(str).length;return String(str).substring(iLen, iLen - n);}}
function PopWindow(url,name,h,w,left,top) {var optiontxt;optiontxt = "height=" + h + ",width=" + w + ",left=" + left + ",top=" + top + ",status=0,location=0,scrollbars=1,toolbar=0,resizable=1";var w = window.open(url,name,optiontxt);w.focus();return false;}
function scrollToMark(mrk){$('html, body').animate({scrollTop: $("#" + mrk).offset().top}, 2000);}

// Other Functions
function LoadContent(A){
	if(A.lenth == 0){return;}
	var MyLoc = "";var qStr = "";
	if (A.indexOf("#!/") > -1){MyLoc = A.replace("#!/","");}
	if(MyLoc.indexOf("/?") > 0){var sPos = MyLoc.indexOf("/?")+1;var ePos = MyLoc.length;qStr = MyLoc.substr(sPos,ePos);MyLoc = MyLoc.replace("/" + qStr,"");}
	qStr = qStr.replace(/and/g,"AND");
	if (qStr.length > 0){var url = MyLoc + ".php" + qStr;} else {var url = MyLoc + ".php";}
	url = url.replace(/&/g,"and");
	var mytitle = "NEASA | " + MyLoc.toUpperCase();
	while (mytitle.indexOf("_") > 0){mytitle = mytitle.replace("_"," ");}
	ClearPopDivs();
	GetPage(url,mytitle);
}

var xmlhttp_GetPage;
function GetPage(pg,ttl){
	if (pg.length==0){return;}
	xmlhttp_GetPage = GetXmlHttpObject();
	if (xmlhttp_GetPage == null){alert ("Your browser does not support XMLHTTP!");return;}
	xmlhttp_GetPage.onreadystatechange = function(){
		var errDisp = "<div style=\"padding: 5px; background-color: #ffffff;\"><span style=\"font-size: 24px;\"><b>Page not found!</b></span><br /><br /><b>Sorry! The page you have requested cannot be found.<br />Please ensure the link is spelled correctly.</b><br /><br /><a href=\".\" style=\"color: #0000ff;\"><b>Click here</b></a> <b>to go to our homepage</b></div>";
		if (xmlhttp_GetPage.readyState == 1){GetElm("loader").innerHTML = "<div class=\"loader\"><b>Loading Page...</b></div>";}
		if (xmlhttp_GetPage.readyState == 4){if (xmlhttp_GetPage.status == 404){GetElm("content").innerHTML = errDisp;} else {GetElm("content").innerHTML = xmlhttp_GetPage.responseText;}document.title = ttl;GetElm("loader").innerHTML = "";}
	};
	xmlhttp_GetPage.open("POST","sourcepages.php?p=" + pg,true);
	xmlhttp_GetPage.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp_GetPage.send("sourcepages.php?p=" + pg);
}

function ShowFeed(city){
	GetElm('weatherfeed').setAttribute('src','flash.php?fl=' + city);
}

function contact(){
	var myname = fixForURL(GetElm('myname').value);
	var company = fixForURL(GetElm('company').value);
	var tel = fixForURL(GetElm('tel').value);
	var fax = fixForURL(GetElm('fax').value);
	var email = fixForURL(GetElm('email').value);
	var feed = fixForURL(GetElm('feed').value);
	var num = fixForURL(GetElm('num').value);
	var qstr = "&myname=" + myname + "&company=" + company + "&tel=" + tel + "&fax=" + fax + "&email=" + email + "&feed=" + feed + "&num=" + num;
	divpopup('POST','contact_submit.php',qstr,'contact_submit',false,true);
}

function member_registration(){
	var firstname = fixForURL(GetElm('firstname').value);
	var lastname = fixForURL(GetElm('lastname').value);
	var tel = fixForURL(GetElm('tel').value);
	var cell = fixForURL(GetElm('cell').value);
	var fax = fixForURL(GetElm('fax').value);
	var email = fixForURL(GetElm('email').value);
	var password = fixForURL(GetElm('password').value);
	var confirm_password = fixForURL(GetElm('confirm_password').value);
	var num = fixForURL(GetElm('num').value);
	var qstr = "&firstname=" + firstname + "&lastname=" + lastname + "&tel=" + tel + "&cell=" + cell + "&fax=" + fax + "&email=" + email + "&password=" + password + "&confirm_password=" + confirm_password + "&num=" + num;
	divpopup('POST','member_registration_submit.php',qstr,'member_registration_submit',false,true);
}

function Change_Ver_Image(){var pnum = Math.floor(Math.random()*10000);GetElm('verification_image').setAttribute('src','random_image.php?id=' + pnum);GetElm('num').value = "";}

function password_recovery(){
	var email = fixForURL(GetElm('email').value);
	var qstr = "&email=" + email;
	divpopup('POST','password_recovery_submit.php',qstr,'password_recovery_submit',false,true);
}

function login(){
	var usrnm = fixForURL(GetElm('usrnm').value);
	var pswrd = fixForURL(GetElm('pswrd').value);
	var qstr = "&usrnm=" + usrnm + "&pswrd=" + pswrd;
	GetElm('usrnm').value = "";GetElm('pswrd').value = "";
	divpopup('POST','login_submit.php',qstr,'login_submit',false,true);
}

function add_user(){
	var firstname = fixForURL(GetElm('firstname').value);
	var lastname = fixForURL(GetElm('lastname').value);
	var email = fixForURL(GetElm('email').value);
	var password = fixForURL(GetElm('password').value);
	var confirm_password = fixForURL(GetElm('confirm_password').value);
	var qstr = "&firstname=" + firstname + "&lastname=" + lastname + "&email=" + email + "&password=" + password + "&confirm_password=" + confirm_password;
	divpopup('POST','member_add_users_submit.php',qstr,'member_add_users_submit',false,true);
}

function delete_user(id){
	divpopup('POST','member_delete_user_submit.php','&id=' + id,'delete_user',false,true);
}
