package market.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import market.*;
import market.util.*;
import market.thread.*;
import market.util.text.Text;

/**
 * This is a market master servlet. <br>
 * Type in browser: http://hostmarket:port/servlet/MarketServlet?... It function is: <br>
 * 1. Start Scedule:<br>
 *    Parameter: ...MarketServlet?ReqType=start <br>
 * 2. Stop Scedule:<br>
 *    Parameter: ...MarketServlet?ReqType=stop <br>
 * 3. Return Market Key:<br>
 *    Parameter: ...MarketServlet?ReqType=GetMarketKey <br>
 * 4. Registrate base URL:<br>
 *    Parameter: ...MarketServlet?ReqType=regurl&srcString=host&langKey=English
 * &timeBase=100&frequence=2&keepInDomain=false&keepInPath=true&grabLevels=3 <br>
 * 5. Delete base URL:<br>
 *    Parameter: ...MarketServlet?ReqType=delurl&schedSrcKey=1
 * 6. Edit base URL:<br>
 *    Parameter: ...MarketServlet?ReqType=editurl&srcKey=34&timeBase=100
 * &frequence=2&keepInDomain=false&keepInPath=true&grabLevels=3
 * 7. Change base URL status:<br>
 *    Parameter: ...MarketServlet?ReqType=status&srcKey=34&activate=true|false
 * 8. Get base market configuration menu:<br>
 *    Parameter: ...MarketServlet?ReqType=getconf
 * 9. Get marketMaster configuration menu:<br>
 *    Parameter: ...MarketServlet?ReqType=getm_conf
 * 10. Get marketMaster configuration menu:<br>
 *    Parameter: ...MarketServlet?ReqType=getm_conf
 * 11. Get market Owerview menu:<br>
 *    Parameter: ... MarketServlet?ReqType=overview
 * 12. Get market base logs menu:<br>
 *    Parameter: ...MarketServlet?ReqType=logs
 * 13. Get marketMaster log file from day date:<br>
 *    Parameter: ...MarketServlet?ReqType=getlogfile&date=2000-03-06
 * 14. Get market base URL menu:<br>
 *    Parameter: ...MarketServlet?ReqType=getsrclist
 * 15. Load new market.cfg file:<br>
 *    Parameter: ...MarketServlet?ReqType=loadconf
 * 16. Save new market.cfg file:<br>
 *    Parameter: ...MarketServlet?ReqType=saveconf
 * 17. Change config param with new value:<br>
 *    Parameter: ...MarketServlet?ReqType=conf&param=marketCfgPath
 * &value=g:\market\test\market.cfg
 * 18. Get dialog to edit base URL:<br>
 *    Parameter: ...MarketServlet?ReqType=getedit&srcKey=146
 * 19. Get dialog to add new base URL:<br>
 *    Parameter: ...MarketServlet?ReqType=getadd
 * 20. Refreshes a frame with WR and RW speed<br>
 *    Parameter: ...MarketServlet?ReqType=refresh
 * Creation date: (12/21/99 7:04:09 PM)
 * @author: tin
 */

public class MarketServlet extends HttpServlet {

	// Constant
	private final static byte TASK_ERROR = 0;
	private final static byte TASK_START = 1;
	private final static byte TASK_STOP = 2;
	private final static byte TASK_CONF = 3;
	private final static byte TASK_GET_CONF_PAGE = 4;
	private final static byte TASK_GET_OVERVIEW_PAGE = 5;	
	private final static byte TASK_GET_LOGS_PAGE = 6;
	private final static byte TASK_GET_CONF_MARKET_PAGE = 7;
	private final static byte TASK_SAVE_CONF = 8;
	private final static byte TASK_LOAD_CONF = 9;
	private final static byte TASK_GET_LOG_FILE = 10;
	private final static byte TASK_URL_STATUS = 11;
	private final static byte TASK_GET_SRC_LIST_PAGE = 12;	
	
	private final static byte TASK_NEW_URL = 13;		
	private final static byte TASK_ADD_URL = 14;
	private final static byte TASK_DEL_URL = 15;
	private final static byte TASK_EDIT_URL = 16;
	private final static byte TASK_GET_EDIT_PAGE = 17;
	private final static byte TASK_GET_ADD_PAGE = 18;
	private final static byte TASK_REFRESH = 20;
	
	private final static byte TASK_GET_MARKET_KEY = 19;
	//	private static

	//Threads

	public static Schedule mSchedule;
	public static SourceList srcList;
	public static LangTable langTable; // This is a table whit Language

	// Field for instance only	
	private byte taskType;
	public String status;
	private String name = "MarketServlet";
/**
 * market constructor comment.
 */
public MarketServlet() {
	super();
}
/**
 * Destroy servlet.
 * Creation date: (26.2.00 17:28:03)
 */
public void destroy() {}
/**
 * Resolv TaskType ( Registration, Start, Stop or Error )
 * Creation date: (12/16/99 11:31:06 AM)
 * @return byte
 * @param sTaskType java.lang.String
 */
public byte getTask(String sTaskType) {
	
	if ( sTaskType == null ) return (TASK_ERROR);
	
	if ( sTaskType.equalsIgnoreCase(Const.ADD_URL) ) {
		return (TASK_ADD_URL);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.DEL_URL) ) {
			return (TASK_DEL_URL);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.START) ) {
			return (TASK_START);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.STOP) ) {
			return (TASK_STOP);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_MARKET_KEY) ) {
			return (TASK_GET_MARKET_KEY);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_EDIT_PAGE) ) {
			return (TASK_GET_EDIT_PAGE);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_ADD_PAGE) ) {
			return (TASK_GET_ADD_PAGE);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_CONF_PAGE) ) {
			return (TASK_GET_CONF_PAGE);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_OVERVIEW_PAGE) ) {
			return (TASK_GET_OVERVIEW_PAGE);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_SRC_LIST_PAGE) ) {
			return (TASK_GET_SRC_LIST_PAGE);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_LOGS_PAGE) ) {
			return (TASK_GET_LOGS_PAGE);
	}
	else if ( sTaskType.equalsIgnoreCase(Const.GET_LOG_FILE) ) {
			return (TASK_GET_LOG_FILE);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_CONF_PAGE) ) {
			return (TASK_GET_CONF_PAGE);
	}
	else if ( sTaskType.equalsIgnoreCase(Const.SAVE_CONF) ) {
			return (TASK_SAVE_CONF);
	}
	else if ( sTaskType.equalsIgnoreCase(Const.LOAD_CONF) ) {
			return (TASK_LOAD_CONF);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.CONF) ) {
			return (TASK_CONF);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.GET_CONF_MARKET_PAGE) ) {
			return (TASK_GET_CONF_MARKET_PAGE);
	} 
	else if ( sTaskType.equalsIgnoreCase(Const.EDIT_URL) ) {
			return (TASK_EDIT_URL);
	}
	else if ( sTaskType.equalsIgnoreCase(Const.NEW_URL) ) {
			return (TASK_NEW_URL);
	}	
	else if ( sTaskType.equalsIgnoreCase(Const.URL_STATUS) ) {
			return (TASK_URL_STATUS);
	}
	else if ( sTaskType.equalsIgnoreCase(Const.REFRESH_SPEED) ) {
			return (TASK_REFRESH);
	}
	else return (TASK_ERROR);

}
/**
 * Init servlet.
 * Creation date: (15.2.00 21:58:40)
 * @param config javax.servlet.ServletConfig
 * @exception javax.servlet.ServletException The exception description.
 */
public void init(ServletConfig config) throws ServletException {
	super.init(config);
	
	String path = getInitParameter(ConfigMarket.nameMarketCfgPath);
	System.out.println( path );
	if (path != null) {
		if (ConfigMarket.init(path)) {
			status = "Parameter is loaded.";
			if (initOtherMarket()) {
				mSchedule = new Schedule();
				status += " Other servlet is loaded. Schedule is created.";
			} else
				status += " Other servlet is not loaded!";
		} else
			status = "Parameter is not load!";
	} else
		status = "Error input parameter!";
		
	if (ConfigMarket.logWriter != null) {
		ConfigMarket.logWriter.log( name + ": Init result : " + status, LogPrinter.INFO);
		ConfigMarket.logWriter.log( name + ": Init from file: " + path + " completed.", LogPrinter.INFO);
	}
}
/**
 * Init other market servlets.
 * Creation date: (25.3.2000 “. 18:41:42)
 * @return boolean
 */
