var remote_win = null;
var IE4 = (document.all) ? true : false;
var NS4 = (document.layers) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;

var IEwiz = 0;
var Sent = 0;

function pagechange(GOTOpageValue) {

	var param_name = "tid";

	document.dataform.tid.value= GOTOpageValue;	

	if (Sent == 0 && document.dataform.dirty.value != "") {
		document.dataform.submit();
		Sent = 1;
	} else {
		
		if (document.dataform.popup_doc){
  			param_name = "popup_doc";
		}
		
		window.location = "index.php?" + param_name + "=" + GOTOpageValue;
	}

}

function DataChange(DirtyValue){
	document.dataform.dirty.value = DirtyValue;
}

function writetoforiegnlayer(field,txt) {
    
	if (IE4) {
		window.opener.document.dataform.all[field].innerHTML = txt;
	}

	if (NS4) {
		window.opener.document.dataform.layers[field].document.write(txt);
		window.opener.document.dataform.layers[field].document.close();
	}

	if (NS6) {
		over = window.opener.document.getElementById(field);
		range = window.opener.document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
  }

  
}

function writelayer(lay,txt) {


	if (IE4) {
		document.all[lay].innerHTML = txt;
	}

	if (NS4) {
		
		document.layers[lay].document.write(txt);
		document.layers[lay].document.close();
	}

	if (NS6) {
	
		var elm = document.getElementById([lay]);
		elm.setAttribute('innerHTML',''); 
		elm.setAttribute('innerHTML',txt); 
		
	
		//elm.setAttribute('nodeValue',txt);
		var range = document.createRange();
		range.setStartBefore(elm);
		var domfrag = range.createContextualFragment(txt);
		//alert(domfrag);
		while (elm.hasChildNodes()) {
			elm.removeChild(elm.lastChild);
		}
		elm.appendChild(domfrag);
		
   	}
}


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 remote2v(URLpage,URLtitle,Wheight,Wwidth,Wmenu,Wresize){

 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=no';
 if (Wmenu) {
  settings  = settings+',menubar=yes';
 }
 
 	if (Wresize) {
 	settings  = settings+',resizable=yes';
	} else {
			settings  = settings+',resizable=no';
	}
  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 Presentation() {

	NewWindow=window.open("../Presentation.php","Presentation","scrollbars,resizable,height=350,width=600");
	}
function Award() {
	NewWindow=window.open("../Awards.php","Awards","scrollbars,resizable,height=350,width=700");
	}

function CatCheck()
{
   var Cat = document.dataform.cat1;

   if  (Cat.value == 0 && Cat.value != 0.1 )
   	{
     	 alert("You have selected a category heading. Please select one of the lines that doesn't start with a number.");
     	 Cat.value = 0.1;

   }
 }


function writetoforeignlayer(field,txt) {
    
	if (IE4) {
		window.opener.document.dataform.all[field].innerHTML = txt;
	}

	if (NS4) {
		window.opener.document.dataform.layers[field].document.write(txt);
		window.opener.document.dataform.layers[field].document.close();
	}

	if (NS6) {
		over = window.opener.document.getElementById(field);
		range = window.opener.document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
  }

  
}

function writelayer(lay,txt) {

	if (IE4) {
		document.all[lay].innerHTML = txt;
	}

	if (NS4) {
		
		document.layers[lay].document.write(txt);
		document.layers[lay].document.close();
	}

	if (NS6) {
	
		var elm = document.getElementById(lay);
		elm.setAttribute('innerHTML',''); 
		elm.setAttribute('innerHTML',txt); 
		
	
		//elm.setAttribute('nodeValue',txt);
		var range = document.createRange();
		range.setStartBefore(elm);
		var domfrag = range.createContextualFragment(txt);
		//alert(domfrag);
		while (elm.hasChildNodes()) {
			elm.removeChild(elm.lastChild);
		}
		elm.appendChild(domfrag);
		
   	}
}

/* -------------------------------- Toggle Stylesheets with title ------------------------------------------------- */
// function for changing stylesheets using document.styleSheets
function setStyleSheet(css_title) {
	for ( i = 0; i < document.styleSheets.length; i++ ) {
	  if ( document.styleSheets[i].title ) {
	  		document.styleSheets[i].disabled = true;
	    if ( document.styleSheets[i].title == css_title ){
	      	document.styleSheets[i].disabled = false;
	    }
	  }
	}
}

function removeObjectsFromList(obj) {
	var lgth = obj.options.length;
	for (i = 0; i < lgth; i++) {
		obj.options[0] = null;
	}
	obj.options.length = 0;
}

function addOptionToSelectList(win,obj,text,value,selected) {
	var found = 0;
	if (obj!=null && obj.options!=null) {
		if(IE4){
			var opt = win.document.createElement('option');
			var opt_txt = win.document.createTextNode(text);
			opt.appendChild(opt_txt);
			opt.setAttribute("value", value);
			obj.appendChild(opt);
		} else {
			obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
	}
}