extArray = new Array(".jpg", ".jpeg", ".gif",".swf");

function LimitAttachImage(form, file)
{
	allowSubmit = false;
	if (!file) return false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++)
	{
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit)
	{
		return false;
	}
	else
	{
		return true;
	}
}

extArray2 = new Array(".mp3");

function LimitAttachMP3(form, file)
{
	allowSubmit = false;
	if (!file) return false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray2.length; i++)
	{
		if (extArray2[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit)
	{
		return false;
	}
	else
	{
		return true;
	}
}

extArray3 = new Array(".swf",".dcr",".java");

function LimitAttachGames(form, file)
{
	allowSubmit = false;
	if (!file) return false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray3.length; i++)
	{
		if (extArray3[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit)
	{
		return false;
	}
	else
	{
		return true;
	}
}

extArray4 = new Array(".pdf");

function LimitAttachPDF(form, file)
{
	allowSubmit = false;
	if (!file) return false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray4.length; i++)
	{
		if (extArray4[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit)
	{
		return false;
	}
	else
	{
		return true;
	}
}

extArray5 = new Array(".jpg",".jpeg");

function LimitAttachJPG(form, file)
{
	allowSubmit = false;
	if (!file) return false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray5.length; i++)
	{
		if (extArray5[i] == ext) { allowSubmit = true; break; }
	}
	if (!allowSubmit)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function case_changer(textString)
{
	var tempVal = textString;
	tempVal = tempVal.toLowerCase();
	return tempVal;
}

function checkdate(inputDate){
//	window.onerror=null // for all other strange errors
//input date form = dd/mm/yyyy
	var err=0;
	var psj=0;
	a=inputDate;
	if (a.length != 10) {err=1 };

	d = a.substring(0, 2);// day
	c = a.substring(2, 3);// '/'
	b = a.substring(3, 5);// month
	e = a.substring(5, 6);// '/'
	f = a.substring(6, 10);// year

	//basic error checking
	if (b<1 || b>12) err = 1;
	if (c != '/') err = 1;
	if (d<1 || d>31) err = 1;
	if (e != '/') err = 1;
	if (f<0 || f>2050) err = 1;
	
	//advanced error checking

	// months with 30 days
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) err=1;
	}

	// february, leap year
	if (b==2){
		// feb
		var g=parseInt(f/4);
		if (isNaN(g)) {
			err=1;
		}

		if (d>29) err=1;
		if (d==29 && ((f/4)!=parseInt(f/4))) err=1;
	}

	if (err==1){
		return(false);
	}
	else{
		return(true);
	}
}

function isPresentDate(inputDate)
{

	var val = true;
	var today = new Date();
	var nowDay = today.getDate();
	//add leading zero for day number less than 10
	if (nowDay < 10) {
	nowDay = "0" + nowDay;
	}
	var nowMonth = today.getMonth();
	nowMonth  += 1;
	//add leading zero for months less than 10
	if (nowMonth < 10) {
	nowMonth = "0" + nowMonth;
	}
	var nowYear = today.getYear();
//check year returned - if less than 1900 add 1900 to it (cater for netscape 4.08)
	if (nowYear < 1900) {
	nowYear += 1900;
	}
	todayDate = nowYear + "" +  nowMonth + "" +  nowDay;
	
	if  (inputDate <= todayDate)
	{
		val = false;
	}	
	return val;
}


function text_length(textString,textMin,textMax)
{
	var val = true;
	if (textString.length < textMin || textString.length > textMax)
	{
		val = false;
	}
	return val;
}

function text_length_min(textString,textMin)
{
	var val = true;
	if (textString.length < textMin )
	{
		val = false;
	}
	return val;
}

function text_length_max(textString,textMax)
{
	var val = true;
	if (textString.length > textMax)
	{
		val = false;
	}
	return val;
}

function validate_numbers(num,numMin,numMax,allowedValue)
{
	var val = true;
	if (num != allowedValue)
	{
		if (isNaN(num) || num.length < numMin || num.length > numMax  )
		{
			val = false;
		}
	}
	return val;
}

function validate_numbers_min(num,numMin,allowedValue)
{
	var val = false;
	if (num != allowedValue)
	{
		if (isNaN(num) || num.length < numMin )
		{
			val = true;
		}
	}
	return val;
}

function validate_numbers_max(num,numMax,allowedValue)
{
	var val = false;
	if (num != allowedValue)
	{
		if (isNaN(num) || num.length > numMax  )
		{
			val = true;
		}
	}
	return val;
}

function validate_email(email,allowedValue)
{
	var val = true;
    if (email != allowedValue)
	{
		if (!emailCheck (email))
		{
			val = false;
		}
		
	}    
	
	return val; 
}



function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

//alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

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("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}



function validate_na(laAutLink,laAutLinkText)
{
	var val = false; 
    if ((laAutLink == "N/A" || laAutLink == "n/a") && (laAutLinkText != "N/A" && laAutLinkText != "n/a"))
	{
		val = true; 
	} 
	else if ((laAutLinkText == "N/A" || laAutLinkText == "n/a") && (laAutLink != "N/A" && laAutLink != "n/a"))
	{
		val = true; 
	}       

	return val; 
}

function JustSoSWFWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="") {
		bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug image"){
	  if (hugMargin == ""){
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight) {
		scrHeight = scrHeightTemp;
	  } 
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth) {
		scrWidth = scrWidthTemp;
	  }
	  
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
 	}

	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("vwd_justso.htm","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' >');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+imageWidth+'" height="'+imageHeight+'">'); 
	newWindow.document.write('<param name="movie" value="'+imageName+'">'); 
	newWindow.document.write('<param name="quality" value="high">'); 
	newWindow.document.write('<embed src="'+imageName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+imageWidth+'" height="'+imageHeight+'"></embed>'); 
	newWindow.document.write('</object>'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();


	}
}
                                     