public boolean initOtherMarket() {
	int result;
	ConfigMarket.logWriter.log(getClass().getName() + ": Try load market_XServer!", LogPrinter.INFO);
	try {
		ConfigMarket.wrServer = (market.market_util.m_wrServer) getServletConfig().getServletContext().getServlet(ConfigMarket.marketWrServer);
		result = ConfigMarket.wrServer.market_wrServerInit(ConfigMarket.marketKey);
		if ( result!=market.market_util.Constants.NO_ERROR) {
			ConfigMarket.logWriter.log(name + ": Can't load market_wrServer!", LogPrinter.ERROR);
			return false;
		} else {
			ConfigMarket.logWriter.log(name + ": Loaded market_wrServer!", LogPrinter.INFO);
		}
	} catch (Exception e) {
		ConfigMarket.logWriter.log(name + ": Can't load market_wrServer! : " + e, LogPrinter.ERROR);
		return false;
	}
	try {
		ConfigMarket.rwServer = (market.market_util.m_rwServer) getServletConfig().getServletContext().getServlet(ConfigMarket.marketRwServer);
		//		ConfigMarket.rwServer.market_rwServerInit();
		result = ConfigMarket.rwServer.market_rwServerInit(ConfigMarket.marketKey);
				if ( result != market.market_util.Constants.NO_ERROR) {
			ConfigMarket.logWriter.log(name + ": Can't load market_rwServer!", LogPrinter.ERROR);
			return false;
		} else {
			ConfigMarket.logWriter.log(name + ": Loaded market_rwServer!", LogPrinter.INFO);
		}

	} catch (Exception e) {
		ConfigMarket.logWriter.log(name + ": Can't load market_rwServer! : " + e, LogPrinter.ERROR);
		return false;
	}
	try {
		ConfigMarket.mdvServer = (market.MDVServer.MDVInterFace) getServletConfig().getServletContext().getServlet(ConfigMarket.marketMDVServer);
		//		ConfigMarket.rwServer.market_rwServerInit();
		ConfigMarket.mdvServer.mdvSetMarketKey(ConfigMarket.marketKey);
		ConfigMarket.logWriter.log(name + ": Loaded MDVServer!", LogPrinter.INFO);
	} catch (Exception e) {
		ConfigMarket.logWriter.log(name + ": Can't load MDVServer! : " + e, LogPrinter.ERROR);
		return false;
	}
	return true;
}
/**
 * Init source information.
 * Creation date: (29.2.2000 “. 22:43:31)
 * @return boolean
 */
protected synchronized boolean initSource() {

	ConfigMarket.logWriter.log( name +": Try load lang table!", LogPrinter.INFO);
	// Load Langage Table
	langTable = Schedule.getLangTable();
	if (langTable == null) {
		status = "Market can't load language table.";
		ConfigMarket.logWriter.log( name +": " + status, LogPrinter.INFO);
		mSchedule = null;
		return false;
	}
	ConfigMarket.logWriter.log( name +": Src list is loaded.", LogPrinter.INFO);
	langTable.print();

	ConfigMarket.logWriter.log( name +": Try load src list!", LogPrinter.INFO);
	// Load Source List
	srcList = Schedule.getSrcList(); //  srcFile 
	if (srcList == null) {
		status = "Market can't load base source list.";
		ConfigMarket.logWriter.log( name +": " + status, LogPrinter.INFO);
		mSchedule = null;
		return false;
	} else
		status = "Market load source and language.";
		
	srcList.sort();
	srcList.print();
	
	ConfigMarket.logWriter.log( name + ": " + status, LogPrinter.INFO);

	return true;
}
/**
 * This method was be call when user want to change URL status (active / deactive). <br> 
 * Creation date: (12/21/99 7:09:18 PM)
 * @return boolean ( true for successfully registration )
 * @param req sun.servlet.http.HttpServletRequest
 */
 public boolean mActive(HttpServletRequest req ) {
 
	boolean active;
	long baseSrcKey;
 	String temp;

	srcList.fillSrcString();
 	temp = req.getParameter( Const.SRC_KEY );
 	
 	if ( null == temp ) return false;
 	
	baseSrcKey = Long.valueOf( temp ).longValue();
	
	temp = req.getParameter( Const.ACTIVE );
	
 	if ( null == temp ) return false;
 	
	active  = temp.equalsIgnoreCase("true");
	
	System.out.println( active );
	
	boolean res = mSchedule.scdActivateURL(baseSrcKey, active );
	status = mSchedule.getLastOperationResult();
	return res;
}
	//Methods

  public static void main(String args[]){
	MarketServlet market = new MarketServlet();
   
	PrintWriter out = new PrintWriter( System.out );
	try { 
		out = new PrintWriter( new FileOutputStream("C:\\temp\\interface.html") );
		market.mStartServlet( out );
//	 	market.mFormSrcList( out , srcList, langTable );
//		market.mFormAdd( out , srcList, langTable );
//  	market.mFormEdit( out , srcList, langTable );
//		market.mFormOverview( out , srcList, langTable );
//		market.mFormLogs( out , srcList, langTable );
//		market.mFormConf( out);
		market.mFormConfigParam( out );		
	} catch (Exception e){System.out.println(e.toString());}
	
	out.println("Hello");
	String sTask = args[0];

	long srcKey; 
	

	byte taskType = market.getTask( sTask );

	switch ( taskType ) {
		case TASK_ADD_URL :
		  out.println("Registrate URL");
		  mSchedule.scdSubscribeURL( "www.marto.com", 2, 12312, 1, 1, 1, 2, "Marto 1.0");

		  out.println("Done");
		break;
		case TASK_START :
		  out.println("Market Servlet Starting...");
		  market.mStartServlet( out );
		  out.println("Done");
		break;
		case TASK_STOP :
		  out.println("Market Servlet Soping...");
// Stop Scedule  		  
		  out.println("Done");
		break;
		case TASK_ERROR :
	    defaut:
	      market.mFormSrcList( out , srcList, langTable );
   		  out.println("Error!");

	}


  }  
/**
 * This method was be call when user want edit market parameter. <br> 
 * Creation date: (12/21/99 7:09:18 PM)
 * @return boolean ( true for successfully registration )
 * @param req sun.servlet.http.HttpServletRequest
 */
 public boolean mConf(HttpServletRequest req) {

	String paramName;
	String paramValue;

	String temp;

 	temp = req.getParameter( Const.PARAM );
 	if ( null == temp ) return false;
	paramName = temp;

	temp = req.getParameter( Const.VALUE );
 	if ( null == temp ) return false;
	paramValue = temp;

	boolean res = ConfigMarket.setParam( paramName, paramValue );

	return ( res );	
}
/**
 * This method was be call when user want delete base Source. <br> 
 * Creation date: (10/02/00 7:09:18 PM)
 * @return boolean ( true for successfully registration )
 * @param req sun.servlet.http.HttpServletRequest
 */
 public boolean mDelUrl(HttpServletRequest req) {

	long baseSrcKey;

	String temp;

 	temp = req.getParameter( Const.BASE_SRC_KEY );
	baseSrcKey = Long.valueOf( temp ).longValue();

	boolean res = mSchedule.scdDeleteURL( baseSrcKey );
	status = mSchedule.getLastOperationResult();
	return ( res );	
}
/**
 * This method was be call when user want edit base Source. <br> 
 * Creation date: (12/21/99 7:09:18 PM)
 * @return boolean ( true for successfully editing )
 * @param req sun.servlet.http.HttpServletRequest
 */
 public boolean mEditUrl(HttpServletRequest req) {

	long baseSrcKey;
	int timeBase; 
	int frequence; 
	int keepInPath;
	int keepInDomain; 
	int grabLevels;
	String userAgent;

	String temp;
	try {
		temp = req.getParameter( Const.TIME_BASE );
		timeBase = Integer.valueOf(temp).intValue();

		temp = req.getParameter( Const.FREQ );
		frequence = Integer.valueOf(temp).intValue();

		temp = req.getParameter( Const.KEEP_IN_PATH );
		keepInPath = ( temp.equalsIgnoreCase("true") ) ? 1:0; 

		temp = req.getParameter( Const.KEEP_IN_DOMAIN );
		keepInDomain = ( temp.equalsIgnoreCase("true") ) ? 1:0; 

		temp = req.getParameter( Const.GRAB_LEVEL );
		grabLevels = Integer.valueOf(temp).intValue();

		temp = req.getParameter( Const.SRC_KEY );
		baseSrcKey = Long.valueOf(temp).longValue();

		userAgent = req.getParameter( Const.USER_AGENT );
		 

		boolean res = mSchedule.scdEditURL( baseSrcKey, timeBase, frequence, 
											keepInPath, keepInDomain, grabLevels, userAgent );
		
		status = mSchedule.getLastOperationResult();
		return ( res );
	}catch( Exception e ){
		status = " Error in parameter! ";
		return false;		
	}	
}
/**
 * Return Web page to browser. <br> This page contein list of all baseSource and interfce to: <br> 
 * - Subscribe new baseSource <br>
 * Creation date: (12/16/99 11:31:06 AM)
 * @param fileOut java.io.PrintWriter
 * @param srcList market.util.SourceList
 * @param langList market.util.LangTable
 */
