// Image array
var magImageArray = new Array();
var storeImageArray = new Array();
var partnerImageArray = new Array();

// Function to change the style for a single item
function changeLink(id, newClass) {
	document.getElementById(id).className = newClass;
}

// Function to create a new image
function newImage(arg) {
  if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
  }
}

// Function to change the style on mouse over for the left nav menu items
function changeMenuItem(tdID, tdClass, linkID, linkClass) {
	document.getElementById(tdID).className = tdClass;
	document.getElementById(linkID).className = linkClass;
}

// Function to create links for table cells
function gotoLink(linkURL) {
	if(linkURL!="")
		document.URL = linkURL;
}

// Function to close a layer
function closeLayer(id) {

	if (document.getElementById) {
		document.getElementById(id).style.visibility = "hidden";
		document.getElementById(id).style.display = "none";
	} else if (document.all) {
		document.all[id].style.visibility="hidden";
		document.getElementById(id).style.display = "none";
	} else if (document.layers) {
		document.layers[id].visibility="hide";
		document.getElementById(id).style.display = "none";
	}
}

// Function to open a layer
function openLayer(id) {

	if (document.getElementById) {
		document.getElementById(id).style.visibility = "visible";
		document.getElementById(id).style.display = "block";
	} else if (document.all) {
		document.all[id].style.visibility="visible";
		document.getElementById(id).style.display = "block";
	} else if (document.layers) {
		document.layers[id].visibility="show";
		document.getElementById(id).style.display = "block";
	}
}

// Function to clear the search box on click
function clearSearchBox() {
	document.quickSearchForm.quickSearch.value="";
}

var currentSpeaker = -1;
var currentEvent = -1;
var currentSponsor = -1;

// Function to auto rotate items on home page
function rotateHomePageItems() {

	if (currentSpeaker != -1) {

		var newSpeaker = currentSpeaker + 1;
		var newSpeakerID = "speaker" + newSpeaker;
		var currentSpeakerID = "speaker" + currentSpeaker;

		if (document.getElementById) {
			if (!document.getElementById(newSpeakerID)) {
				newSpeaker = 0;
				newSpeakerID = "speaker" + newSpeaker;
			}

			document.getElementById(currentSpeakerID).style.visibility = 'hidden';
			document.getElementById(currentSpeakerID).style.display = 'none';

			document.getElementById(newSpeakerID).style.visibility = 'visible';
			document.getElementById(newSpeakerID).style.display = 'block';

		} else if (document.all) {

			if (!document.all[newSpeakerID]) {
				newSpeaker = 0;
				newSpeakerID = "speaker" + newSpeaker;
			}

			document.all[currentSpeakerID].style.visibility = 'hidden';
			document.getElementById(currentSpeakerID).style.display = 'none';

			document.all[newSpeakerID].style.visibility = 'visible';
			document.getElementById(newSpeakerID).style.display = 'block';

		} else if (document.layers) {

			if (!document.layers[newSpeakerID]) {
				newSpeaker = 0;
				newSpeakerID = "speaker" + newSpeaker;
			}

			document.layers[currentSpeakerID].style.visibility = 'hide';
			document.getElementById(currentSpeakerID).style.display = 'none';

			document.layers[newSpeakerID].style.visibility = 'show';
			document.getElementById(newSpeakerID).style.display = 'block';

		}

		currentSpeaker = newSpeaker;

	} else {
		currentSpeaker = 0;
	}

	if (currentEvent != -1) {

		var newEvent = currentEvent + 1;
		var newEventID = "event" + newEvent;
		var currentEventID = "event" + currentEvent;

		if (document.getElementById) {
			if (!document.getElementById(newEventID)) {
				newEvent = 0;
				newEventID = "event" + newEvent;
			}

			document.getElementById(currentEventID).style.visibility = 'hidden';
			document.getElementById(currentEventID).style.display = 'none';

			document.getElementById(newEventID).style.visibility = 'visible';
			document.getElementById(newEventID).style.display = 'block';

		} else if (document.all) {

			if (!document.all[newEventID]) {
				newEvent = 0;
				newEventID = "event" + newEvent;
			}

			document.all[currentEventID].style.visibility = 'hidden';
			document.getElementById(currentEventID).style.display = 'none';

			document.all[newEventID].style.visibility = 'visible';
			document.getElementById(newEventID).style.display = 'block';

		} else if (document.layers) {

			if (!document.layers[newEventID]) {
				newEvent = 0;
				newEventID = "event" + newEvent;
			}

			document.layers[currentEventID].style.visibility = 'hide';
			document.getElementById(currentEventID).style.display = 'none';

			document.layers[newEventID].style.visibility = 'show';
			document.getElementById(newEventID).style.display = 'block';

		}

		currentEvent = newEvent;

	} else {
		currentEvent = 0;
	}

	if (currentSponsor != -1) {

		var newSponsor = currentSponsor + 1;
		var newSponsorID = "sponsor" + newSponsor;
		var currentSponsorID = "sponsor" + currentSponsor;

		if (document.getElementById) {
			if (!document.getElementById(newSponsorID)) {
				newSponsor = 0;
				newSponsorID = "sponsor" + newSponsor;
			}

			document.getElementById(currentSponsorID).style.visibility = 'hidden';
			document.getElementById(currentSponsorID).style.display = 'none';

			document.getElementById(newSponsorID).style.visibility = 'visible';
			document.getElementById(newSponsorID).style.display = 'block';

		} else if (document.all) {

			if (!document.all[newSponsorID]) {
				newSponsor = 0;
				newSponsorID = "sponsor" + newSponsor;
			}

			document.all[currentSponsorID].style.visibility = 'hidden';
			document.getElementById(currentSponsorID).style.display = 'none';

			document.all[newSponsorID].style.visibility = 'visible';
			document.getElementById(newSponsorID).style.display = 'block';

		} else if (document.layers) {

			if (!document.layers[newSponsorID]) {
				newSponsor = 0;
				newSponsorID = "sponsor" + newSponsor;
			}

			document.layers[currentSponsorID].style.visibility = 'hide';
			document.getElementById(currentSponsorID).style.display = 'none';

			document.layers[newSponsorID].style.visibility = 'show';
			document.getElementById(newSponsorID).style.display = 'block';

		}

		currentSponsor = newSponsor;

	} else {
		currentSponsor = 0;
	}

	setTimeout('rotateHomePageItems()', 5000);

}
// *************************************DSlavinsky CODE starts here***************************************************************

function submitenter(e, admaction){
    var keycode;

    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
      doAction(admaction);
      return false;
    } else
     return true;
  }

function viewLogo(filePath){

    	logoWindow = window.open("", "LogoPopup", "width=300,height=200,screenX=100,left=25,screenY=30,top=25,scrollbars=no,resizable=no");
    	document.masterForm.FILE_PATH.value = filePath;
    	document.masterForm.page.value = "view_logo";
    	document.masterForm.action="index.jsp";
    	document.masterForm.target="LogoPopup";
			window.name="LogoWindow";
		  logoWindow.focus();
			document.masterForm.submit();
}

