// Javascript Code for DesignByAkn website
//============================================================
// Prevent right clicks from happening on website
if (document.all) {
}
else if (document.getElementById) { 
    document.captureEvents(Event.MOUSEDOWN)
}
else if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN)
}
document.onmousedown = mousedown_handler

function mousedown_handler(mouse_event) {
    // This is the message that will appear
    var no_right_click = "Sorry, right-clicking is not allowed!"
    
    if (document.all) {
        //Probably Internet Explorer 4 and later
        if (event.button == 2 || event.button == 3) {
            alert(no_right_click)
            return false
        }
    }
    else if (document.getElementById) { 
        // Probably Netscape 6 and later
        if (mouse_event.which == 3) {
            alert(no_right_click)
            return false
        }
    }
    else if (document.layers) {
        // Probably Netscape 4
        if (mouse_event.which == 3) {
            alert(no_right_click)
            return false
        }
    }
}

//=========================================================
// Checks for blanks on the form passed to function
function check4blanks(form) {	
	for (var $i = 0; $i < form.elements.length; $i++) 	{
		if (form.elements[$i].value =="") {
			alert(form.elements[$i].name + " is empty.");
			form.elements[$i].focus();
			return false;
		}	}  }

// Validate Both Passwords Match
function passCheck() {
	var P1 = document.getElementById("strPass1").value
	var P2 = document.getElementById("strPass2").value

	if (P1 != P2) {
		alert("Passwords DON'T match.  Please re-enter both Passwords again.");
		document.getElementById("strPass1").focus();
		document.getElementById("strPass1").select();
	}  }
	
// Select All of Password2 text
function gotoPass2() {
	document.getElementById("strPass2").focus()
	document.getElementById("strPass2").value = "";
}

// Calls Email Check PHP code to verify email address is unique or not
function uniqueEmail() {
	location.href = "http://www.designbyakn.com/checkEmail.php?strEmail=" + 
	document.getElementById("strEmail").value;
}

//=====================================================
// Validates an email address from field passed to function
function CheckEmail(field) {
		email = field.value;
		AtLoc = email.indexOf("@");
		AtPos = email.lastIndexOf("@");
		StopPos = email.lastIndexOf(".");
		EmailLength = field.value.length - 1;
		AtCount = 0;
		
		// Run loop to see how many @s are in email
		while (AtLoc != -1) {
			AtCount++;
			AtLoc = email.indexOf("@", AtLoc + 1);
		}
		// if more than one @ sign
		if (AtCount > 1) {
			alert("Not a valid Email address");
			field.focus()
			return false }  		
		 //no @ or Period
		if (AtPos == -1 || StopPos == -1) { 
			alert("Not a valid Email address");
			field.focus()
			return false }  
		//Last Period before @
		if (StopPos < AtPos) 	{  
			alert("Not a valid Email address");
			field.focus()
			return false }  
		//@ and Period can't be next to either other
		if (StopPos - AtPos == 1) 	{  
			alert("Not a valid Email address");
			field.focus()
			return false	}  
		// @ can not be at beginning of address
		if (AtPos == 0) 	{  
			alert("Not a valid Email address");
			field.focus()
			return false	}  
		// Period can't be at end of address
		if (StopPos == EmailLength) 	{  
			alert("Not a valid Email address");
			field.focus()
			return false	}
/*		// Calls Email Check PHP code to verify email address is unique or not
		location.href = "http://www.designbyakn.com/checkEmail.php?strEmail=" + 
		document.getElementById("strEmail").value;*/
}

//=======================================================
// Get the current Day, Date and Time (Standard)
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
var h1 = 0
var m1 = ""
var weekday=new Array(7)
weekday[0]="Sunday"
weekday[1]="Monday"
weekday[2]="Tuesday"
weekday[3]="Wednesday"
weekday[4]="Thursday"
weekday[5]="Friday"
weekday[6]="Saturday"
var month = new Array(12)
month[0]="January"
month[1]="February"
month[2]="March"
month[3]="April"
month[4]="May"
month[5]="June"
month[6]="July"
month[7]="August"
month[8]="September"
month[9]="October"
month[10]="November"
month[11]="December"
// add a zero in front of numbers<10
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
// Change time from Military
if (h <12) {
	h1 = h;
	m1 = "AM";
} else if (h == 0) {
	h1 = 12;
	m1 = "AM";
} else if (h == 12) {
	h1 = 12;
	m1 = "PM";
} else if (h > 12) {	
	h1 = (h - 12);
	m1 = "PM"
}
//Display the Day, Date and Time	
document.getElementById('datetime').innerHTML=
weekday[today.getDay()] + 
",  " + 
month[today.getMonth()] + " " +
today.getDate() + ", " +
today.getFullYear() + "  - " +
h1 +":"+m+":"+s + m1
// Run update every 1 second or 1000 milliseconds
t=setTimeout('startTime()', 1000)
}

function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}

//=============================================================
// Show or Hides Menu's Submenus for Left Navigation Table - leftmenu.php
function showhideDiv(divname) {
	var divn = document.getElementById(divname);
	// if previous SubMenu showing from another Menu Item then close it.
	if (pdivn != "NoDivYet") {
		if (pdivn != divname) {
			if (document.getElementById(pdivn).style.display == "block") {
				document.getElementById(pdivn).style.display = "none";
				smonoff = 0;
			}
		}
	}
	// Assign Global variable  to last menu object used
	// Global assigned on actual page
	pdivn = divname;
	// Main Menu Item - OnClick - toggle submenu based on existing state
	if (divname != "NoDivYet") {		
			if (document.getElementById(pdivn).style.display == "block") {
				divn.style.display = "none";
				smonoff = 0;
			} else {
				divn.style.display = "block";
				smonoff = 1;
			}
	}
}

//====================================================
// Counter timer for Sub-Menu Hide on Lost Div Focus
function divTimeout(divname, t) {
		var divn = document.getElementById(divname);
		if (sdivcount == 0) {
			//alert("1st time" + sdivcount);
			sdivcount = 1;
		} else if (sdivcount == 1) {
			//alert("2nd time" + sdivcount);
			sdivcount = sdivcount + 1;
		}  else if (sdivcount == 2) {
			//alert("reset count" + sdivcount);
			sdivcount = 0;
			setTimeout('showhideDiv(divn)', t);
		}
}
// Immediate Timeout for Any submenu showing
function mDivTimeout(t) {
	if  (smonoff == 1) {
		setTimeout('showhideDiv("NoDivYet")', t);
	}
}
//==========================================================


/*
// Close the submenu object
function closeDiv(subm) {
	if (document.getElementById(subm).style.display == "block")  {
		document.getElementById(subm).style.display = "none";
		smonoff = 0;
	}
}
// Toggles Submenu List on/off
function toggleDiv(divname) {
	if (document.getElementById) {
		//w3com standard
		var xdiv = document.getElementById(divname);
		 if (xdiv.style.display == "block") {
		 	xdiv.style.display = "none";
		} else {
			xdiv.style.display = "block";
			xdiv.focus();
		}
	}
}
*/
//====================================================

