/* FILE::			Navigation.js
 *
 * This file contains, some functions used for submitting the value of
 * PVO_Search.jsp in a NYCSERV Protocol format.
 *
 * <p> </p>
 * <pre>
 ******************************************************************************
 *                     M O D I F I C A T I O N   L O G                        *
 *                                                                            *
 *                                                                            *
 *      DATE        RELEASE #   AUTHOR      DESCRIPTION                       *
 *      ----        ---------   ------      -----------                       *
 *      08/04/2000  1.0         Guru    Created and unit Tested               *
 *                                                                            *
 ******************************************************************************
 * </pre>
 *
 * @author  Gurusamy Kadarkaraisamy
 * @version 1.0
 *
 *
 */


var protocol ;
var logging = false;
var loggingWindow;
var search_executing = false;

function goToHomePage()
{
	goToURL('NYCSERVMain');
}

function goToURL(url)
{
	location.href = url;
}

function openTicketPopUp()
{
	openPopUpWindow('violationSample.html','TicketPopUp','310','480','no','no','no','no');
}

function PVO_Violations(vioNum)
{

	if (!search_executing)
	{
		
	
		var vio="";
		if(ticketValidate(vioNum))
		{
			
			//top.g_CurrentFunction = 'Pay Parking Tickets'
			//top.g_FuncSet=1;
			setField("PVO_VIOLATION_NUMBER",TrimChar(vioNum," "));
			setServiceName("PVO_VIO_BY_VIO_NUMBER");
			search_executing = true;
			submitProtocolForm();
		}
	}
}

function PVO_RequestHearingSearchTicket(vioNum)
{

	if (!search_executing)
	{
		
	
		var vio="";
		if(ticketValidate(vioNum))
		{
			
			//top.g_CurrentFunction = 'Pay Parking Tickets'
			//top.g_FuncSet=1;
			setField("PVO_VIOLATION_NUMBER",TrimChar(vioNum," "));
			setServiceName("PVO_HEARING_REQUEST_SEARCH_BY_VIO_NUMBER");
			search_executing = true;
			submitProtocolForm();
		}
	}
}

function PVO_Violations_PlateId(plateId,towcheck,state,ptype)
{
    if (plateNoValidate(plateId))
	{
		//top.g_CurrentFunction = 'Pay Parking Tickets'
		//top.g_FuncSet=1;
 		setField("PVO_PLATE_ID",TrimChar(TrimChar(plateId.value," "),"-"));
 		setField("PVO_STATE_NAME",state);
 		setField("PVO_SEARCH_FOR_TOW",towcheck);
 		setField("PVO_PLATE_TYPE",ptype);
 		if (towcheck == 'true')
			setServiceName("PVO_VIO_BY_PLATE_AND_TOW");
		else
			setServiceName("PVO_VIO_BY_PLATE");
		submitProtocolForm();
	}
}

function PVO_Violations_PlateIdFor311(plateId,towcheck,state,ptype)
{
    if (plateNoValidate(plateId))
	{
		//top.g_CurrentFunction = 'Pay Parking Tickets'
		//top.g_FuncSet=1;
 		setField("PVO_PLATE_ID",TrimChar(TrimChar(plateId.value," "),"-"));
 		setField("PVO_STATE_NAME",state);
 		setField("PVO_SEARCH_FOR_TOW",towcheck);
 		setField("PVO_PLATE_TYPE",ptype);
		setServiceName("311_PVO_VIO_BY_PLATE_AND_TOW");
		submitProtocolForm();
	}
}

function PVO_Violations_PlateId_Search(plateId,towcheck,collateralcheck,state,ptype)
{

	if (!search_executing)
	{

		if (plateNoValidate(plateId))
		{
			
			//top.g_CurrentFunction = 'Pay Parking Tickets'
			//top.g_FuncSet=1;
	 		setField("PVO_PLATE_ID",TrimChar(TrimChar(plateId.value," "),"-"));
	 		setField("PVO_STATE_NAME",state);
	 		setField("PVO_SEARCH_FOR_TOW",towcheck);
	 		setField("PVO_PLATE_TYPE",ptype);
	
			// if the box is checked, do not search for collateral plates
	 		if (collateralcheck )
				setField("PVO_COLLATERAL",'FALSE');
			else
		 		setField("PVO_COLLATERAL",'TRUE');
	
	 		if (towcheck) { 	// was towcheck == 'true' s/b towcheck
				setServiceName("PVO_VIO_BY_PLATE_AND_TOW");
				}
			else {
				setServiceName("PVO_VIO_BY_PLATE");
				}
			search_executing = true;
			submitProtocolForm();
		}
	}
	
	
}

function PVO_Violations_MultiplePlate()
{
   
	
		var theForm = getProtocolForm();
	    	if ((eval("theForm."+ "PVO_SEARCH_FOR_TOW")).value == 'true')
			setServiceName("PVO_VIO_BY_MULTIPLE_PLATE_AND_TOW");
		else
			setServiceName("PVO_VIO_BY_MULTIPLE_PLATE");
		submitProtocolForm();
	
}

function PVO_Violations_MultiplePlateFor311()
{
   
	
		var theForm = getProtocolForm();
		setServiceName("311_PVO_VIO_BY_MULTIPLE_PLATE_AND_TOW");
		submitProtocolForm();
	
}
function selectRow(plateid,towcheck,state,ptype,e1date,e2date,dup)
{
       setField("PVO_PLATE_ID",TrimChar(TrimChar(plateid," "),"-"));
	   setField("PVO_STATE_NAME",state);
	   setField("PVO_SEARCH_FOR_TOW",towcheck);
	   setField("PVO_PLATE_TYPE",ptype);
	   setField("PVO_PLATE_EFFECTIVE_DATE",e1date);
	   setField("PVO_PLATE_EXPIRATION_DATE",e2date);
	   setField("DUPLICATE_PLATE", dup);
}

