/*
	Image Cross Fade Redux
	Version 1.0
	Last revision: 02.15.2006
	steve@slayeroffice.com

	Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*/

  window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;

function so_init()
{
	if(!d.getElementById || !d.createElement)return;

	css = d.createElement('link');
	css.setAttribute('href','/css/slideshow2.css');
	css.setAttribute('rel','stylesheet');
	css.setAttribute('type','text/css');
	css.setAttribute('media','screen');
	d.getElementsByTagName('head')[0].appendChild(css);

	imgs = d.getElementById('rotator').getElementsByTagName('img');
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = 'block';
	imgs[0].xOpacity = .99;

	setTimeout(so_xfade,5000);
}

function so_xfade()
{
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;

	cOpacity-=.03;
	nOpacity+=.03;

	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;

	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);

	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		setTimeout(so_xfade,5000); // COMENT OUT TO STOP CONTINUOS ROTATION
	}
	else
	{
		setTimeout(so_xfade,50);
	}

	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}



var win;

function OpWin(i,x,y) {
win = open(i, '', 'width='+x+',height='+y+',resizable=0,toolbar=0,scrollbars=0,location=0,menubar=0,status=0,titlebar=1,top=0,left=0');
}

function doSearchOld() {
	with (self.document.m2moduleform_1) {
        if(m2searchinput.value == "") {
			alert("Please enter a search word or phrase");
			m2searchinput.focus();
		 }
		 else {
		 submit();
		 }
	}
}

function doSearch() {
	document.getElementById('cntnt01moduleform_1').submit();
}



//////////////////////////////////
// form validation methods library

// string is valid email
function isEmail(s) {
  var apos = s.indexOf('@');
  var dpos = s.indexOf('.');
  if (apos<=0 || dpos<=0) {
	return false; 
  }
  if (dpos+1>=s.length) {
	return false; 
  }
  return true;
}				

// string contains only whitespace
function isBlank(s) {
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c!=' ') && (c!='\n') && (c!='\t')) return false;
	}
	return true;
}		

// string is empty or only whitespace
function isEmpty(s) {
	if (!(s.value==null || s.value=="" || s.value=="-" || isBlank(s.value)))return false;
	return true;	
}	

// string is numeric
function isNumber(s) {
 if (isEmpty(s)) {
  return false;
 }	
 for (var i = 0; i < s.value.length; i++) {
   var ch = s.value.substring(i, i + 1);
   if((ch!=' ') && (ch!='\n') && (ch!='\t')) 
     if (ch < "0" || "9" < ch)return false;
 }
 return true;
}		

// string is numeric
function isFloat(s) {
 if (isEmpty(s)) {
  return false;
 }
 if (isNaN(parseFloat(s))) {
  return false;
 }
 for (var i = 0; i < s.value.length; i++) {
   var ch = s.value.substring(i, i + 1);
   if((ch!=' ') && (ch!='\n') && (ch!='\t') && (ch!='.')) 
     if (ch < "0" || "9" < ch)return false;
 }
 return true;
}




function clearfield(fieldid) {
	if(document.getElementById(fieldid).value == "-") { document.getElementById(fieldid).value = ""; }
}


function formVerify() {
	var msg;
	var empty_fields = "";
	var err = "";

  // you
  if (isEmpty(document.contactform.name))
    empty_fields += "\n  - your name";
  if (isEmpty(document.contactform.company))
    empty_fields += "\n  - your company";
  if (!isEmail(document.contactform.email.value))
    err += "\n  - your email";
  if (isEmpty(document.contactform.subject))
    empty_fields += "\n  - your subject";
  if (isEmpty(document.contactform.message))
    empty_fields += "\n  - your message";
  if (!empty_fields && !err) return true;

	msg = "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "\n\n";

	if ( (empty_fields.length > 1) || (err.length > 1) )
	{
		msg += "The following required field(s) are incomplete or incorrectly formatted:" + empty_fields + err + "\n";
		msg += "\n";
	}

	alert(msg);

  return false;
}
