// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Fix Explorer Mac overflow bug

function beforeOnLoad(){
	var agent = navigator.userAgent.toLowerCase(); 
	if(agent.indexOf("mac") != -1 && document.all && document.getElementsByTagName){
		if(document.body.clientHeight > 500){
			document.getElementsByTagName("body")[0].style.overflow = "hidden";
		}
	}
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// PNG alpha transparency in Win IE 5.5+

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent)
{
	document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs()
{
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--)
	{
		if (itsAllGood && img.src.match(/\.png$/i) != null)
		{
			var src = img.src;
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Form Validation
// Use it like this: <form action="/web/contact/" method="post" onsubmit="return formCheck(this);">

function formCheck(formobj)
	{
	// 1) enter names of mandatory fields
	var fieldRequired = Array('fullname', 'email', 'subject', 'comments');

	// 2) enter descripts to appear in the alert box
	var fieldDescription = Array('Your name', 'Your email address', 'The subject of the message', 'Your comments');

	// 3) enter alert box message
	var alertMsg = "Sorry about this, but you can't submit the form until ALL the compulsory fields have been filled out.\n";
	alertMsg += '____________________________________________________\n\n'
	alertMsg += "Please complete the following fields, then press 'Submit' again:\n\n";

	// set this count var to see if any blank fields were found
	var c = 0;

	for (var i = 0; i < fieldRequired.length; i++)
		{
		var obj = formobj.elements[fieldRequired[i]];
		document.getElementById(fieldRequired[i]).style.backgroundColor = '#' + 'ffffff';
		if (obj)
			{
			switch(obj.type)
				{
				case 'text':
				case 'textarea':
				if (obj.value == '' || obj.value == null)
					{
					alertMsg += ' - ' + fieldDescription[i] + '\n';
					document.getElementById(fieldRequired[i]).style.backgroundColor = '#' + '4682B4';
					c++;
					}
				break;
				}
			}
		}
	
	alertMsg += '\nThese fields have been highlighted for your attention.';

	// if no blank fields were found, alter the submit button text and submit
	if (c == 0)
		{
		document.getElementById('submit').value = 'submitting...';
		return true;
		}
	
	// if blank fields were still found show alert box and deny submission
	else
		{
		alert(alertMsg);
		c = 0;
		return false;
		}
	}

	
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Description: This script is for opening external windows.

openWin = function(url,name,width,height,xpos,ypos,chrome,scroll){
  var x, y, w, h, moveX=0, moveY=0, features="";
  chrome = chrome ? "yes" : "no";
  scroll = scroll ? "yes" : "no";
  features += "toolbar="+chrome+",location="+chrome+",status="+chrome+",menubar="+chrome;
  features += ",scrollbars="+scroll+",resizable="+scroll;
  if(width) features += ",width="+width;
  if(height) features += ",height="+height;
  if(xpos && window.screen){
    w = window.screen.availWidth;
    width = parseInt(width);
    switch(xpos){
      case "left": x = 0; break;
      case "center": x = (w-width)/2; break;
      case "right": x = w-width; break;
      default: x = xpos;
    }
    features += ",screenX="+x+",left="+x;
    var moveX = x;
  }
  if(ypos && window.screen){
    h = window.screen.availHeight;
    height = parseInt(height);
    switch(ypos){
      case "top": y = 0; break;
      case "middle": y = (h-height)/2; break;
      case "bottom": y = h-height; break;
      default: y = ypos;
    }
    features += ",screenY="+y+",top="+y;
    var moveY = y;
  }
  openWinReference = window.open(url,name,features);
  if(moveX || moveY){
    // position the window for browsers that don't recognize screenX, screenY
    openWinReference.moveTo(moveX,moveY);
  }
}
openScroll = function(url,name,width,height){
  openWin(url,name,width,height,false,false,false,"scroll");
}
openCenter = function(url,name,width,height){
  openWin(url,name,width,height,"center","middle");
}
openCenterScroll = function(url,name,width,height){
  openWin(url,name,width,height,"center","middle",false,"scroll");
}
openFull = function(url,name){
  openWin(url,name,false,false,false,false,"chrome","scroll");
}

// --------------------------------------------------
// Example/Usage:

/*
<a href="#" onclick="openWin('blank.html', 'blank', '400', '300');">no position, no features, no scroll</a>
<a href="#" onclick="openWin('blank.html', 'blank', '400', '300', 'center');">center, no features, no scroll</a>
<a href="#" onclick="openWin('blank.html', 'blank', '400', '300', 'center', 'middle');">center/middle, no features, no scroll</a>
<a href="#" onclick="openWin('blank.html', 'blank', '400', '300', 'right', 'middle', 'chrome');">right/middle, features, no scroll</a>
<a href="#" onclick="openWin('blank.html', 'blank', '400', '300', 'left', 'bottom', false, 'scroll');">left/bottom, no features, scroll</a>
<a href="#" onclick="openWin('blank.html', 'blank', '400', '300', 'center', '50');">center/50, no features, no scroll</a>
<a href="#" onclick="openWin('blank.html', 'blank', false, false, false, false, 'chrome', 'scroll');">no size, no position, features, scroll</a>

--- Preset Functions --- 

<a href="#" onclick="openScroll('blank.html', 'blank', '400', '300');">openScroll</a>
<a href="#" onclick="openCenter('blank.html', 'blank', '400', '300');">openCenter</a>
<a href="#" onclick="openCenterScroll('blank.html', 'blank', '400', '300');">openCenterScroll</a>
<a href="#" onclick="openFull('blank.html', 'blank');">openFull</a>
*/