// <![CDATA[	
var d = new Date();
var year = d.getFullYear();

//Email subscription form validation
var rxEmailAddress	= /^(\w+|[.]|[-]+)+[@](\w+|[-]+)+[.](\w+|[.]|[-]+)+$/;

function submitEmailGuide()
{
	var txtEmail	= document.getElementById('ea');
	
	var errors		= '';

	if (txtEmail.value.length < 6 || txtEmail.value.length > 255 || !rxEmailAddress.test(txtEmail.value))
	{
		errors = errors + '- enter a valid email address between 6 and 255 characters in length\r\n';
	}

	if (errors.length > 0)
	{
		window.alert('Sorry, please correct the following before submitting the Free Guide form:\r\n\r\n' + errors);
		return false;
	}
	else
	{
		return true;
	}
}


function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function doPopups()
{
if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName('a');
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		var relAttribute = String(anchor.getAttribute('rel'));
		if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('popup'))){
			anchor.onclick = function () {window.open(this.href); return false;}
		}
	}
}

function clearOnFocus(type)
{
  if (!document.getElementsByTagName) return false;
  var fields = document.getElementsByTagName(type);
  for (var i=0; i < fields.length; i++) {
    if (fields[i].className.match("clearonfocus")) {
      fields[i].onfocus = function() {
        if (this.value == this.defaultValue) {
          this.value = "";
          return false;
		}
      }
	  fields[i].onblur = function() {
        if (this.value == "") {
          this.value = this.defaultValue;
          return false;
		}
      }
    }
  }
}

function doButtonImages() {
  if (!document.getElementsByTagName) return false;
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i < inputs.length; i++) {
    if (inputs[i].type=="submit" || inputs[i].type=="button") {
      	inputs[i].onmouseover = function() {this.className += "Hover";}
		inputs[i].onmouseout = function() {this.className = this.className.replace(/Hover/g, "");}
    }
  }
}

// Unobtrusive scroller object
var fdScroller = {
        scrollLoop:false,
        scrollInterval:null,
        currentBlock:null,
        lastY:0,
        requestedY:0,
        init: function() {
                var lnks = document.getElementsByTagName('a');
                var removeLoc = window.location + ' ';

                // strip any #target, force a String cast
                if(removeLoc.indexOf('#') != -1) {
                        removeLoc = removeLoc.substr(0, removeLoc.indexOf('#'));
                } else {
                        removeLoc = removeLoc.substr(0, removeLoc.length - 1);
                }

                for(var i = 0, lnk; lnk = lnks[i]; i++) {
                        tmploc = lnk.href.replace(removeLoc,'');
                        if(tmploc.charAt(0) == '#' && !lnk.onclick) lnk.onclick = fdScroller.initScroll;
                }
        },
        getWindowHeight: function(){
                var myHeight = 0;
                if( typeof( window.innerWidth ) == 'number' ) {
                        //Non-IE
                        myHeight = window.innerHeight;
                } else if( document.documentElement &&
                                ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                        //IE 6+ in 'standards compliant mode'
                        myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                        //IE 4 compatible
                        myHeight = document.body.clientHeight;
                }
                return myHeight;
        },
        getScrollLeft: function(){
                if(document.all) return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
                else return window.pageXOffset;
        },
        getScrollTop: function(){
                if(document.all) return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
                else return window.pageYOffset;
        },
        getElementYpos: function(el){
                var y = 0;
                while(el.offsetParent){
                        y += el.offsetTop
                        el = el.offsetParent;
                }
                return y;
        },
        initScroll: function(e){
                var targ;

                if (!e) var e = window.event;
                if (e.target) targ = e.target;
                else if (e.srcElement) targ = e.srcElement;
                if (targ.nodeType == 3) targ = targ.parentNode;

                if(targ.href && targ.href.indexOf('#') != -1) {
                        var where = targ.href.substr(targ.href.indexOf('#')+1,targ.href.length);
                        fdScroller.currentBlock = document.getElementById(where);
                        if(!fdScroller.currentBlock) return;

                        var documentHeight = document.getElementsByTagName('body').offsetHeight;
                        var windowHeight = fdScroller.getWindowHeight();
                        var ypos = fdScroller.getElementYpos(fdScroller.currentBlock);
                        if(ypos > documentHeight - windowHeight) ypos = documentHeight - windowHeight;
                        fdScroller.requestedY = ypos;
                        fdScroller.scroll();
                }

                return false;
        },
        scroll: function(){
                var left = fdScroller.getScrollLeft();
                var top  = fdScroller.getScrollTop();

                if(Math.abs(top-fdScroller.requestedY) <= 1){
                        window.scrollTo(0,fdScroller.requestedY);
                        fdScroller.lastY = -1;
                } else {
                        fdScroller.lastY = top;
                        window.scrollTo(0, Math.round(top+((fdScroller.requestedY-top)/2)));
                        setTimeout(fdScroller.scroll,50);
                }
        }
}

