function getHeight() {
        var wh = 0;
        if (typeof(window.innerHeight)=="number") {
                wh = window.innerHeight;
        }
        else {
                if (document.documentElement && document.documentElement.clientHeight) {
                        wh = document.documentElement.clientHeight;
                }
                else {
                        if (document.body && document.body.clientHeight) {
                                wh = document.body.clientHeight;
                        }
                }
        }
        return wh;
} 

function getWidth() {
        var wh = 0;
        if (typeof(window.innerWidth)=="number") {
                wh = window.innerWidth;
        }
        else {
                if (document.documentElement && document.documentElement.clientWidth) {
                        wh = document.documentElement.clientWidth;
                }
                else {
                        if (document.body && document.body.clientWidth) {
                                wh = document.body.clientWidth;
                        }
                }
        }
        return wh;
} 
 
function launchExtWindow(url,title,h,w, name){
// Bookmark is a boolean variable that defaults to false.  When set to true, a button will be 
// created at the footer of the window to bookmark the URL that was sent.
	var browser_h = getHeight();	
	var browser_w = getWidth();	
	
	if(h == undefined){
		var h = browser_h - 50;
	}
	
	if(w == undefined){
		var w = browser_w - 50;
	}	
	
	if (name == undefined) {
		var randomnumber=Math.floor(Math.random()*1001)
		var winid = 'win' + randomnumber;	
		var iframeid = 'if' + randomnumber;	
	} else {
		var winid = name;
	}
	
	//if the height of the window is greater than that of the browser, resize the window and maintain the proportions.
	if(h >= browser_h){
		var ratio = (browser_h-50)/h;
		h = browser_h - 50;
		w = Math.round(ratio*w)-1;
	}

	wleft = w / 2;
	wtop = h / 2;
	launchwin = new Ext.Window(
                       {id:winid,
					   title:title,
					   width:w,
					   height:h,
					   resizable:true,
					   modal:true,
					   iconCls: '',//iconUpload
					   autoScroll:true,
					   autoLoad:{url:url, scripts:true}, 
					  	tools:[{id:'print',
								qtip: 'Print Abstract',
								handler: function(event, toolEl, panel){
									// print login
									//Since you cannot print directly from the ext. window. Here is a workaround.
									var win = window.open('','','location=0,status=0,scrollbars=0,toolbar=1,width=25,height=25');
										win.blur();//Then, takes the window out of focus
									    win.moveTo(wleft, wtop);  //Move to center										
										win.document.write(Ext.WindowMgr.getActive().body.dom.innerHTML); //Writes contents of EXT window to Browser win.
										win.print(); //Prints
										win.close(); //closes window.
								}
							}]
                       }
               ).show(); 
	
	}


function AddAbstract(action_url, div, load_url, em_id) {
var RegEx = /true/;
	 Ext.Ajax.request({url:action_url,method: 'GET'  
				,success: function (result, request) { 
					var searchValue = result.responseText.search(RegEx);
					if (searchValue != -1){
						document.getElementById('add_' + em_id).innerHTML = 'Abstract Added';
						document.getElementById('blank_' + em_id).innerHTML = '';
						reload_div(load_url, div);
					} else  {
						Ext.MessageBox.alert('Failed', 'Sorry, Abstract cannot be added to session. <br>You have reached your limit.'); 
					}
				}
	  ,failure: function ( result, request) { 
				Ext.MessageBox.alert('Failed', result.responseText); 
				} 
	  });
}

function shut() {
	Ext.WindowMgr.get('WinSessionEvents').destroy();
}

