
//draws date
function drawDate(){
	var d = new Date();
	var m = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var wd = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

	document.write(wd[d.getDay()] + ", " + m[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear());
}


//delete
function submitMessage(frm){

	if(frm.name.value.length == 0){
		alert("Please enter your name");
		frm.name.select();
		return false;

	}else if(frm.email.value == 0){
		alert("Please enter your email address");
		frm.email.select();
		return false;

	}else if(!isValidEmail(frm.email.value)){
		alert("Please enter a valid email address");
		frm.email.select();
		return false;
	
	}else if(frm.message.value.length == 0){
		alert("Please enter a message");
		frm.message.select();
		return false;
	
	}else{

		return true;
	}
}



//shows popup window
function popup(url, width, height, scroll){
	var left = (screen.width - width) /2;
	var top = (screen.height - height) / 2;	
	var scrl  = "no";
	
	if(scroll) scrl = "yes";

	var props = "height=" + height + ", width=" + width + ", top=" + top + ", left=" + left + ",scrollbars=" + scrl + ", resizable";

	window.open(url, "popup", props);

	return false;
}


//loads a press box
function loadPress(region, id){
	window.location = "press.php?r=" + region + "#press_" + id;
}


//selects color from color picker
function selectColor(color){
	var cpwindow = document.getElementById("cpwindow");
	document.frm.color.value = color.toUpperCase();
	document.frm.color.style.backgroundColor = "#"+color.toUpperCase();
	cpwindow.style.visibility = "hidden";
	return false;
}


//shows color picker
function showCP(){
	var cpwindow = document.getElementById("cpwindow");
	cpwindow.style.visibility = "visible";
	cpwindow.style.display = "block";
	return false;
}


function openwindow(url) {
	var options = 'scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no';
    options += ',width=' + screen.availWidth + ',height=' + screen.availHeight;
    options += ',screenX=0,screenY=0,top=0,left=0';
    var win = window.open(url, '', options);
    win.focus();
    win.moveTo(0, 0);
    win.resizeTo(screen.availWidth, screen.availHeight);
}


function isValidEmail(str){
	var regex = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\.\\w+([-.]\\w+)*");
			
	if(str.length > 0 && !regex.test(str)){
		return false;
	}else{
		return true;
	}
}



//
//
//  submenu functions
//
//

var hider;

function showSubMenu(obj){
	//return;

	var sub = document.getElementById("regionSubMenu");
	var pos = findPos(obj);
	
	sub.style.left= (pos.x - 3) + "px";
	sub.style.top = (pos.y + 19) + "px";
	sub.style.width = "200px";
	sub.style.textAlign = "left";
	sub.style.display = "";
}

function resetSubMenu(){
	hider = setInterval("closeSubMenu()", 100);
}

function refreshSubMenu(){
	clearInterval(hider);
}

function closeSubMenu(){
	document.getElementById("regionSubMenu").style.display = "none";
	clearInterval(hider);
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {x:curleft,y:curtop};
}