// initiate the dropmenu
function dropMenu() {
	menu = new DropMenu('primaryNav');	
}

window.onload = function ()
{
	doPopups();
	clearOnFocus('input');
	clearOnFocus('textarea');
	doButtonImages();
	fdScroller.init();
	//dropMenu();
}

$(document).ready(function() {
		   
	/*$header = $(".datatable thead");
	$pos = $header.offset();
	$("th", $header).each(function() {
		$(this).data("initwidth", $(this).width());								 
	});
	
	function setHeader() {
		$screenposY = $pos.top - $(window).scrollTop();
		if($screenposY < 20) {
			$header.css({ 'position' : 'fixed', 'top' : 0 });
			$header.parent().css({ 'marginTop' : 122 });
			$("th", $header).each(function() {
				$(this).css("width", parseInt($(this).data("initwidth")));								 
			});			
		}
		else {
			$header.css({ 'position' : 'static' });
			$header.parent().css({ 'marginTop' : 0 });
		}
	}

	$(window).bind("load scroll", function() {
		setHeader();										 
	});*/
	/*$(".datatable.scrollable").chromatable({							
		width: "761px",
    	height: "520px",
    	scrolling: "yes"
								});*/
	
		/*------------------------------------------------------------------------------------------------- Quote Button on TDs ------------------------*/
	
		var offset, $value;
	
		$('table.enq').after('<a href="#" class="enquire">Quote</a><form style="display:none" id="codeform" action="http://www.gocomsys.com/quote.html" method="post"><input type="hidden" name="enqcode" /></form>');
	
		$('table.enq').delegate("tbody tr", "mouseenter", function() {

			$value = $("td:first-child", this).text();
			
			offset = $(this).offset();
			var width = $("td:first-child", this).width();
			$(".enquire").css({'display' : 'block', 'position' : 'absolute', 'top' : offset.top, 'left' : offset.left + (width-47)});
		});
		
		$("thead th.enq").bind("mouseenter", function() {

			$value = $("span", this).text();
			
			offset = $(this).offset();
			var height = $(this).height();
			$(".enquire").css({'display' : 'block', 'position' : 'absolute', 'top' : offset.top + height, 'left' : offset.left});
		});
		
		$('table.enq').bind("mouseleave", function() {
			$(".enquire").css({'display' : 'none'});
		});	
		
		$('.enquire').bind("mouseenter", function() {
			$('.enq tr').each(function() {						
				if($(this).offset().top == offset.top) $(this).trigger("mouseover");
			});
			
			$('th.enq').each(function() {						
				if($(this).offset().left == offset.left) $(this).trigger("mouseover");
			});
		});
		
		$('.enquire').bind("click", function() {
			$("#codeform input[name='enqcode']").val($value);
			$("#codeform").trigger("submit");
			return false;
		});
		
		/*------------------------------------------------------------------------------------------------- Quote Button on THs ------------------------*/		
		   
});























// ]]>
