var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 


function e(id)
{
	return document.getElementById(id)?document.getElementById(id):false;
}

function printPage() {
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
  if(mac)
  	{
    	alert("Please click Command-P to print this page.");
	}else{
    	alert("Please click Control-P to print this page.");		
	}
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

// Check if Flash is available
var MM_FlashCanPlay = false;
var MM_contentVersion = 7;
var img_innerHTML;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i)
			{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i]; 
			}
		MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {

		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
		document.write('</SCR' + 'IPT\> \n');
}

if(!MM_FlashCanPlay)
{
	//alert("Flash missing");
}



function findPosition( oLink ) {
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oLink.x, oLink.y ];
  }
}

function tip_show(obj)
{
	obj.alt_title = obj.title;
	obj.title = '';
	var tip_cont = e('tool_tip_container');
	var tip_text_cont = e('tool_tip_text');
	if((tip_cont)&&(tip_text_cont)&&(obj.alt_title!=''))
	{
		
		var pos = findPosition(obj)
		var obj_w = obj.offsetWidth;
		// move to pos
		
		if(um.mie)
		{
			//special mac offset
			off_x = -38;
			off_y = -80;
		}else{
			off_x = 0;
			off_y = 0;				
		}
		tip_cont.style.left = pos[0] + obj_w + off_x + 3;
		tip_cont.style.top = pos[1] + off_y + 5;
		
		// change text
		tip_text_cont.innerHTML = obj.alt_title;
		
		// turn on
		tip_cont.style.display = 'block';
	}
}
function tip_hide(obj)
{
	obj.title=obj.alt_title;
	var tip_cont = e('tool_tip_container');
	// turn tip off
	if(tip_cont)
	{
		tip_cont.style.display = 'none';
		tip_cont.style.left = 0;
		tip_cont.style.top = 0;
	// put away
	}
}


function validate_form(obj,field_array)
{
	//alert('validating form');
	var field_len = field_array.length;
	for(var i=0;i<field_len;i++)
	{
		var field_info = field_array[i];
		var field_id = field_info[0];
		var field_title = field_info[1];
		var field_datatype = field_info[2];
		
		if(field_datatype=='email')
		{
			if(!testEmail(obj,field_id))
			{
				showEmailError(field_title);
				fieldFocus(obj, field_id);
				return false;
			}
		}else if(field_datatype=='string')
		{		
			field_minlength = field_info[3];
			if(!testString(obj,field_id,field_minlength))
			{
				showStringError(field_title, field_minlength);
				fieldFocus(obj, field_id);
				return false;
			}			
		}else if(field_datatype=='combo')
		{
			if(!testCombo(obj,field_id))
			{
				showComboError(field_title);
				fieldFocus(obj, field_id);
				return false;
			}			
		}		
	}
	return true;
}

function fieldFocus(obj, field)
{
	obj[field].focus();
	//obj[field].style.border="1px solid red";
}

function testString(obj,field,minLen)
{
	var val = obj[field].value;
	if(val.length < minLen)
	{
		return false;
	}else{
		return true;
	}
}

function testCombo(obj,field)
{
	var val = obj[field].value;
	if(val=='')
	{
		return false;
	}else{
		return true;
	}
}
function testEmail(obj,field)
{

	var val = obj[field].value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(val))
	{
		return true;
	}else{
		return false;
	}
}

function showEmailError(field)
{
	alert("Invalid email in '" + field + "' field, please fix and re-submit.");
	return false;
}
function showStringError(field,minLen)
{
	alert("Invalid entry in '" + field + "' field, must be at least "+ minLen+" characters in length, please fix and re-submit.");
	return false;
}
function showComboError(field)
{
	alert("Please select item in '" + field + "'.");
	return false;
}
function showError(field)
{
	alert("Invalid entry in '" + field + "' field, please fix and re-submit.");
	return false;
}