function sendEventEmail(){

    	emailWindow = window.open("", "EmailPopup", "width=600,height=300,screenX=100,left=25,screenY=30,top=25,scrollbars=yes,resizable=yes");
    	document.emailForm.page.value = "emailEvent";
    	document.emailForm.target="EmailPopup";
			window.name="EmailWindow";
		  emailWindow.focus();
			document.emailForm.submit();
}

function removeFile(fieldName){

	//Used on event_overview, onClick of RemoveFile-checkboxes
	if(fieldName=="surveyFile")
	{
		if(document.masterForm.removeSurveyFile.checked)
			document.masterForm.SPONSOR_QUESTION_FILE_NAME.value = "";
		else
			document.masterForm.SPONSOR_QUESTION_FILE_NAME.value = document.masterForm.SPONSOR_QUESTION_FILE_NAME.value;
	}
	
	if(fieldName=="logo")
	{
		if(document.masterForm.removeLogo.checked)
			document.masterForm.EVENT_LOGO_FILE_NAME.value = "";
		else
			document.masterForm.EVENT_LOGO_FILE_NAME.value = document.masterForm.init_EVENT_LOGO_FILE_NAME.value;
	}

 if(fieldName=="brochure")
	{
		if(document.masterForm.removeBrochure.checked)
			document.masterForm.EVENT_BROCHURE_FILE_NAME.value = "";
 		else
 			document.masterForm.EVENT_BROCHURE_FILE_NAME.value = document.masterForm.init_EVENT_BROCHURE_FILE_NAME.value;
  }

 if(fieldName=="header")
	{
		if(document.masterForm.removeHeader.checked)
			document.masterForm.EVENT_HEADER_FILE_NAME.value = "";
 		else
 			document.masterForm.EVENT_HEAEDER_FILE_NAME.value = document.masterForm.init_EVENT_HEADER_FILE_NAME.value;
  }

 if(fieldName=="photo")
	{
		if(document.masterForm.removePhoto.checked)
			document.masterForm.SPEAKER_PHOTO_FILE_NAME.value = "";
 		else
 			document.masterForm.SPEAKER_PHOTO_FILE_NAME.value = document.masterForm.init_SPEAKER_PHOTO_FILE_NAME.value;
  }

 if(fieldName=="sponsorLogo")
	{
		if(document.masterForm.removePhoto.checked)
			document.masterForm.SPONSOR_IMAGE_FILE_NAME.value = "";
 		else
 			document.masterForm.SPONSOR_IMAGE_FILE_NAME.value = document.masterForm.init_SPONSOR_IMAGE_FILE_NAME.value;
  }

 if(fieldName=="venuePhoto")
	{
		if(document.masterForm.removePhoto.checked)
			document.masterForm.VENUE_PHOTO_FILE_NAME.value = "";
 		else
 			document.masterForm.VENUE_PHOTO_FILE_NAME.value = document.masterForm.init_VENUE_PHOTO_FILE_NAME.value;
  }

}

function addModEvent(id){

	document.masterForm.EVENT_ID.value = id;
	doAction('addmod_event');

}

function deleteEvent(id){
	if(confirm("Are you sure you want to PERMANENTLY delete this Event and ALL of its related data?\nThis action CANNOT be undone!")){
				if(confirm("PLEASE CONFIRM:\nAre you positive that you want to DELETE this Event?")){

			document.masterForm.EVENT_ID.value = id;
		  doAction('delete_event');
		}
	}
}

function listEvents(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_events');
}

function deleteEventQuestion(id){

	if(confirm("Are you sure you want to permanently delete this question?")){
	document.masterForm.EVENT_QUESTION_ID.value = id;
	doAction('delete_event_question');
	}
}

function addModEventQuestion(id){

	document.masterForm.EVENT_QUESTION_ID.value = id;
	doAction('addmod_event_question');

}

function addModEventQuestionChoice(id){

	document.masterForm.EVENT_QUESTION_CHOICE_ID.value = id;
	doAction('addmod_event_question_choice');

}

 function ltrim(str) { return str.replace(/(^\s*)/g, ""); }
  function rtrim(str) { return str.replace(/(\s*$)/g, ""); }
  function trim(str)  { return ltrim(rtrim(str));}

function fillShortText(){
	var longText = trim(document.masterForm.EVENT_QUESTION_CHOICE_TEXT.value);
	if(trim(document.masterForm.EVENT_QUESTION_CHOICE_TEXT_SHORT.value) == "")
	{
		document.masterForm.EVENT_QUESTION_CHOICE_TEXT_SHORT.value = longText.substring(0,49);
		document.masterForm.EVENT_QUESTION_CHOICE_TEXT_SHORT.focus();
	}
}

function applyChoice(){

	var longText = trim(document.masterForm.EVENT_QUESTION_CHOICE_TEXT.value);
	var shortText = trim(document.masterForm.EVENT_QUESTION_CHOICE_TEXT_SHORT.value);

	if(longText == "" || shortText == "")
	{
		alert("Please enter both long and short choice text.\n");
	}
 else
  {
  	doAction('apply_event_question_choice');
  }
}

function deleteEventQuestionChoice(id){

	if(confirm("Are you sure you want to delete this response choice?")){
	document.masterForm.EVENT_QUESTION_CHOICE_ID.value = id;
	doAction('delete_event_question_choice');
	}
}

function removeEventOffer(id){

	if(confirm("Are you sure you want to permanently delete this offer?")){
	document.masterForm.EVENT_OFFER_ID.value = id;
	doAction('delete_event_offer');
}
}

function addModEventOffer(id){

	document.masterForm.EVENT_OFFER_ID.value = id;
	doAction('addmod_event_offer');

}

function listAgenda(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_agenda');
}

function addModAgenda(id){

	document.masterForm.AGENDA_ID.value = id;
	doAction('addmod_agenda');

}
function resetAgendaDateTime(){

	//reset Date and Time if No Time is checked off
	if(document.masterForm.AGENDA_ACTIVITY_NO_TIME.checked)
	{
		document.masterForm.AGENDA_ACTIVITY_DATE.value = "";
		document.masterForm.AGENDA_ACTIVITY_START.selectedIndex = 0;
		document.masterForm.AGENDA_ACTIVITY_END.selectedIndex = 0;
		document.masterForm.AGENDA_ACTIVITY_START_MINUTES.selectedIndex = 0;
		document.masterForm.AGENDA_ACTIVITY_END_MINUTES.selectedIndex = 0;
		document.masterForm.startAmPm.selectedIndex = 0;
		document.masterForm.endAmPm.selectedIndex = 0;
		document.masterForm.AGENDA_ACTIVITY_HIDE_TIME.checked =false;
		}
	
}

