<?php 
require "common/libs/dbutil.php";
?>

<script type="text/javascript">

function createCookie(namevalues,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	
	else var expires = "";
	document.cookie = namevalues+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) 
{
	createCookie(name+"=",1);
}

function RememberMeUsed()
{
	var uname 		= document.getElementById("uid").value;
	var password 	= document.getElementById("pwd").value;

	if(document.getElementById("save_login").checked)
	{
		createCookie("wifirush="+uname,1);
		createCookie(uname+"="+password,1);
		
		if(document.getElementById("auto_logme").checked)
		{
			createCookie("wifiautologin=1",1);
		}
		else
		{
			eraseCookie("wifiautologin");
		}
	}
	else
	{
		eraseCookie("wifirush");
		eraseCookie(uname);
		eraseCookie("wifiautologin");
	}
	
	
}

/*
function onLoad()
{	
	if ( (readCookie("wifirush")!="") && (readCookie("wifirush")!= null) ) 
	{
		document.getElementById("uid").value = readCookie("wifirush");
		document.getElementById("pwd").value = readCookie(document.getElementById("uid").value);
		document.getElementById("save_login").checked = true;
	}

	if ( (readCookie("wifiautologin")!="") && (readCookie("wifiautologin")!= null) )
	{
		document.getElementById("auto_logme").checked = true;
	}
	
}
*/

function onLoad()
{	
	//alert("Here");
	if ( (readCookie("wifirush")!="") && (readCookie("wifirush")!= null) ) 
	{
		document.getElementById("uid").value = readCookie("wifirush");
		var username = document.getElementById("uid").value;
		var nasID    = <?php echo $nasid; ?>;
		x_authUserCredentials(username, nasID, cb_authUserCredentials);
	}

}


function cb_authUserCredentials(result)
{
	//alert(result);
	var str_records     = new String(result);
	var array_record    = str_records.split("~~"); 
	var accountStatus   = array_record[0];
	var userPercentage  = array_record[1];

	if ( (accountStatus == "Active") && (userPercentage < 100) )
	{
		//alert("If "+accountStatus +" and "+ userPercentage);
		
		if ( (readCookie("wifirush")!="") && (readCookie("wifirush")!= null) ) 
		{
			document.getElementById("pwd").value = readCookie(document.getElementById("uid").value);
			document.getElementById("save_login").checked = true;
		}
	
			//alert(readCookie("wifiautologin"));
		if ( (readCookie("wifiautologin")!="") && (readCookie("wifiautologin")!= null) )
		{
			//alert("autologin not set");
			document.getElementById("auto_logme").checked = true;
			doTimer();
		}
	}
	else
	{
		//alert("Else "+accountStatus +" and "+ userPercentage);
		eraseCookie("wifiautologin");
		if ( (readCookie("wifirush")!="") && (readCookie("wifirush")!= null) ) 
		{
			document.getElementById("pwd").value = readCookie(document.getElementById("uid").value);
			document.getElementById("save_login").checked = true;
		}
	
		document.getElementById("auto_logme").checked = false;
		
	}	
		ToggleTimerOption();
	
}



function redirectPage(URL)
{
   var f = document;	
   if(f.src)
	  f.src = URL;
   else if(f.location)
   {
	  if(f.location.href)
	  {	
		  f.location.href = URL;
	  }
   }
}

function ToggleAutoOption()
{
/*	if(document.getElementById("save_login").checked)
	{
		var browser = getBrowser();
		if(browser == "ff")
			document.getElementById("tblrow_timer").style.display = "table-row";
		else
			document.getElementById("tblrow_timer").style.display = "block";
	}
	else
	{
		document.getElementById("tblrow_timer").style.display = "none";
	}*/
}

function ToggleTimerOption()
{
	if(document.getElementById("auto_logme").checked)
	{
		document.getElementById("tblrow_timer").style.display = "block";
	}
	else
	{
		document.getElementById("tblrow_timer").style.display = "none";
	}
}

