String.prototype.trim = function() {
	return (this || "").replace(/^\s+|\s+$/g, "");

}
// Class IPaper
IPaper = function(prodCd, evtType, prodTitle, evtAuthors, evtReviews) {

	this.prodCd = prodCd;
	this.evtType = evtType;
	this.prodTitle = prodTitle;
	this.evtAuthors = evtAuthors;
	this.evtReviews = evtReviews;

	// Stores the gen num and the selected paper type
	// the gen num is used to identify the select object so we can save
	// the selected index if someone has changed the type.
	this.eventgennum = "";
	this.selectedPaperType = "";
	getId = function() {
		return this.prodCd;
	};
};
// Class PaperList
PaperList = function(size) {
	this.listItems = new Array(size);
	this.getItem = function(index) {
		return this.listItems[index];
	};
	this.setItem = function(index, val) {
		this.listItems[index] = val;
	};
	this.getSize = function() {
		return this.listItems.length;
	};
	this.getList = function() {
		return this.listItems;
	};
	this.setList = function(listItems) {
		this.listItems = listItems;
	};
	this.moveItem = function(fr, to) {

		// Simple swap
		var tempVar = this.listItems[fr];
		this.listItems[fr] = this.listItems[to];
		this.listItems[to] = tempVar;
		/*
		 * if(to < fr){ _items = new Array(this.getSize()); for(j=0; j<this.getSize();
		 * j++){ if(j<to || j>fr){ _items[j] = this.getItem(j); } else{
		 * if(j==to){ _items[j] = this.getItem(fr); } else{ _items[j] =
		 * this.getItem(j-1); } } }//end of for-loop this.listItems = _items;
		 * }//end of if-loop
		 * 
		 * else if(to > fr) { }
		 */
		return this.listItems;
	};
};
// Init List
function _initList(_count, _aList) {
	for (i = 0; i < _count; i++) {
		prodCd = "";
		evtType = "";
		prodTitle = "";
		evtAuthors = "";
		evtReviews = "";
		// alert(prodCd+':'+prodTitle+':'+evtType+':'+evtAuthors+':'+evtReviews);
		_aList.setItem(i, new IPaper(prodCd, evtType, prodTitle, evtAuthors,
				evtReviews));
	}
}
// Initialize Paper List.
function initPaperList() {
	sessionPaperList = new PaperList(sessionPaperCount);
	_initList(sessionPaperCount, sessionPaperList);
}
function movep(fr, dir, target) {

	var to = 0;
	if (dir == "up") {
		to = fr - 1;
	} else {
		if (dir == "dn") {
			to = fr + 1;
		}
	}
	// alert('Moving :'+dir);
	// save UI fields to objects
	saveToList(target);
	// re-order the objects
	target.moveItem(fr, to);
	// load the objects to UI fields
	loadFromList(target);
	// refresh the DIVs(readOnly cells) with data from UI fields
	// refreshDIV(target, prefix);
}
function movePaper(fr, dir) {
	movep(fr, dir, sessionPaperList);
}
function saveToList(partiList) {
	var _size = partiList.getSize();
	for (i = 0; i < _size; i++) {
		_inputPaperProdCd = document.getElementById("PaperProdCd" + i);

		// DIV
		_inputPresType = document.getElementById("PresType" + i);

		// Select Element
		// _eventgennum = document.getElementById("eventgennum" + i);
		// jslog.debug("presentation Type element: "+_eventgennum.innerHTML);
		// jslog.debug("select Type id: type"+_eventgennum.innerHTML);
		// _inputPresTypeSelect = document.getElementById("type" +
		// _eventgennum.innerHTML);
		// jslog.debug("_inputPresTypeSelect: "+_inputPresTypeSelect.value);

		_inputPaperTitle = document.getElementById("PaperTitle" + i);
		_inputPaperAuthors = document.getElementById("PaperAuthors" + i);
		_inputPaperReviews = document.getElementById("PaperReviews" + i);

		partiList.getItem(i).prodCd = _inputPaperProdCd.innerHTML;
		partiList.getItem(i).evtType = _inputPresType.innerHTML;
		partiList.getItem(i).prodTitle = _inputPaperTitle.innerHTML;
		partiList.getItem(i).evtAuthors = _inputPaperAuthors.innerHTML;
		partiList.getItem(i).evtReviews = _inputPaperReviews.innerHTML;
		// partiList.getItem(i).selectedPaperType =
		// _inputPresTypeSelect.selectedIndex;

		// We will now make a copy of the gennum in the current location
		_eventgennum = document.getElementById("eventgennum" + i);
		// jslog.debug("presentation Type element: "+_eventgennum.innerHTML);
		partiList.getItem(i).eventgennum = _eventgennum.innerHTML;

	}
}
function loadFromList(partiList) {
	var _size = partiList.getSize();
	for (i = 0; i < _size; i++) {

		// Retrieving the HTML Elements.
		_inputPaperProdCd = document.getElementById("PaperProdCd" + i);

		// DIV
		_inputPresType = document.getElementById("PresType" + i);

		_inputPaperTitle = document.getElementById("PaperTitle" + i);
		_inputPaperAuthors = document.getElementById("PaperAuthors" + i);
		_inputPaperReviews = document.getElementById("PaperReviews" + i);
		_eventgennum = document.getElementById("eventgennum" + i);

		_inputPaperProdCd.innerHTML = unescape(partiList.getItem(i).prodCd);
		// Div
		_inputPresType.innerHTML = partiList.getItem(i).evtType;
		_inputPaperTitle.innerHTML = partiList.getItem(i).prodTitle;
		_inputPaperAuthors.innerHTML = partiList.getItem(i).evtAuthors;
		_inputPaperReviews.innerHTML = partiList.getItem(i).evtReviews;
		_eventgennum.innerHTML = partiList.getItem(i).eventgennum;

		// We will now use the gennum stored earlier to identify the div
		// and then use the key to retrieve the element and change the
		// value of the position
		// jslog.debug("Processing eventgennum:
		// "+partiList.getItem(i).eventgennum);
		tokensArray = getTokens(partiList.getItem(i).eventgennum, "#");
		/*
		 * for( var x=0;x < tokensArray.length; x++) {
		 * jslog.debug("tokensArray["+x+"]: "+tokensArray[x]); }
		 */
		var _paperKeyElement = document.getElementById("paperKey"
				+ tokensArray[0]);
		var keyValue = "";
		for ( var x = 0; x < tokensArray.length; x++) {
			keyValue = keyValue + tokensArray[x];
			keyValue = keyValue + "#";
		}
		keyValue = keyValue + i;
		_paperKeyElement.value = keyValue;

		// jslog.debug("After Change _paperKeyElement:
		// "+_paperKeyElement.value);

	}
}

