
function LoadPopup(doc, name, w, h, scroll) {
	if (!w) w=820;
	if (!h) h=600;
	if (!doc) doc = "about:blank";
	if (!scroll) scroll = 0;
	if (!name || name=='') {
		var tmp = new Date();
		name = "dm_"+tmp.getTime();
	}
	var win = window.open(doc, name,  'status=yes,toolbar=0,scrollbars='+scroll+',menubar=0,titlebar=0,resizable=1,width='+w+',height='+h);
	if (win) {
		win.moveTo(screen.width/2-w/2, screen.height/2-h/2);
		win.focus();
	} else {
		popup_alert();
	}
}

function popup_alert() {
	init();
	if (confirm (popup_msg)) {
		document.location = popup_goto;
	}
}

function ClosePopup(doc) {
	if(win)	win.close();
	document.location = doc;
}

function focusElem(obj, str)
{
 if (obj.value == str) obj.value = "";
 return true;
}


function SetVisible(ce) {
	var elem;
	for (var i=0; i<SetVisible.arguments.length; i++) {
		elem = document.getElementById(SetVisible.arguments[i]);
		elem.style.visibility = "visible";
	}
}

function SetInvisible() {
	var elem;

	for (var i=0; i<SetInvisible.arguments.length; i++) {
		elem = document.getElementById(SetInvisible.arguments[i]);
		elem.style.visibility = "hidden";
	}
}

function Disable() {
	var form;
	form = Disable.arguments[0];
	for (var i=1; i<Disable.arguments.length; i++) {
		document.forms[form][Disable.arguments[i]].disabled = true;
	}
}

function Enable() {
	var form;
	form = Enable.arguments[0];
	for (var i=1; i<Enable.arguments.length; i++) {
		document.forms[form][Enable.arguments[i]].disabled = false;
	}
}


function togglePlayer(div_ref, div2_ref)
{
	hza = document.getElementById(div_ref);
	hzb = document.getElementById(div2_ref);

	hma = document.getElementById('player_m_cv');
	hmb = document.getElementById('player_m_gim');
	if (hza.style.display == 'block')
	{
		hza.style.display = 'none';
		hzb.style.display = 'block';
		hmb.className = 'gunnar_in_the_morning_player_active';
		hma.className = 'candidates_videos_player';
	}
	else
	{
		hza.style.display = 'block';
		hzb.style.display = 'none';
		hma.className = 'candidates_videos_player_active';
		hmb.className = 'gunnar_in_the_morning_player';
	}
}
function togglePlayerP(div_ref, div2_ref)
{
	hza = document.getElementById(div_ref);
	hzb = document.getElementById(div2_ref);

	hma = document.getElementById('p_player_m_cv');
	hmb = document.getElementById('p_player_m_reuters');
	if (hza.style.display == 'block')
	{
		hza.style.display = 'none';
		hzb.style.display = 'block';
		hmb.className = 'p_reuters_player_active';
		hma.className = 'p_candidates_videos_player';
	}
	else
	{
		hza.style.display = 'block';
		hzb.style.display = 'none';
		hma.className = 'p_candidates_videos_player_active';
		hmb.className = 'p_reuters_player';
	}
}
function showDiv(div_ref) {

	state = 'block';
	hza = document.getElementById(div_ref);
	if (hza==undefined) return 0;
	hza.style.display = state;

}

function hideDiv(div_ref) {
	state = 'none';
	hza = document.getElementById(div_ref);
	if (hza==undefined) return 0;
	hza.style.display = state;
}

function DeleteAllOptions(formname, selectname) {
	document.forms[formname].elements[selectname].options.length = 0;
}

function AddOption(formname, selectname, text, val) {
  var obj=document.forms[formname].elements[selectname];
  var length= obj.options.length;
  obj.options[length]= new Option (text,val,false,false);
}

function is_empty(val) {
	str_empty = "\\s*";
	pcre_empty = new RegExp("^"+str_empty+"$");
	return pcre_empty.test( val );
}

function is_alphanumeric(string, ignoreWhiteSpace) {
	if (string.search) {
		if ((ignoreWhiteSpace && string.search(/[^\w\s]/)!=-1) ||
			(!ignoreWhiteSpace && string.search(/[\W]+/) != -1)) return false;
	} else {
		return false;
	}
	return true;
}

function is_url(string)
{
	if (string.match("http") || string.match("www\.")){
		{
			return true;
		}
	}
	return false;
}

function is_email(field) {
	var good;
	var goodEmail = field.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	if (goodEmail){
   		return true;
	}
	return false;
}

function is_numeric(field) {
	var charpos = field.search("[^0-9]");
	if(field.length > 0 && charpos >= 0) {
		return false;
	}
	return true;
}

function checkEmail(field, msg) {
	if (!is_email(field)) {
		alert(msg);
		return false;
	}
	return true;
}