public void mFormAdd(PrintWriter fileOut, SourceList srcList, LangTable langList) {
	SrcElement[] arr;
	int len;
	int i;
	int j;

	String char2int;
	
	srcList.fillSrcString();
	arr = srcList.srcBundle;
	len = srcList.lastElm;
	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	fileOut.println("<TITLE>Add</TITLE>");
	fileOut.println("<SCRIPT Language = \"JavaScript\">");
	fileOut.println("<!--\n function add_new(obj){str=\"\";  ");
	fileOut.println("str=\"" + Const.SRC_STRING + "=\"+obj.SrcValue.value + \"&" + Const.USER_AGENT + "=\"+obj.userAgent.value + \"&" + Const.LANG_KEY + "=\"+obj.langKey.value+\"&" + Const.TIME_BASE + "=\"+obj.timeBase.value+\"&" + Const.FREQ + "=\"+obj.frequence.value+\"&" + Const.KEEP_IN_PATH + "=\"+obj.KeepInPath.value+\"&" + Const.KEEP_IN_DOMAIN + "=\"+obj.KeepInDomain.value+\"&" + Const.GRAB_LEVEL + "=\"+obj.GrabLevels.value;");
	fileOut.println("str=\"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.ADD_URL + "&\"+str;\n ");
	fileOut.println("	this.window.location=str;\n}\n");
	fileOut.println("function b_srcList(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_SRC_LIST_PAGE +"\";");	
	fileOut.println("}-->");	

	fileOut.println("</SCRIPT>");
	
	fileOut.println("</HEAD>");
	fileOut.println("<BODY  text = \"black\">");
	fileOut.println("<TABLE>");
	fileOut.println("<TR><TD width = 150><B>Market Name :</B></TD><TD>" + ConfigMarket.marketName + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Location : </B></TD><TD>" + ConfigMarket.marketLocation + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Deskription : </B></TD><TD>" + ConfigMarket.marketDescription + "</TD></TR>");
	fileOut.println("</TABLE>");
	fileOut.println("<form name = \"table\" ><input type=\"hidden\"  name = \"len\" value=\"" + len + "\">");

	fileOut.println("<TABLE border=\"1\" cellspacing=\"1\" >");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>URL</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>scrKey</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Language </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Time Base </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Frequence</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER> Keep In Path </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER> Keep In Domain </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Grab Levels</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER><NOBR>Last Checked</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER><NOBR>User Agent</TD></TR>\n");
	for (i = 0; i < len; i++) {
		String	color = "BLACK";
		String languageName = langList.ltResolveKeyToFullName(arr[i].langKey);
		if( !arr[i].active ){
			color = "GRAY";
		}
	  	fileOut.println("<TR><input type=\"hidden\"  name = \"active\" value=\"" + arr[i].active + "\"></TD>"); 
		fileOut.println("<TD><FONT color =\""+color+"\" >" + arr[i].srcString + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + arr[i].srcKey + "</FONT></TD>\n");
		fileOut.println("<TD ><CENTER><FONT color =\""+color+"\" >" + languageName + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].timeBase) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].frequence) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].keepInPath) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].keepInDomain) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].grabLevels) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].lastChecked) + "</FONT></TD>\n");
		fileOut.println("<TD><FONT color =\""+color+"\" ><NOBR>" + arr[i].userAgent + "</FONT></TD></TR>\n");
	} //  Tuk shte svurshva for zikala
	fileOut.println(" </TABLE>\n");
	fileOut.println(" </form>\n");
	fileOut.println("<p><FORM name = \"NewURL\">\n");
	fileOut.println("<table border=\"1\" cellspacing=\"1\" align = \"left\">\n");
	fileOut.println("<tr><td>Enter URL</td><td><INPUT TYPE=\"text\" size = 70 NAME=\"SrcValue\" value=\"http://\"></td></tr>\n");
	fileOut.println("<tr><td>User Agent</td><td><INPUT TYPE=\"text\" size = 70 NAME=\"userAgent\" value=\"Mozilla\"></td></tr>\n");
	fileOut.println("<tr><td>Select Lanuage</td><td><SELECT NAME=\"langKey\">\n ");
	for (j = 0; j < langList.lastElm; j++) {
		fileOut.println("<option value = \"" + langList.table[j].name + "\">" + langList.table[j].name + "\n");
	}
	fileOut.println("</select></td>	</tr>\n");
	fileOut.println("<tr><td>Time Base </td> <td><INPUT TYPE=\"text\" NAME=\"timeBase\"> In minutes from midnight(1 - 1200)</td></tr>\n");
	fileOut.println("<tr><td>Frequence</td><td><INPUT TYPE=\"text\" NAME=\"frequence\">1=24 hours interval</td></tr>\n");
	fileOut.println("<tr><td>Keep In Path </td><td><select  NAME=\"KeepInPath\">\n ");
	fileOut.println("<option value = \"true\" selected>true\n");
	fileOut.println("<option value = \"false\">false\n");
	fileOut.println("</select> Stay on given URL</td></tr>\n");
	fileOut.println("<tr><td>Keep In Domain </td><td><select  NAME=\"KeepInDomain\">\n ");
	fileOut.println("<option value = \"true\" selected>true\n");
	fileOut.println("<option value = \"false\">false\n");
	fileOut.println("</select>Stay on given domain</td></tr>\n");
	fileOut.println("<tr><td>Grab Level</td><td><INPUT TYPE=\"text\" NAME=\"GrabLevels\">How many layers deep</td></tr>\n");
	fileOut.println(" <input type=\"button\"name=\"add\" value = \"Add\" onClick = \"add_new(this.form);\">\n");
	fileOut.println(" <input type=\"button\"name=\"srcList\" value = \"Source List\" onClick = \"b_srcList();\">\n");
	fileOut.println("</table></FORM>\n");
	fileOut.println("</BODY></HTML>\n");
	fileOut.close();
} // FormHtml
/**
 * Return Web page to browser. <br> This is the configuration page  <br> 
 * Creation date: (27/02/00 11:21:06 AM)
 * @param fileOut java.io.PrintWriter
 */
public void mFormConf(PrintWriter fileOut) {

	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	fileOut.println("<TITLE>Configurations</TITLE>");
	fileOut.println("<SCRIPT Language = \"JavaScript\">");
	fileOut.println("<!-- ");
	fileOut.println(" function mServ(){");
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_CONF_MARKET_PAGE+ "\"; \n}");
	fileOut.println("function log(){");
	fileOut.println("//this.window.location = \"Logs.html\";");
	fileOut.println("}");
	fileOut.println("function config(){");
	fileOut.println("//this.window.location = \"TestHtml.html\";");
	fileOut.println("}");
	fileOut.println("function mdvServ(){");
	fileOut.println("this.window.location =\""+ConfigMarket.hostMDVServer+"?"+ Const.REQ_TYPE +"=0\" ");
	fileOut.println("}");
	fileOut.println("function mWrServ(){");
	fileOut.println("this.window.location =\""+ConfigMarket.hostMarketWrServer+"?"+ Const.REQ_TYPE +"=3\" ");
	fileOut.println("}");
	fileOut.println("function mRwServ(){");
	fileOut.println("this.window.location =\""+ConfigMarket.hostMarketRwServer+"?"+ Const.REQ_TYPE +"=3\" ");
	fileOut.println("}");
	fileOut.println("function b_over(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_OVERVIEW_PAGE +"\";");	
	fileOut.println("}-->");	
	fileOut.println("</SCRIPT>");

	fileOut.println("</HEAD>");
	fileOut.println("<BODY  text = \"black\">");
	fileOut.println("<H1 align = \"center\">CONFIGURATIONS</H1>");
	fileOut.println("<TABLE>");
	fileOut.println("<TR><TD width = 150><B>Market Name :</B></TD><TD> " + ConfigMarket.marketName + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Location : </B></TD><TD>" + ConfigMarket.marketLocation + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Deskription : </B></TD><TD>" + ConfigMarket.marketDescription + "</TD></TR>");
	fileOut.println("</TABLE>");
	fileOut.println("<HR>");
	fileOut.println("<FORM name=\"logs\">");
	fileOut.println("<p><input type=\"button\" value=\"Overview\" onClick=\"b_over();\">");
	fileOut.println("<p><input type=\"button\" value=\"marketServlet\" onClick=\"mServ();\">");
	fileOut.println("<p><input type=\"button\" value=\"MDVServer\" onClick=\"mdvServ();\">");
	fileOut.println("<p><input type=\"button\" value=\"mWrServer\"onClick=\"mWrServ();\">");
	fileOut.println("<p><input type=\"button\" value=\"mRwServer\" onClick=\"mRwServ();\">");
	fileOut.println("</FORM>");
	fileOut.println("</BODY></HTML>\n");
	fileOut.close();
} // FormConf
/**
 * Return Web page to browser. <br> This is the configuration page of market Servlet <br> 
 * Creation date: (27/02/00 11:21:06 AM)
 * @param fileOut java.io.PrintWriter
 */
