// Core Javascript functions
function showBox(){
	$('local_overlay').show();
//  document.getElementById('local_overlay').style.display='block';
	center('local_box');
//	return false;
}

function hideBox(){
	$('local_box').hide();
	$('local_overlay').hide();
	return false;
}

function center(element){
    try{
    	element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement &&
			 ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body &&
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}

function showProcessbar() {
  var crossobj=document.all? document.all.processbar : document.getElementById('processbar');
  var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
  //define universal dsoc left point
  var dsocleft=document.all? iebody.scrollLeft : pageXOffset
  //define universal dsoc top point
  var dsoctop=document.all? iebody.scrollTop : pageYOffset

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

//override width/height
  myWidth = 1000;
  myHeight = 600;

  //if the user is using IE 4+ or Firefox/ NS6+
  if (document.all||document.getElementById){
    crossobj.style.left=parseInt(dsocleft)+(myWidth/2)+"px"
    crossobj.style.top=dsoctop+(myHeight/2)+"px"
  }

  document.getElementById('processbar').style.display='block';
}

function hideProcessbar() {
  document.getElementById('processbar').style.display='none';
}

function checkMailform() {
	document.getElementById('name').style.backgroundColor="#FFFFFF";
	document.getElementById('email').style.backgroundColor="#FFFFFF";
	var errs = 0;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	name = trim(name);
	email = trim(email);
	if (name.length < 5) {
		document.getElementById('name').style.backgroundColor="yellow";
		errs = errs + 1;
	}
	if (email.length < 5) {
		document.getElementById('email').style.backgroundColor="yellow";
		errs = errs + 1;		
	}
	if (! validateEmail(email)) {
		document.getElementById('email').style.backgroundColor="yellow";
		errs = errs + 1;
	}
	if (errs == 0) { return true }
	else { return false }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function validateEmail(emailAddr) {
	var atpos=emailAddr.indexOf("@");
	var dotpos=emailAddr.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=emailAddr.length)
		{
		return false;
		}
	return true;
}
