﻿// **** JAVASCRIPT FUNCTIONS FOR ASU **** \\
// M. WIlliams (Nimbus.info)
// v091120

//alert("JS Loaded");


//JQ DD [http://javascript-array.com/scripts/jquery_simple_drop_down_menu/]
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
	$('#jsddm > li').bind('click', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;
//END JQ DD

//LEGACY FUNCTIONS 16/2/2010

function checkLength(taObj,max)
	{
		if(taObj.value.length>max)
			{
				alert("Maximum character limit exceeded. Please delete some text and try again...")
				taObj.focus();
			}
	}

function textCounter(counterId, obj, maxlimit) {
  var re
  re = new RegExp("\r\n","g")
  x = obj.value.replace(re,"").length ;
  if (x > maxlimit) {
    return false;
  } else {
    c = _getElement(counterId);
    left = maxlimit - obj.value.length;
    c.innerHTML = left + '';
    return true;
  }
}
		function textAreaMaxLength(field, maxlimit) {
  if (field.value.length > maxlimit) {
    field.value = field.value.substring(0, maxlimit);
  }
}
	
	function maxLength(myField,myLength)
		{
			
			var mblength=document.getElementById(myField).value.length;
			
   					if (mblength>myLength)
   						{
   			
   							overlength=mblength-myLength;
   							alert("CONTENT TOO LONG!\n\nThis area is limited to "+myLength+" characters. Your current message contains "+mblength+" characters and therefore needs to be reduced in length by "+overlength+" characters.\n\nPlease delete some of your text, or rephrase it to reduce its length.");
   							document.getElementById(myField).focus();
   							return false;
   						}
		}
	//**** end max length code

function validateemail(address,fieldname)
		{
			//THIS FUNCTION VALIDATES AN EAMIL ADDRESS
							
							thisfieldname=fieldname.name;
							var c=1
							if (address.indexOf("@") != "-1" && address.indexOf(".") != "-1" && address!= "")
									{
										return true; 
 									}
 							else if (address=="")
 									{
 										return true;
 									}
  							else
   									{
   										alert("Your email address seems to contain invalid characters.\n\nPlease correct this mistake and try again");
										c=2
   									}
   							if (c==1)
   								{
	   								return true;
	   							}
   							else
   								{
   									return c;
   								}
		}

//  FUNCTION ONLY VALIDATE EMAIL CONTENTS, NOT VALIDATING ENTRY MADE
	// 		EXECUTES ON BLUR
	function emailOnly(address,fieldname)
		{
			var c=validateemail(address,fieldname);
			if (c==2)
				{
					document.getElementById(fieldname).focus();
					return false;
				}
			else
				return true;
		}


function validate(form,noelements,showprogress)
		{
			//THIS FUNCTION WILL confirm entry in to any field identified to it as being mandatory (hopefully)
				var c=1;
				for (i=1;i<=noelements;i++) 
					{
						var thiscontent=document.getElementById(i).value;
						var thiselementname=document.getElementById(i).name;
						if (thiscontent=="")
							{
								alert("Mandatory information missing!\n\n"+thiselementname+" is a mandatory field.\nPlease enter the requested information in the relevant field!");
								c=2;
								document.getElementById(i).focus();
								return false;
							}
						if (thiselementname=="email")
							{
								c=validateemail(thiscontent,"email");
								if (c==2)
									{
										form.email.select();
										form.email.focus();
										return false;
									}
							}
					}
			
			if (c!=1)
				return false;
			else
					
				{
					if (showprogress!="")
						{
									  strAppVersion = navigator.appVersion;
									  if (document.getElementById(showprogress).value != "")
									  {
									    if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
									    {
									      winstyle = "dialogWidth=385px; dialogHeight:140px; center:yes";
									      window.showModelessDialog('<% = barref %>&b=IE',null,winstyle);
									    }
									    else
									    {
									      window.open('<% = barref %>&b=NN','','width=370,height=115', true);
									    }
									  }
									  return true;
						}
					else
						return true;
				}		
		}

function expandDiv(divID)
		{
			var docHeight,maxHeight;		//=0;
			var newHeight=0;
			var myDiv=document.getElementById(divID);

				docHeight=document.body.scrollHeight;
				maxHeight=docHeight-400;	//for a body DIV this is as tall as it needs to be taking off header, showcase and footer
					
			while (document.body.scrollHeight<=docHeight && newHeight<3200 && newHeight<maxHeight)
				{
					newHeight=myDiv.offsetHeight+10;
					myDiv.style.height=newHeight+"px";
				}
		}