// This function is used to disable the presentation type selection element
// on the form passed in as a aparameter.
function disablePaperTypeSelection(evtSchedGenNums) {

	var _sessOrderingLinkDivEnabled = document
			.getElementById("EnableSessionOrderingLink");
	var _sessOrderingLinkDivDisabled = document
			.getElementById("DisableSessionOrderingLink");

	var enabledClassName = "displayAttributeVisible";// _sessOrderingLinkDivEnabled.className;
	var disabledClassName = "displayAttributeNotVisible";// _sessOrderingLinkDivDisabled.className;

	for ( var cnt = 0; cnt < evtSchedGenNums.length; cnt++) {
		var id = "type" + evtSchedGenNums[cnt];
		var _inputPresTypeSelect = document.getElementById(id);
		_inputPresTypeSelect.disabled = true;

		id = "SessionOrderingDiv" + evtSchedGenNums[cnt];
		var _sessionOrderingDiv = document.getElementById(id);
		_sessionOrderingDiv.className = enabledClassName;

	}

	_sessOrderingLinkDivEnabled.className = disabledClassName;
	_sessOrderingLinkDivDisabled.className = enabledClassName;

}

function enablePaperTypeSelection(evtSchedGenNums) {

	var _sessOrderingLinkDivEnabled = document
			.getElementById("EnableSessionOrderingLink");
	var _sessOrderingLinkDivDisabled = document
			.getElementById("DisableSessionOrderingLink");

	var enabledClassName = "displayAttributeVisible";// _sessOrderingLinkDivEnabled.className;
	var disabledClassName = "displayAttributeNotVisible";// _sessOrderingLinkDivDisabled.className;

	for ( var cnt = 0; cnt < evtSchedGenNums.length; cnt++) {
		var id = "type" + evtSchedGenNums[cnt];
		var _inputPresTypeSelect = document.getElementById(id);
		_inputPresTypeSelect.disabled = false;

		id = "SessionOrderingDiv" + evtSchedGenNums[cnt];
		var _sessionOrderingDiv = document.getElementById(id);

		// jslog.debug("_sessionOrderingDiv:"+_sessionOrderingDiv);
		// jslog.debug("disabledClassName:"+disabledClassName);
		_sessionOrderingDiv.className = disabledClassName;

	}

	_sessOrderingLinkDivEnabled.className = enabledClassName;
	_sessOrderingLinkDivDisabled.className = disabledClassName;

	// jslog.debug(" _sessOrderingLinkDivEnabled:
	// "+_sessOrderingLinkDivEnabled.className);
	// jslog.debug(" _sessOrderingLinkDivDisabled:
	// "+_sessOrderingLinkDivDisabled.className);

}