function testAutologin()
{	
	var respvar = "<?php echo $_GET['res']; ?>";
	
	if (respvar.indexOf("failed") > -1)
	{
		eraseCookie("wifiautologin");
		//alert("res = failed ");
	}
	else
	{
		//alert("res = not failed");	
	}
}

var c=10;
var t;
var timer_is_on=0;

function timedCount()
{
   document.getElementById('txt').value=c;
   if (c==0)
   {
        stopCount();
  var message = "../../autologin/autologin.php?button=Login&res=<?php echo $res?>&uamip=<?php echo $uamip?>&uamport=<?php echo $uamport?>&challenge=<?php echo $challenge?>&chal=<?php echo $challenge?>&userurl=<?php echo $userurl?>&nasid=<?php echo $nasid?>&mac=<?php echo $mac?>&dhcpmac=<?php echo $dhcpmac?>&urlredirect=<?php echo $urlredirect?>&uid="+document.getElementById("uid").value+"&pwd="+document.getElementById("pwd").value;

	redirectPage(message);

	return 0;
   }

	c=c-1;
	t=setTimeout("timedCount()",1000);
}

function doTimer()
{
	if (!timer_is_on)
	{
		timer_is_on=1;
		timedCount();
	}
}

function stopCount()
{
	clearTimeout(t);
	timer_is_on=0;
}


</script>
<script type="text/javascript">
<?php
	sajax_show_javascript();
?>
</script> 
<link rel="stylesheet" type="text/css" href="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/css/layout.css" title="WiFiRUSH Hotspot Systems" />
<div id="header-bg">
	<div id="header"> 
		<div id="top"> 
			<table width="900" border="0">
  				<tr>
    				<td>
					<h2><?php echo $hotspots->Fields('HotSpotName'); ?></h2>
					<h3><p><?php echo $hotspots->Fields('Address'); ?> <?php echo $hotspots->Fields('City'); ?> <?php echo $hotspots->Fields('State'); ?> <?php echo $hotspots->Fields('ZIP'); ?>

					| Phone: <?php echo $hotspots->Fields('SalesPhone'); ?></p></h3>
				</td>
    				<td align="right">
					<a href="http://1.1.1.1"><img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/logo.jpg" width="" height="" alt="WiFiRUSH Hotspot Systems" title="WiFiRUSH Hotspot Systems" border="0"/></a>
				</td>
  				</tr>
				</table>
		</div> 
		<div id="topright">
<!--			<img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/wifi.gif" alt="WiFi Wireless Internet!" title="WiFi Wireless Internet!"> -->
		</div>
	</div>
</div>

