window.onresize = function() {
	checkheight();
	}
$(document).ready(function(){
	checkheight();
	setTimeout("checkheight()", 3000);
	setTimeout("checkheight()", 5000);
	$(".menu_link").mouseover(function() {
	var background = '#' + this.id + '_over';
	var img_bg = 'images/link_' + this.id + '_over.png';
	$(background).css({backgroundImage:"url(" + img_bg + ")"});
	});
	$(".menu_link").mouseout(function() {
	var background = '#' + this.id + '_over';
	$(background).css("background", "none");
	});
});

function checkheight() {
	var heightdiv = document.getElementById('content_div');
	var consultant = document.getElementById('consultant');
	var newtop = (heightdiv.offsetHeight - 218) + "px";
	consultant.style.top = newtop;
	var logo = document.getElementById('logo');
	var newleft = findPosX(logo) + 25;
	newleft = newleft + 'px';
	consultant.style.left = newleft;
	
	var menu_above = document.getElementById('menu_links_wrap');
	var newtop_menu = (233)  + 'px';
	menu_above.style.top = newtop_menu;
	newtop_menu = findPosX(logo) - 9  + 'px';
	menu_above.style.left = newtop_menu;
}

function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
  
function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function restore(id) {
		if(document.getElementById(id).value == 'Please fill in your name.' || document.getElementById(id).value == 'Please fill in e-mail.' || document.getElementById(id).value == 'Invalid email address!' || document.getElementById(id).value == 'Please fill in the subject' || document.getElementById(id).value == 'Please write your message here') {
			document.getElementById(id).value ='';
		}
	}
function checkform() {
	var name;
	var email;
	var subject;
	var message;
	var err_fields;
	var valid_email;
	name = document.getElementById('yourname').value;
	email = document.getElementById('youremail').value;
	subject = document.getElementById('emailsubject').value;
	message = document.getElementById('emailmessage').value;
	valid_email = echeck(email);
	
	
	if(name === '') { error('Please fill in your name.', 'yourname'); return false; }
	if(email === '') { error('Please fill in e-mail.', 'youremail'); return false;  }
	if (valid_email !== true) { error("Invalid email address!", 'youremail' ); return false; };
	if(subject === '') { error('Please fill in the subject', 'emailsubject'); return false;  }
	if(message === '') { error('Please write your message here', 'emailmessage'); return false;  }
	
	if(name !== '' && email !== '' && subject !== '' && message !== '') { return true; } 
	}
	function error(err, field) {
	var error_message;
	document.getElementById(field).value = err;
	return false;
	}
	function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return "Invalid e-mail address";
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return "Invalid e-mail address";
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return "Invalid e-mail address";
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return "Invalid e-mail address";
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return "Invalid e-mail address";
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return "Invalid e-mail address";
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return "Invalid e-mail address";
		 }

 		 return true					
	}
