// JavaScript Document

function GotoLocation(link){
 	DispWin = window.open(link,'Pwindow','width=630,height=450,toolbar=no,scrollbars=yes,resizable=yes,status=no,directories=no,location=yes,menubar=no,titlebar=no');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML += unescape(newText);
}

function passKeyword__OLD__ONE__(KeywordId,Keyword) {
	var test = document.form1.explorationKeywords.value;
	where = test.indexOf(Keyword);
	if(where == -1 || test == "") {
		document.form1.explorationKeywords.value += Keyword + " (" + KeywordId + ")\n";
	}
}

function passKeyword(keywordId,Keyword) {
	if( document.getElementById('extraKeywords') ) {
	 if(document.getElementById('extraKeywords').style.display == 'none') {
		document.getElementById('extraKeywords').style.display = 'block';
	 }
	
	 var rowText = Keyword + "&nbsp;<input type=checkbox name='explorationKeywords[]' value='" + keywordId + "' checked><br />";

	 MM_setTextOfLayer('extraKeywords','',rowText);
	}
	else {
	 var test = document.getElementById('explorationKeywords').value;
	 where = test.indexOf(Keyword);
	 if(where == -1 || test == "") {
		document.getElementById('explorationKeywords').value += Keyword + " (" + keywordId + ")\n";
	 }
	}
}

function passExplorer(explorationId,explorationName) {
	document.getElementById('indicatorRefExploreId').value = explorationId;
	document.getElementById('indicatorRefExploreName').value = explorationName;
}

function popUpMini(link){
 DispWin = window.open(link,'Mwindow','width=450,height=450,toolbar=no,scrollbars=yes,resizable=yes,status=no,directories=no,location=no,menubar=no,titlebar=no');
}

function isNumeric( objElement )
{ 
	var varElement = objElement.value ;
	if( varElement.length > 0 )
	{
		var varChar = varElement.slice( varElement.length - 1, varElement.length ) ;
		if( isNaN(parseInt(varChar)) )
		{
			alert("Only numbers (0-9) are allowed here.") ;
			varElement = varElement.slice(0,varElement.length-1) ;
			objElement.value = varElement ;
		}
	}
}

function getSelectValue( objSelect )
{
	var varValue = objSelect.options[objSelect.selectedIndex].value ;
	return varValue ;
}

// Return true if strText is empty or contains only spaces
function isBlank( strText )
{ 
	if( strText.length == 0 ) { return true ; }
	for( var intPos = 0 ; intPos < strText.length ; intPos ++ )
	{
		if( strText.charCodeAt(intPos) != 32 ) { return false ; }
	}
	return true ;
}

function submitCHK( objForm )
{ 

// Check name is entered
	if( objForm.explorationName.value.length < 1 || isBlank(objForm.explorationName.value) )
	{
		alert("Please enter a name for your Exploration.");
		objForm.explorationName.focus() ;
		return false ;
	}

// Check address is entered
	if( objForm.explorationColA.value.length < 1 || isBlank(objForm.explorationColA.value) )
	{
		if( objForm.explorationColB.value.length < 1 || isBlank(objForm.explorationColB.value) )
		{
			if( objForm.explorationColC.value.length < 1 || isBlank(objForm.explorationColC.value) )
			{
				if( objForm.explorationColD.value.length < 1 || isBlank(objForm.explorationColD.value) )
				{
					if( objForm.explorationColE.value.length < 1 || isBlank(objForm.explorationColE.value) )
					{
						if( objForm.explorationColF.value.length < 1 || isBlank(objForm.explorationColF.value) )
						{
							if( objForm.explorationFilter.value.length < 1 || isBlank(objForm.explorationFilter.value) )
							{
							alert("You must enter at least one formula into a column or filter.");
							objForm.explorationcolAName.focus() ;
							return false ;
							}
						}
					}
				}
			}
		}
	}
	
	var colArray = new Array('A','B','C','D','E','F')
	
	for( i = 0 ; i < colArray.length ; i ++ )
	{
		if( !isBlank(objForm.elements['explorationcol' + colArray[i] + 'Name'].value) )
		{
			if( isBlank(objForm.elements['explorationcol' + colArray[i]].value) )
			{
				alert("You have entered a name for Column " + colArray[i] + ", please enter a formula for this column.");
				objForm.elements['explorationcol' + colArray[i]].focus() ;
				return false ;
			}
		}
	}
	
}

function submitCHKind( objForm )
{ 

// Check name is entered
	if( objForm.indicatorName.value.length < 1 || isBlank(objForm.indicatorName.value) )
	{
		alert("Please enter a name for your Indicator.");
		objForm.indicatorName.focus() ;
		return false ;
	}

// Check address is entered
	if( objForm.indicatorNotes.value.length < 1 || isBlank(objForm.indicatorNotes.value) )
	{
		if( objForm.indicatorFormula.value.length < 1 || isBlank(objForm.indicatorFormula.value) )
		{
			alert("You must enter at least a formula or notes for this indicator.");
			objForm.indicatorFormula.focus() ;
			return false ;
		}
	}	
}

function submitCHKcontact( objForm )
{ 

// Check comment is entered
	if( objForm.Comment.value.length < 1 || isBlank(objForm.Comment.value) )
	{
		alert("Please enter a comment or question.");
		objForm.Comment.focus() ;
		return false ;
	}

// Check name is entered
	if( objForm.Contact_name.value.length < 1 || isBlank(objForm.Contact_name.value) )
	{
		alert("Please enter your name.");
		objForm.Contact_name.focus() ;
		return false ;
	}

// Check email is entered
	if( objForm.Contact_email.value.length < 1 || isBlank(objForm.Contact_email.value) )
	{
		alert("You must enter an email address.");
		objForm.Contact_email.focus() ;
		return false ;
	}	
}