// This function used for hiding,showing
// of accepted or rejected, or withdraw papers.
// param types: areTheyChecked(string,number,string);
function areTheyChecked(theitem, len, action) {
	var selectedn = 0;
	for ( var i = 0; i < len; i++) {
		var cb = document.getElementById("cb" + i);
		if (cb.checked) {
			selectedn++;
		}
	}
	if (selectedn > 0) {
		hideItem("accepteds");
		if (action == "withdraw") {
			displayItem("withdrawn");
		} else {
			if (action == "reject") {
				displayItem("myrejected");
			}
		}
	} else {
		alert("You need to select at least one paper before pressing the "
				+ theitem + " button.");
	}
}
// param types: presentationType()
function presentationType(theval, theid) {
	var time = document.getElementById("time" + theid);
	var timesel = document.getElementById("timesel" + theid);
	if (theval == "PPRES" || theval == "OPRES") {
		time.style.display = "";
		timesel.style.display = "";
	} else {
		time.style.display = "none";
		timesel.style.display = "none";
	}
}
// This function makeHigh makes the selected row
// higligted
// param types: makeHigh(boolean,string);
function makeHigh(idn, action) {
	var theid = document.getElementById("paper" + idn);
	var theid2 = document.getElementById("papert" + idn);
	if (action) {
		theid.className = "row-highlight";
		theid2.className = "row-highlight";
	} else {
		theid.className = "";
		theid2.className = "";
	}
}
function checkTwoNotChecked(thelast) {
	var item1 = document.getElementById("author");
	var item2 = document.getElementById("coauthor");
	if (item1.checked && item2.checked) {
		switch (thelast) {
		case 1:
			item2.checked = false;
			break;
		case 2:
			item1.checked = false;
			break;
		}
	}
}
// This function is used to display title
// author on session details page.
// param types: displayTitleAuthor(string,number);
function displayTitleAuthor(act, count) {
	var show = document.getElementById("showta");
	var hide = document.getElementById("hideta");
	if (act == 1) {
		show.style.display = "none";
		hide.style.display = "";
	} else {
		show.style.display = "";
		hide.style.display = "none";
	}
	for ( var i = 1; i <= count; i++) {
		var d = document.getElementById("papert" + i);
		if (act == 1) {
			d.style.display = "";
		} else {
			d.style.display = "none";
		}
	}
}
// This function is used expand or collaps
// session/meeting list in userHome page.
// param types: fullList(number,number);
function fullList(theaction, meetingSize) {
	var theamount = meetingSize;
	for (i = 0; i < theamount; i++) {
		var therow = document.getElementById(i + "_HideShow");
		var theminus = document.getElementById(i + "_HideShow--off");
		var theplus = document.getElementById(i + "_HideShow--on");
		if (theaction == 1) {
			therow.style.display = "";
			theminus.style.display = "";
			theplus.style.display = "none";
		} else {
			therow.style.display = "none";
			theminus.style.display = "none";
			theplus.style.display = "";
		}
	}
}