function resetAgendaNoDateTime() {
		//reset No Date/Time if Hide Date/Time is checked off
	document.masterForm.AGENDA_ACTIVITY_NO_TIME.checked = false;
}

function resetAgendaNoTime(){

	//reset checkbox if date is entered
	//alert("Inside resetCheckbox");
	//alert(document.masterForm.AGENDA_ACTIVITY_NO_TIME.checked);
	if(document.masterForm.AGENDA_ACTIVITY_DATE.value != "" || document.masterForm.AGENDA_ACTIVITY_START.selectedIndex != 0 ||
			 document.masterForm.AGENDA_ACTIVITY_END.selectedIndex != 0 || document.masterForm.AGENDA_ACTIVITY_START_MINUTES.selectedIndex != 0 ||
			 document.masterForm.AGENDA_ACTIVITY_END_MINUTES.selectedIndex != 0 || document.masterForm.startAmPm.selectedIndex != 0 ||
			 document.masterForm.endAmPm.selectedIndex != 0)
	{document.masterForm.AGENDA_ACTIVITY_NO_TIME.checked = false;}

}

function applyAgenda(){

	var errMess = "";
	var err = false;
	
	 if(((document.masterForm.AGENDA_ACTIVITY_NO_TIME.checked == false && (!document.masterForm.AGENDA_ID.value == "")) || document.masterForm.AGENDA_ACTIVITY_HIDE_TIME.checked || document.masterForm.AGENDA_ACTIVITY_DATE.value != "" || document.masterForm.AGENDA_ACTIVITY_START.selectedIndex != 0 ||
			 document.masterForm.AGENDA_ACTIVITY_END.selectedIndex != 0 || document.masterForm.AGENDA_ACTIVITY_START_MINUTES.selectedIndex != 0 ||
			 document.masterForm.AGENDA_ACTIVITY_END_MINUTES.selectedIndex != 0 || document.masterForm.startAmPm.selectedIndex != 0 ||
			 document.masterForm.endAmPm.selectedIndex != 0) && (document.masterForm.AGENDA_ACTIVITY_DATE.value == "" || document.masterForm.AGENDA_ACTIVITY_START.selectedIndex == 0 ||
			 document.masterForm.AGENDA_ACTIVITY_END.selectedIndex == 0 || document.masterForm.AGENDA_ACTIVITY_START_MINUTES.selectedIndex == 0 ||
			 document.masterForm.AGENDA_ACTIVITY_END_MINUTES.selectedIndex == 0 || document.masterForm.startAmPm.selectedIndex == 0 ||
			 document.masterForm.endAmPm.selectedIndex == 0))
	 {
	 		errMess = "Please enter valid Date and Time OR check off 'No Date/Time'.\n";
	 		err = true;
	 	}
	
	else if(document.masterForm.AGENDA_ACTIVITY_DATE.value == "" && document.masterForm.AGENDA_ACTIVITY_START.selectedIndex == 0 &&
			 document.masterForm.AGENDA_ACTIVITY_END.selectedIndex == 0 && document.masterForm.AGENDA_ACTIVITY_START_MINUTES.selectedIndex == 0 &&
			 document.masterForm.AGENDA_ACTIVITY_END_MINUTES.selectedIndex == 0 && document.masterForm.startAmPm.selectedIndex == 0 &&
			 document.masterForm.endAmPm.selectedIndex == 0)
		{
			document.masterForm.AGENDA_ACTIVITY_NO_TIME.checked = true;
		}

  
	 if(!err)
	 	doAction('apply_agenda');
	else
		alert(errMess);


}

function deleteAgenda(id){

	document.masterForm.AGENDA_ID.value = id;
	doAction('delete_agenda');

}

function listSpeakers(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_speakers');
}

function addModSpeaker(id){

	document.masterForm.SPEAKER_ID.value = id;
	doAction('addmod_speaker');

}

function removeSpeaker(id){

	if(confirm("Are you sure you want to permanently delete this speaker?")){
	document.masterForm.SPEAKER_ID.value = id;
	doAction('delete_speaker');
}
}

function listAgendaSpeakers(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('addmod_agenda');
}

function removeAgendaSpeaker(id){
	if(confirm("Are you sure you want to remove this Agenda Speaker?")){
	document.masterForm.AGENDA_SPEAKER_ID.value = id;
	doAction('delete_agenda_speaker');
 }
}

function addEventSpeaker(id, saveEventSpeaker){

	document.masterForm.SPEAKER_ID.value = id;
	document.masterForm.saveEventSpeaker.value = saveEventSpeaker;
	doAction('addmod_event_speaker');

}

function listEventSpeakers(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_event_speakers');
}

function removeEventSpeaker(evspid,spid){
	if(confirm("Are you sure you want to remove this Event Speaker?\nIt would also remove it from Event Agenda.")){
	document.masterForm.EVENT_SPEAKER_ID.value = evspid;
	document.masterForm.SPEAKER_ID.value = spid;
	doAction('delete_event_speaker');
 }
}

function deleteSpeaker(id){
	if(confirm("Are you sure you want to remove this Speaker?\nIt would also remove it from all of the linked Events!")){

	document.masterForm.SPEAKER_ID.value = id;
	doAction('delete_speaker');
}
}

function removeEventVenue(vid){
	if(confirm("Are you sure you want to remove this Venue?\n")){
	document.masterForm.EVENT_VENUE_ID.value = vid;
	doAction('delete_event_venue');
 }
}

function updateAgendaSpeakerType(agSpid, spid){

	document.masterForm.AGENDA_SPEAKER_ID.value = agSpid;
	document.masterForm.SPEAKER_ID.value = spid;
	doAction('update_agenda_speaker_type');

}

function addEventSponsor(spid,evspid){

	document.masterForm.SPONSOR_ID.value = spid;
	document.masterForm.EVENT_SPONSOR_ID.value = evspid;
	doAction('addmod_event_sponsor');
}

function selectEventSponsor(id){

	document.masterForm.SPONSOR_ID.value = id;
	doAction('select_event_sponsor');
}

function removeEventSponsor(id){
	if(confirm("Are you sure you want to remove this Event Sponsor?")){
	document.masterForm.EVENT_SPONSOR_ID.value = id;
	doAction('delete_event_sponsor');
 }
}

function updateEventSponsorType(evSpID, spID, spTypeId, ord){

	document.masterForm.EVENT_SPONSOR_ID.value = evSpID;
	document.masterForm.SPONSOR_ID.value = spID;
	document.masterForm.PREV_SPONSOR_TYPE_ID.value = spTypeId;
	document.masterForm.PREV_EVENT_SPONSOR_ORDER.value = ord;
	doAction('update_event_sponsor_type');

}


function listEventSponsors(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_event_sponsors');
}


