var sent_form = false;
var my_win = false;

function BlockDblSubmit() {
	if (sent_form) {
		return false;
	} else {
		sent_form = true;
		return true;
	}
}

function _confirm(message, href) {
	if (!sent_form) {
		if (confirm(message)) {
			sent_form = true;
			window.location.href=href;
		}
	}
}

function openWin(url, id, width, height, scrollbar, focused) {
	if (height > screen.height-80) {
		ts = 0;
		height = screen.height - 80;
	} else {
		ts = Math.round((screen.height-height)/2-50);
	}
	ls = Math.round((screen.width-width)/2);
	params = "width="+width+",height="+height+",top="+ts+",left="+ls+",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars="+scrollbar;
	var my_win = window.open(url, id, params);
	if (my_win.opener == null) my_win.opener = self;
	if (focused!=0)
		my_win.focus();
	return my_win;
}

function isNatural(num) {
	if (num == 'NaN')
		return false;
	
	var pattern = /^\d+$/;
	return (!num || !pattern.test(num) ? false : true);
}

function isDecimal(num) {
	var pattern = /^\d+\.?\d*$/;
	return (!num || !pattern.test(num) ? false : true);
}

function isValidEmail(email) {
	var pattern = /^[\w\.\-]+\@[\w\.\-]+\.[0-9a-z]{2,}$/i;
	return (pattern.test(email) ? true : false);
}

function isValidURL(url) {
	var pattern = /^https?\:\/\/[\w\.\-]+\.[0-9a-z]{2,6}[\w\.\-\&\%\#\/\?\=\~\@]*$/;
	return (pattern.test(url) ? true : false);
}

function changeBgColor(row) {
	row.className = (row.className=='dark' ? 'light' : 'dark');
}

function checkForPattern(pattern, value) {
	if (!pattern) return false;
	eval("_pattern = "+pattern+";");
	return _pattern.test(value);
}

function gotoAnchor(anchor) {
	document.location.replace(anchor);
	return false;
}

function gotoTop() {
	scrollTo(0,0);
	return false;
}

var logformshow=false;
sw=screen.width;
left_pos = Math.round(sw/2)+170;
function showloginform () {
	if (logformshow==false) {
		document.getElementById("custlogin").style.display = "block";
		document.getElementById("custshadow").style.display = "block";
		document.getElementById("custshadow").style.left=left_pos+'px';
		document.getElementById("custlogin").style.left=left_pos+'px';
		logformshow=true;
	} else {
		document.getElementById("custshadow").style.display = "none";
		document.getElementById("custlogin").style.display = "none";
		logformshow=false;
	}
}

function suggestiontext (focus) {
	default_text = " type here and get keyword suggestion...";
	searchfield=document.getElementById("fq");
	if (searchfield.value==default_text && focus==true) {
		searchfield.style.color="#000000";
		searchfield.value="";
	} else if (searchfield.value=="" && focus==false) {
		searchfield.style.color="#aaaaaa";
		searchfield.value=default_text;
	}
}



function collapse_expand(mess_id, expand) {
	if (expand) {
		document.getElementById(mess_id+"_collapsed").style.display = "none";
		document.getElementById(mess_id+"_expanded").style.display = "block";
		document.getElementById(mess_id).style.display = "block";
	} else {
		document.getElementById(mess_id+"_collapsed").style.display = "block";
		document.getElementById(mess_id+"_expanded").style.display = "none";
		document.getElementById(mess_id).style.display = "none";
	}
}

function check_logindata() {
	var x,m,d,y,eml,mdays,errors;
	errors=0; eml='';
	mdays=new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
	x=document.getElementById('loginemail');	if (x) eml=x.value; else errors=1;
	x=document.getElementById('m');	if (x) m=parseInt(x.value); else errors=1;
	x=document.getElementById('d');	if (x) d=parseInt(x.value); else errors=1;
	x=document.getElementById('y');	if (x) y=parseInt(x.value); else errors=1;
	if (!isValidEmail(eml))
		errors=1;
	else if (m<1 || m>12 || d<1 || d>mdays[m] || y<1900)
		errors=1;
	else if (m==2 && d==29 && ((y-4*Math.floor(y/4))>0.5))
		errors=1;
	if (errors) {
		x=document.getElementById('signinerror');
		if (x) x.style.display='block';
		return false;
	}
	return true;
}