// This function use to toggle view
// for session and meeting on userHome page
// param types: toggleCom(number,number);
function toggleCom(theid, theaction) {
	var therow = document.getElementById(theid);
	var thetogOn = document.getElementById(theid + "--on");
	var thetogOff = document.getElementById(theid + "--off");
	if (theaction == 1) {
		therow.style.display = "";
		thetogOn.style.display = "none";
		thetogOff.style.display = "";
	} else {
		therow.style.display = "none";
		thetogOn.style.display = "";
		thetogOff.style.display = "none";
	}
}
// This function use to toggle view
// param types: toggleItem(number,number);
function toggleItem(theid, theaction) {
	var therow = document.getElementById(theid);
	var thetogOn = document.getElementById(theid + "--on");
	var thetogOff = document.getElementById(theid + "--off");
	if (theaction == 1) {
		therow.style.display = "";
		thetogOn.style.display = "none";
		thetogOff.style.display = "";
	} else {
		therow.style.display = "none";
		thetogOn.style.display = "";
		thetogOff.style.display = "none";
	}
}
// param types: updatePaperDetails()
function updatePaperDetails(uri, frm, bol1, bol2) {
	if (newtrim(document.getElementById("paperTitle").value) == "") {
		alert("Paper title can not be blank.");
		document.getElementById("paperTitle").focus();
		return;
	}
	if (document.getElementById("paperTitle").value.length > 500) {
		alert("Paper title must be 500 characters or less.");
		document.getElementById("paperTitle").focus();
		return;
	}
	if (newtrim(document.getElementById("paperAbstract").value) == "") {
		alert("Paper abstract can not be blank.");
		document.getElementById("paperAbstract").focus();
		return;
	} else {
		callMyAction(uri, frm, bol1, bol2);
	}
}
// Updated withdraw or reject papers with reason.
function updateEventLog(uri, frm, bol1, bol2, itm) {
	var emptyCheck = false;
	for (i = 0; i < itm; i++) {
		if (newtrim(document.getElementById("withdrawReason" + i).value) == "") {
			alert("Withdraw/Reject reason must be entered.");
			emptyCheck = true;
			document.getElementById("withdrawReason" + i).focus();
			return;
		}
	}
	if (!emptyCheck) {
		callMyAction(uri, frm, bol1, bol2);
		if (frm == "_withdrawForm") {
			hideItem("withdrawn");
			displayItem("accepteds");
		} else {
			if (frm == "_rejectForm") {
				hideItem("myrejected");
				displayItem("accepteds");
			}
		}
	}
}
function updateEventLog(uri, frm, bol1, bol2, itm) {
	var emptyCheck = false;
	for (i = 0; i < itm; i++) {
		if (newtrim(document.getElementById("withdrawReason" + i).value) == "") {
			alert("Withdraw/Reject reason must be entered.");
			emptyCheck = true;
			document.getElementById("withdrawReason" + i).focus();
			return;
		}
	}
	if (!emptyCheck) {
		callMyAction(uri, frm, bol1, bol2);
		if (frm == "_withdrawForm") {
			hideItem("withdrawn");
			displayItem("accepteds");
		} else {
			if (frm == "_rejectForm") {
				hideItem("myrejected");
				displayItem("accepteds");
			}
		}
	}
}
// Trim whitespace from left and right sides of s.
function newtrim(s) {
	return s.replace(/^\s*/, "").replace(/\s*$/, "");
}
// Function used by Organizer Approval Form
function updatePaperApproval(url, frm, bol1, bol2) {
	var chk = validateApprovalForm();
	if (chk == true) {
		callMyAction(url, frm, bol1, bol2);
	} else {
		return;
	}
}
// Function to validate Organizer Approval Form
function validateApprovalForm() {

	clearMessage();
	var paperCnt = document.getElementById("paperCount").value;
	var submitFrm = true;
	for (i = 0; i < paperCnt; i++) {

		var prodCd = document.getElementById("divProdCd" + i).innerHTML;

		// alert("prodCd:"+prodCd);

		var transRadioElements = document.getElementsByName("tran" + i);
		var transSwSelected = false;
		var transSwValue = "";
		for ( var x = 0; x < transRadioElements.length; x++) {

			if (transRadioElements[x].checked == true) {
				transSwValue = transRadioElements[x].value;

				if (transSwValue == 'Y') {
					transSwSelected = true;
				}
			}
		}

		if (transSwSelected) {
			// If a paper is selected for transactions then the paper has to be
			// published.
			var publishRadioElements = document.getElementsByName("pub" + i);
			var publishRadioSelected = false;
			var publishRadioValue = "";
			for ( var x = 0; x < publishRadioElements.length; x++) {

				if (publishRadioElements[x].checked == true) {
					publishRadioSelected = true;
					publishRadioValue = publishRadioElements[x].value;
				}
			}

			if ((!publishRadioSelected) || publishRadioValue == "N"
					|| publishRadioValue == "") {
				errorMessages[errorMessages.length] = writeFieldLabel(prodCd)
						+ "Please update transactions switch to No. You cannot recommend for transactions if you select to not publish the paper.";
			}

		}

		// If a paper has been rejected then the rejection reason has to be
		// entered.
		var publishRadioElements = document.getElementsByName("pub" + i);
		var publishRadioSelected = false;
		var publishRadioValue = "";
		for ( var x = 0; x < publishRadioElements.length; x++) {

			if (publishRadioElements[x].checked == true) {
				publishRadioSelected = true;
				publishRadioValue = publishRadioElements[x].value;
			}
		}
		if (publishRadioSelected && publishRadioValue == 'N') {
			var rejectionReasonElement = document.getElementById("rejReason"
					+ i);
			if (newtrim(rejectionReasonElement.value) == '') {
				errorMessages[errorMessages.length] = writeFieldLabel(prodCd) + 'Please enter the reason for rejecting this paper from the publishing process.';
			}

		}
	}

	if (initLength == errorMessages.length) {
		return true;
	} else {
		showMessage();
		return false;
	}
	return false;
	// return submitFrm;
}

// }

/*
 * if (pub[0].checked == false && pub[1].checked == false) { alert("Please
 * select Yes or No to Publish paper?"); document.getElementById("orgComments" +
 * i).focus(); submitFrm = false; return submitFrm; } if (pub[0].checked == true &&
 * pub[0].value == "Y") { var tran = document.getElementsByName("tran" + i); if
 * (tran[0].checked == false && tran[1].checked == false) { alert("Please select
 * Yes or No to recommend this paper for Transactions?");
 * document.getElementById("orgComments" + i).focus(); submitFrm = false; return
 * submitFrm; } if (newtrim(document.getElementById("orgComments" + i).value) ==
 * "") { alert("Comments can not be blank.");
 * document.getElementById("orgComments" + i).focus(); submitFrm = false; return
 * submitFrm; } } if (pub[1].checked == true && pub[1].value == "N") { if
 * (newtrim(document.getElementById("rejReason" + i).value) == "") {
 * alert("Reject reason must be entered."); document.getElementById("rejReason" +
 * i).focus(); submitFrm = false; return submitFrm; } }
 */