public void mFormConfigParam(PrintWriter fileOut) {

	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	fileOut.println("<TITLE>Param configurations</TITLE>");
	fileOut.println("<SCRIPT Language = \"JavaScript\">");
	fileOut.println("<!-- ");
	fileOut.println("function change(obj){");
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.CONF+"&"+Const.PARAM+"=\"+obj.name+\"&"+ Const.VALUE +"=\"+obj.paramName.value; \n}");
	fileOut.println("function b_over(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_OVERVIEW_PAGE +"\";");	
	fileOut.println("}");
	fileOut.println("function b_conf(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_CONF_PAGE +"\";");	
	fileOut.println("}");
	fileOut.println("function save_to(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.SAVE_CONF +"\";");	
	fileOut.println("}");
	fileOut.println("function load_from(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.LOAD_CONF +"\";");	
	fileOut.println("}-->");	
	fileOut.println("</SCRIPT>");

	fileOut.println("</HEAD>");
	fileOut.println("<BODY  text = \"black\">");
	fileOut.println("<TABLE>");
	fileOut.println("<TR><TD width = 150><B>Market Name :</B></TD><TD> " + ConfigMarket.marketName + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Location : </B></TD><TD>" + ConfigMarket.marketLocation + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Deskription : </B></TD><TD>" + ConfigMarket.marketDescription + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Status:</B></TD><TD>" + status+ "</TD></TR>");
	fileOut.println("</TABLE>");
	fileOut.println("<HR>");
	fileOut.println("<input type =\"button\" value=\"Overview\" onClick =\"b_over();\">");
	fileOut.println("<input type =\"button\" value=\"Main Config\" onClick =\"b_conf();\">");
	fileOut.println("<input type =\"button\" value=\"Save to file\" onClick =\"save_to();\">");
	fileOut.println("<input type =\"button\" value=\"Load from file\" onClick =\"load_from();\">");
	fileOut.println("<HR>");
	fileOut.println("<TABLE  border = 2 cellpadding =5 cellspacing = 2 name=\"all\">");

	fileOut.println("<TR>");
	fileOut.println("	<TD>");
	fileOut.println("				<TABLE name=\"marketServlet\" border >");
	fileOut.println("				<TR>");
	fileOut.println("				<TH COLSPAN = 3 ALIGN = \"CENTER\">market Servlet<TH>");
	fileOut.println("				</TR>");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameMarketCfgPath+"</TD>");	
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameMarketCfgPath+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.marketCfgPath +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");
	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameLogFilePath +"</TD>");
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameLogFilePath+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.logFilePath +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");

	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameFileLogLevel +"</TD>");
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameFileLogLevel+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.fileLogLevel +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");

	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameScreenLogLevel +"</TD>");
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameScreenLogLevel+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.screenLogLevel +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");



	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD COLSPAN = 3 ALIGN = \"CENTER\"> 0 -None 1 -Erorr 2 -Info 3-Debug 4 -All; </TD>");
	fileOut.println("				</TR>");

	
	
	fileOut.println(" 			</TABLE>");
	fileOut.println("	</TD>");
	fileOut.println("</TR>");

	fileOut.println("<TR>");
	fileOut.println("	<TD>");
	fileOut.println("				<TABLE name =\"Schedule\"border >");
	fileOut.println("				<TR>");
	fileOut.println("				<TH COLSPAN = 3 ALIGN = \"CENTER\">Schedule , Netrunner , Parser <TH>");
	fileOut.println("				</TR>");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameHostSourceServer+"</TD>");	
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameHostSourceServer+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.hostSourceServer +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");
	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameHostResourceServer +"</TD>");
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameHostResourceServer+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.hostResourceServer +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");
	fileOut.println(" 			</TABLE>");
	fileOut.println("	</TD>");
	fileOut.println("</TR>");

	fileOut.println("<TR>");
	fileOut.println("	<TD>");
	fileOut.println("				<TABLE name=\"Downloader\" border >");
	fileOut.println("				<TR>");
	fileOut.println("				<TH COLSPAN = 3 ALIGN = \"CENTER\">Downloader<TH>");
	fileOut.println("				</TR>");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameMAX_DOC_SIZE+"</TD>");	
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameMAX_DOC_SIZE+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.MAX_DOC_SIZE+"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");
	fileOut.println(" 			</TABLE>");
	fileOut.println("	</TD>");
	fileOut.println("</TR>");

	fileOut.println("<TR>");
	fileOut.println("	<TD>");
	fileOut.println("				<TABLE name =\"WrProcessor\"border >");
	fileOut.println("				<TR>");
	fileOut.println("				<TH COLSPAN = 3 ALIGN = \"CENTER\">WrProcessor<TH>");
	fileOut.println("				</TR>");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameHostMarketWrServer+"</TD>");	
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameHostMarketWrServer+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.hostMarketWrServer +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");
	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameHostMarketRwServer+"</TD>");
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameHostMarketRwServer+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.hostMarketRwServer  +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");
	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameHostMDVServer+"</TD>");
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameHostMDVServer+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.hostMDVServer+"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");

	fileOut.println("\n");
	fileOut.println("				<TR>");
	fileOut.println("				<TD  width= 150>"+ConfigMarket.nameWrProcessorTimeSleep +"</TD>");
	fileOut.println("				<FORM NAME=\""+ConfigMarket.nameWrProcessorTimeSleep+"\">");
	fileOut.println("				<TD><INPUT TYPE=\"text\" SIZE = 50 NAME=\"paramName\" value=\""+ ConfigMarket.wrProcessorTimeSleep +"\"></TD>");
	fileOut.println("				<TD> <INPUT TYPE=\"button\" value=\"Change\" onClick= change(this.form)></TD>");
	fileOut.println("				</FORM>");
	fileOut.println("				</TR>");

	fileOut.println(" 			</TABLE>");
	fileOut.println("	</TD>");
	fileOut.println("</TR>");
	fileOut.println("</BODY></HTML>\n");
	fileOut.close();
} // FormOverview
/**
 * Return Web page to browser. <br> This page contein list of all baseSource and interfce to: <br> 
 * - Edit existing baseSource <br>
 * Creation date: (12/16/99 11:31:06 AM)
 * @param req HttpServletRequest 
 * @param fileOut java.io.PrintWriter
 * @param srcList market.util.SourceList
 * @param langList market.util.LangTable
 */
