//----------------------------------------------------------------
//  User Pages
//----------------------------------------------------------------
var loginpage = "http://www.novus.co.nz/customerindex.php"; // Change this to the page the login panel is on.

var imgSubmit = ""; //Change to the path to your login image,if you don't want the standard button, otherwise do not change.
var imgReset = "";  //Change to the path to your reset image,if you don't want the standard button, otherwise do not change.

//----------------------------------------------------------------
//  Login Functions
//----------------------------------------------------------------
function login(username,password){
    location.replace("http://www.novus.co.nz/validation.php?0," + username + "," + password);
    setCookie("tklogin",1); 
}

function logout() {
    deleteCookie("tklogin");
    top.location.href = loginpage;
}

//----------------------------------------------------------------
// Cookie Handler
//----------------------------------------------------------------
var ckTemp = document.cookie;

function setCookie(name, value) { 
 if (value != null && value != "")
     document.cookie=name + "=" + escape(value) + ";";
 ckTemp = document.cookie;
}

function deleteCookie(name) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function getCookie(name) { 
    var index = ckTemp.indexOf(name + "=");
    if(index == -1) return null;
    index = ckTemp.indexOf("=", index) + 1;
    var endstr = ckTemp.indexOf(";", index);
    if (endstr == -1) endstr = ckTemp.length;
    return unescape(ckTemp.substring(index, endstr));
}
  
function checkCookie() {
    var temp = getCookie("tklogin");
    if(!temp==1) {
        alert('access denied'); 
        top.location.href=loginpage; }
}

//----------------------------------------------------------------
// Login Panel
//----------------------------------------------------------------

function BuildLoginPanel2() {
    document.write('<form name="logon"><table align="left" border="0"><tr><td align="right">');
    document.write('<small><font face="Arial">Username:</font></small></td>');
    document.write('<td><small><font face="Arial"><input type="text" name="username" size="8"></font></small></td></tr>');
    document.write('<tr><td align="right"><small><font face="Arial">Password:</font></small></td>');
    document.write('<td><small><font face="Arial"><input type="password" name="password" size="8"></font></small></td></tr>');
    if(imgSubmit == ""){
        document.write('<tr><td align="center" colspan="2"><p><input type="button" value="Login" name="Logon" onclick="login(username.value,password.value)">'); 
    } else {
        document.write('<tr><td align="center" colspan="2"><p><input type="image" src="'+imgSubmit+'" name="Logon" onclick="login(username.value,password.value)">');
    }
    if(imgReset == ""){
        document.write('<input type="reset" value="Reset" name="Reset">');
    } else {
        document.write('<input type="image" src="'+imgReset+'" name="Reset" onclick="logon.reset();">');
    }
    document.write('</p></td></tr></table></form>');
}

function BuildLoginPanel() {
    document.write('<form name="logon"><table align="left" border="0"><tr><td align="right">');
    document.write('<small><font face="Arial">Username:</font></small></td>');
    document.write('<td><small><font face="Arial"><input type="text" name="username" size="8"></font></small></td></tr>');
    document.write('<tr><td align="right"><small><font face="Arial">Password:</font></small></td>');
    document.write('<td><small><font face="Arial"><input type="password" name="password" size="8"></font></small></td></tr>');
    if(imgSubmit == ""){
        document.write('<tr><td align="center" colspan="2"><p><input type="button" value="Login" name="Logon" onclick="login(username.value,password.value)">'); 
    } else {
        document.write('<tr><td align="center" colspan="2"><p><input type="image" src="'+imgSubmit+'" name="Logon" onclick="login(username.value,password.value)">');
    }
    document.write('</p></td></tr></table></form>');
}