function getTokens(material, separator) {
	// Create array of tokens.
	var tokens = new Array();
	var nextToken;

	// If no separators found, single token is the material string itself.
	if (material.indexOf(separator) < 0) {
		tokens[0] = material;
		return tokens;
	} // end if

	// Establish initial start and end positions of the first token.
	start = 0;
	end = material.indexOf(separator, start);

	// Counter for how many tokens were found.
	var counter = 0;

	// Go through material, token at a time.
	while (material.length - start > 1) {
		nextToken = material.substring(start, end);
		start = end + 1;
		if (material.indexOf(separator, start + 1) < 0) {
			end = material.length;
		} // end if
		else {
			end = material.indexOf(separator, start + 1);
		} // end else

		tokens[counter] = tokentrim(nextToken);

		counter++;
	} // end if

	// Return the initialised array.
	return tokens;

} // end getTokens function

function tokentrim(strToTrim) {
	return (strToTrim.replace(/^\s+|\s+$/g, ''));
} // end trim function

if (!window.SessPg) {
	window.SessPg = {};
}
function $elm(id) {
	return document.getElementById(id);
}
SessPg.abstractMap = {};
SessPg.url = window.location.href;

SessPg.fetchAbstract = function(evtGen, prodCd) {
	var exist = SessPg.abstractMap[evtGen];
	if (exist == null || exist == 'undefined' || exist == undefined) {
		try {
			var xhrObj = makeHttpObject();
			var idxQuest = SessPg.url.indexOf('?');
			var serializedFrm = (idxQuest == -1) ? '?' : '';
			serializedFrm += "paperGen=" + evtGen + "&reqReason=getAbstract"
					+ "&papProdCd=" + prodCd;
			xhrObj.open('POST', SessPg.url, true);
			xhrObj.onreadystatechange = function(req) {

				if (xhrObj.readyState == 4) {
					if (xhrObj.status == 200) {

						SessPg.abstractMap[evtGen] = xhrObj.responseText;
						$elm(evtGen + 'abstract--on').style.display = "none";
						$elm(evtGen + 'abstract--off').style.display = "";
						$elm(evtGen + 'abstract').style.display = "";
						$elm(evtGen + 'abstract').innerHTML = SessPg.abstractMap[evtGen];
					}
				}
			};

			xhrObj.setRequestHeader('Content-Type',
					'application/x-www-form-urlencoded');
			xhrObj.send(serializedFrm);

		} catch (e) {
			alert(e);
		}
	} else {
		$elm(evtGen + 'abstract--on').style.display = "none";
		$elm(evtGen + 'abstract--off').style.display = "";
		$elm(evtGen + 'abstract').style.display = "";
		$elm(evtGen + 'abstract').innerHTML = SessPg.abstractMap[evtGen];
	}
}

SessPg.hideAbstract = function(evtGen) {
	$elm(evtGen + 'abstract--on').style.display = "";
	$elm(evtGen + 'abstract--off').style.display = "none";
	$elm(evtGen + 'abstract').style.display = "none";

}
SessPg.resourceIdMap = {};
SessPg.downloadManuscript = function(evtGen, prodCd) {
	var inside = {};
	inside.setResourceHrefSrc = function(prodCd) {
		var resourceId = SessPg.resourceIdMap[prodCd];
		if ('' == resourceId) {
			alert('Sorry there was not resource to download ');
			return;
		}
		var dwnloadlnk = 'http://' + window.location.hostname
				+ '/servlets/techpapers/manuscriptResources.do?resourceID='
				+ resourceId;
		$elm('hiddenDownloadFrame').src = dwnloadlnk;
	}

	var exist = SessPg.resourceIdMap[prodCd];
	if (exist == null || exist == 'undefined' || exist == undefined) {
		try {
			var xhrObj = makeHttpObject();
			var idxQuest = SessPg.url.indexOf('?');
			var serializedFrm = (idxQuest == -1) ? '?' : '';
			serializedFrm += "paperGen=" + evtGen + "&reqReason=getResourceId"
					+ "&papProdCd=" + prodCd;
			xhrObj.open('POST', SessPg.url, true);
			xhrObj.onreadystatechange = function(req) {

				if (xhrObj.readyState == 4) {
					if (xhrObj.status == 200) {
						SessPg.resourceIdMap[prodCd] = xhrObj.responseText;
						inside.setResourceHrefSrc(prodCd);
					}
				}
			};

			xhrObj.setRequestHeader('Content-Type',
					'application/x-www-form-urlencoded');
			xhrObj.send(serializedFrm);

		} catch (e) {
			alert(e);
		}
	} else {
		inside.setResourceHrefSrc(prodCd);
	}
}
if (!window.ThisPg) {
	ThisPg = {};
}

ThisPg.url = window.location.href;
ThisPg.REV_STATUS_COOKIE = {};