function load_ext (showMe_ID, url, div) {
	//Set Image Variables
	
	var showImg1 = Ext.get(showMe_ID +'_a');
	var showImg2 = Ext.get(showMe_ID +'_b');
	var loader = Ext.get(div);
	
	//Make all this a JS function ~ make sure YOUR path is correct!!
	Ext.BLANK_IMAGE_URL = '/ext-2.1/resources/images/default/s.gif';

	//this runs on DOM load - you can access all the good stuff now.
	Ext.onReady(function() {
		
	//simple function to slide text up and down and optionally hide..
	var slideText = function(direction,element){
	
	//ShowMe: This is the div that will display the new content.
	var showMe = Ext.get(element);
		 
			switch(direction){
				//determine the direction of travel
				case 'up' :
						//lets check to see if this is visible and if not then its already hidden :)
						if (showImg1.isVisible()) {
							//if we get here then the element is visible
							showMe.load({url: url,scripts: true, callback:callback}); //
							showMe.slideIn('t', {easing: 'easeOut',duration: .5,useDisplay: true });
						}
					break;
				case 'down' :
						//lets check to see if this is visible and if it is then we do nothing :)
						if (showImg2.isVisible()) {
							//if we get here then the element is visible
							showMe.slideOut('t', {easing: 'easeOut',duration: .5,remove: false,useDisplay: true});
						}		
					break;
				default :
					//the default action is simply to toggle the element
					showMe.toggle();
					break
			}
		//ends the slider function	
	}
	
		var callback = function(){
				loader.unmask();
		}
		
		
		Ext.get(showMe_ID +'_a').on( 'click',function(e,t){
			slideText('up', showMe_ID);
			Ext.get(t.id).frame('0000FF',1);
			showImg1.setDisplayed(false);
			showImg2.setDisplayed(true);
			loader.mask('Loading Abstracts');	
		});
		
		Ext.get(showMe_ID +'_b').on('click',function(e,t){
			//simple toggle of this element
			slideText('down', showMe_ID);
			Ext.get(t.id).frame('0000FF',1);
			showImg1.setDisplayed(true);
			showImg2.setDisplayed(false);
		});
		
		//alert('END- DOWN  (IMAGE ONE)' + showImg1.isVisible() + ' (IMAGE TWO) ' + showImg2.isVisible());
	});
	
	
}

function turnoff (tab) {
	var turnoffURL = 'index.cfm?fuseaction=home.TurnOFFTabs&tabs='+tab;
	Ext.Ajax.request({url:turnoffURL,method: 'GET' ,success: function (result, request) {}
	  ,failure: function ( result, request) {Ext.MessageBox.alert('Failed', result.responseText); } 
	});
}


function loadPageDiv (div, url, swap) {
	var showPage = Ext.get(div);
		showPage.mask('Loading');	
		showPage.load({url:url,scripts:true,callback:callback});
		
		//Call back function
		var callback = function(){
			showPage.unmask();
		}
		
		//If swap string exists, execute the following.
		if (swap != undefined) {
			Ext.onReady(function() {
			var showImg1 = Ext.get(div +'_a');
			var showImg2 = Ext.get(div +'_b');
			
			showImg1.setDisplayed(false);
			showImg2.setDisplayed(true);
			});
		}
	
}




function Submit_popup(form, status){
	if (form.criteria.value == "" || form.criteria.value == null) {
		Ext.MessageBox.alert('Alert:' , 'Please provide a search term to proceed.'); 
		return false;
	} else {
		if (status == '') {
			var load_url = 'index.cfm?fuseaction=abstract.popupsearchResults&ptt_id=10&criteria='+form.criteria.value +'&am_group=' + form.am_group.value; 
			return launchExtWindow(load_url,'Search Results',480,640);
		}else {
			var load_url = 'index.cfm?fuseaction=abstract.popupsearchResults&ptt_id=10&criteria='+form.criteria.value +'&am_group=' + form.am_group.value + 
							'&parent_code='+form.parent_code.value; 
			return launchExtWindow(load_url,'Search Results',480,640);
		}
			
	}
}


function launchIEWindow (url) {
	var win = window.open(url,'','location=0,status=0,scrollbars=1,toolbar=0,width=850,height=600');
		win.focus();
		win.print();
}

function ValidatePrint(form, url){
	var em_id_List = "&prints=";
	var hasChecked = false;
		for(var i=0; i<form.prints.length; i++){
			if (form.prints[i].checked){
				em_id_List = em_id_List + form.prints[i].value + ",";
				hasChecked = true;
			}
		}
		if (hasChecked == false){
			Ext.MessageBox.alert('Alert:' , "You must select at least 1 abstract to print");
			return false;
		}
		
		if (hasChecked == true){
			var em_list =  Left(em_id_List, String(em_id_List).length-1);
			var load_url = url + em_list;
				if (navigator.appName == "Microsoft Internet Explorer") {
					return launchIEWindow (load_url);
				} else {
				   return launchExtWindow(load_url,'Print Selected',480,640); 
				}
		}
		
	
}