public void mFormEdit( HttpServletRequest req, PrintWriter fileOut, SourceList srcList, LangTable langList ) {

	SrcElement[] arr;
	int len;
	int i;
	int j;
	long srcKey;
	try{
		String temp = req.getParameter( Const.SRC_KEY );
		srcKey = Long.valueOf(temp).longValue();
	}catch( Exception e ){
		return; 
	}
	
   int selected = srcList.findSrc( srcKey );	
// -------------------------------------
	if( selected == -1 ){
		return;
	}
// -------------------------------------
	String char2int;
	
	srcList.fillSrcString();
	arr = srcList.srcBundle;
	len = srcList.lastElm;
	
	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	fileOut.println("<TITLE>Edit</TITLE>");
	fileOut.println("<SCRIPT Language = \"JavaScript\">");
	fileOut.println("<!--\n function edit_url(obj){str=\"\";  ");
	fileOut.println("str=\"" + Const.SRC_KEY + "=\"+obj.name+ \"&" + Const.USER_AGENT + "=\"+obj.userAgent.value+ \"&" + Const.TIME_BASE + "=\"+obj.timeBase.value+\"&" + Const.FREQ + "=\"+obj.frequence.value+\"&" + Const.KEEP_IN_PATH + "=\"+obj.KeepInPath.value+\"&" + Const.KEEP_IN_DOMAIN + "=\"+obj.KeepInDomain.value+\"&" + Const.GRAB_LEVEL + "=\"+obj.GrabLevels.value;");
	fileOut.println("str=\"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.EDIT_URL + "&\"+str;\n ");
	fileOut.println("	this.window.location=str;\n}\n");
	fileOut.println("function b_srcList(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_SRC_LIST_PAGE +"\";");	
	fileOut.println("}-->");	
	fileOut.println("</SCRIPT>");
	
	fileOut.println("</HEAD>");
	fileOut.println("<BODY  text = \"black\">");
	fileOut.println("<TABLE>");
	fileOut.println("<TR><TD width = 150><B>Market Name :</B></TD><TD> " + ConfigMarket.marketName + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Location : </B></TD><TD>" + ConfigMarket.marketLocation + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Deskription : </B></TD><TD>" + ConfigMarket.marketDescription + "</TD></TR>");
	fileOut.println("</TABLE>");
	fileOut.println("<form name = \"table\" ><input type=\"hidden\"  name = \"len\" value=\"" + len + "\">");

	fileOut.println("<TABLE border=\"1\" cellspacing=\"1\" >");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>URL</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>scrKey</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Language </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Time Base </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Frequence</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER> Keep In Path </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER> Keep In Domain </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Grab Levels</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER><NOBR>Last Checked</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER><NOBR>User Agent</TD></TR>\n");
	for (i = 0; i < len; i++) {
		String	color = "BLACK";
		String languageName = langList.ltResolveKeyToFullName(arr[i].langKey);
		if( !arr[i].active ){
			color = "GRAY";
		}
	  	fileOut.println("<TR><input type=\"hidden\"  name = \"active\" value=\"" + arr[i].active + "\"></TD>"); 
		fileOut.println("<TD><FONT color =\""+color+"\" >" + arr[i].srcString + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + arr[i].srcKey + "</FONT></TD>\n");
		fileOut.println("<TD ><CENTER><FONT color =\""+color+"\" >" + languageName + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].timeBase) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].frequence) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].keepInPath) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].keepInDomain) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].grabLevels) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].lastChecked) + "</FONT></TD>\n");
		fileOut.println("<TD><FONT color =\""+color+"\" ><NOBR>" + arr[i].userAgent + "</FONT></TD></TR>\n");

	} //  Tuk shte svurshva for zikala
	fileOut.println(" </TABLE>\n");
	fileOut.println(" </form>\n");

	fileOut.println("<p><FORM name = \""+ srcKey +"\">\n");
	fileOut.println("<table  align = \"left\">\n");
	fileOut.println("<tr><td>Enter URL</td><td><INPUT TYPE=\"text\" size = 70 NAME=\"SrcValue\" value=\""+ arr[selected].srcString +"\"://\"></td></tr>\n");
	fileOut.println("<tr><td>User Agent</td><td><INPUT TYPE=\"text\" size = 70 NAME=\"userAgent\" value=\""+ arr[selected].userAgent +"\"://\"></td></tr>\n");
	fileOut.println("<tr><td>Select Lanuage</td><td><SELECT NAME=\"langKey\">\n ");
	for (j = 0; j < langList.lastElm; j++) {
	  if (langList.table[j].langKey == arr[selected].langKey)
		 fileOut.println("<option value = \"" + langList.table[j].name + "\" selected >" + langList.table[j].name + "\n");
		 else
		 fileOut.println("<option value = \"" + langList.table[j].name + "\">" + langList.table[j].name + "\n");
	}
	fileOut.println("</select></td>	</tr>\n");
	fileOut.println("<tr><td>Time Base </td> <td><INPUT TYPE=\"text\" NAME=\"timeBase\" value = \""+String.valueOf(arr[selected].timeBase)+"\"> In minutes from midnight(1 - 1200)</td></tr>\n");
	fileOut.println("<tr><td>Frequence</td><td><INPUT TYPE=\"text\" NAME=\"frequence\" value = \""+  String.valueOf(arr[selected].frequence)  +"\">1=24 hours interval</td></tr>\n");
	fileOut.println("<tr><td>Keep In Path </td><td><select  NAME=\"KeepInPath\">\n ");
	if( arr[selected].keepInPath ){
	fileOut.println("<option value = \"true\" selected>true\n");
	fileOut.println("<option value = \"false\">false\n");
	}
	else{
	fileOut.println("<option value = \"true\">true\n");
	fileOut.println("<option value = \"false\" selected>false\n");
	}
	fileOut.println("</select> Stay on given URL</td></tr>\n");
	fileOut.println("<tr><td>Keep In Domain </td><td><select  NAME=\"KeepInDomain\">\n ");
	if( arr[selected].keepInDomain ){	
	fileOut.println("<option value = \"true\" selected>true\n");
	fileOut.println("<option value = \"false\">false\n");
	}
	else{
  	fileOut.println("<option value = \"true\" >true\n");
	fileOut.println("<option value = \"false\" selected>false\n");
	}
	fileOut.println("</select>Stay on given domain</td></tr>\n");
	fileOut.println("<tr><td>Grab Level</td><td><INPUT TYPE=\"text\" NAME=\"GrabLevels\" value =\""+ String.valueOf(arr[selected].grabLevels) +"\">How many layers deep</td></tr>\n");
	fileOut.println(" <input type=\"button\" value = \"Edit\" onClick = \"edit_url(this.form);\">\n");
	fileOut.println(" <input type=\"button\"name=\"srcList\" value = \"Source List\" onClick = \"b_srcList();\">\n");
	fileOut.println("</table></FORM>\n");
	fileOut.println("</BODY></HTML>\n");
	fileOut.close();
} // FormHtml
/**
 * Return Web page to browser. <br> This is the Log page <br>
 * Creation date: (25/02/00 11:31:06 AM)
 * @param fileOut java.io.PrintWriter
 */