ThisPg.doCookieJob = function() {
	ThisPg.cookie = document.cookie;
	ThisPg.splitCook = ThisPg.cookie.split(';');
	for (i = 0; i < ThisPg.splitCook.length; i++) {
		var trgtCook = ThisPg.splitCook[i].indexOf('REV_STATUS_COOKIE');
		if (trgtCook != -1) { // if name of the the cooke is REV_STATUS_COOKIE
			// do following
			var splt = ThisPg.splitCook[i].split('='); // splits string
			// 'REV_STATUS_COOKIE'
			// and rest of the value
			// from the cookie
			// string
			if (!splt[1])
				continue;
			var value = splt[1]; // splt[1] is the cookie name and splt[2] is
			// the value of the cooking string
			var cookValSplt = value.split(','); // this cookie value is a
			// combination of different
			// values split with character
			// ',' comma
			for (idx = 0; idx < cookValSplt.length; idx++) { // for the total
				// lenght of
				// split var
				var row = cookValSplt[idx].split("[]");// again each split
				// character has key
				// value pair split with
				// '[]' character, as
				// the delimiter
				ThisPg.REV_STATUS_COOKIE[row[0]] = row[1]; // row[0] is the key
				// row[1] is the
				// value
			}
		}
	}
}

ThisPg.doCookieJob();

ThisPg.checkIfRevSent = function(prodCd) {
	ThisPg.doCookieJob();
	var exist = ThisPg.REV_STATUS_COOKIE[prodCd];

	if (exist == null || exist == 'undefined' || exist == undefined) {
		var xhrObj = makeHttpObject();
		var idxQuest = ThisPg.url.indexOf('?');
		var serializedFrm = (idxQuest == -1) ? '?' : '';
		serializedFrm += "reqReason=getReviewSentStatus" + "&prodCd=" + prodCd;
		xhrObj.open('POST', ThisPg.url, true);
		xhrObj.onreadystatechange = function(req) {

			if (xhrObj.readyState == 4) {
				if (xhrObj.status == 200) {

					var retVal = xhrObj.responseText;
					ThisPg.REV_STATUS_COOKIE[prodCd] = retVal;
					exist = retVal;// ThisPg.REV_STATUS_COOKIE[prodCd];
					spitAlert();
				}
			}
		};

		xhrObj.setRequestHeader('Content-Type',
				'application/x-www-form-urlencoded');
		xhrObj.send(serializedFrm);

	} else {
		spitAlert();
	}
	function spitAlert() {
		if ('N' == exist) {
			var alrtMsg = "PLEASE NOTE : A review(s) has been completed for this technical paper ,"
					+ prodCd + ",\n";
			alrtMsg += "that has not yet been released to the paper's author(s).  You may continue if you wish \n"
			alrtMsg += "without releasing the review(s).  If you do wish to release the review(s), please save\n"
			alrtMsg += "your work on this page first.  Any work not saved before navigating to a different part\n"
			alrtMsg += "of MyTechZone will be lost."
			alert(alrtMsg);
		}
	}

}

PaperParticPg = {};
log = function(args) {
	var console = window.console
	if (undefined == console) {
		return;
	}
	console.log(args);

}
PaperParticPg.handleBioUpload = function(ref, $evt, custNum) {
	log('ref : ' + ref);
	var evt = $evt || window.event;
	log('evt  ' + evt);
	var bioFile = document.getElementById('bioFile/' + custNum);
	var bioFileVal = new String(bioFile.value).trim();
	if ('' == bioFileVal) {
		alert('Please specify the file to upload . ');
		return false;
	}

	var bioFormDiv = document.getElementById('bioFormDiv');
	var bioForm = bioFormDiv.getElementsByTagName('form')[0];
	bioForm.appendChild(bioFile);
	bioForm.custNum.value = custNum;
	bioForm.submit();
}

function findPos(ref) {

	var obj = ref;// document.getElementById(ref);
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft - obj.scrollLeft;
			curtop += obj.offsetTop - obj.scrollTop;
			var position = '';
			if (obj.style && obj.style.position)
				position = obj.style.position.toLowerCase();
			if ((position == 'absolute') || (position == 'relative'))
				break;
			while (obj.parentNode != obj.offsetParent) {
				obj = obj.parentNode;
				curleft -= obj.scrollLeft;
				curtop -= obj.scrollTop;
			}
			obj = obj.offsetParent;
		}
	} else {
		if (obj.x)
			curleft += obj.x;
		if (obj.y)
			curtop += obj.y;
	}
	return {
		left :curleft,
		top :curtop
	};
}

PaperParticPg.closeBioFrameHoldDiv = function() {
	log('inside closeBioFrameHoldDiv');
	var bioFrameHoldDiv = document.getElementById('bioFrameHoldDiv');
	if (undefined == bioFrameHoldDiv) {
		return;
	}
	document.body.removeChild(bioFrameHoldDiv);
	removeProcessingDiv();

	log('inside closeBioFrameHoldDiv');

}

