/********************************************************
   Break out of frames
 ********************************************************/

if (top.location != location) {
  top.location.href = document.location.href ;
}



/********************************************************
   Dynamic Menu
 ********************************************************/

// create the later that slides on page scroll



function initStatLyr() {
  // args: id, left, top, w, h, duration of glide to location onscroll, acceleration factor
  // acceleration factor should be -1 to 1. -1 is full deceleration


  if(!glideMenu) return;

  window.getScrollY = function(){ 
  							var sy = 0;
						  if (document.documentElement && document.documentElement.scrollTop)
							sy = document.documentElement.scrollTop;
						  else if (document.body && document.body.scrollTop) 
							sy = document.body.scrollTop; 
						  else if (window.pageYOffset)
							sy = window.pageYOffset;
						  else if (window.scrollY)
							sy = window.scrollY;
						  
						  return sy-100;
						}

  statLyr = new Glider("menu",0, 0,null,null,1000,-1);
  statLyr.show();
}

function init() {
 	ScrollLinks.start();
  	if(sameHeight) {
  						if(document.getElementById("thirdlevelmenu")){
  							setEvalProp("thirdlevelmenu","main",-27);
  						} else {
  							setEvalProp("menu","main",0);
  						}  						
  	}
	initStatLyr();
	
}


/********************************************************
   Form Validation
 ********************************************************/

function checkClearValue(field, label){   
  if(field.value == label)
    field.value = "";
}

function checkFillValue(field, label){
  if(field.value.length == 0)
    field.value = label;
}

function isEmpty(str){
  return (str == null) || (trim(str).length == 0);
}

function isEmail(str){
  var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
  return re.test(str);
}


function validateContactForm(form){
  
  var realName = form.realname.value;
  var subject = form.messageSubject.value;
  var email = form.email.value;
  var message = form.message.value;

  var errors = "";
  var count = 0;

  if(realName == "" || realName == "NAME")
    errors += "\n    " + (++count) + ". Missing name";
  
  if(subject == "" || subject == "SUBJECT")
    errors += "\n    " + (++count) + ". Missing subject";
  
  if(email == "" || email == "E-MAIL")
    errors += "\n    " + (++count) + ". Missing e-mail";
  else if(!isEmail(email))
    errors += "\n    " + (++count) + ". Invalid e-mail";
    
  if(message == "" || message == "MESSAGE")
    errors += "\n    " + (++count) + ". Missing message";
  
  
  if(errors != ""){
    alert("Please correct the following and try again:\n" + errors);
    return false;
  }  

  return true;
}



/********************************************************
   Centered, popup window
 ********************************************************/

function popupCenter(url, width, height, opt){
  var top = (screen.height/2)-(height/2);
  var left = (screen.width/2)-(width/2);
  var features = 'height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=' + opt;
  theWin = window.open(url,'',features);
}


/********************************************************
   Dynamically fills remaining page height
 ********************************************************/

function setDynProp(id, footerId){
  var px = window.opera ? 0: "px";
  var el = document.getElementById(id);
  var footer = document.getElementById(footerId);

  if(el && footer){    
    var winHt = getWindowHeight();
    var prop = winHt - (footer.offsetTop + footer.offsetHeight);
    el.style.height = prop + px;    
  }
}


function setEvalProp(id, reference, corr){
  var px = window.opera ? 0: "px";
  var el = document.getElementById(id);
  var rf = document.getElementById(reference);

  if(el && rf){    

	if(rf.offsetHeight > (el.offsetHeight+corr)){
    var rfHt = rf.offsetHeight+corr;
    el.style.height = rfHt + px;  
  } else {

	if(corr) corr=-5; /* q&d */

    var elHt = el.offsetHeight+corr;
    rf.style.height = elHt + px;  
  
  }
  
  }
}

/********************************************************
   Returns the browser's window height
 ********************************************************/
 
function getWindowHeight() {
  var winHt = 0;

  if (window.innerHeight)
    winHt = window.innerHeight - 10;
  else if (document.documentElement && document.documentElement.clientHeight)
    winHt = document.documentElement.clientHeight;
  else if (document.body && document.body.clientHeight)
    winHt = document.body.clientHeight;

  return winHt;
}