public void mFormLogs(PrintWriter fileOut ) {

	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	fileOut.println("<TITLE>Logs</TITLE>");
	fileOut.println("<SCRIPT Language = \"JavaScript\">");
	fileOut.println("<!-- ");
	fileOut.println("function log(obj){");
	fileOut.println("   	for(i=0; i< 4; i++){");	
	fileOut.println("     	if (obj.server[i].checked ){");	
	fileOut.println("        window.location = obj.server[i].value+\"?" + Const.REQ_TYPE + "=" + Const.GET_LOG_FILE +"&"+Const.DATE_NAME+"=\"+obj.from.value;");	
	fileOut.println("        obj.view.value= obj.server[i].value;");	
	fileOut.println("}\n }\n }\n");	
	fileOut.println("function validate(obj ){");	
	fileOut.println("str = obj.value;");	
	fileOut.println("	for(i=0 ; i<str.length ; i++){");	
	fileOut.println("        ch = str.charCodeAt(i)");	
	fileOut.println("		   if(   (ch < 47  ||   ch > 58)  && !( ch ==45 && ( i==4 || i==7) ) || str.length <10 ){");	
	fileOut.println("	         alert(\"    The date i not valid! The date must be: dd-mm-yyyy\");");	
	fileOut.println("          obj.value=\"Error\";");	
	fileOut.println("          return;");	
	fileOut.println("}\n}\n}\n");	
	fileOut.println("function b_over(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_OVERVIEW_PAGE +"\";");	
	fileOut.println("}-->");	
	fileOut.println("</SCRIPT>");

	fileOut.println("</HEAD>");
	fileOut.println("<BODY  text = \"black\">");
	fileOut.println("<TABLE>");
	fileOut.println("<TR><TD width = 150><B>Market Name :</B></TD><TD> " + ConfigMarket.marketName + "</TD></TR>");	
	fileOut.println("<TR><TD width = 150><B>Market Location : </B></TD><TD>" + ConfigMarket.marketLocation + "</TD></TR>");	
	fileOut.println("<TR><TD width = 150><B>Market Deskription : </B></TD><TD>" + ConfigMarket.marketDescription + "</TD></TR>");	
	fileOut.println("</TABLE>");
	fileOut.println("<FORM name=\"logs\">");	
	fileOut.println("<TABLE cellspacing=3>");	
	fileOut.println("<TR align =\"center\">");	
	fileOut.println("<TH>chek</TH>");
	fileOut.println("<TH>Name</TH>");	
	fileOut.println("	<TH>date</TH>");	
	fileOut.println("<TH>date</TH>");	
	fileOut.println("</TR>");
	fileOut.println("<TR>");	
	fileOut.println("<TD><input type=\"radio\" name = \"server\" value=\""+ ConfigMarket.MarketMasterName + "\"></TD>");	
	fileOut.println("<TD>MarketServlet</TD>");	
	fileOut.println("<TD>from<input type=\"text\" maxlength=10 size=10 name=\"from\" onBlur= \"validate(this);\"></TD>");
	fileOut.println("	<TD>to<input type=\"text\"  READONLY size=10 maxlength=10 name=\"to\"onBlur=\"validate(this);\" ></TD>");	
	fileOut.println("</TR>");	
	fileOut.println("<TR>");	
	fileOut.println("<TD><input type=\"radio\" name = \"server\" value=\""+ ConfigMarket.hostMarketWrServer + "\"></TD>");	
  	fileOut.println("	<TD>wrServer</TD>");	
	fileOut.println("</TR>");	
	fileOut.println("<TR>");	
  	fileOut.println("<TD><input type=\"radio\" name = \"server\" value=\"rwServer\"></TD>");	
	fileOut.println("<TD>rwServer</TD>");	
	fileOut.println("</TR>");	
  	fileOut.println("<TR>");	
	fileOut.println("	<TD><input type=\"radio\" name = \"server\" value=\"DVServer\"></TD>");	
	fileOut.println("	<TD>DVServer</TD>");	
  	fileOut.println("</TR>");	
	fileOut.println("</TABLE>");	
	fileOut.println("<input type =\"button\" value=\"View\" onClick = \"log(this.form);\">");	
  	fileOut.println("<input type =\"button\" value=\"Overview\" onClick =\"b_over();\">");	
	fileOut.println("<input type=\"text\" name =\"view\">");	
	fileOut.println("</FORM>");	
	fileOut.println("</BODY></HTML>\n");
	fileOut.close();
} // FormLogs
/**
 * Return Web page to browser. <br> This is the main page . Contains links to<br> 
 * - SourceList<BR>
 * - Logs<BR>
 * - Configuration <BR>
 * - Start/Stop market servlet<BR>
 * Creation date: (25/02/00 11:31:06 AM)
 * @param fileOut java.io.PrintWriter
 * @param srcList market.util.SourceList
 * @param langList market.util.LangTable
 */
public void mFormOverview(PrintWriter fileOut) {
	String scheduleStatus = "";
	String grabberStatus = "NOT Working";
	String Start_Stop = "";
	String ST_SP = "";
	
	if ((mSchedule != null) && mSchedule.isAlive() ) {
		scheduleStatus = "Working";
		Start_Stop = "Stop";
		ST_SP = Const.STOP;
	} else {
		scheduleStatus = "NOT Working";
		Start_Stop = "Start";
		ST_SP = Const.START;
	}

	if ( (mSchedule != null) && mSchedule.isGrabberWork()) {
		grabberStatus = "Working";
		Start_Stop = "Stop";
		ST_SP = Const.STOP;
	}
	
	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	fileOut.println("<TITLE>Overview</TITLE>");
	fileOut.println("<SCRIPT Language = \"JavaScript\">");
	fileOut.println("<!-- ");
	fileOut.println("function srcList(){");
	fileOut.println("this.window.location = \"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_SRC_LIST_PAGE + "\"; \n}");
	fileOut.println("function log(){");
	fileOut.println("this.window.location = \"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_LOGS_PAGE + "\"; \n}");
	fileOut.println("function config(){");
	fileOut.println("this.window.location = \"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_CONF_PAGE + "\"; \n}");
	fileOut.println("function StrStp(){");
	fileOut.println("this.window.location =\"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + ST_SP + "\";\n}");
	fileOut.println("function r_init(){");
	fileOut.println("this.window.location = \"" + ConfigMarket.MarketMasterName + "?" + ConfigMarket.nameMarketCfgPath + "=" + Text.strSetDoubleSlash(ConfigMarket.marketCfgPath) + "\"; \n}");
	fileOut.println("-->");
	fileOut.println("</SCRIPT>");
	fileOut.println("</HEAD>");
	fileOut.println("<BODY  text = \"black\">");
	fileOut.println("<TABLE>");
	fileOut.println("<TR><TD width = 150><B>Market Name :</B></TD><TD> " + ConfigMarket.marketName + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Location : </B></TD><TD>" + ConfigMarket.marketLocation + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Deskription : </B></TD><TD>" + ConfigMarket.marketDescription + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Status : </B></TD><TD><B> Schedule:  </B>" + scheduleStatus + "  <B>Grabber: </B>" + grabberStatus + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Working URLs : </B></TD><TD> " + " ConfigMarket.marketWorkUrls " + " </TD></TR>");
	fileOut.println("</TABLE>");
	fileOut.println("<HR>");
	fileOut.println("<B>Status : </B>" + status + "<P>");
	fileOut.println("<HR>");
	fileOut.println("<FORM name = \"logs\">");
	fileOut.println("<input type=\"button\" value=\"" + Start_Stop + "\" onClick=\"StrStp();\">");
	fileOut.println("<input type=\"button\" value=\"Source List\" onClick=\"srcList();\">");
	fileOut.println("<input type=\"button\" value=\"Logs\"onClick=\"log();\">");
	fileOut.println("<input type=\"button\" value=\"Configurations\" onClick=\"config();\">");
	fileOut.println("<input type=\"button\" value=\"ReInit\" onClick=\"r_init();\">");
	fileOut.println("</FORM>");
	fileOut.println("<HR>");
	fileOut.println("<iframe frameborder=\"0\" src=\""+ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.REFRESH_SPEED+"\" width=\"500\" height=\"200\">");
	fileOut.println("<HR>");
	fileOut.println("<H2 align=\"center\">TOP 9</H2>");
	fileOut.println("</BODY></HTML>\n");
	fileOut.close();
} // FormOverview
/**
 * Return Web page to browser. <br> This is the configuration page  <br> 
 * Creation date: (27/02/00 11:21:06 AM)
 * @param fileOut java.io.PrintWriter
 */
public void mFormSpeedFrame(PrintWriter fileOut) {

	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	if ( (mSchedule != null) && mSchedule.isGrabberWork()) {
  	    fileOut.println("<META HTTP-EQUIV=\"refresh\" CONTENT=\"5;url="+ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.REFRESH_SPEED+"\" >");
  	 }
	fileOut.println("</HEAD>");		
	fileOut.println("<BODY>");
	fileOut.println("<B> WR Speed :</B>"+Graber.getWrRate()+"<B> WR/sec </B><P><B> RW Speed :</B>"+ Graber.getRwRate()+"<B> RW/sec </B><P>");
	fileOut.println("</BODY>");
	fileOut.println("</HTML>");
	fileOut.close();
} // FormConf
/**
 * Return Web page to browser. <br> This page contein list of all baseSource and interfce to: <br> 
 * - Subscribe new baseSource <br>
 * - Delete baseSource <br>
 * - Activate/Deactivate baseSource <br>
 * - Edit baseSource <br> 
 * Creation date: (12/16/99 11:31:06 AM)
 * @param fileOut java.io.PrintWriter
 * @param srcList market.util.SourceList
 * @param langList market.util.LangTable
 */