function removeProcessingDiv(){
	var processingDiv = document.getElementById('processingDiv');
	if(processingDiv){
		document.body.removeChild(processingDiv);
	}
	
}

PaperParticPg.showBioUpload = function(ref, $evt, custNum) {
	onProcessMessage();
	log('ref : ' + ref);
	var evt = $evt || window.event;
	log('evt  ' + evt);
	var target = evt.target || evt['srcElement'];

	var xc = evt.clientX;
	var xy = evt.clientY;

	var top = window.scollY;
	if (top == undefined) {
		top = document.body.scrollTop;
	}

	// var bioRow = document.getElementById('bioRow/' + custNum);
	var position = findPos(ref);
	/*
	 * bioRow.style.display = ''; bioRow.style.position = 'absolute';
	 * bioRow.style.left = position.left; bioRow.style.top = position.top + 25 +
	 * top;
	 */
	var uri = '/servlets/techpapers/participants/showBioUpload.do?evtSchedGenNum={0}&evtName={1}&prodGrpCd={2}&idTyp=paper&custNum={3}';
	uri = uri.replace('{0}', EventSchedId['evtSchedGenNum']);
	uri = uri.replace('{1}', EventSchedId['evtName']);
	uri = uri.replace('{2}', EventSchedId['prodGrpCd']);
	uri = uri.replace('{3}', custNum);
	uri += '&fakeDt=' + new Date();

	var bioHtmlHold = document.getElementById('bioHtmlHold');
	
	updateOverlayTitle("Submit Biography Information");
	updateOverlayIframe(uri,250);
	openPop();
}

function moveParticPres(custNum, moveType) {
	var viewParticipantForm = document.forms['viewParticipantForm'];

	var particType = 'pres';
	var sortFormDiv = document.getElementById('sortFormDiv'); // this div
	// contains the
	// placeHolder
	// form
	var form = sortFormDiv.getElementsByTagName('form')[0];// this form is
	// nothing but to
	// store input
	// hidden types

	// assigning values to the placholder hidden inputs
	form['sortHelper.custNum'].value = custNum;
	form['sortHelper.moveType'].value = moveType;
	form['sortHelper.particType'].value = particType;

	viewParticipantForm.action = 'sortParticipant.do';
	// appending values from the placholder hidden inputs to the
	// viewParticipantForm and submitting
	viewParticipantForm.appendChild(form['sortHelper.custNum']);
	viewParticipantForm.appendChild(form['sortHelper.moveType']);
	viewParticipantForm.appendChild(form['sortHelper.particType']);
	viewParticipantForm.submit();
}
var SessionBin = window.SessionBin;
if (undefined == SessionBin) {
	SessionBin = {};
}
SessionBin.fixSessionBinOrgDisplay = function() {
	
	var orgDisplayTd = document.getElementById('orgDisplayTd');
	
	var hldDiv = document.createElement('div');
	document.body.appendChild(hldDiv);
	hldDiv.style.display = "none";
	
	var orgDisplayTbl = document.createElement('table');
	hldDiv.appendChild(orgDisplayTbl);
	
	var hiddenOrgs = document.getElementById('hiddenOrgs');
	var divs = hiddenOrgs.getElementsByTagName('div');
	var divsLen = divs.length;
	
	log('divsLen : '+divsLen);
	var totalRow = parseInt(divsLen / 3);
	log('total Row before : '+totalRow);
	
	var mod = divsLen % 3;
	if (mod >= 1) {
		totalRow = parseInt(totalRow) + parseInt(1);
	}
	
	log('total Row totalRow : '+totalRow);
	var divCtr = new Number(0);
	log('totalRow len : '+totalRow);
	for ( var i = 0; i < totalRow; i++) {
		
		var tr = document.createElement('tr');
		orgDisplayTbl.appendChild(tr);

		var td1 = document.createElement('td');
		tr.appendChild(td1);
		
		var td2 = document.createElement('td');
		tr.appendChild(td2);
		
		var td3 = document.createElement('td');
		tr.appendChild(td3);
		try {
			
			var idx = divCtr + i;
			var $__div1 = divs[idx];
			if($__div1 != undefined){
				td1.innerHTML = $__div1.innerHTML;
				log('append td1' +$__div1);
			}
			
			
			divCtr++;
			idx = divCtr + i;
			var $__div2 = divs[idx];
			if($__div2 != undefined){
				td2.innerHTML = $__div2.innerHTML;
				log('append td2 : '+$__div2);
			}
			
			divCtr++;
			idx = divCtr + i;
			var $__div3 = divs[idx];
			if($__div3 != undefined){
				td3.innerHTML = $__div3.innerHTML;
				log('append td3 : '+$__div3);
			}
			
			
			
		} catch (e) {
			log(e);
		}
	}
	log('inner : ');
	//log(hldDiv.innerHTML);
	orgDisplayTd.innerHTML = hldDiv.innerHTML;
	
}

