/*
Display live digital clock for every page..

Version 1	Christopher
*/
/* Start of Coding for Login */
function formsubmit()
 {
  var message='';
  
		if(document.f1.param1.value == "")
    message=message+"Please enter your Email Address \n";
    
     	if(document.f1.param2.value == "")
    message=message+"Please enter your Password \n";
  		          
     if(message != '')
     {
 		alert(message);
 		return false;
     }
	else  
     	{
     	if(document.f1.param1.value != '' && document.f1.param1.value != '-' )
     		{
 				var check=validate_email(document.f1.param1.value);
	   			if(check)
	   			{
 				document.f1.submit();
 				}
 			}	
 		}
 		
}

/* End of Coding for Login */

/* Start of Coding for date and time */
function makeArray() {
     for (i = 0; i<makeArray.arguments.length; i++)
         this[i + 1] = makeArray.arguments[i];
 }
 function makeArray0() {
     for (i = 0; i<makeArray0.arguments.length; i++)
         this[i] = makeArray0.arguments[i];
 }
 function y2k(number) 
 { 
      return (number < 1000) ? number + 1900 : number;
 }
 
 function displayDate()
  {
    var months = new makeArray('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
    var days = new makeArray0('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
 
    var today = new Date();
    var day   = days[today.getDay()];
    var date  = today.getDate();
    var month = today.getMonth() + 1;
    var year  = y2k(today.getYear());
    return date+", "+months[month]+" "+year;
     
}
function MakeArrayday(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MakeArraymonth(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function funClock() {
 
var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
movingtime = "<b>"+displayDate()+" - "+hours + ":" + minutes + ":" + seconds + " " + dn + "</b>";
document.getElementById('clock').innerHTML=movingtime; //For firefox
setTimeout("funClock()", 1000)
}
/* End of Coding for date and time */


/* Start of Coding for Pop-ups */
function previewLink(widht,height,windowName,url)
{
 	//Modified by Christopher 10/22/2008 Centering Pop-Up for All Size Screen
	//get the width and height of the window
    var wide = widht;
    var high = height;
    var winEditPage = windowName;
    //this gets the total available width and height of the users screen
    screen_height = window.screen.availHeight;
    screen_width = window.screen.availWidth; 

    //this gets the left and top point by saying total width of the screen divided by 2 (center), minus the width of your window divided by 2, which make its center point the middle of the screen. Same for the top
    left_point = parseInt(screen_width/2)-(wide/2); 
    top_point = parseInt(screen_height/2)-(high/2); 

    //just doing a simple popup window here, but plugging your info into it, and setting the top and left corners to be our calculated points that will center your window.
    winEditPage = window.open(''+url+'', ''+winEditPage+'', 'width='+wide+',height='+high+',left='+left_point+',top='+top_point+',toolbar=no,location=no,scrollbars=yes,status=no,resizable=yes,fullscreen=no');     //make sure your window is in the front 
    winEditPage.focus(); 

}
/* End of Coding for Pop-ups */

/* Start of Checking for Valid Email Stracture */

function validate_email(emailStr)
 {
  
 	var emailPat=/^(.+)@(.+)$/
  	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  	var validChars="\[^\\s" + specialChars + "\]"
  	var quotedUser="(\"[^\"]*\")"
  	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
  	var atom=validChars + '+'
  	var word="(" + atom + "|" + quotedUser + ")"
  	// The following pattern describes the structure of the user
  	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
  	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
  
  	var matchArray=emailStr.match(emailPat)
  	if (matchArray==null) {
  		alert("Email address seems incorrect (check @ and .'s)")
  		return false;
  	}
  	var user=matchArray[1]
  	var domain=matchArray[2]
  
  	// See if "user" is valid
  	if (user.match(userPat)==null) {
  	    // user is not valid
  	    alert("The Email Address username doesn't seem to be valid.")
  	    return false;
  	}
  
  	var IPArray=domain.match(ipDomainPat)
  	if (IPArray!=null) {
  	    // this is an IP address
  		  for (var i=1;i<=4;i++) {
  		    if (IPArray[i]>255) {
  			alert("The Email Address  Destination IP address is invalid!")
  		        return false;
  		    }
  	      }
  	   return true;     
    
  	}
  
  	// Domain is symbolic name
  	var domainArray=domain.match(domainPat)
  	if (domainArray==null) {
  		alert("The Email Address  domain name doesn't seem to be valid.")
  	        return false;
  	}
  
  
  	var atomPat=new RegExp(atom,"g")
  	var domArr=domain.match(atomPat)
  	var len=domArr.length
  	if (domArr[domArr.length-1].length<2 ||
  	    domArr[domArr.length-1].length>3) {
  	   // the address must end in a two letter or three letter word.
  	   alert("The Email Address must end in a three-letter domain, or two letter country.")
  	   return false;
  	}
  
  	// Make sure there's a host name preceding the domain.
  	if (len<2) {
  	   var errStr="The Email Address is missing a hostname!"
  	   alert(errStr)
  	   return false;
  	}
    
    return true;
    }// End of checking Email
    
/* Start of Replacing a string with the given value */   
function getStatus(code) {
 	var check = "";
	if (code == "D") check="Deactivated";
    else if (code == "A") check="Activated";
    else if (code == "R") check="Removed";
	else check="No Data";
    document.write(check); 		
}
/* End of Replacing a string with the given value */   

/* Start of Selecting and Deselecting all forms */   
function selectAll(cb,state) {
for (i = 0; i < document.f1.elements.length; i++) {
	var checkbox = document.f1.elements[i];

	if (checkbox.type == 'checkbox' && checkbox.name.indexOf(cb) > -1) {
		if ((cb == 'SLi') && (state == false) && (checkbox.checked)) {
		
	
		}
			checkbox.checked = state;
		}
}
}
/* End of Selecting and Deselecting all forms */ 

function confirmSelect(form,name,message,message2)
{
	//alert(form);alert(name);alert(message);alert(message2);
	// Created by Christopher 11/04/2008
	// Checking if at least one checkbox is selected. 
	var total=0; 
	for(var e=0; e < form.elements.length; e++)
	{ 
		if(form.elements[e].checked)
		{ 
		//total =total +1;
		total++;
		} 
 	} 
 	if(total < 1)
		{ 
		alert(message)
		return false; 
		} 
   else if(total > 1)
		{ 
		alert(message2)
		selectAll(name,false);
		return false; 
		} 
  return true;
}

function getBodyElement( val )
{
 	var myWidth = 0, myHeight = 0;
 	if( typeof( window.innerWidth ) == 'number' ) {
 		//Non-IE
 		myWidth = window.innerWidth;
 		myHeight = window.innerHeight;
 	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
 		//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
   		myHeight = document.documentElement.clientHeight;
 	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
 		myWidth = document.body.clientWidth;
   		myHeight = document.body.clientHeight;
 	}
 	
 	if( val =='h' ){
 	return myHeight;
 	}
  	if( val =='w' ){
 	return myWidth;
 	}
	
}