public void mFormSrcList(PrintWriter fileOut, SourceList srcList, LangTable langList) {
	SrcElement[] arr;
	int len;
	int i;
	int j;

	String char2int;
	
	srcList.fillSrcString();
	arr = srcList.srcBundle;
	len = srcList.lastElm;
	fileOut.println("<HTML>");
	fileOut.println("<HEAD>");
	fileOut.println("<TITLE>Source List</TITLE>");
	fileOut.println("<SCRIPT Language = \"JavaScript\">");
	fileOut.println("<!-- \n  function del(obj){  broi=0; \n  str=\"\";	\nlen=obj.len.value;\n	for (i=0;i<len;i++){\n if(obj.tab[i].checked ) { \n  if (str !=\"\") \n str=str+\"&\"; \nstr =str + obj.tab[i].value;\n	} \n} this.window.location=\"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.DEL_URL + "&" + Const.BASE_SRC_KEY + "=\"+str;\n }\n  ");
	fileOut.println("function get_add(){");
	fileOut.println("this.window.location=\"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_ADD_PAGE +"\" \n }\n ");
	fileOut.println("function get_edit(obj){");
	fileOut.println("for( i=0 ; i< obj.len.value ; i++){");
	fileOut.println("    if( obj.tab[i].checked){");
	fileOut.println("       srcKey = obj.tab[i].value;");
	fileOut.println("this.window.location=\"" + ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_EDIT_PAGE +"&"+Const.SRC_KEY +"=\"+srcKey; \n }\n ");
	fileOut.println("}");
	fileOut.println("}");
	//----------------
	fileOut.println("function ch_state(obj){");
	fileOut.println("for( i=0 ; i< obj.len.value ; i++){");
	fileOut.println("    if( obj.tab[i].checked){");
	fileOut.println("       srcKey = obj.tab[i].value;");
	fileOut.println("	     if(obj.active[i].value == \"true\"){");
	fileOut.println("	     this.window.location=\"MarketServlet?ReqType=urlstatus&"+Const.SRC_KEY+"=\"+ srcKey + \"&"+Const.ACTIVE+"=false\"; ");
	fileOut.println("        }else");
	fileOut.println("        if(obj.active[i].value == \"false\"){"); 
	fileOut.println("	     this.window.location=\"MarketServlet?ReqType=urlstatus&"+Const.SRC_KEY+"=\"+ srcKey + \"&"+Const.ACTIVE+"=true\"; ");
	fileOut.println("	     }");
	fileOut.println("	}");
	fileOut.println(" }"); 
	fileOut.println("}");
	//-----------------   	
	fileOut.println(" function change(obj){");
	fileOut.println("len=obj.len.value;	");
	fileOut.println("   for (i=0;i<len;i++){ ");
	fileOut.println("        if(obj.tab[i].checked ) {   ");
	fileOut.println("	             if( obj.active[i].value == \"true\"){");
	fileOut.println("                     obj.change_state.value =\"Deactivate\";");
	fileOut.println("                    }else if( obj.active[i].value == \"false\") {");
	fileOut.println("                   obj.change_state.value =\" Activate   \";");
	fileOut.println("}\n}\n}\n}\n");
	fileOut.println("function b_over(){");	
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.GET_OVERVIEW_PAGE +"\";");	
	fileOut.println("}");

	fileOut.println("function start_url(obj){");
	fileOut.println("for( i=0 ; i< obj.len.value ; i++){");
	fileOut.println("    if( obj.tab[i].checked){");
	fileOut.println("        srcKey = obj.tab[i].value;");
	fileOut.println("this.window.location = \""+ ConfigMarket.MarketMasterName + "?" + Const.REQ_TYPE + "=" + Const.NEW_URL +"&" +Const.SRC_KEY+"=\"+srcKey;");	
	fileOut.println("	}");
	fileOut.println(" }"); 
	fileOut.println("}-->");	
	
	fileOut.println("</SCRIPT>");

	fileOut.println("</HEAD>");
	fileOut.println("<BODY  text = \"black\">");
	fileOut.println("<TABLE>");
	fileOut.println("<TR><TD width = 150><B>Market Name :</B></TD><TD>" + ConfigMarket.marketName + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Location : </B></TD><TD>" + ConfigMarket.marketLocation + "</TD></TR>");
	fileOut.println("<TR><TD width = 150><B>Market Deskription : </B></TD><TD>" + ConfigMarket.marketDescription +"</TD></TR>");
	fileOut.println("</TABLE>");
	fileOut.println("<HR>");
	fileOut.println("<B> Status :</B>"+status+"<P>");
	
	fileOut.println("<form name = \"table\" ><input type=\"hidden\"  name = \"len\" value=\"" + len + "\">");

	fileOut.println("<TABLE border=\"1\" cellspacing=\"1\" >");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>chek</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>URL</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>scrKey</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Language </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Time Base </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Frequence</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER> Keep In Path </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER> Keep In Domain </TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER>Grab Levels</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER><NOBR>Last Checked</TD>\n");
	fileOut.println("<TD bgcolor=\"#C0C0C0\"><CENTER><NOBR>User Agent</TD></TR>\n");
	for (i = 0; i < len; i++) {
		String	color = "BLACK";
		String	color1;
		String languageName = langList.ltResolveKeyToFullName(arr[i].langKey);
		if( !arr[i].active ){
			color = "GRAY";
		}
		if( arr[i].processing ){
			color1 = "GREEN";
		}else if( arr[i].error ){
			color1 = "GREEN";
		}else{
			color1 = color;
		}	


		fileOut.println("<TR><TD><p><INPUT TYPE=\"radio\" NAME=\"tab\" value =\"" + arr[i].srcKey + "\"onClick = \"change(this.form);\">");
	  	fileOut.println("<input type=\"hidden\"  name = \"active\" value=\"" + arr[i].active + "\"></TD>"); 
		fileOut.println("<TD><FONT color =\""+color1+"\" >" + arr[i].srcString + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color1+"\" >" + arr[i].srcKey + "</FONT></TD>\n");
		fileOut.println("<TD ><CENTER><FONT color =\""+color+"\" >" + languageName + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].timeBase) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].frequence) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].keepInPath) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].keepInDomain) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].grabLevels) + "</FONT></TD>\n");
		fileOut.println("<TD><CENTER><FONT color =\""+color+"\" >" + String.valueOf(arr[i].lastChecked) + "</FONT></TD>\n");
		fileOut.println("<TD><FONT color =\""+color+"\" ><NOBR>" + arr[i].userAgent + "</FONT></TD></TR>\n");
	} //  Tuk shte svurshva for zikala
	fileOut.println(" </TABLE>\n");
	// Buttons "Delate" "Deactivate/Activate" "Edit" "Add"
	fileOut.println(" <input type=\"button\" value = \"Delete\" onClick = \"del(this.form);\">\n");
	fileOut.println(" <input type=\"button\"name=\"change_state\" value = \"Deactivate\" onClick = \"ch_state(this.form);\">\n");
	fileOut.println(" <input type=\"button\"name=\"edit\" value = \"Edit\" onClick = \"get_edit(this.form);\">\n");
	fileOut.println(" <input type=\"button\"name=\"add\" value = \"Add\" onClick = \"get_add();\">\n");
	fileOut.println(" <input type=\"button\"name=\"overview\" value = \"Overview\" onClick = \"b_over();\">\n");
	fileOut.println(" <input type=\"button\"name=\"newurl\" value = \"Start url\" onClick = \"start_url(this.form);\">\n");	
	fileOut.println(" </form>\n");
	fileOut.println("</BODY></HTML>\n");
	fileOut.close();
} // FormHtml
/**
 * This method was be call when user want to start URL at the moment. It's just for tests <br> 
 * Creation date: (10/03/00 7:09:18 PM)
 * @return boolean ( true for successfully registration )
 * @param req sun.servlet.http.HttpServletRequest
 */
 public boolean mNewUrl(HttpServletRequest req, SourceList srcList) {

	SrcElement[] arr;
	 
	int active;
	int i;
	int len;
	long src_Key;
 	String temp;

	srcList.fillSrcString();
	arr = srcList.srcBundle;
	len = srcList.lastElm;
 	temp = req.getParameter( Const.SRC_KEY );
 	if ( null == temp ) return false;
 	
	src_Key = Long.valueOf( temp ).longValue();
	int selected = srcList.findSrc( src_Key );
	mSchedule.startGraber( arr[selected] );
	
	return true;	
}
/**
 * This method was be call when user want registrate new base Source. <br> 
 * Creation date: (12/21/99 7:09:18 PM)
 * @return boolean ( true for successfully registration )
 * @param req sun.servlet.http.HttpServletRequest
 */
 public boolean mRegUrl(HttpServletRequest req) {

	String srcString, userAgent;
	boolean res;
	int langKey; 
	int timeBase; 
	int frequence; 
	int keepInPath;
	int keepInDomain; 
	int grabLevels;

	String temp;
	try {
	 	temp = req.getParameter( Const.SRC_STRING );
		srcString = temp;

	 	temp = req.getParameter( Const.LANG_KEY );
		langKey = langTable.ltResolveName( temp );
		
		temp = req.getParameter( Const.TIME_BASE );
		timeBase = Integer.valueOf(temp).intValue();

		temp = req.getParameter( Const.FREQ );
		frequence = Integer.valueOf(temp).intValue();

		temp = req.getParameter( Const.KEEP_IN_PATH );
		keepInPath = ( temp.equalsIgnoreCase("true") ) ? 1:0; 

		temp = req.getParameter( Const.KEEP_IN_DOMAIN );
		keepInDomain = ( temp.equalsIgnoreCase("true") ) ? 1:0; 

		temp = req.getParameter( Const.GRAB_LEVEL );
		grabLevels = Integer.valueOf(temp).intValue();

		temp = req.getParameter( Const.USER_AGENT );
		userAgent = temp;

		System.out.println( mSchedule );
		res = mSchedule.scdSubscribeURL( srcString, langKey, timeBase, frequence, 
											keepInPath, keepInDomain, grabLevels, userAgent );
		
		status = mSchedule.getLastOperationResult();
		
		return ( res );
	}catch( Exception e ){
		e.printStackTrace();
		status = " Error in parameter! ";
		return false;
	}
	
}
/**
 * Init market servlet and start Schedule. <br>
 * 1. Check for strarted schedule.<br>
 * 2. Load file: market.cfg ( marketName, marketDescribtion, ... ) in static field on ConfigMarket <br>
 * 3. Create instance of ScheduleThread<br>
 * 4. Load Langage Table<br>
 * 5. Load Source List<br>
 * 6. Start mSchedule<br>
 * Creation date: (12/30/99 9:14:39 PM)
 * @param  out java.io.PrintWriter
 */