SessionBin.saveSessionBin = function() {
	var frm = document.getElementById('newSessionBinSaveForm');

	var iputs = frm.getElementsByTagName('input');
	var isOrgSelected = false;
	for ( var i = 0; i < iputs.length; i++) {
		var type = iputs[i].type;
		if ('checkbox' != type) {
			continue;
		}
		if (type.indexOf('.custNumSelect') != -1) {
			continue;
		}
		var chkbox = iputs[i];
		if (chkbox.checked) {
			isOrgSelected = true;
			break;
		}
	}

	var messages = document.getElementById('messages');
	var fontTag = messages.getElementsByTagName('font')[0];
	fontTag.color = 'red';
	fontTag.innerHTML = "";
	var msg = "";
	var allClear = 2;
	var title = new String(frm['sessionBin.title'].value).trim();
	if ('' == title) {
		msg += "Please type in the session group name. </br>";
		allClear--;
	}

	if (!isOrgSelected) {
		msg += "Please select at least one organizer. </br>";
		allClear--;
	}

	if (allClear != 2) {

		fontTag.innerHTML = msg;
		return false;

	}

	frm.submit();

}

SessionBin.savePaperAssignment = function(ref, event) {
	if(SessionBin.eventBins.length <2){
		alert('There are no Session Groups to  assign.');
		return false;
	}
	var frm = document.getElementById('assignPaperToSessionGroupForm');
	frm.submit();

}

SessionBin.showHideTitleAndAuthor = function(ref, event) {

	var display = '';
	var span = ref.getElementsByTagName('span')[0];
	var classNm = span.className;
	if ('$show' == classNm) {
		span.className = '$hide';
		span.innerHTML = 'Hide Title, Authors and Status';
	} else {
		span.className = '$show';
		span.innerHTML = 'Show Title, Authors and Status';
		display = 'none';
	}
	var rowPart = [ 'title', 'participants', 'status' ];
	for ( var i = 0; i < rowPart.length; i++) {
		var row = rowPart[i];
		for ( var dx = 0; dx < SessionBin.papers.length; dx++) {
			var id = row + '/' + SessionBin.papers[dx];
			var node = document.getElementById(id);
			node.style.display = display;
		}
	}
}

SessionBin.showHideAbstract = function(ref, event) {

	var rowPart = [ 'abstract' ];
	var display = '';
	var span = ref.getElementsByTagName('span')[0];
	var classNm = span.className;
	if ('$show' == classNm) {
		span.className = '$hide';
		span.innerHTML = 'Hide Abstract';
	} else {
		span.className = '$show';
		span.innerHTML = 'Show Abstract';
		display = 'none';
	}

	for ( var i = 0; i < rowPart.length; i++) {
		var row = rowPart[i];
		for ( var dx = 0; dx < SessionBin.papers.length; dx++) {
			var id = row + '/' + SessionBin.papers[dx];
			var node = document.getElementById(id);
			node.style.display = display;
		}
	}
}
SessionBin.finalizeGroupingAssignment = function(ref, event) {
	if(SessionBin.eventBins.length <2){
		alert('There are no Session Groups assigned yet.');
		return false;
	}
	var msg = "This action will finalize the grouping process for this session and prohibit creation of new session\n ";
	msg += 	  "groups and the assignment of papers to session groups. An email notification will be sent to the \n";
	msg +=    "staff representative that this process is complete.  Are you sure you are finished?";
	var ok = confirm(msg);
	if (!ok) {
		return false;
	}
	var frm = document.getElementById('finalizeForm');
	frm.submit();

}

SessionBin.selectAllOrg = function (ref,evt){
	var tocheck = false;
	if(ref.checked){
		tocheck = true;
	}
	
	for(var i = 0; i<SessionBin.organizers.length;i++){
		var custNum = SessionBin.organizers[i];
		var iputName = 'sessionOrganizer['+i+'].custNumSelect';
		var iput = document.getElementsByName(iputName);
		if(iput[0]){
			iput[0].checked = tocheck;
		}
	}
	
	
}

function onProcessMessage() {
	var textDiv = document.createElement('div');
	var midHeight = (window.screen.height / 2) - 20;
	var midWidth = (window.screen.width / 2) - 20;

	/*
	 * document.body.appendChild(textDiv); textDiv.id = 'processingTextDiv';
	 * textDiv.innerHTML = '<h1 style="font-size: 25px;color:red">Please wait
	 * while we fetch the results.</h1>'; textDiv.style.position = 'absolute';
	 * textDiv.style.left = midWidth+'px'; textDiv.style.top =midHeight+'px';
	 */

	var div = document.createElement('div');
	document.body.appendChild(div);
	div.setAttribute("id", "processingDiv");

	div.style.height = document.body.scrollHeight; + 'px';
	div.style.width = document.body.scrollWidth + 'px';
	div.style.position = 'absolute';
	div.style.left = '0px';
	div.style.top = '0px';
	div.className = 'progressDimmed';

}