function PVO_Check_Violation_Status(vioNum)
{
	if(ticketValidate(vioNum))
	{
		setField("PVO_VIOLATION_NUMBER",TrimChar(vioNum," "));
		setServiceName("PVO_CHECK_VIOLATION_STATUS_DETAILS");
		submitProtocolForm();
	}
}

function PVO_Check_Status()
{
	setServiceName("PVO_CHECK_STATUS");
	submitProtocolForm();
}

function PVO_Violation_Search( )
{
	setServiceName("PVO_QUERY_SETUP");
	submitProtocolForm();
}

function submitProtocolForm ()
{
	fvLogEntry ();
	var theForm = getProtocolForm();
	if (submitProtocol(theForm))
	{
	   theForm.submit();
	}
	fvLogExit ();
	return true;
}

function submitProtocol (form)
{
	fvLogEntry ();
	verify(form);
	return true;
	fvLogExit ();
}

function showMessage ()
{
	fvLogEntry ();
	var errorMsg = getErrorMessage();
	if (errorMsg != "") {
		alert(errorMsg);
		setErrorMessage("");
	fvLogExit ();
	}
}

function showMessageFix (errmsg)
{
	var errorMsg = getErrorMessage();
	if (errorMsg != "done") {
		alert(errmsg);
		setErrorMessage("done");
	}
}

function getField (theErrorForm,theField)
{
	return (eval("document."+theErrorForm +"." + theField)).value;
}

function getErrorMessage()
{
	return document.ErrorForm.ErrorMessage.value;
}

function verify (form)
{
	fvLogEntry ();
	protocol = new oProtocol();
	protocol.fbBuildRequest(form)
	fvLogExit ();
	return true;
}

function setErrorMessage(theValue)
{
	fvLogEntry ();
	document.ErrorForm.ErrorMessage.value = theValue;
	fvLogExit ();
}

function setField (theErrorForm, theField, theValue)
{
	fvLogEntry ();

	// Check to see if the form field exists before trying to update its value
	if ((eval("document."+theErrorForm+"." + theField)) != undefined)
	{
		(eval("document."+theErrorForm+"." + theField)).value=theValue;
	}
	fvLogExit ();
}

function setField (theField, theValue)
{
	fvLogEntry ();
	var theForm = getProtocolForm();

	// Check to see if the form field exists before trying to update its value
	if (typeof(theForm) != 'undefined') {
		(eval("theForm."+ theField)).value=theValue;
	}
	fvLogExit ();
}

// logging helper
function fvLogEntry ()
{
	if (logging) {
		if (loggingWindow == null)
		{
			loggingWindow = window.open();
		}
		loggingWindow.document.write("Entered function: " + fvLogEntry.caller.toString().match(/function (\w*)/)[1] + "<BR>");

	}
}
// logging helper
function fvLogExit ()
{
	if (logging) {
		if (loggingWindow == null)
		{
			loggingWindow = window.open();
		}
		loggingWindow.document.write("Exited function: " + fvLogExit.caller.toString().match(/function (\w*)/)[1] + "<BR>");

	}
}

function setServiceName (theServiceName)
{
	fvLogEntry ();
	var theForm = getProtocolForm();
	theForm.ServiceName.value = theServiceName;
	fvLogExit ();
}

function getSearchType ()
{
	fvLogEntry ();
	var theForm = getProtocolForm();
	searchType = theForm.SearchType.value;
	fvLogExit ();
	return searchType;
}

function setSearchType (searchType)
{
	fvLogEntry ();
	var theForm = getProtocolForm();
	theForm.SearchType.value = searchType;
	fvLogExit ();
}
function getProtocolForm ()
{
	fvLogEntry ();

	if (navigator.appName == 'Netscape'){
		if (document.forms[0] == undefined)
			return document.outer.document.forms["NycservProtocolForm"];
		else
			return document.forms["NycservProtocolForm"];
	} else {
		return document.forms["NycservProtocolForm"];
	}
	fvLogExit ();
}

function openPopUpWindow(URL,name,width,height,loc,scroll,tool,resize)
{
	var windowprops = "location=" + loc +",scrollbars="+scroll+",menubars=yes,toolbar="+tool+",resizable="+resize+",resizable=0" +
	",left=" + 25 + ",top = "+ 25 + ",width=" + width + ",height=" + height;
	popup = window.open(URL,name,windowprops);
	popup.focus();
}   //end of the function for the pop-up window

function openCVVInfo() 
{
	openPopUpWindow('cvv_info.html','FAQPopUp','800','450','no','yes','yes','yes');
}
 


function gotoContactUspage()
{
	openPopUpWindow('ContactUs.html','FAQPopUp','650','450','no','yes','yes','yes');
}

function PTX_Payment_History_Search()
{
	setServiceName("TAX_PAYMENT_HISTORY_QUERY_SETUP");
	submitProtocolForm();
}


function ChoosePaymentType(serviceName)
{
	setServiceName(serviceName);
	submitProtocolForm();
}

function getLink()
{
	fvLogEntry ();
	var theForm = getProtocolForm();
	linkType = theForm.LinkType.value;
	fvLogExit ();
	return linkType;
}

function setLink(linkType, textbox)
{
	fvLogEntry ();
	var theForm = getProtocolForm();
	if (navigator.appName == 'Netscape') {
		theForm.LinkType.value = "";
	}
	if (typeof(textbox) != 'undefined') {
		if ( (textbox.value.length > 0 ) && ((textbox.value != "") || (textbox.value != "0.00")) ) {
			theForm.LinkType.value = linkType;
		}
	}
	fvLogExit ();
}