function addEventVenue(id){

	document.masterForm.VENUE_ID.value = id;
	doAction('addmod_venue');

}

function listEventVenues(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('addmod_event_venue');
}

function applyEventVenue(venueID,saveEventVenue){

	document.masterForm.VENUE_ID.value = venueID;
	document.masterForm.saveEventVenue.value = saveEventVenue;
	doAction('apply_event_venue');

}

/*************************************************DS Code Ends here********************************************/
/*************************************************John's Code********************************************/
function deleteVenues(id){
	if(confirm("Are you sure you want to remove this Venue?\nIt would also remove it from all of the linked Events!")){

	document.masterForm.VENUE_ID.value = id;
	doAction('delete_venue');
}
}

function listVenues(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_venues');
}

function addModVenue(id){

	document.masterForm.VENUE_ID.value = id;
	doAction('addmod_venue');
}

function deleteSponsor(id){
	if(confirm("Are you sure you want to remove this Sponsor?\nIt would also remove it from all of the linked Events!")){

	document.masterForm.SPONSOR_ID.value = id;
	doAction('delete_sponsor');
	}
}

function listSponsors(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_sponsors');
}

function addModSponsor(id, showPulldown){

	document.masterForm.showPulldown.value = showPulldown;
	document.masterForm.SPONSOR_ID.value = id;
	doAction('addmod_sponsor');
}

function addModSponsorType(id){

	document.masterForm.SPONSOR_TYPE_ID.value = id;
	doAction('addmod_sponsor_type');
}

function updateSponsorFeature(id, objDummy, objField){

	document.masterForm.SPONSOR_ID.value = id;

	//to make sure that the checkbox submits a value, assign it to the hidden field
	if(objDummy.checked)
		objField.value = "Y";
	else
		objField.value = "N";

	doAction('update_sponsor_feature');
}

function updateEventFeature(id, objDummy, objField){

	document.masterForm.EVENT_ID.value = id;

	//to make sure that the checkbox submits a value, assign it to the hidden field
	if(objDummy.checked)
		objField.value = "Y";
	else
		objField.value = "N";

	doAction('update_event_feature');
}

function activateEmail(id, objDummy, objField){

	document.masterForm.EMAIL_ID.value = id;

	//to make sure that the checkbox submits a value, assign it to the hidden field
	if(objDummy.checked)
		objField.value = "Y";
	else
		objField.value = "N";

	doAction('activate_email');
}


function updateSpeakerFeature(id, objDummy, objField){

	document.masterForm.SPEAKER_ID.value = id;

	//to make sure that the checkbox submits a value, assign it to the hidden field
	if(objDummy.checked)
		objField.value = "Y";
	else
		objField.value = "N";

	doAction('update_speaker_feature');
}

function deleteContact(id){

	if(confirm("Are you sure you want to remove this Contact?\nIt would also remove it from all of the linked Events!")){
		document.masterForm.CONTACT_ID.value = id;
	doAction('delete_contact');
}
}

function addModContact(ctid, evctid){

	if(ctid != "")
		document.masterForm.CONTACT_ID.value = ctid;

	if(evctid != "")
	{
		 	document.masterForm.EVENT_CONTACT_ID.value = evctid;
		 	document.masterForm.showFields.value = "Y";
	}
	doAction('addmod_contact');
}

function listContacts(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_contacts');
}

function addEventContact(id){

	document.masterForm.CONTACT_ID.value = id;
	document.masterForm.showFields.value = "Y";
	doAction('addmod_event_contact');
}

function listEventContacts(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_event_contacts');
}

function removeEventContact(id){
	if(confirm("Are you sure you want to remove this Event Contact?")){
	document.masterForm.EVENT_CONTACT_ID.value = id;
	doAction('delete_event_contact');
 }
}

function deleteEmail(id){

	document.masterForm.EMAIL_ID.value = id;
	doAction('delete_email');
}

function listEmail(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_email');
}

function addModEmail(id){

	document.masterForm.EMAIL_ID.value = id;
	doAction('addmod_email');
}

function deleteWebCast(id){

	document.masterForm.WEBCAST_ID.value = id;
	doAction('delete_webcast');
}

function addModWebCast(id){

	document.masterForm.WEBCAST_ID.value = id;
	doAction('addmod_webcast');
}

function listWebCast(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_webcast');
}

function deleteSoundOff(id){

	document.masterForm.COMMENT_ID.value = id;
	doAction('delete_soundoff');
}

function addModSoundOff(id){

	document.masterForm.COMMENT_ID.value = id;
	doAction('addmod_soundoff');
}

function listSoundoff(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_soundoff');
}

function deleteRegistrant(id){
	if(confirm("Are you sure you want to permanently delete this Registrant?\n")){

			document.masterForm.REGISTRANT_ID.value = id;
			doAction('delete_registrant');
	 }
}

function removeEventRegistrant(id){
	if(confirm("Are you sure you want to remove this Registrant?\n")){
			document.masterForm.EVENT_REGISTRANT_ID.value = id;
			doAction('delete_registrant');
 }
}

function listRegistrants(startRow){

	document.masterForm.startRow.value = startRow;
	doAction('list_registrants');
}

function listEventRegistrants(startRow){

	document.masterForm.startRegistrantRow.value = startRow;
	doAction('list_registrants');
}

function addModRegistrant(regid, evregid){

	document.masterForm.REGISTRANT_ID.value = regid;
	document.masterForm.EVENT_REGISTRANT_ID.value = evregid;
	doAction('addmod_registrant');
}

function searchsubmitenter(e){
    var keycode;

    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
      document.quickSearchForm.pagesearch.value = "search";
			document.quickSearchForm.submit();
      return false;
    } else
     return true;
  }

function search(){
	document.quickSearchForm.pagesearch.value = "search";
	document.quickSearchForm.submit();
}

function printAgenda(eventID){

			//var printURL = "/?page=eventagenda&eventID=" + eventID + "&printable=true";
    	document.masterForm.printable.value ="true";
    	document.masterForm.eventID.value = eventID;
    	document.masterForm.page.value = "eventagenda";
     	agendaWindow = window.open("", "agendaPopup", "width=800, height=700, screenX=100, left=50, screenY=100, top=0, scrollbars=yes, resizable=no");
			window.name="Printable";
			document.masterForm.target = "agendaPopup";
		  agendaWindow.focus();
			document.masterForm.submit();
}

function viewSpeaker(speakerID){

			var printURL = "/?page=speaker&speakerID=" + speakerID + "&window=popup";
    	speakerWindow = window.open(printURL, "speakerPopup", "width=555, height=350, screenX=100, left=50, screenY=100, top=0, scrollbars=yes, resizable=yes");
			window.name="View Speaker";
		  speakerWindow.focus();

}

////////////////////
//UPLOAD FUNCTIONS//
////////////////////

