﻿function showModal(elem,txt){setLayerPosition(elem)
if(txt!=null){txt.focus();txt=null;}
elem=null;}
function hideModal(elem){var shadow=document.getElementById('divShadow');shadow.style.display='none';elem.style.display='none';shadow,elem=null;window.onresize=null;}
function showEmailSubscription(){var email=document.getElementById('emailSubscription');var txtEmail=document.getElementById('txtEmailSubscription');showModal(email,txtEmail);email,txtEmail=null;window.onresize=function(){setLayerPosition(document.getElementById('emailSubscription'));}}
function hideEmailSubscription(){hideModal(document.getElementById('emailSubscription'));}
function showLogin(){var admin=document.getElementById('adminLogin');var txtUser=document.getElementById('txtUsername');showModal(admin,txtUser);window.onresize=function(){setLayerPosition(document.getElementById('adminLogin'));}
admin,txtUser=null;}
function hideLogin(){hideModal(document.getElementById('adminLogin'));}
function validateLogin(frm,url){var hold=frm.txtUsername;if(isBlanks(hold.value)){alert('You gotta have a username, genius!');hold.focus();return false;}
if(hold.value.indexOf(' ')!=-1){alert('No spaces allowed');hold.select();return false;}
hold=frm.txtPassword;if(isBlanks(hold.value)){alert('Password is required!');hold.focus();return false;}
attemptLogin(frm.txtUsername.value,hold.value,url);hold=null;return true;}
function getBrowserDimensions(){var intH,intW=0;if(self.innerHeight){intH=window.innerHeight;intW=window.innerWidth;}
else{if(document.documentElement&&document.documentElement.clientHeight){intH=document.documentElement.clientHeight;intW=document.documentElement.clientWidth;}
else{if(document.body){intH=document.body.clientHeight;intW=document.body.clientWidth;}}}
return{width:parseInt(intW),height:parseInt(intH)};}
function setLayerPosition(elem){var heightArray=new Array(document.documentElement.scrollHeight,document.body.scrollHeight,document.body.offsetHeight,window.innerHeight);var shadow=document.getElementById('divShadow');var browser=getBrowserDimensions();var intLeft,intTop;if(elem.offsetWidth==0&&elem.trueWidth){intLeft=(browser.width==0)?20:parseInt((browser.width-elem.trueWidth)/2);intTop=(browser.height==0)?20:parseInt((browser.height-elem.trueHeight)/2);}
else{intLeft=(browser.width==0)?20:parseInt((browser.width-elem.offsetWidth)/2);intTop=(browser.height==0)?20:parseInt((browser.height-elem.offsetHeight)/2);}
shadow.style.height=maxArrayValue(heightArray)+'px';shadow.style.display='block';elem.style.left=intLeft+'px';elem.style.top=intTop+'px';elem.style.display='block';if(!elem.trueWidth){elem.trueWidth=elem.offsetWidth;elem.trueHeight=elem.offsetHeight;}
shadow,elem,browser,intLeft,intTop,heightArray=null;}
function maxArrayValue(arr){var num=0;if(arr.length>0){num=new Number(arr[0]);for(var i=1;i<arr.length;i++){if(arr[i]>num)
num=new Number(arr[i]);}}
return num;}
function attemptLogin(user,pass,url){var xmlHttp=getXmlHttp();xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){var resp=xmlHttp.responseText;if(resp=='ok'){if(confirm('Successful login!\n\nClick OK to go to the admin menu.'))
window.location=url+'admin.aspx';else{hideLogin();window.location.reload(true);}}
else{alert('Authentication Failed');document.getElementById('txtPassword').select();}}}
xmlHttp.open('GET',url+'login.ashx?txtUsername='+user+'&txtPassword='+pass,true);xmlHttp.send(null);}
function menuOnLoad(){var frmLogin=document.forms.frmLogin;if(frmLogin!=null){var lnkAdmin=document.getElementById('Menu_lnkAdmin');var lnkEmail=document.getElementById('lnkEmailSubscription');var lnkCancelLogin=document.getElementById('lnkCancelLogin');var lnkCancelEmail=document.getElementById('lnkCancelSubscribe');var lnkSubscribe=document.getElementById('lnkSubscribe');var divShadow=document.getElementById('divShadow');var lnkLogin=document.getElementById('lnkLogin');var txtUser=document.getElementById('txtUsername');var txtPass=document.getElementById('txtPassword');var txtEmail=document.getElementById('txtEmailSubscription');var frmSubscribe=document.forms.frmSubscribe;lnkEmail.onclick=showEmailSubscription;lnkCancelEmail.onclick=hideEmailSubscription;lnkAdmin.onclick=showLogin;lnkCancelLogin.onclick=hideLogin;frmSubscribe.onsubmit=function(){var hold=document.getElementById('txtEmailSubscription');if(isEmailValid(hold.value)){var subscribeWin=window.open('http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1297759','emailVerify','scrollbars=yes, width=550, height=520, left=200, top=200');if(subscribeWin!=null){subscribeWin.focus();subscribeWin=null;}
return true;}
else{alert('Invalid email address');hold.select();return false;}}
divShadow.ondblclick=function(){hideLogin();hideEmailSubscription();}
lnkLogin.onclick=function(){var hidRoot=document.getElementById('hidRoot');return validateLogin(document.forms.frmLogin,hidRoot.value);}
lnkSubscribe.onclick=function(){if(document.forms.frmSubscribe.onsubmit()){document.forms.frmSubscribe.submit();hideEmailSubscription();}}
txtUser.onkeydown=function(){enterKeyCheck(event,lnkLogin.onclick);}
txtPass.onkeydown=function(){enterKeyCheck(event,lnkLogin.onclick);}
txtEmail.onkeydown=function(){enterKeyCheck(event,lnkSubscribe.onclick);}
txtEmail.onfocus=function(){if(this.value.toLowerCase()=='enter your email address here')
this.select();}
txtEmail.onblur=function(){if(this.value=='')
this.value='Enter Your Email Address Here';}
frmLogin.onsubmit=function(){return false;}
frmLogin,lnkAdmin,lnkEmail,lnkCancelEmail,lnkCancelLogin,divShadow,lnkLogin,txtUser,txtPass=null;}}
addLoadEvent(menuOnLoad);