<div id="main-container-bg">
	<div id="main-container">
		<div id="content">
			<div id="left-content">
				<div id="new-customers">
					<h2>How do I get online?</h2>
					<a href="<?php echo $wificpa[site_url]; ?>advancedlogin/signup.php?nasid=<?php echo $nasid; ?>">Create a NEW ACCOUNT with a Credit Card or a pre-paid Voucher Code.</a>
					<a href="<?php echo $wificpa[site_url]; ?>advancedlogin/signup.php?nasid=<?php echo $nasid; ?>"><img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/CreateAccount.gif" border=0></a>	
				</div>
				<div id="existing-customers">
					<h2>Manage Your Existing Account</h2>
					<p><a href="<?php echo $wificpa[site_url]; ?>advancedlogin/index.php?nasid=<?php echo $nasid; ?>">Manage your account, Renew your account, change your subscription package, etc.</a></p>
					<a href="<?php echo $wificpa[site_url]; ?>advancedlogin/index.php?nasid=<?php echo $nasid; ?>"><img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/ManageAccount.gif" border=0></a>
					<p><a href="<?php echo $wificpa[site_url]; ?>advancedlogin/lookup_password.php?nasid=<?php echo $nasid; ?>">Forgotten your username or password? Click here to retrieve your user details.</a></p>
					</div>
				<div id="login">
					<form name="form_1" action="<?php echo $wificpa[site_url]; ?>advancedlogin/site-doc/" method="get">
					<?php
					echo "<input type=\"hidden\" name=\"chal\" value=\"" . $_GET["challenge"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"nasid\" value=\"" . $_GET["nasid"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"mac\" value=\"".$_GET["mac"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"challenge\" value=\"" . $_GET["challenge"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"userurl\" value=\"" . $_GET["userurl"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"res\" value=\"" . $_GET["res"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"dhcpmac\" value=\"" . $_GET["dhcpmac"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"urlredirect\" value=\"" . $_GET["urlredirect"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"uamip\" value=\"" . $_GET["uamip"] . "\" />\n";
					echo "<input type=\"hidden\" name=\"uamport\" value=\"" . $_GET["uamport"] . "\" />\n";
					?>
					 <input type="hidden" name="login" value="Login">
			
					<h2>Log into your account</h2>
					<?php 
					if ($_GET["cparam"]== "mac_exists")
					echo "<p class=\"body_text\" style=\"color:red\" >Automatic, MAC Authentication failed.  <br><span class=\"style10\" style=\"color:red\">Account Expired or Bandwidth Exceeded</span></p>\n";
					?>
					
					<p>Please enter your username:</p>
					<p><input type="text" size="65" name="uid" id="uid" value="<?php echo $username ?>" /></p>
			
					<p>Please enter your password:</p>
					<p><input type="password" size="65" name="pwd" id="pwd" value="<?php echo $password; ?>" /></p>
			
					<p>	<input class="form_input" type="checkbox" id="save_login" onChange="ToggleAutoOption()" name="save_login">
					<label for="remember_me">Remember Me</label></p>
	
					<p>	<input class="form_input" type="checkbox" id="auto_logme" name="auto_logme">
					<label for="login_auto" >Log me in automatically</label></p>
			
					<h3><input type="image" src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/go.gif" onClick="RememberMeUsed()" border=0/></h3>
					</div>
			
					<div id="tblrow_timer" name="tblrow_timer" class="form_submit" style="display:none">
					<input type="text" id="txt" size="2" /> &nbsp; <input class="form_submit" type="button" value="stop autologin" onclick="stopCount()" />
					</div>
			
					</form>
			
			
					<script type="text/javascript">
					onLoad();
					//logmein();
					var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
					document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
					</script>
			
					<script type="text/javascript">
					try {
						var pageTracker = _gat._getTracker("UA-7639257-3");
						pageTracker._trackPageview();
						} catch(err) {}
					</script>
			</div>
				
			<div id="right-content">
				<div id="advert-1" class="advertisement">
					<img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/ad1-bg.gif" alt="Image Title" title="Image Title">
				</div>

				<div id="advert-2" class="advertisement">
					<img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/ad2-bg.gif" alt="Image Title" title="Image Title">
				</div>

				<div id="advert-3" class="advertisement">
					<img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/ad3-bg.gif" alt="Image Title" title="Image Title">
				</div>

				<div id="advert-4" class="advertisement">
					<img src="<?php echo $wificpa[site_url]; ?>hotspot_files/<?php echo $nasid; ?>/images/ad4-bg.gif" alt="Image Title" title="Image Title">
				</div>
			</div>
		<div id="support">
			<h2><?php echo $hotspots->Fields('HotSpotName'); ?> - Support</h2>
			<p>Your payment & personalinformation is secured with 128bit SSL encryption during the login process. This protocol is similar to that used on-line banking systems and financial institutions to process transactions over the internet and is meant to protect any personal data requested during the log-in process. <strong>Please call <?php echo $hotspots->Fields('TechPhone'); ?> for technical support.</strong></p>
			<h3>WiFi HotSpot Solution & Design provided by <a href="http://www.WiFiRUSH.com">Superstring Group, LLC.</a> Copyright 2010. All rights reserved.</h3>
		</div>

	</div>
</div>

<div id="footer"> 
</div>