function doDocumentAction(act){

	document.masterForm.method = "POST";

	if(act == "apply_close_sponsor_survey_question" || act == "apply_sponsor_survey_question")
 	{

	/**
 		if(document.masterForm.EVENT_HIDDEN.checked == false){
			document.masterForm.EVENT_HIDDEN.value = "F";
 		}
**/
  	if(document.masterForm.SPONSOR_QUESTION_FILE.value != "")
  	 {
  	 	document.masterForm.action = "conferences_document_sponsor_survey_controller.jsp";
  	 	document.masterForm.SPONSOR_QUESTION_FILE_NAME.value = document.masterForm.SPONSOR_QUESTION_FILE.value;

			 doUploadAction(act);
  	 }
  	else{
  		 doAction(act);
	  }
 	}


	if(act == "apply_venue" || act == "apply_event_venue") {

		if(document.masterForm.VENUE_PHOTO_FILE.value != "")
		{
			document.masterForm.VENUE_PHOTO_FILE_NAME.value = document.masterForm.VENUE_PHOTO_FILE.value;
			document.masterForm.action = "conferences_document_venues_controller.jsp";

			doUploadAction(act);
		}
		else {
			doAction(act);
		}
	}

	if(act == "apply_sponsor")
	{
		if(document.masterForm.EVENT_ID)
  		document.masterForm.page.value = "apply_event_sponsor";
  	else
  		document.masterForm.page.value = act;

  	//make sure that the checkbox value gets submitted
  	if(document.masterForm.SPONSOR_FEATURED_DUMMY)
  	{
	  	if(document.masterForm.SPONSOR_FEATURED_DUMMY.checked)
	  		document.masterForm.SPONSOR_FEATURED.value = "Y";
	  	else
	  		document.masterForm.SPONSOR_FEATURED.value = "N";
	  }

  	if(document.masterForm.SPONSOR_IMAGE_FILE)
  	{
			if(document.masterForm.SPONSOR_IMAGE_FILE.value != "")
			{
				document.masterForm.SPONSOR_IMAGE_FILE_NAME.value = document.masterForm.SPONSOR_IMAGE_FILE.value;
				document.masterForm.action = "conferences_document_sponsors_controller.jsp";
				doUploadAction(act);
			}
			else
				doAction(document.masterForm.page.value);
		 }
		else
			doAction(document.masterForm.page.value);

	}

	if(act == "apply_event_overview" || act == "apply_close_event_overview")
 	{


		if(document.masterForm.EVENT_FEATURED.checked == false){
			document.masterForm.EVENT_FEATURED.value = "F";
 		}

 		if(document.masterForm.EVENT_HIDDEN.checked == false){
			document.masterForm.EVENT_HIDDEN.value = "F";
 		}

  	if(document.masterForm.EVENT_BROCHURE_FILE.value != "" || document.masterForm.EVENT_LOGO_FILE.value != "" || document.masterForm.EVENT_HEADER_FILE.value != "" )
  	 {
  	 	 document.masterForm.action = "conferences_document_event_controller.jsp";

	  	 if(document.masterForm.EVENT_BROCHURE_FILE.value != "")
	  	  	document.masterForm.EVENT_BROCHURE_FILE_NAME.value = document.masterForm.EVENT_BROCHURE_FILE.value;

	  	 if(document.masterForm.EVENT_LOGO_FILE.value != "")
	  	 		document.masterForm.EVENT_LOGO_FILE_NAME.value = document.masterForm.EVENT_LOGO_FILE.value;

			 if(document.masterForm.EVENT_HEADER_FILE.value != "")
	  	  	document.masterForm.EVENT_HEADER_FILE_NAME.value = document.masterForm.EVENT_HEADER_FILE.value;

			 doUploadAction(act);
  	 }
  	else{
  		 doAction(act);
	  }
 	}

 	if(act == "apply_speaker")
 	{
  	if(document.masterForm.EVENT_ID)
  		document.masterForm.page.value = "apply_event_speaker";
  	else
  		document.masterForm.page.value = act;

  	//make sure that the checkbox value gets submitted
  	if(document.masterForm.SPEAKER_FEATURED_DUMMY.checked)
  		document.masterForm.SPEAKER_FEATURED.value = "Y";
  	else
  		document.masterForm.SPEAKER_FEATURED.value = "N";

  	if(document.masterForm.SPEAKER_PHOTO_FILE.value != "")
  	 {
  	 	 document.masterForm.action = "conferences_document_speaker_controller.jsp";
  	 	 document.masterForm.SPEAKER_PHOTO_FILE_NAME.value = document.masterForm.SPEAKER_PHOTO_FILE.value;
  		 doUploadAction(act);
	   }
  	else
  	 	 	doAction(document.masterForm.page.value);
 	}


}

function fixNumber(number) {
				tmpNumber = new NumberFormat(number);
				tmpNumber.setCommas(false);
				tmpNumber.setPlaces(2);
				tmpNumber.setCurrencyPrefix('');
				return(tmpNumber.toFormatted());
}

function fixNumericData(objField){

	/*Won't let user enter a non-numeric value into a given field*/

	  	 if(objField)
	  	 {
		  		if (isNaN(objField.value))
		      {
		           while (isNaN(objField.value))
		           {
		                objField.value = objField.value.substring(0,objField.value.length-1);
		           }
		      }
		  }
	 }

function doUploadAction(act) {
	document.masterForm.encoding = "multipart/form-data";
	document.masterForm.target = "_self";
	document.masterForm.page.value = act;
	document.masterForm.submit();
}

function doEventAction(act){

	if(document.masterForm.EVENT_ID.value == "")
	 	alert("Please save new Event before viewing its components");
	else
		doAction(act);
}

function applyEmail(){

//make sure that the checkbox value gets submitted
  	if(document.masterForm.EMAIL_ACTIVE_DUMMY)
  	{
	  	if(document.masterForm.EMAIL_ACTIVE_DUMMY.checked)
	  		document.masterForm.EMAIL_ACTIVE.value = "Y";
	  	else
	  		document.masterForm.EMAIL_ACTIVE.value = "N";
	  }

	  doAction('apply_email');
}

function applyEventOffer(){

//make sure that the checkbox value gets submitted
  	if(document.masterForm.EVENT_OFFER_COMPLIMENTARY_DUMMY)
  	{
	  	if(document.masterForm.EVENT_OFFER_COMPLIMENTARY_DUMMY.checked)
	  		document.masterForm.EVENT_OFFER_COMPLIMENTARY.value = "Y";
	  	else
	  		document.masterForm.EVENT_OFFER_COMPLIMENTARY.value = "N";
	  }

	  if(document.masterForm.EVENT_OFFER_IS_DEFAULT_DUMMY)
  	{
	  	if(document.masterForm.EVENT_OFFER_IS_DEFAULT_DUMMY.checked)
	  		document.masterForm.EVENT_OFFER_IS_DEFAULT.value = "Y";
	  	else
	  		document.masterForm.EVENT_OFFER_IS_DEFAULT.value = "N";
	  }

	  doAction('apply_event_offer');
}