public void mStartServlet(PrintWriter out) {

	// 1. Check for strarted schedule.
	
	if ( (mSchedule != null) && mSchedule.isAlive() ) {
		status = "Market already started.";
		System.out.println("Market already started.");
		return;
	}
	
	// 2. Load file: market.cfg ( marketName, marketDescribtion, ... ) in static field on ConfigMarket
	if ( !ConfigMarket.isInit )
	{
		System.out.println("Init:");
		if ( !ConfigMarket.init( ConfigMarket.marketCfgPath ) ){
			
			return;
		}
	}
	
	if ( srcList == null ) {
		// 4. Load Langage Table
		// 5. Load Source List
		if ( !initSource() ){
			return;
		}
	}
	
	System.out.println(" Load m_Docs Cache... ");
	
	if ( !ConfigMarket.initMDocs_Cache() ) {
		System.out.println(" Can't load m_Docs Cache... ");
	}
	
	// 3. Create instance of ScheduleThread
	System.out.println(" Create Scedule... ");
	srcList.reset();
	mSchedule = new Schedule( Const.SCHEDULE_TIME_SLEEP, srcList, langTable );
	
		
	// 6. Start mSchedule
	System.out.println("Start Schedule ");
	mSchedule.start();
}
/**
 * This method was be call when servlet run <br> 
 * Creation date: (12/21/99 7:09:18 PM)
 * @param req sun.servlet.http.HttpServletRequest
 * @param res sun.servlet.http.HttpServletResponse
 * @exception javax.servlet.ServletException The exception description.
 * @exception java.io.IOException The exception description.
 */
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException {
	res.setContentType("text/html");
	PrintWriter out = res.getWriter();
	
	String sTask = req.getParameter(Const.REQ_TYPE);
	
	ConfigMarket.logWriter.log( name + ": Request : " + sTask, LogPrinter.INFO);

	if (sTask == null) {
		String path = req.getParameter(ConfigMarket.nameMarketCfgPath);
		if (path != null) {
			if (ConfigMarket.init(path)) {
				mSchedule = new Schedule();
				status = "Parameter is loaded.";
			} else
				status = "Parameter is not load.";
		} else
			status = "Error input parameter!";
		mFormOverview(out);
		out.close();
		return;
	}
	
	taskType = getTask(sTask);
	
	if (!ConfigMarket.isInit) {
		out.print("First Init Market Servlet, please !");
		return;
	}
	
	if ((taskType >= TASK_GET_MARKET_KEY) && (mSchedule == null)) {
		status = "First start Market Servlet!";
		mFormOverview(out);
		out.close();
		return;
	}
	
	switch (taskType) {
		case TASK_START :
			ConfigMarket.logWriter.log( name + ": Schedule Starting...", LogPrinter.INFO);
			mStartServlet(out);
			//status = "Market Servlet Starting...Done";
			mFormOverview(out);
			break;
		case TASK_STOP :
			if ((mSchedule != null) && ( mSchedule.isAlive() || mSchedule.isGrabberWork() ) ) {
				ConfigMarket.logWriter.log( name + ": Schedule Stoping...", LogPrinter.INFO);
				// Stop Scedule
				mSchedule.stopAllGraber();
				mSchedule.stop();
				mSchedule = new Schedule(Const.SCHEDULE_TIME_SLEEP, srcList, langTable);
				ConfigMarket.logWriter.flush();
				status = "Market Servlet Stoping...Done";
			} else {
				status = "Market Servlet is not running!";
			}
			mFormOverview(out);
			break;
		case TASK_CONF :
			mConf(req);
			mFormConfigParam(out);
			break;
		case TASK_SAVE_CONF :
			ConfigMarket.cfgSaveProperty(ConfigMarket.marketCfgPath);
			mFormConfigParam(out);
			break;
		case TASK_LOAD_CONF :
			ConfigMarket.cfgLoadProperty(ConfigMarket.marketCfgPath);
			mFormConfigParam(out);
			break;
		case TASK_GET_OVERVIEW_PAGE :
			mFormOverview(out);
			break;
		case TASK_GET_LOGS_PAGE :
			mFormLogs(out);
			break;
		case TASK_GET_LOG_FILE :
			res.setContentType("text/plant");
			String date = req.getParameter(Const.DATE_NAME);
			ConfigMarket.logWriter.getLogFile(date, out);
			break;
		case TASK_GET_CONF_PAGE :
			mFormConf(out);
			break;
		case TASK_GET_CONF_MARKET_PAGE :
			mFormConfigParam(out);
			break;
		case TASK_GET_MARKET_KEY :
			res.setContentType("text/plant");
			ConfigMarket.logWriter.log( name + ": Give market key.", LogPrinter.INFO);
			out.print(ConfigMarket.marketKey);
			break;
		case TASK_ADD_URL :
			ConfigMarket.logWriter.log( name + ": Start Registrate URL...", LogPrinter.INFO);
			mRegUrl(req);
			status = "Add URL. Result: " + status;
			mFormSrcList(out, srcList, langTable);
			break;
		case TASK_EDIT_URL :
			ConfigMarket.logWriter.log( name + ": Start Edit URL...", LogPrinter.INFO);
			mEditUrl(req);
			status = "Edit URL. Result: " + status;
			mFormSrcList(out, srcList, langTable);
			break;
		case TASK_DEL_URL :
			ConfigMarket.logWriter.log( name + ": Start Del URL...", LogPrinter.INFO);
			mDelUrl(req);
			status = "Del URL. Result:" + status;
			mFormSrcList(out, srcList, langTable);
			break;
		case TASK_GET_EDIT_PAGE :
			mFormEdit(req, out, srcList, langTable);
			break;
		case TASK_GET_ADD_PAGE :
			mFormAdd(out, srcList, langTable);
			break;
		case TASK_GET_SRC_LIST_PAGE :
			ConfigMarket.logWriter.log( name + ": Start Get Src List...", LogPrinter.INFO);
			if (initSource())
				mFormSrcList(out, srcList, langTable);
			else {
				status = "Can't init source list:";
				mFormOverview(out);
			}
			break;
		case TASK_URL_STATUS :
			mActive(req);
			mFormSrcList(out, srcList, langTable);
			break;
		case TASK_NEW_URL :
			mNewUrl(req, srcList);
			mFormSrcList(out, srcList, langTable);
			break;
		case TASK_ERROR :
			status = " Error! ReqType: " + sTask + " Errorcode: " + taskType + " Error: " + TASK_ERROR ;
			break;
		case TASK_REFRESH:
		    mFormSpeedFrame(out);
		    //System.out.println("KOTEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV");
	    	out.close();
	    	return;
		    //break;
		default:	
		 	mFormOverview(out);
	}

	out.close();
	if (null != ConfigMarket.logWriter){
		ConfigMarket.logWriter.log( name + ": " + status, LogPrinter.INFO);
		ConfigMarket.logWriter.flush();
	}	
}
}