function UncheckSubPrint(form){
		//alert(form);
		var myform = eval('document.' + form );
		//alert(myform.print.length);
		for(var i=0;i< myform.prints.length;i++){
		if (myform.prints[i].checked){
			myform.prints[i].checked = false;
		}//end if
	}//end for
	

}//end UncheckSubPrint

function CheckSubPrint(form){
		
		var myform = eval('document.' + form );
		//alert(myform.prints.length);alert(myform.prints[0].value);
		
		for(var i=0; i< myform.prints.length; i++){
		
		if (!myform.prints[i].checked && !myform.prints[i].disabled){
			myform.prints[i].checked = true;
		}//end if
	}//end for
	

}//end UncheckSubPrint

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
    }
}

function relaunchWindow (url, title) {
	//Destroy current window
	Ext.WindowMgr.getActive().destroy();
	
	//Relaunch New window
	launchExtWindow(url, title ,650,800);
}


function address_detail(customer){
	var  addressdetail ='index.cfm?fuseaction=submission.popupaddressdetail&customer=' +customer;
	launchExtWindow(addressdetail,'Address Detail' ,220,400);
}

function SessionTitleEdit(session){
	var page_url = 'index.cfm?fuseaction=abstract.popupEditSession&session_num=' + session;
		launchExtWindow(page_url,'Rename Session Title',275,665);
	}
	
function ContentCodeTitle(session) {
	var page_url = 'index.cfm?fuseaction=abstract.popupAddContentCode&session_num=' + session;
	launchExtWindow(page_url,'CME Content Codes',400,1000);
}
function printSession(session){
	var page_url = 'index.cfm?fuseaction=abstract.popupPrintSession&session_num=' + session;
		if (navigator.appName == "Microsoft Internet Explorer") {
			launchIEWindow (page_url);
		} else {
			 launchExtWindow(page_url,'Print Session',600,800);
		}
		
	}

function popAddModerator(session){
	var page_url = 'index.cfm?fuseaction=abstract.popupChairpersonfind&session_num=' + session;
		launchExtWindow(page_url,'Add Moderators',650,800);
}

function popBoomarks(em_id){
var page_url = 'index.cfm?fuseaction=home.popupBookmark&em_id=' + em_id;
	launchExtWindow(page_url,'Add Bookmark',375,635);
}

function openImgPreview(em_id, ab_id) {
	var page_url = 'index.cfm?fuseaction=grade.ExtpopImage&em_id='+em_id +'&ab_id='+ab_id;
	launchExtWindow(page_url,'Image Fullview',800,800);
}

function printSingle(area_group,parent_code,child_code,em_id){
 var single_url = 'index.cfm?fuseaction=reports.popupPrintAbstracts&printwhat=all&ptt_id=10&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code + '&em_id=' + em_id;


	if (navigator.appName == "Microsoft Internet Explorer") {
		launchIEWindow (single_url);
	} else {
		 launchExtWindow(single_url,'Print Selected',480,640);
	}
}

function printAbstractSingle(em_id,ptt_id){
var page_url = '#request.self#?fuseaction=reports.popupPrintAbstracts&printwhat=notassigned&em_id=' + em_id + '&ptt_id=' + ptt_id;
		if (navigator.appName == "Microsoft Internet Explorer") {
			launchIEWindow (page_url);
		} else {
			launchExtWindow(page_url,'Print All Abstracts',600,800);
		}
}


function printSubUngraded(area_group,parent_code,child_code, ptt_id){
var page_url = 'index.cfm?fuseaction=reports.popupPrintAbstracts&printwhat=ungraded&ptt_id='+ptt_id + '&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code;

	if (navigator.appName == "Microsoft Internet Explorer") {
		launchIEWindow (page_url);
	} else {
		launchExtWindow(page_url,'Print All Abstracts',600,800);
	}

}

function printSubAll(area_group,parent_code,child_code, ptt_id){
var page_url = 'index.cfm?fuseaction=reports.popupPrintAbstracts&printwhat=all&ptt_id='+ptt_id + '&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code;
	
	if (navigator.appName == "Microsoft Internet Explorer") {
		launchIEWindow (page_url);
	} else {
		launchExtWindow(page_url,'Print All Abstracts',600,800);
	}
}