function validateCountry(){
	if(document.registrationForm.REGISTRANT_COUNTRY[document.registrationForm.REGISTRANT_COUNTRY.selectedIndex].value != "US" && document.registrationForm.REGISTRANT_COUNTRY[document.registrationForm.REGISTRANT_COUNTRY.selectedIndex].value != "CA"){
		document.getElementById('stateAsterisk').style.visibility = "hidden";
	}
	else{
  	document.getElementById('stateAsterisk').style.visibility = "visible";
	}
}

function updateOffer(){

	if(document.registrationForm.offercode.value != "")
	 {
	 	document.registrationForm.registerpage.value = "update_offer";
		document.registrationForm.action = "index.jsp";
		document.registrationForm.submit();
	 }
	else
		{
			alert("Please enter an Offer Code.\n");
		}
}


function getRadioGroupVal(radioObj)
{
	var ret = "";
	for (i=0;i<radioObj.length;i++)
	{
		if (radioObj[i].checked)
		{
		 	ret = radioObj[i].value;
		 	break;
		}
	}
	return ret;
}


function getSelPrice(arry, offrSelID)
{	
	var retVal = "";
	for (i=0;i<arry.length;i++)
	{				
		if (arry[i].eveOptionID==offrSelID)	{	
			retVal=arry[i].eveOfferOptPrice;		

		}
	}
	return retVal;
}

function getRadioGroupIndex(radioObj)
{
	var retIndex = "0";
	for (i=0;i<radioObj.length;i++)
	{

		if (radioObj[i].checked)
		{		
		 	retIndex = i;
		 	break;
		}
	}
	return retIndex;
}

function fillSpcPrc(spPriRdObj, pricBoxObj)
{	
	if(spPriRdObj && pricBoxObj){
		var evntOfferSelIndex = getRadioGroupIndex(spPriRdObj);		
		var evntOfferPrice 		= getSelPrice(evntOptArray,spPriRdObj[evntOfferSelIndex].value);					
		pricBoxObj.value 			= evntOfferPrice;
	}
}

function register() {
	
	var email = trim(document.registrationForm.REGISTRANT_EMAIL_ADDRESS.value);
	var errs = false;

	if(trim(document.registrationForm.REGISTRANT_SALUTATION.options[document.registrationForm.REGISTRANT_SALUTATION.selectedIndex].value) == "" && errs == false){
		alert("Please select a salutation.");
		errs = true;
	}
	if(trim(document.registrationForm.REGISTRANT_FIRST_NAME.value) == "" && errs == false){
		alert("Please enter a first name.");
		errs = true;
		document.registrationForm.REGISTRANT_FIRST_NAME.focus();
	}
	if(trim(document.registrationForm.REGISTRANT_LAST_NAME.value) == "" && errs == false){
		alert("Please enter a last name.");
		errs= true;
		document.registrationForm.REGISTRANT_LAST_NAME.focus();
	}
	if(trim(document.registrationForm.REGISTRANT_TITLE.value) == "" && errs == false){
		alert("Please enter a title.");
		errs= true;
		document.registrationForm.REGISTRANT_TITLE.focus();
	}
	if(trim(document.registrationForm.REGISTRANT_COMPANY_NAME.value) == "" && errs == false){
		alert("Please enter a company name.");
		errs= true;
		document.registrationForm.REGISTRANT_COMPANY_NAME.focus();
	}
	if(trim(document.registrationForm.REGISTRANT_ADDRESS_1.value) == "" && errs == false){
		alert("Please enter an address.");
		errs= true;
		document.registrationForm.REGISTRANT_ADDRESS_1.focus();
	}
	if(trim(document.registrationForm.REGISTRANT_CITY.value) == "" && errs == false){
		alert("Please enter a city.");
		errs= true;
		document.registrationForm.REGISTRANT_CITY.focus();
	}
	if(trim(document.registrationForm.REGISTRANT_COUNTRY.options[document.registrationForm.REGISTRANT_COUNTRY.selectedIndex].value) == "" && errs == false){
		alert("Please select a country.");
		errs= true;
	}
	if((document.registrationForm.REGISTRANT_COUNTRY.options[document.registrationForm.REGISTRANT_COUNTRY.selectedIndex].value == "US" || document.registrationForm.REGISTRANT_COUNTRY.options[document.registrationForm.REGISTRANT_COUNTRY.selectedIndex].value == "CA") && errs == false){
		if(trim(document.registrationForm.REGISTRANT_STATE.value) == ""){
			alert("Please enter a state or province.");
			errs = true;
		}
	}
	if(trim(document.registrationForm.REGISTRANT_ZIP_CODE.value) == "" && errs == false){
		alert("Please enter a postal code.");
		errs= true;
		document.registrationForm.REGISTRANT_ZIP_CODE.focus();
	}
	if(email == "" || email == "" || email.indexOf("@") == -1 || email.indexOf("@") == 0 || email.indexOf("@") == (email.length - 1) || email.indexOf(".") == -1 || email.indexOf(".") == (email.length - 1) || email.indexOf("@") + 1 == email.indexOf(".") || email.indexOf(".") + 1 == email.indexOf("@")){
	  alert("Please enter valid Email Address");
	  document.registrationForm.REGISTRANT_EMAIL_ADDRESS.focus();
	  errs = true;
	}
	if(trim(document.registrationForm.REGISTRANT_PHONE_NUMBER.value) == "" && errs == false){
		alert("Please enter a phone number.");
		errs= true;
		document.registrationForm.REGISTRANT_PHONE_NUMBER.focus();
	}
	if(document.registrationForm.REGISTRANT_INDUSTRY) {
		if(trim(document.registrationForm.REGISTRANT_INDUSTRY.options[document.registrationForm.REGISTRANT_INDUSTRY.selectedIndex].value) == "" && errs == false){
			alert("Please select an industry.");
			errs= true;
		}
	}
	if(document.registrationForm.REGISTRANT_ANNUAL_REVENUE) {
		if(trim(document.registrationForm.REGISTRANT_ANNUAL_REVENUE.options[document.registrationForm.REGISTRANT_ANNUAL_REVENUE.selectedIndex].value) == "" && errs == false){
			alert("Please select your companies annual revenue.");
			errs= true;
		}
	}
	if(document.registrationForm.ccType){
		if(trim(document.registrationForm.ccType.options[document.registrationForm.ccType.selectedIndex].value) == "" && errs == false){
			alert("Please select a credit card type.");
			errs= true;
		}
		if(trim(document.registrationForm.ccNumber.value) == "" && errs == false){
			alert("Please enter a credit card number.");
			errs= true;
			document.registrationForm.ccNumber.focus();
		}
	}
	
	//-- Only use this for special pricing event
	if(document.registrationForm.eventOfferOptionButton)
	{
		//-- retrieve selected index
		var evntOfferSelIndex = getRadioGroupIndex(document.registrationForm.eventOfferOptionButton);			
		
		//-- retrieves the selected index value
		var evntOfferPrice = getSelPrice(evntOptArray, document.registrationForm.eventOfferOptionButton[evntOfferSelIndex].value);
				
		if(evntOfferSelIndex != "" || evntOfferSelIndex> -1)
		{		
			document.registrationForm.EVENT_OFFER_OPTION_ID.value = document.registrationForm.eventOfferOptionButton[evntOfferSelIndex].value;
			document.registrationForm.spp.value = evntOfferPrice;
			
			//alert("EVENT_OFFER_OPTION_ID=" +document.registrationForm.EVENT_OFFER_OPTION_ID.value );
			//alert("spp=" + document.registrationForm.spp.value);
		}
		else
		{
			errs= true;
			alert("Please register an option price for this event");
		}
	}

	if(errs == false){
		if(document.registrationForm.EVENT_ID)
		{
			document.registrationForm.registerpage.value = "register";
		}
		else
		{
			document.registrationForm.registerpage.value = "joinList";
		}
		document.registrationForm.action = "index.jsp";
		document.registrationForm.submit();
	}
}

