var popup = '';
function openWin(windowURL, windowName, windowFeatures) {
    //closeWin();
    popup = window.open(windowURL, windowName, windowFeatures);
    if (popup) {
        popup.focus();
    }
}

function closeWin() {
    this.window.close();
}

function myDateFormat(dt){
  var  dayno    =  dt.getDate() ;
  var  monthno  =  dt.getMonth() ;
  var  yearno   =  dt.getFullYear() ;
  
  var  daystr ;
  if       ((dayno == 1) 
            || 
            (dayno == 21)     
            || 
            (dayno == 31)
            )
            {daystr  =  dayno + "st"}
  else  if  ((dayno == 2)
             ||
             (dayno == 22)
            )
            {daystr  =  dayno + "nd"}  
  else  if  ((dayno == 3)
             ||
             (dayno == 23)
            )
            {daystr  =  dayno + "rd"}
  else      {daystr  =  dayno + "th"}
  
  if        (monthno ==  0)  {monthstr  =  "January"}
  else  if  (monthno ==  1)  {monthstr  =  "February"}
  else  if  (monthno ==  2)  {monthstr  =  "March"}
  else  if  (monthno ==  3)  {monthstr  =  "April"}
  else  if  (monthno ==  4)  {monthstr  =  "May"}
  else  if  (monthno ==  5)  {monthstr  =  "June"}
  else  if  (monthno ==  6)  {monthstr  =  "July"}
  else  if  (monthno ==  7)  {monthstr  =  "August"}
  else  if  (monthno ==  8)  {monthstr  =  "September"}
  else  if  (monthno ==  9)  {monthstr  =  "October"}
  else  if  (monthno == 10)  {monthstr  =  "November"}
  else  if  (monthno == 11)  {monthstr  =  "December"}    

  var dtstr  =  daystr + " of " + monthstr + ", " + yearno
  
  return  dtstr
} //function mydateformat()

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   var greeting = "Good Morning";

   if (hour   > 11) { ap = "PM"; }
   if (hour == 12 || hour < 17) { greeting = "Good Afternoon"; }
   if (hour >= 17) { greeting = "Good Evening"; }
   if (hour   > 12) { hour = hour - 12;    }
   if (hour   == 0) { hour = 12;            }
   if (hour   < 10) { hour   = hour;   }
   if (minute < 10) { minute = "0" + minute; }
   var timeString = "<strong>" + greeting + "</strong>" + ".  It is now " + 
                    "<strong>" + hour + ':' + minute + ap + "</strong>";
   return timeString;
} // function getClockTime()

function showElement(element) {
    if (document.getElementById) {
        document.getElementById(element).style.display="block";
    } else if (document.all) {
        document.all[element].style.display="block";
    }
}

function hideElement(element) {
    if (document.getElementById) {
        document.getElementById(element).style.display="none";
    } else if (document.all) {
        document.all[element].style.display="none";
    } 
}

function doBlink() {
	var blink = document.all.tags("BLINK")
	for (var i=0; i<blink.length; i++)
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
	if (document.all)
		setInterval("doBlink()",1000)
}
window.onload = startBlink;

function clearError(id) {
    document.getElementById(id).style.visibility = "hidden";
}

function showError(id) {
    document.getElementById(id).style.visibility = "visible";
}
function warn(errors) {
    for (i = 0; i < errors.length; i++) {
        showError(errors[i]);
    }
}

        function checkForInvalidCharacters(strInput) {
            var invalidChars = "?&=";
            for (var i = 0; i < invalidChars.length; i++) {
                strBadChar = invalidChars.charAt(i);            //get next invalid character
                if (strInput.indexOf(strBadChar,0) > -1) return strBadChar;     //if there is one in Email
            }
            return "";
        }//checkForInvalidCharacters

        function checkContactForm() {
        var form = document.contact;
        var errorCount = 0;
        var errors = new Array();

        
        var alerts = '';
        var digits = "0123456789";
        var digitsandletters = "0123456789abcdefghijklmnopqrstuvwxyz";
        
        var fullNameError = "false";
        if (form.full_name.value == ""){
            alerts += "Please fill in your full name.\n";
            fullNameError = "true";
        }
        if (fullNameError == "true") {
            errors[errorCount] = "fullNameError";
            errorCount++;
        }
        
         var emailError = "false";
        if (form.email_addr.value == "") {
            alerts += "Please enter your email address.\n";
            emailError = "true";
        }
        if ( form.email_addr.value.indexOf("@")<1 && form.email_addr.value!="" ) {
            alerts += "Please verify that your email address contains the '@' sign.\n";
            emailError = "true";
        }
        if ( form.email_addr.value.indexOf(" ")>=0 && form.email_addr.value!="" ) {
            alerts += "Please verify that your email address does not contain any spaces.\n";
            emailError = "true";
        }
        if ((form.email_addr.value.indexOf ('@',0) == -1 ||
             form.email_addr.value.indexOf ('.',0) == -1) &&
             form.email_addr.value != "") {
            alerts += "Please verify that your email address is valid.\n";
            emailError = "true";
        }
        strBadChar = checkForInvalidCharacters(form.email_addr.value);
        if (strBadChar.length > 0) {
            alerts = alerts + "Email Address cannot include the " + strBadChar + " character.\n";
            emailError = "true";
        }
        if (emailError == "true") {
            errors[errorCount] = "emailError";
            errorCount++;
        }

        var subject  = form.subject.options[form.subject.selectedIndex].value;
        if (subject=="none"){
            alerts += "Please select subject from the drop-down list.\n";
            errors[errorCount] = "subjectError";
            errorCount++;
        }
        
        var commentsError = "false";
        if (form.comments.value == ""){
            alerts += "Please fill a comment.\n";
            commentsError = "true";
        }
        if (commentsError == "true") {
            errors[errorCount] = "commentsError";
            errorCount++;
        }
        
        if (alerts != ""){
            alert(alerts);
            warn(errors);
            return (false);
        } else {
            
            return (true);
        }
    }//checkContactForm()
    
    function stripTags(comments) {
       a = comments.indexOf("<");
       b = comments.indexOf(">");
       len = comments.length;
       c = comments.substring(0, a);
       if(b == -1)
        b = a;
        d = comments.substring((b + 1), len);
        comments = c + d;
        tagCheck = comments.indexOf("<");
        if(tagCheck != -1)
            comments = stripTags(comments);
            return comments;
    }