function printUngraded(area_group,parent_code,child_code){
var page_url = 'index.cfm?fuseaction=reports.popupPrintAbstracts&printwhat=ungraded&ptt_id=3&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code;

if (navigator.appName == "Microsoft Internet Explorer") {
		launchIEWindow (page_url);
	} else {
		launchExtWindow(page_url,'Print All Abstracts',600,800);
	}
}

function printAbstractSession(em_id,ptt_id){
	
	var page_url = 'index.cfm?fuseaction=reports.popupPrintAbstracts&printwhat=selected&prints=' + em_id + '&ptt_id=' + ptt_id;

	if (navigator.appName == "Microsoft Internet Explorer") {
		launchIEWindow (page_url);
	} else {
		launchExtWindow(page_url,'Print All Abstracts',600,800);
	}
}

function printAll(area_group,parent_code,child_code){ 
var page_url = 'index.cfm?fuseaction=reports.popupPrintAbstracts&printwhat=all&ptt_id=3&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code;

if (navigator.appName == "Microsoft Internet Explorer") {
		launchIEWindow (page_url);
	} else {
		launchExtWindow(page_url,'Print All Abstracts',600,800);
	}
}


function blindGrade(setting){
var page_url = 'index.cfm?fuseaction=home.popupBlind&blind_grade=' + setting;

launchExtWindow(page_url,'Blind Grade',150,300);
}



function popDetail(area_group,parent_code,child_code){

var IE_url = 'index.cfm?fuseaction=home.popupDetail&ptt_id=10&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code +'&scripts=y';
var ext_url = 'index.cfm?fuseaction=home.popupDetail&ptt_id=10&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code;

if (navigator.appName == "Microsoft Internet Explorer") {
		var win = window.open(IE_url,'','location=0,status=0,scrollbars=1,toolbar=0,width=800,height=600');
	} else {
		launchExtWindow(ext_url,'Abstracts' ,600,900);
	}
}

function popGrader(area_group,parent_code,child_code, ptt_id){
var page_url = 'index.cfm?fuseaction=grade.ExtpopProgress&area_group=' + area_group + '&parent_code=' + parent_code + '&child_code=' + child_code + '&ptt_id='+ ptt_id;

launchExtWindow(page_url,'Grade Progress',600,800);
}


function toggle(div, imgswap){
	var showMe = Ext.get(div);
	
	if (imgswap != undefined ) {
		var showImg1 = Ext.get(div +'_a');
		var showImg2 = Ext.get(div +'_b');
	}
	
	 Ext.onReady(function() {
		//Set the DIV to toggle
		showMe.toggle();
		
		//Set the commands to invisible/visible states
		if (showMe.isVisible()) {
				//if we get here then the element is invisible
				showMe.slideIn('t', {easing: 'easeOut',duration: .5,useDisplay: true });
				if (imgswap != undefined) {
					showImg1.setDisplayed(false);
					showImg2.setDisplayed(true);
				}
			}
		if (!showMe.isVisible()) {
				//if we get here then the element is visible
				showMe.slideOut('t', {easing: 'easeOut',duration: .5,remove: false,useDisplay: true});
				if (imgswap != undefined) {
					showImg1.setDisplayed(true);
					showImg2.setDisplayed(false);
				}
			}
	 }); 
}