function validateOrder(){

		if(document.masterForm.EVENT_SPONSOR_ORDER){

			if(document.masterForm.EVENT_SPONSOR_ORDER.value < 1 || trim(document.masterForm.EVENT_SPONSOR_ORDER.value) == ""){
				alert("Please enter a valid order");;
				document.masterForm.EVENT_SPONSOR_ORDER.focus();
			}
			else{
				validateDocURL(document.masterForm.SPONSOR_URL.value, 'apply_sponsor');
			}
		}
		else{
				validateDocURL(document.masterForm.SPONSOR_URL.value, 'apply_sponsor');
			}

}

function checkURL(externalURL, eventURL, act) {
	var bool = true;

	if(externalURL != ""){
			if(externalURL.substring(0, 7) != "http://" && externalURL.substring(0, 8) != "https://"){
				alert("Please enter a valid external registration URL.")
				bool = false;
			}
	}

	if(eventURL != ""){
			if(eventURL.substring(0, 7) != "http://" && eventURL.substring(0, 8) != "https://"){
				alert("Please enter a valid URL.")
			}
			else{
				if(bool)
					doDocumentAction(act);
			}
		}
		else{
				if(bool)
					doDocumentAction(act);
		}
}

function validateDocURL(stringURL, act) {

	if(stringURL != ""){
		if(stringURL.substring(0, 7) != "http://" && stringURL.substring(0, 8) != "https://"){
			alert("Please enter a valid URL.")
		}
		else{
			doDocumentAction(act);
		}
	}
	else{
			doDocumentAction(act);
	}
}

function validateVenueDocURL(stringURL, mapURL, act) {

		var errs = false;

		if(stringURL != "" || mapURL != ""){
			if(stringURL != ""){
				if(stringURL.substring(0, 7) != "http://" && stringURL.substring(0, 8) != "https://"){
					alert("Please enter a valid URL.")
					errs = true;
				}
			}
			if(mapURL != ""){
				if(mapURL.substring(0, 7) != "http://" && mapURL.substring(0, 8) != "https://"  && errs == false){
					alert("Please enter a valid map URL.")
					errs = true;
				}
			}

			if(errs == false){
				doDocumentAction(act);
			}
		}
		else{
			doDocumentAction(act);
		}
}

function validateSponsorURL(stringURL, act) {

		var errs = false;
		if(document.masterForm.EVENT_SPONSOR_ORDER) {
			if(!errs && document.masterForm.EVENT_SPONSOR_ORDER.value < 1){
				alert("Please enter a sponsor order that is greater than or equal to one.");
				errs = true;
			}
		}

		if(!errs && stringURL != ""){
			if(stringURL.substring(0, 7) != "http://" && stringURL.substring(0, 8) != "https://"){
					alert("Please enter a valid URL.")
					errs = true;
			}
			else{
				doDocumentAction(act);
			}
		}
		else if (!errs){
			doDocumentAction(act);
		}
}

function validateURL(stringURL, act) {

		if(stringURL != ""){
			if(stringURL.substring(0, 7) != "http://" && stringURL.substring(0, 8) != "https://"){
					alert("Please enter a valid URL.")
			}
			else{
				doAction(act)
			}
		}
		else{
			doAction(act)
		}
}
function moveSpeakerUp(evspId,order,spId){

	if(order == 1){
		alert("This speaker can not be moved up the list.");
	}
	else{
		document.masterForm.PREV_EVENT_SPEAKER_ORDER.value = order;
		var ord = order - 1;
		document.masterForm.EVENT_SPEAKER_ORDER.value = ord;
		document.masterForm.EVENT_SPEAKER_ID.value = evspId;
		document.masterForm.SPEAKER_ID.value = spId;
		doAction("order_event_speakers")
	}
}

function moveSpeakerDown(evspId,order,spId){

		document.masterForm.PREV_EVENT_SPEAKER_ORDER.value = order
		var ord = 0;
		ord = 1*order + 1;
		document.masterForm.EVENT_SPEAKER_ORDER.value = ord;
		document.masterForm.EVENT_SPEAKER_ID.value = evspId;
		document.masterForm.SPEAKER_ID.value = spId;
		doAction("order_event_speakers");

}

function moveUp(evspId, spTypeId, order, spId){

	if(order == 1){
		alert("This sponsor can not be moved up the list.");
	}
	else{
		document.masterForm.PREV_EVENT_SPONSOR_ORDER.value = order
		var ord = order - 1;
		document.masterForm.EVENT_SPONSOR_ORDER.value = ord;
		document.masterForm.EVENT_SPONSOR_ID.value = evspId;
		document.masterForm.SPONSOR_TYPE_ID.value = spTypeId;
		document.masterForm.SPONSOR_ID.value = spId;
		doAction("order_event_sponsors")


	}

}

function moveDown(evspId, spTypeId, order, spId){

		document.masterForm.PREV_EVENT_SPONSOR_ORDER.value = order
		var ord = 0;
		ord = order -1;
		ord = ord + 2;
		document.masterForm.EVENT_SPONSOR_ORDER.value = ord;
		document.masterForm.EVENT_SPONSOR_ID.value = evspId;
		document.masterForm.SPONSOR_TYPE_ID.value = spTypeId;
		document.masterForm.SPONSOR_ID.value = spId;
		doAction("order_event_sponsors");

}

