var remote_win = null;

function openNewWindow(URL, windowName, windowFeatures) {
	newWindow=window.open(URL, windowName, windowFeatures);
}


var newWin = null;

function openIt(dat,Wwidth,Wheight,Wmenu) {

	LeftPosition = (screen.width) ? (screen.width-Wwidth)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-Wheight)/2 : 0;
	settings = 'width='+Wwidth+',height='+Wheight+',top='+TopPosition+',left='+LeftPosition+',scrollbars,resizable';

	if (Wmenu) {
		settings  = settings+',menubar';
	}

	newWin = window.open("","",settings);
	newWin.document.open();

	var _s ="";
	_s+="<html><body>";
	_s+="<form method=post name=frm action='http://www.call4abstracts.com/tools/spell.php'>";
	_s+="<TEXTAREA style=\"DISPLAY: none\"  rows=20 cols=75 WRAP=VIRTUAL name=\"content\">"+dat+"</TEXTAREA>";
	_s+="<"+"script>";
	_s+="document.frm.submit();";
	_s+="</"+"script>";
	_s+="</form>";
	_s+="</body></html>";
	newWin.document.write(_s);
	//newWin.document.close();
}


function IsEmailValid(FormName,ElemName)
{
	var EmailOk  = true
	var Temp     = document.forms[FormName].elements[ElemName]
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1
	var Invalid  = "Your e-mail address does not appear to be valid. Please make sure that your address contains the '@' symbol, that there are no spaces in your address and that you have only entered one address."

	// How many '@' signs are there
	var numOfAts = 0
	for(i = 0; i < Temp.value.length; i++){
		theChar = Temp.value.charAt(i);
		if(theChar == '@'){
			numOfAts = numOfAts + 1
		}
	}

	if ((AtSym < 1) ||                     // '@' cannot be in first position
	(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	(Period == Length ) ||             // Must be atleast one valid char after '.'
	(Space  != -1) ||                  // No empty spaces permitted
	(numOfAts > 1))                    // No more than one '@' sign
	{
		EmailOk = false
		alert(Invalid)
		Temp.focus()
	}
	return EmailOk
}


function checkForBadChars(args) //Can take one or more textareas as arguments
{
	if(parseInt(navigator.appVersion) >= 4 ) //charCodeAt is only supported in the 4.0 browsers
	{
		var theOutput = "";
		var openSpan = "<SPAN STYLE='background-color: yellow'>";
		var closeSpan = "</SPAN>";
		var dataIsOk = true;

		for(var j = 0; j < arguments.length; j++)
		{
			theOutput = theOutput + "<P>"; //Separate each textarea in the preview
			var theText = arguments[j].value;

			for(var i = 0; i < theText.length; i++)
			{
				var theChar = theText.charAt(i);
				var theCharCode = theText.charCodeAt(i);
				if(theCharCode > 127)
				{
					theOutput = theOutput + openSpan + theChar + closeSpan;
					dataIsOk = false;
				}
				else
				{
					theOutput = theOutput + theChar;
				}
			}
		}

		if(!dataIsOk)
		{
			var docHead = "<HTML><HEAD><TITLE>Character Errors</TITLE></HEAD><BODY BGCOLOR='#ffffff' onBlur='window.close();'>";
			var alertMsg = "<FONT COLOR='red'><H2><I>Submission Error</I></H2></FONT><P><I>The submission program does not recognize the characters highlighted in <SPAN STYLE='background-color: yellow'>yellow</SPAN>.</I></P>" +
			"<P><I>All special characters, such as '&#177;', and Greek characters, such as '<FONT FACE='Symbol'>a</FONT>', must be entered using the special bracket codes from the list of supported special characters.</I></P><P><I>You wrote:</I></P></I>";
			var openBlock = "<BLOCKQUOTE>";
			var closeBlock = "</BLOCKQUOTE>";
			var closeLink = "<BR><BR><CENTER><A HREF='javascript:window.close();'>Close window</A></CENTER>";
			var docFoot = "</BODY></HTML>";

			window.open("../conversions.php","conversions","scrollbars,resizable,height=350,width=600");
			var window2 = window.open("","errorwindow","width=600,height=450,scrollbars");
			window2.document.open();
			window2.document.write(docHead + alertMsg + openBlock + theOutput + closeBlock + closeLink + docFoot);
			window2.document.close();
			return false;
		}
		else
		{
			return true;
		}
	}
}


function checkCCNum(){

	var ccnum = document.ccform.cc_number.value;
	numIsGood = true;

	for(var i = 0; i < ccnum.length; i++){

		var item = ccnum.charAt(i);
		if(isNaN(item) || item == " ") {
			numIsGood = false
		}
	}

	if(!numIsGood){

		alert("Please enter only numbers in this field (do not enter spaces or other non-numeric characters).");
		document.ccform.cc_number.focus();
		return false;
	}
}


function remote(URLpage,URLtitle,Wheight,Wwidth,Wmenu){

	LeftPosition = (screen.width) ? (screen.width-Wwidth)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-Wheight)/2 : 0;
	settings = 'width='+Wwidth+',height='+Wheight+',top='+TopPosition+',left='+LeftPosition+',scrollbars,resizable';
	if (Wmenu) {
		settings  = settings+',menubar';
	}
	remote_win = window.open(URLpage,URLtitle,settings)
}

function SelectOption ( where,which ){
	var f = document.DataForm;

	for ( i = 0; i < f.elements.length; i++ ){
		orderElement = f.elements[i];
		if ( orderElement.name == where ){
			for ( var j=0; j<orderElement.length; j++ ){
				if (eval(orderElement.options[j].value==which)){
					orderElement.options[j].selected = true;
				}
			}
		}
	}
}

function presCheck ( ){
	var f = document.DataForm["au_pres"];
	if (f!=null){
		for ( i = 0; i < f.length; i++ ){
			f[i].checked = false;

		}
	}
}


function DataChange(DirtyValue){
	document.DataForm.Dirty.value=DirtyValue;
}

function SubmitServiceType2(display,tablenum)
{
	var table=document.getElementById("table"+tablenum); //alert(document.getElementById("table2"));
	if(display)
	{
		table.style.display="";
	} else  {
		table.style.display="none";
	}
}