function executeJavascript(divid){
	try{
	//alert(divid);
	var d=document.getElementById(divid).getElementsByTagName("script");
	//if(d.length > 0){alert(d.length);}
	for(var x=0;x<d.length;x++) {
		//with(window) {
			eval(d[x].text);
		//}// end with
	}// end for		
	}catch(e){}
}
					
					
function checkField(theform, divID) {
var hasChecked = false;
var hasImgChecked = false;
		//Check if a grade has been selected. 
		for(var i=0; i<theform.abstractGrade.length; i++){
			if (theform.abstractGrade[i].checked){
				hasChecked = true;
			}
		}
		
		//Check if image has been selected. 
		if (theform.abstractImage != undefined) {
			for(var i=0; i<theform.abstractImage.length; i++){
				if (theform.abstractImage[i].checked){
					hasImgChecked = true;
				}
			}
		}
		
		if ((!hasChecked) && (!theform.abstractConflict.checked) && (!theform.abstractTransfer.checked) && (!theform.abstractDuplicate.checked) ) {
			Ext.MessageBox.alert('Alert:' , 'Please select a grade'); 
			return  false;
		} else if (theform.abstractImage != undefined) {
			if ((!hasImgChecked) && (!theform.abstractTransfer.checked) && (!theform.abstractDuplicate.checked)) {
				Ext.MessageBox.alert('Alert:' , 'Please indicate if the image influenced your grade.'); 
				return  false;
			} else  {Ext.get(divID).mask('Grading Abstract');
					return  SubmitForm(theform, divID); }
		} else if (theform.abstractTransfer.checked) {
			if ((theform.abstractComments.value == "") || (theform.abstractComments.value == null)) {
				Ext.MessageBox.alert('Alert:' , 'You must provide comments about the transfer.'); 
				return false;
			} else  {Ext.get(divID).mask('Grading Abstract As Transfer');
					return  SubmitForm(theform, divID); }
		} else if (theform.abstractDuplicate.checked) {
			if ((theform.abstractComments.value == "") || (theform.abstractComments.value == null)) {
				Ext.MessageBox.alert('Alert:' , 'You must provide comments about the duplicate.'); 
				return false;
			} else  {Ext.get(divID).mask('Grading Abstract As Duplicate');
				return  SubmitForm(theform, divID);  }
		} else {
			Ext.get(divID).mask('Grading Abstract');
			return  SubmitForm(theform, divID);
		}						
}

function checkGradeField(theform) {
var hasChecked = false;
var hasImgChecked = false;
		//Check if a grade has been selected. 
		for(var i=0; i<theform.abstractGrade.length; i++){
			if (theform.abstractGrade[i].checked){
				hasChecked = true;
			}
		}
		
		//Check if image has been selected. 
		if (theform.abstractImage != undefined) {
			for(var i=0; i<theform.abstractImage.length; i++){
				if (theform.abstractImage[i].checked){
					hasImgChecked = true;
				}
			}
		}
	
		//alert(theform.abstractImage);
		if ((!hasChecked) && (!theform.abstractConflict.checked) && (!theform.abstractTransfer.checked) && (!theform.abstractDuplicate.checked)) {
			Ext.MessageBox.alert('Alert:' , 'Please select a grade'); 
			return  false;
		} else if (theform.abstractImage != undefined) {
			if (!hasImgChecked) {
			Ext.MessageBox.alert('Alert:' , 'Please indicate if the image influenced your grade.'); 
			return  false;
			} else  { return  true; }
		} else if (theform.abstractTransfer.checked) {
			if ((theform.abstractComments.value == "") || (theform.abstractComments.value == null)) {
				Ext.MessageBox.alert('Alert:' , 'You must provide comments about the transfer.'); 
				return false;
			} else  { return  true; }
		} else if (theform.abstractDuplicate.checked) {
			if ((theform.abstractComments.value == "") || (theform.abstractComments.value == null)) {
				Ext.MessageBox.alert('Alert:' , 'You must provide comments about the duplicate.'); 
				return false;
			} else  { return  true; }
		} else {
			return  true;
		}					
}

function checkBkField(theform, divID) {
		///alert(theform);
		if ((theform.bk_title.value == '') || (theform.bk_title.value == null)) {
			Ext.MessageBox.alert('Alert:' , 'You must provide a Bookmark Title.'); 
			return false;
		} else {
			return  SubmitForm(theform, divID); 
		}
}





function ValidOption1(form, divID){
	
		if(form.am_group[form.am_group.selectedIndex].value == ''){
			Ext.MessageBox.alert('Alert:' ,"please select an Area");
			return false;
		} else if(form.parent_code[form.parent_code.selectedIndex].value == ''){
			Ext.MessageBox.alert('Alert:' ,"Please Select a Parent Category");
			return false;
		}else if(form.child_code[form.child_code.selectedIndex].value == ''){
			Ext.MessageBox.alert('Alert:' ,"Please Select a Child Category");
			return false;
		} else {			
		Ext.get(divID).mask('Saving Transfer');
		return SubmitForm(theform, divID);
		}
}// end fucntion