function registerNow(evId){

		document.registerForm1.target = "_self";
		document.registerForm1.action = "index.jsp";
		document.registerForm1.page.value = "eventregister";
		document.registerForm1.eventID.value = evId;

		document.registerForm1.submit();

}

function doAction(act){

	document.masterForm.target = "_self";
	//reset quickSearch if another tab was selected
	if(document.masterForm.quickSearch && document.masterForm.initAdminAction)
		{
			if( document.masterForm.initAdminAction.value != act)
				document.masterForm.quickSearch.value = "";
	  }
	document.masterForm.page.value = act;
  document.masterForm.action = "index.jsp";
	document.masterForm.submit();

}

//Ben's Code for Adding new Sponsor Survey 1.8.06
function addNewSurvey(sponsorID){
	alert(sponsorID);
	//doAction('addmod_sponsor_survey');
}

function deleteSurvey(id){
	if(confirm("Are you sure you want to remove this Survey?")){
		document.masterForm.SPONSOR_SURVEY_ID.value = id;
		doAction('delete_survey');
	}
}


function deleteSponsorSurveyQuestion(id){
	if(confirm("Are you sure you want to remove this survey question?")){
		document.masterForm.SPONSOR_QUESTION_ID.value = id;
		doAction('delete_sponsor_survey_question');
	}
}

function addModSurvey(id){
	document.masterForm.SPONSOR_SURVEY_ID.value = id;
	doAction('addmod_sponsor_survey');
}

function addModSponsorSurveyQuestion(id){

	document.masterForm.SPONSOR_QUESTION_ID.value = id;
	doAction('addmod_sponsor_survey_question');

}

function addModSponsorSurveyQuestionChoice(id){

	document.masterForm.SPONSOR_QUESTION_CHOICE_ID.value = id;
	doAction('addmod_sponsor_survey_question_choice');
}

function applySponsorSurveyChoice(){
	
	
	var longText = trim(document.masterForm.SPONSOR_QUESTION_CHOICE_TEXT.value);


	if(longText == "" )
	{
		alert("Please enter choice text.\n");
	}
 else
  {
  	doAction('apply_sponsor_survey_question_choice');
  }
}

function deleteSponsorSurveyQuestionChoice(id){

	if(confirm("Are you sure you want to remove this survey question choice?")){
		document.masterForm.SPONSOR_QUESTION_CHOICE_ID.value = id;
		doAction('delete_sponsor_survey_question_choice');
	}
}

function viewResults(id){
	
	if( id != ''){
		document.masterForm.SPONSOR_SURVEY_ID.value = id;
		doAction('addmod_survey_results');
	}
}

function addModSponsorSurveyChoiceOption(id){

	document.masterForm.SPONSOR_QUESTION_CHOICE_OPTION_ID.value = id;
	doAction('addmod_sponsor_survey_question_choice_option');
}

function deleteSponsorSurveyQuestionChoiceOption(id){

	if(confirm("Are you sure you want to remove this option?")){
		document.masterForm.SPONSOR_QUESTION_CHOICE_OPTION_ID.value = id;
		doAction('delete_sponsor_survey_question_choice_option');
	}
}

function applySponsorSurveyChoiceOption(){
	var longText = trim(document.masterForm.SPONSOR_QUESTION_CHOICE_OPTION_TEXT.value);


	if(longText == "" )
	{
		alert("Please enter choice option text.\n");
	}
 else
  {
 	 	doAction('apply_sponsor_survey_question_choice_option');
  }
	
	

}

function applyCloseSponsorSurveyChoice(){
	
	var longText = trim(document.masterForm.SPONSOR_QUESTION_CHOICE_TEXT.value);


	if(longText == "" )
	{
		alert("Please enter choice text.\n");
	}
 else
  {
 	 doAction('apply_close_sponsor_survey_question_choice');
  }
	
}

function submitSurvey(){		

	var id = document.surveyForm.surveyID.value;	
  
	var cookieName = 'username' + '_' + id;
	username=getCookie(cookieName);	
	username = id;
  
  //Development mode
	//setCookie('username'+ '_' + username,username ,1, '//');		
	
	//Production mode
	setCookie('username'+ '_' + username,username ,1, '/');		
	
	document.surveyForm.page.value = "apply_survey";
  document.surveyForm.action = "/index.jsp";
	document.surveyForm.submit();
}

function validateSurveyQuestion(act){

	if(checkDate()){
			doAction(act);
	}
	
}

  
function checkDate(){
	var retBool = true;
	var today = new Date(); 
	var startDate = new Date();
	var endDate = new Date();
	

	startDate.setFullYear( document.masterForm.SURVEY_START_DATE.value.substring(6, 10),  document.masterForm.SURVEY_START_DATE.value.substring(0, 2)-1, document.masterForm.SURVEY_START_DATE.value.substring(3, 5) );	
	
	
	
	endDate.setFullYear( document.masterForm.SURVEY_END_DATE.value.substring(6, 10),  document.masterForm.SURVEY_END_DATE.value.substring(0, 2)-1, document.masterForm.SURVEY_END_DATE.value.substring(3, 5) );

 	if(startDate > endDate){
		alert('Start Date cannot be before end date');
		retBool =false;
	}

	
	return retBool;	
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(c_name)
	{
		
		
		if (document.cookie.length>0)
		{ 
			c_start=document.cookie.indexOf(c_name + "=")
			
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
				return unescape(document.cookie.substring(c_start,c_end))
			} 
		}
		return ""
	}
	
	function setCookie(c_name,value,expiredays, myPath)
	{
		var exdate=new Date()
		exdate.setDate(exdate.getDate()+expiredays)
		document.cookie=c_name+ "=" +escape(value)+	((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) + ((myPath==null) ? "" : "; path="+myPath)
	}


	
	function checkCookie(surveyURL, sponsorURL, id)
	{
		var cookieName = 'username' + '_' + id;
		username=getCookie(cookieName);	
		
	
	
	
	
		if (username!=null && username!="")
	  {
			if( username.toString() == id){	
				window.location.href = sponsorURL;			
			}				
	  }
		else 
	  {	
	  	
		 	username = id;
		  //if (username!=null && username!="")		 
		  //	setCookie('username'+ '_' + username,username ,1);		
		 	window.location.href = surveyURL;		  
		}
	}
	
	function applyCloseEvent(eventID)
	{
		
		if(document.masterForm.EVENT_IS_FULL.checked == false){
			document.masterForm.EVENT_IS_FULL.value = "F";
 		}
		doAction('apply_close_event');
	}
	
	
	//-- Create special pricing object, blee 030608
	function eventOptionObj(eveOptionID,eveOfferID,eveOfferOptPrice,eveOfferOptDescr)
	{
		this.eveOptionID			= eveOptionID;
		this.eveOfferID				= eveOfferID;
		this.eveOfferOptPrice	= eveOfferOptPrice;
		this.eveOfferOptDescr	= eveOfferOptDescr;
	}