//
// Javascript User Login 4.0
// Some Rights Reserved
// http://webdeveloper.50webs.com
//

// Script Preferences
var accountsFolder = "promocodes/"; //A relative path representing where the user account file is (e.g. "../" or "" or "users/")
var fileExtention = ".htm"; // Extention of the user account file (e.g. ".htm" or ".html")
var processingMsg = "Verifying Promo code..."; // The message that will be displayed to the user when they press the login button
var failedMsg = "Invalid Promo code"; // The message that will be displayed to the user if they provide invalid credentials


// Script Functions (Edit only if you agree to the terms of use)


function jul_start() {

	jul_auth.location.href.replace("about:blank");

	document.getElementById('password').disabled = false;

	document.getElementById('password').value = "";
	document.getElementById('password').focus();
	document.getElementById('jul_ctrl_box').innerHTML = jul_buttons;

	var jul_buttons = '<input name="submit" type="submit" value="Submit" title="Login" class="input_btn" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="reset" type="reset" value="Clear" title="Reset Form" class="input_btn" />';
	
	document.getElementById('jul_ctrl_box').innerHTML = jul_buttons;
	
	document.cookie = "jul_test=okay; max-age=" + 60*60*24 + "; path=/";
	if (document.cookie.indexOf('jul_test') == -1) {
		document.getElementById('jul_ctrl_box').innerHTML = "Please Enable Cookies";
	}
}

function removeSpaces(string) {
 var temp = string;
	temp = temp.replace(/ /g,'');
	return temp;
}

function jul_login() {
	document.getElementById('password').disabled = true;
	document.getElementById('jul_ctrl_box').innerHTML = processingMsg;
	setTimeout("jul_fail();", 5000); // after 15 seconds display error message

	var password= document.getElementById('password').value.toLowerCase();
	var accountURL= accountsFolder + password + fileExtention; // compiled filename that loads user-file
	jul_auth.location.replace(accountURL);
}

function jul_fail() {
	document.getElementById('jul_ctrl_box').innerHTML = failedMsg;
	setTimeout("jul_start();", 1500);
}

function jul_success(URL, name) {
	var auth= new Date()
	var authMi = "" + auth.getMinutes();
	var authHo = "" + auth.getHours();
	var authDa = "" + auth.getDate();
	var authMo = "" + auth.getMonth();
	var authYe = "" + auth.getFullYear();
	authYe = authYe.slice(2,4);
	if ((authYe*1) >= 50) { authYe= authYe-50; }
	if ((authYe*1) == 0) { authYe= 51; }
	if (authMi.length < 2) { authMi = "0" + authMi }
	if (authHo.length < 2) { authHo = "0" + authHo }
	if (authDa.length < 2) { authDa = "0" + authDa }
	if (authMo.length < 2) { authMo = "0" + authMo }
	if (authYe.length < 2) { authYe = "0" + authYe }
	var sendout ="";
	var str = authYe + authMo + authDa + authHo + authMi + name;
	for (i=0;i<str.length;i++){
		var char = ""
		var uni = str.charCodeAt(i);
		var char = "" + uni * authYe
		for (j=char.length;j<4;j++){
			char= "0" + char;
		}
		sendout+= char
	}
	document.cookie = "jul_auth=" +sendout+ "; max-age=" + 60*60*24 + "; path=/";
	location.href= "../" + URL;
}