function ValidOption2(form, divID){
	if(form.am_group[form.am_group.selectedIndex].value == ''){
			Ext.MessageBox.alert('Alert:' ,"please select an Area");
			return false;
	} else if(form.parent_code[form.parent_code.selectedIndex].value == ''){
		Ext.MessageBox.alert('Alert:' ,"please select a parent category");
		return false;
	} else {
		Ext.get(divID).mask('Saving Transfer');
		return SubmitForm(theform, divID);	
	}

}// end fucntion


function ValidOption3(form, divID){
	
	if (form.am_group[form.am_group.selectedIndex].value == ''){
		Ext.MessageBox.alert('Alert:' ,"please select an Area");
		return false;
	} else if(form.parent_code[form.parent_code.selectedIndex].value == ''){
		Ext.MessageBox.alert('Alert:' ,"Please Select a Parent Category");
		return false;
	} else {
		Ext.get(divID).mask('Saving Transfer');
		return SubmitForm(theform, divID);
	}
}// end fucntion

function ValidateSearchText(form, divID){
	if(form.criteria.value.length == 0){
		Ext.MessageBox.alert('Alert:' ,"Please enter some search text");
		return false;
	}else{
		Ext.get(divID).mask('Searching Abstracts');
		return true;
	}
}

function ValidateID(form, divID){
	if(form.em_id.value.length == 0){
		Ext.MessageBox.alert('Alert:' ,"Please enter an abstract ID");
		return false;
	}else{
		Ext.get(divID).mask('Searching Abstracts by IDs');
		return true;
	}
}

function ValidateAuthors(form, divID){
	if(form.author_name.value.length == 0){
		Ext.MessageBox.alert('Alert:' ,"Please enter a part of the Authors <b>lastname</b> for the search");
		return false;
	}else{
		Ext.get(divID).mask('Searching Abstract Authors');
		return true;
	}
}

function validateSessions (form, divID) {
	if (form.session_title.value == ""){	
			Ext.MessageBox.alert('Alert:' ,  "You must enter a title for the session");
			return false;
	} else if (form.short_title.value == "") {	
			Ext.MessageBox.alert('Alert:' , "You must enter a short title for this session");
			return false;
	} else {
		Ext.get(divID).mask('Saving Session Title');
		return SubmitForm(form, divID);
	}
}


function checkModField(form, divID) {
	if (form.firstname.value == "") {
		Ext.MessageBox.alert('Alert:' , "Please enter a FIRST name");
		return false; 
	}else if (form.lastname.value == ""){
		Ext.MessageBox.alert('Alert:' , "Please enter a LAST name.");
		return false; 
	} else {
		return SubmitForm(form, divID);
	}
				
}

function CheckModMemberName(form, divID){
	if ((form.lastname.value == "") || (form.lastname.value == null)){
		Ext.MessageBox.alert('Alert:' , "Please enter a LAST name.");
		return false;
	} else {
		Ext.get(divID).mask('Searching Moderators');
		return SubmitForm(form, divID);
	}
}

function CheckModMemberNum(form, divID){
	if ((isNaN(form.memid.value)) || (form.memid.value == '') ){
		Ext.MessageBox.alert('Alert:' , "Please enter a valid membership number.");
		return false;
	} else {
		Ext.get(divID).mask('Searching Moderators');
		return SubmitForm(form, divID);
	}
}

function isEmailAddress (string) {
  var addressPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  return addressPattern.test(string);
}

function ValidateEmail(form, divID){
if (!isEmailAddress(form.userEmail.value)){
			Ext.MessageBox.alert('Alert:' ,"Please enter a valid email address for this author!<br> We\'re expecting something like jdoe@somecompany.com");
			return false
	} else {
		return SubmitForm(form, divID);
	}
	
}

function validateAuthorForm(form, divID){
	if ((document.getElementById('Instdisplay').style.display == '') && (form.tCompany.value == "")) {
			Ext.MessageBox.alert('Alert:' ,"You must enter your Institution");
			return false;
	} else if(form.tNameFirst.value == ""){
		Ext.MessageBox.alert('Alert:' ,"You must enter your first name");
		return false;
	} else if (form.tNameLast.value == ""){
		Ext.MessageBox.alert('Alert:' ,"You must enter your last name");
		return false;
	} else if (form.tPhone1.value == ""){
		Ext.MessageBox.alert('Alert:' ,"You must enter a valid email address");
		return false;
	} else if (form.tAddress1.value == ""){
		Ext.MessageBox.alert('Alert:' ,"You must enter a valid mailing address");
		return false;
	} else if (form.tCity.value == ""){
		Ext.MessageBox.alert('Alert:' ,"You must enter a city");
		return false;
	} else if (form.tState.value == ""){
		Ext.MessageBox.alert('Alert:' ,"You must enter a state or a province");
		return false;
	} else if (form.tpostalCode.value == ""){
		Ext.MessageBox.alert('Alert:' ,"You must enter a zip or postal code");
		return false;
	} else if (form.tCountryCode.selectedIndex <= 0){
		Ext.MessageBox.alert('Alert:' ,"You must select a country");
		return false;
	} else if (!isEmailAddress(form.tPhone1.value)){
			//Ext.MessageBox.alert('Alert:' ,"There is a problem with the email address you entered.\n\nWe\'re expecting something like jdoe@somecompany.com");
			Ext.MessageBox.alert('Alert:' ,"Please enter a valid email address for this author!<br> We\'re expecting something like jdoe@somecompany.com");
			return false;
	} else {
		Ext.get(divID).mask('Adding Moderators');
		return SubmitForm(form, divID);
	}
}

function radio_button_checker(form, divID) {
	// set var radio_choice to false
	var radio_choice = false;

	// Loop from zero to the one minus the number of radio button selections
	for (var counter = 0; counter < form.custID.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (form.custID[counter].checked)  {
			radio_choice = true; 
		}
	}
	
	//For some reason when only one Radio Button Exist, the form radio Lenght is undefined. 
	//This is a work around for that. 
	if (form.custID.length == undefined) {
		if (form.custID.checked) {
			radio_choice = true; 
		}
	}

	if (!radio_choice){
		Ext.MessageBox.alert('Alert:' ,"Please select a customer.");
		return false;
	} else {
		return SubmitForm(form, divID);
	}
}

	
function SubmitForm(form, divID){

	 var status = AjaxRequest.submit(
		form
		,{'onSuccess':function(req){
		   	try{ 
			Ext.get(divID).unmask
			document.getElementById(divID).innerHTML = req.responseText;
			executeJavascript(divID);
			  }catch(e){}
			}
		}
	  );
	return status;  
}



function reload_div (load_url, div) {
	var LoadDiv= Ext.get(div);
		LoadDiv.load({url: load_url,scripts: true, timeout : 180000});
}


function delete_confirm(action_url, div, load_url) {
	Ext.Msg.confirm('Confirm Delete'  , 'Are you sure you want to remove this?', function(btn, text){
					if (btn == 'yes'){
						// If Yes button is clicked. 
						processDelete(action_url, div, load_url);
					} ///end if
		}//end function 
	);// end Ext
}

function delete_session(action_url, div, load_url) {
	Ext.Msg.confirm('Confirm Delete'  , 'Are you sure you want to remove abstract from this session?', function(btn, text){
					if (btn == 'yes'){
						// If Yes button is clicked. 
						processDelete(action_url, div, load_url);
					} ///end if
		}//end function 
	);// end Ext
}


function processDelete(action_url, div, load_url) {
	
	Ext.Ajax.request({url:action_url,method: 'GET'
	  ,success: function (result, request) {
				Ext.get(div).mask('Deleting');
				reload_div(load_url, div);
				}
	  ,failure: function ( result, request) { 
				Ext.MessageBox.alert('Failed', result.responseText); 
				} 
	  });
}

function reminder (element){
	if (element == 'T') {
		if (document.formGrade.abstractTransfer.checked) {
			Ext.MessageBox.alert('REMINDER:', 'You must provide comments about the transfer.');
		}
	} else if (element == 'D') {
		if (document.formGrade.abstractDuplicate.checked) {
		Ext.MessageBox.alert('REMINDER:', 'You must provide a reason for the duplicate in the comments box.');
		}
	}
}


		

Ext.onReady(function(){ });