import java.io.*;	
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.lang.*;
import java.util.*;
import java.util.Date;

public class UserPageGenerator { 
    
    // when login is not correct
    public static void incorrectLogin(PrintWriter out){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>Incorrect Login</TITLE>");
	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=iso-8859-1\">");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>Your Login or Password is Incorrect.</h3>");
	out.println("<FORM ACTION=\""+Config.servletUrl+"LoginServlet\"");  // form action ...when static page, what does method mean???
	out.println("<INPUT TYPE=\"submit\" VALUE=\"back\">");
	out.println("</FORM>");
	out.println("<h3>Haven't Registered yet???</h3>");// click here!!!</h3>");
	out.println("<h3><A href=\""+Config.htmlUrl+"RegistrationPage.htm\">Click here!!!</A></h3>");
	out.println("</BODY></HTML>");
	out.close();
    }

    //when user is suspended
    public static void userIsSuspended(PrintWriter out){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>Login Suspended</TITLE>");
	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=iso-8859-1\">");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>Your Login has been suspended.</h3>");
	out.println("<h3>Plese contact the sysad for further info.</h3>");// click here!!!</h3>");
	out.println("</BODY></HTML>");
	out.close();
    }

    // when user enters some login while registering which has already been taken CHECKED!!!
    public static void enterAnotherLogin(PrintWriter out, String login){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>Registration Page</TITLE>");
	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=iso-8859-1\">");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>Login Name <b> "+login+" </b>has already been taken by another user. Choose another login name.</h3><br>");
	out.println("<h3>Login:</h3>");
	out.println("<FORM ACTION=\""+Config.servletUrl+"RegisterServlet\" method =\"POST\">");
	out.println("<input name=\"userLogin\" size=\"20\" maxlength=\"20\">");
	out.println("<input name=\"whereFrom\" type=\"hidden\" value=\false\">");
	out.println("<INPUT TYPE=\"submit\" VALUE=\"Submit\">");
	out.println("</FORM>");
	out.println("</BODY></HTML>");
	out.close();
    }

    // when user enters some email while registering which has already been taken CHECKED!!!
    public static void enterAnotherEmail(PrintWriter out, String email){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>Registration Page</TITLE>");
	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=iso-8859-1\">");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>Email Address <b> "+email+" </b>has already been taken by another user. Give another email address.</h3><br>");
	out.println("<h3>Login:</h3>");
	out.println("<FORM ACTION=\""+Config.servletUrl+"RegisterServlet\" method =\"POST\">");
	out.println("<input name=\"email\" size=\"40\" maxlength=\"40\">");
	out.println("<input name=\"whereFrom\" type=\"hidden\" value=\false\">");
	out.println("<INPUT TYPE=\"submit\" VALUE=\"Submit\">");
	out.println("</FORM>");
	out.println("</BODY></HTML>");
	out.close();
    }
    
    // generated when a user has been successfully registered //CHECKED
    public static void userRegisteredPage(PrintWriter out, String login, String email){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>User Registered</TITLE>");
	//	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=iso-8859-1\">");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>You have been successfully registered. Your login name is <b> "+login+"</b>. Your password have been mailed to you at <b> "+email+"</b>. You can login with that password and later change the password if you wish.</h3><br>");
	out.println("<h3>Enjoy Bidding!!!</h3>");// goint to main page!!!
	//provide a link to main page here
	out.println("<h3><A href=\""+Config.servletUrl+"LoginServlet2\">Click here!!!</A> to login</h3>");
	out.println("</BODY></HTML>");
	out.close();
    }

    // generates login page for a user 
    public static void loginPage(PrintWriter out){
	
	System.out.println("inside login page");
	out.println("<html>");
	out.println("<head>");
	out.println("<title>Login Page</title>");
	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
	out.println("<SCRIPT LANGUAGE=JavaScript>");
	out.println("function validate(){");
	out.println("if (document.forms[0].userLogin.value==\"\"){");
	out.println("       alert('Please enter a login name.');");
	out.println("       return false;");
	out.println("       }");
	out.println("if (document.forms[0].password.value==\"\"){");
	out.println("       alert('Please enter a login password.');");
	out.println("       return false;");
	out.println("       }");
	out.println("       document.forms[0].submit();");
	out.println("       return true;");
	out.println("       }");
	out.println("</Script>");
	out.println("</head>");
	out.println("<body bgcolor=\"#fffff\" text=\"#000000\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<p align=\"center\"><b><font size=\"6\" face=\"Times New Roman, Times, serif\">Login ");
	out.println("  Page</font></b></p>");
	out.println("<form name=\"form1\" action="+Config.servletUrl+"LoginServlet method=\"GET\">");
	out.println("  <div align=\"center\">");
	out.println("    <table width=\"30%\" border=\"1\" name=\"loginTable\" bordercolor=\"#CCCCCC\" bgcolor=\"#CCCCCC\" height=\"85\">");
	out.println("      <tr>");
	out.println("      <td width=\"40%\"><b>Login Name:</b></td>");
	out.println("      <td width=\"60%\"> <b> ");
	out.println("        <input name=\"userLogin\" size=\"20\" maxlength=\"20\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr>");
	out.println("        <td width=\"40%\" height=\"40\"><b>Password:</b></td>");
	out.println("        <td width=\"60%\" height=\"40\"> <b> ");
	out.println("          <input name=\"password\" size=\"20\" maxlength=\"20\" type=\"password\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("  </table>");
	out.println("  </div>");
	//	out.println("    <input type=\"hidden\" name=\"Submit1\" value=\"Login\">");
	//out.println("    <input type=\"hidden\" name=\"Submit2\" value=\"Login\">");
	//out.println("    <input type=\"hidden\" name=\"Submit3\" value=\"Login\">");
	//out.println("    <input type=\"hidden\" name=\"Submit4\" value=\"Login\">");
	//out.println("    <input type=\"hidden\" name=\"Submit5\" value=\"Login\">");
	out.println("  <div align=\"center\"><b>");
	out.println("    <input type=\"button\" name=\"Submit\" value=\"Login\" onclick=\"validate()\">");
	out.println("    <input type=\"reset\" name=\"Reset\" value=\"Reset\">");
	out.println("    </b> </div>");
	out.println("</form>");
	out.println("<p align=\"center\">&nbsp;</p>");
	out.println("<p align=\"center\"><b>Not a registered member!!! <a href=\""+Config.htmlUrl+"RegistrationPage.htm\"><i>Register");
	out.println("  now</i></a></b></p>");
	out.println("</body>");
	out.println("</html>");
	//	out.close();
    }
    
    
    // generates registration form with all entries filled in case the user wants to change his profile. The 'login name' field cant be changed.  
    public static void changeProfilePage(PrintWriter out, String login, ResultSet rs){
	String fname="", lname="", email="", gender="", address="", city, dob, htmlString, mselected="", fselected="";
	try{
	    while (rs.next()){
		fname=rs.getString(1);
		lname=rs.getString(2);
		email=rs.getString(3);
		gender=rs.getString(4);
		address=rs.getString(5);
		city=rs.getString(6);
	    }
	}catch(SQLException sqle){System.out.println("error l77 userpagegene");}
	
	if (gender.equals("Male")){
	    mselected="checked";
	}
	else{
	    fselected="checked";
	}

	out.println("<html>");
	out.println("<head>");
	out.println("<title>User Profile</title>");
	out.println("<SCRIPT LANGUAGE=JavaScript>");
	out.println("function validate(){");
	out.println("    if (!isFullName()){");
	out.println("	     return false;");
	out.println("        }");
       	out.println("	 var str = document.forms[0].newPassword1.value;");
	out.println("        if ((str != \"\") && (str.length < 4)){");
	out.println("	     alert(\"The password entered is less than 4 chars. Please re-enter the New password.\");");
	out.println("	     document.forms[0].newPassword1.focus();");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 var str2 = document.forms[0].newPassword2.value;");
	out.println("	 if ((str2 != \"\") && (str2.length < 4)){");
	out.println("	     alert(\"The password entered is less than 4 chars.Please re-enter the password.\");");
	out.println("	     document.forms[0].newPassword2.focus();");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 if (str != str2){");
	out.println("	     alert(\"Passwords entered do not match\");");
	out.println("	     document.forms[0].newPassword1.focus();");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 var str4 = document.forms[0].oldPassword.value;");
	out.println("	 if(str.length > 0){");
	out.println("	     if ((str4 == \"\") || (str4.length < 1)){");
	out.println("	         alert(\"You must enter the current password in order to change it to new password\");");
	out.println("		 document.forms[0].oldPassword.focus();");
	out.println("		 return false;");
	out.println("		 }");
	out.println("	     }");
	out.println("	 if (isEmail() == false){");
	out.println("	     return false;");
	out.println("	 }");
	out.println("    if(document.forms[0].address.value==\"\"){");
	out.println("	     alert(\"Please enter your address.\");");
	out.println("	     document.forms[0].address.focus();");
	out.println("	     return false;");
	out.println("	 }");
	out.println("	 aa = new String((document.forms[0].address.value));");
	out.println("	 if (aa.length > 200){");
	out.println("	     alert (\"Please enter your address in less than 200 characters\");");
	out.println("	     document.forms[0].address.focus();");
	out.println("	     return false;");
	out.println("	 }");
	out.println("    if (document.forms[0].city.selectedIndex == 0){");
	out.println("        alert(\"The city field is empty. Please re-enter the city\");");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 document.forms[0].submit();");
	out.println("	 return true;");
	out.println("    }");
	out.println("function isEmail(){");
	out.println("    if (document.forms[0].email.value==\"\"){");
	out.println("        alert (\"Please enter your email address.\");");
	out.println("        document.forms[0].email.focus();");
	out.println("        return false;");
	out.println("        }");
	out.println("    else if(document.forms[0].email.value !=\"\"){");
	out.println("        Str = new String((document.forms[0].email.value));");
	out.println("        Str1 = Str.indexOf(\"@\");");
	out.println("        Str2 = Str.indexOf(\".\");");
	out.println("        Str41 = Str.indexOf(\"!\");");
	out.println("        Str51 = Str.indexOf(\"#\");");
	out.println("        Str61 = Str.indexOf(\"$\");");
	out.println("        Str71 = Str.indexOf(\"%\");");
	out.println("        Str81 = Str.indexOf(\"^\");");
	out.println("        Str91 = Str.indexOf(\"&\");");
	out.println("        Str101 = Str.indexOf(\"(\");");
	out.println("        Str111 = Str.indexOf(\")\");");
	out.println("        Str131 = Str.indexOf(\"+\");");
	out.println("        Str141 = Str.indexOf(\"=\");");
	out.println("        Str151 = Str.indexOf(\"`\");");
	out.println("        Str161 = Str.indexOf(\"~\");");
	out.println("        Str171 = Str.indexOf(\"<\");");
	out.println("        Str181 = Str.indexOf(\">\");");
	out.println("        Str191 = Str.indexOf(\"{\");");
	out.println("        Str201 = Str.indexOf(\"}\");");
	out.println("        Str211 = Str.indexOf(\"[\");");
	out.println("        Str221 = Str.indexOf(\"]\");");
	out.println("        Str241 = Str.indexOf(\"|\");");
	out.println("        Str251 = Str.indexOf(\"/\");");
	out.println("        Str261 = Str.indexOf(\"?\");");
	out.println("        Str271 = Str.indexOf(\",\");");
	out.println("        Str281 = Str.indexOf(\"'\");");
	out.println("        if ((Str41>=0)||(Str51>=0) ||(Str61 >=0) ||(Str71>=0) || (Str81>=0)||(Str91>=0) ||(Str101>= 0)|| (Str111>=0) || (Str131>=0) ||(Str141>=0) ||(Str151>=0) ||(Str161>=0) || (Str171>=0) ||(Str181>=0) || (Str191>=0) || (Str201>=0) || (Str211>=0) || (Str221>=0) || (Str241>=0) || (Str251>=0) || (Str261>=0) || (Str271>=0) || (Str281>=0)){");
	out.println("            alert (\"Please do not enter any special characters in the email\");");
	out.println("            document.forms[0].email.focus();");
	out.println("            return false;");
	out.println("            }");
	//	out.println("        }");
	out.println("        if (Str.length!=Str2+1){");
	out.println("            }");
	out.println("        else{");
	out.println("            alert (\"Please enter a valid email address\");");
	out.println("            document.forms[0].email.focus();");
	out.println("            return false;");
	out.println("            }");
	out.println("        Str3 = Str.indexOf(\"@\",(Str1+1));");
	out.println("        if (Str3<0){");
	out.println("            }");
	out.println("        else{");
	out.println("            alert (\"Your email address cannot have more than one @\");");
	out.println("            document.forms[0].email.focus();");
	out.println("            return false;");
	out.println("            }");
	out.println("        if ((Str1>0) && (Str2>0)){");
	out.println("            }");
	out.println("        else{");
	out.println("            alert (\"Please enter a valid email address\");");
	out.println("            document.forms[0].email.focus();");
	out.println("            return false;");
	out.println("            }");
	out.println("        }");
	out.println("    }");
	out.println("");
	out.println("// Name Validator");
	out.println("function isFullName(){");
	out.println("    var firstName = document.forms[0].firstName.value;");
	out.println("	 var lastName = document.forms[0].lastName.value;");
	out.println("	 if(firstName == \"\"){");
	out.println("	     alert(\"Please enter your first name.\");");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 if(lastName == \"\"){");
	out.println("	     alert(\"Please enter your last name.\");");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 if(isNotAlphabets(firstName)){");
	out.println("	     alert(\"The first name field contains invalid characters or spaces. Please re-enter your first name again.\");");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 if(isNotAlphabets(lastName)){");
	out.println("	     alert(\"The last name field contains invalid characters or spaces. Please re-enter your last name again.\");");
	out.println("	     return false;");
	out.println("	     }");
	out.println("	 return true;");
	out.println("    }");
	out.println("");
	out.println("// Alphabets function");
	out.println("function isNotAlphabets(str){");
	out.println("    for (var i = 0; i < str.length; i++){");
	out.println("	     var ch = str.substring(i, i + 1);");
	out.println("	     if((ch < \"a\" || \"z\" < ch) && (ch < \"A\" || \"Z\" < ch)){");
	out.println("	         return true;");
	out.println("		 }");
	out.println("	     }");
	out.println("	  return false;");
	out.println("     }");
	out.println("</SCRIPT>");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<p><b><font size=\"6\">User Profile</font></b></p>");
	out.println("<FORM ACTION=\""+Config.servletUrl+"UserProfileChangeServlet\" METHOD=POST>");
	out.println("  <table width=\"59%\" border=\"1\" bgcolor=\"#CCCCCC\" bordercolor=\"#CCCCCC\">");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"24\"><b>Login Name:</b></td>");
	out.println("      <td colspan=\"3\" height=\"24\"> <b>"+ login+" </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"20\"><b></b></td>");
	out.println("      <td height=\"20\" colspan=\"3\"><b></b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"38\"><b>First Name:</b></td>");
	out.println("      <td height=\"38\" colspan=\"3\"> <b> ");
	out.println("        <input name=\"firstName\" value=\""+ fname +"\" size=\"20\" maxlength=\"20\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"41\"><b>Last Name:</b></td>");
	out.println("      <td height=\"41\" colspan=\"3\"> <b> ");
	out.println("        <input name=\"lastName\"  value=\""+ lname +"\" size=\"20\" maxlength=\"20\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"36\"><b>Email:</b></td>");
	out.println("      <td height=\"36\" colspan=\"3\"> <b> ");
	out.println("        <input name=\"email\"  value=\""+ email +"\" size=\"30\" maxlength=\"30\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"25\"><b>Gender:</b></td>");
	out.println("      <td colspan=\"2\" height=\"25\"> <b> ");
	out.println("        <input type=radio name=gender value=\"Male\""+ mselected  +">");
	out.println("        Male </b></td>");
	out.println("      <td width=\"47%\" height=\"25\"> <b> ");
	out.println("        <input type=radio name=gender value=\"Female\""+fselected+">");
	out.println("        Female</b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"50\"><b>Address</b></td>");
	out.println("      <td colspan=\"3\" height=\"50\"> <b> ");
	out.println("        <input type=\"text\" name=\"address\" value=\""+ address +"\" size=\"40\" maxlength=\"100\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"25\"><b>City:</b></td>");
	out.println("      <td colspan=\"3\" height=\"25\"> <b> ");
	out.println("        <select name=\"city\">");
	out.println("          <OPTION value=\"\">[Select One] ");
	out.println("          <OPTION value=\"Ahmedabad\">Ahmedabad ");
	out.println("          <OPTION value=\"Bangalore\">Bangalore ");
	out.println("          <OPTION value=\"Baroda\">Baroda ");
	out.println("          <OPTION value=\"Bhopal\">Bhopal ");
	out.println("          <OPTION value=\"Bhubaneshwar\">Bhubaneshwar ");
	out.println("          <OPTION value=\"Calcutta\">Calcutta ");
	out.println("          <OPTION value=\"Chandigarh\">Chandigarh ");
	out.println("          <OPTION value=\"Chennai\">Chennai ");
	out.println("          <OPTION value=\"Cochin\">Cochin ");
	out.println("          <OPTION value=\"Coimbatore\">Coimbatore ");
	out.println("          <OPTION value=\"Delhi\">Delhi ");
	out.println("          <OPTION value=\"Goa\">Goa ");
	out.println("          <OPTION value=\"Hyderabad\">Hyderabad ");
	out.println("          <OPTION value=\"Kanpur\">Kanpur ");
	out.println("          <OPTION value=\"Indore\">Indore ");
	out.println("          <OPTION value=\"Jaipur\">Jaipur ");
	out.println("          <OPTION value=\"Lucknow\">Lucknow ");
	out.println("          <OPTION value=\"Ludhiana\">Ludhiana ");
	out.println("          <OPTION value=\"Madurai\">Madurai ");
	out.println("          <OPTION value=\"Mumbai\">Mumbai ");
	out.println("          <OPTION value=\"Nagpur\">Nagpur ");
	out.println("          <OPTION value=\"NOIDA\">NOIDA ");
	out.println("          <OPTION value=\"Patna\">Patna ");
	out.println("          <OPTION value=\"Pune\">Pune ");
	out.println("          <OPTION value=\"Surat\">Surat ");
	out.println("          <OPTION value=\"Varanasi\">Varanasi ");
	out.println("          <OPTION value=\"Vishakapatnam\">Vishakapatnam ");
	out.println("        </select>");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"13\"><b></b></td>");
	out.println("      <td colspan=\"3\" height=\"13\"><b></b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"25\"><b><font color=\"#FF0000\">Change Password</font></b></td>");
	out.println("      <td colspan=\"3\" height=\"25\"><b></b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"25\"><b>Old Password:</b></td>");
	out.println("      <td colspan=\"3\" height=\"25\"><b>");
	out.println("        <input name=\"oldPassword\" type=\"password\" size=\"20\" maxlength=\"20\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"25\"><b>New Password:</b></td>");
	out.println("      <td colspan=\"3\" height=\"25\"><b>");
	out.println("        <input name=\"newPassword1\" type=\"password\" size=\"20\" maxlength=\"20\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("    <tr> ");
	out.println("      <td width=\"34%\" height=\"26\"><b>Re-Enter New Password:</b></td>");
	out.println("      <td colspan=\"3\" height=\"26\"><b>");
	out.println("        <input name=\"newPassword2\" type=\"password\" size=\"20\" maxlength=\"20\">");
	out.println("        </b></td>");
	out.println("    </tr>");
	out.println("  </table>");
	out.println("  <input type=\"button\" name=\"Register\" value=\"submit\" onclick=\"validate()\">");
	out.println("  <input type=\"reset\" name=\"changeProfileForm\" value=\"Reset\">");
	out.println("</FORM>");
	out.println("</body>");
	out.println("</html>");
	out.close();
    }
    
    
    // when user is not logged in
    public static void passwordDoNotMatch(PrintWriter out, String login){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>Password do Not Match</TITLE>");
	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=iso-8859-1\">");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>Your password do not match.</h3>");
	out.println("<h3>Try again with correct password.</h3>");
	out.println("</BODY></HTML>");
	out.close();
    }
    
    // generating page for query one(successful auctions of a user)
    public static void queryOnePage(PrintWriter out, ResultSet rs, String userLogin){
	out.println("<html><head><title>User Successful Auctions</title>");
	out.println("<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=iso-8859-1\"></head>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	//	while rs.next())
	String printStatement, ratingStatus;
	boolean checkInfo;
	try{	    
	    if (rs==null)
		{checkInfo=false;System.out.println("test");}
	    else
		checkInfo=rs.next();

	    if (checkInfo){
		printStatement="<tr>";
		printStatement=printStatement+"<td><b>Product ID</b></td>";
		printStatement=printStatement+"<td><b>Product Name</b></td>";
		printStatement=printStatement+"<td><b>Winner Login</b></td>";
		printStatement=printStatement+"<td><b>Winning Bid</b></td>";
		printStatement=printStatement+"<td><b>Winner Email</b></td>";
		printStatement=printStatement+"<td><b>Winner Address</b></td>";
		printStatement=printStatement+"</tr>";
		out.println("<table width=\"100%\">");  
		out.println(printStatement);
		
		do {
		    printStatement="<tr>";
		    printStatement=printStatement + "<td>" + rs.getString(1) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(2) + "</td>";
		    printStatement=printStatement + "<td>"+"<a href=\""+Config.servletUrl+"UserRatingServlet?userLogin="+rs.getString(3)+"\">"+ rs.getString(3)+"</a>" + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(4) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(5) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(6) + "</td>";
		    
		    ratingStatus=(SharedObjects.qe).sellerRatedWinnerAs(rs.getString(1));
		    System.out.println("rating status="+ratingStatus);
		    if (!(ratingStatus.equals("noEntry") || ratingStatus.equals("notRated"))){
			printStatement=printStatement + "<td><span style=\"color:red\">You already rated</span></td>";
		    }
		    else if	(ratingStatus.equals("notRated")){
			printStatement=printStatement + "<td><A href="+Config.servletUrl+"UserFeedbackServlet?productId="+rs.getString(1)+"&sellerLogin="+rs.getString(4)+"&winnerLogin="+userLogin+"&toDo=update>Rate Winner</A></td>";
		    }
		    else{// when no entery for this product ID was in feedback table
			printStatement=printStatement + "<td><A href="+Config.servletUrl+"UserFeedbackServlet?productId="+rs.getString(1)+"&sellerLogin="+rs.getString(3)+"&winnerLogin="+userLogin+"&toDo=insert>Rate Winner</A></td>";
		    }
		    printStatement=printStatement + "</tr>";
		    out.println(printStatement);
		}
		while (rs.next());
	    }
	    else{
		printStatement=("<b><c>There are no successful auction.</c></b>");
		out.println(printStatement);   
	    }
	    
	}catch(SQLException sqle){}
	out.println("</table>");
    }
    
    // generating page for query two(unsuccessful auctions of a user)
    public static void queryTwoPage(PrintWriter out, ResultSet rs){
	out.println("<html><head><title>User Unsuccessful Auctions</title></head>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	String printStatement;
	boolean checkInfo;
	try{	    
	    if (rs==null)
		{checkInfo=false;System.out.println("test");}
	    else
		checkInfo=rs.next();
	    
	    if (checkInfo){
		printStatement="<tr>";
		printStatement=printStatement+"<td><b>Product ID</b></td>";
		printStatement=printStatement+"<td><b>Product Name</b></td>";
		printStatement=printStatement+"<td><b>Start Date</b></td>";
		printStatement=printStatement+"<td><b>End Date</b></td>";
		printStatement=printStatement+"</tr>";
		out.println("<table width=\"100%\">");  
		out.println(printStatement);
		
		do {
		    printStatement="<tr>";
		    printStatement=printStatement + "<td>" + rs.getString(1) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(2) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(3) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(4) + "</td>";
		    printStatement=printStatement + "<td><A href="+Config.servletUrl+"AuctionRevivalServlet?productId="+rs.getString(1)+">revive</A></td>";
		    
		    printStatement=printStatement + "</tr>";
		    out.println(printStatement);
		}
		while (rs.next());
	    }
	    else{
		printStatement=("<b><c>There are no unsuccessful auctions.</c></b>");
		out.println(printStatement);   
	    }
		
	    }catch(SQLException sqle){}
	out.println("</table>");
    }

    // generating page for query three (current auctions of a user)
    public static void queryThreePage(PrintWriter out, ResultSet rs1, ResultSet rs2){
	out.println("<html><head><title>User Current Auctions</title></head>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	int count1=0;
	int count2=0;
	String printStatement;
	boolean checkInfo1, checkInfo2;
	
	try{	    
	    if (rs1==null)
		{checkInfo1=false;System.out.println("test");}
	    else
		checkInfo1=rs1.next();
	    
	    if (rs2==null)
		checkInfo2=false;
	    else
		checkInfo2=rs2.next();

	    if (checkInfo1 || checkInfo2){
		printStatement="<tr>";
		printStatement=printStatement+"<td><b>Product ID</b></td>";
		printStatement=printStatement+"<td><b>Product Name</b></td>";
		printStatement=printStatement+"<td><b>Start Date</b></td>";
		printStatement=printStatement+"<td><b>Closing Date</b></td>";
		printStatement=printStatement+"<td><b>Location</b></td>";
		printStatement=printStatement+"<td><b>Bidder Login</b></td>";
		printStatement=printStatement+"<td><b>Bid Amount</b></td>";
		printStatement=printStatement+"</tr>";
		out.println("<table width=\"100%\">");  
		out.println(printStatement);
		
		if (checkInfo1){
		    do {
			printStatement="<tr>";
			printStatement=printStatement + "<td><A href="+Config.servletUrl+"BidServlet?productId="+rs1.getString(1)+">"+rs1.getString(1)+"</A></td>";
			printStatement=printStatement + "<td><A href="+Config.servletUrl+"BidServlet?productId="+rs1.getString(1)+">"+rs2.getString(2)+"</A></td>";
			//			printStatement=printStatement + "<td>" + rs1.getString(1) + "</td>";
			//printStatement=printStatement + "<td>" + rs1.getString(2) + "</td>";
			printStatement=printStatement + "<td>" + rs1.getString(3) + "</td>";
			printStatement=printStatement + "<td>" + rs1.getString(4) + "</td>";
			printStatement=printStatement + "<td>" + rs1.getString(5) + "</td>";
			printStatement=printStatement + "<td>"+"<a href=\""+Config.servletUrl+"UserRatingServlet?userLogin="+rs1.getString(6)+"\">"+ rs1.getString(6)+"</a>" + "</td>";
			//		    printStatement=printStatement + "<td>" + rs1.getString(6) + "</td>";
			printStatement=printStatement + "<td>" + rs1.getString(7) + "</td>";
			printStatement=printStatement + "</tr>";
			out.println(printStatement);
		    }
		    while (rs1.next()) ;
		}
		
		if (checkInfo2){
		    do {
			printStatement="<tr>";

			printStatement=printStatement + "<td><A href="+Config.servletUrl+"BidServlet?productId="+rs2.getString(1)+">"+rs2.getString(1)+"</A></td>";
			printStatement=printStatement + "<td><A href="+Config.servletUrl+"BidServlet?productId="+rs2.getString(1)+">"+rs2.getString(2)+"</A></td>";
			//printStatement=printStatement + "<td>" + rs2.getString(1) + "</td>";
			//printStatement=printStatement + "<td>" + rs2.getString(2) + "</td>";
			printStatement=printStatement + "<td>" + rs2.getString(3) + "</td>";
			printStatement=printStatement + "<td>" + rs2.getString(4) + "</td>";
			printStatement=printStatement + "<td>" + rs2.getString(5) + "</td>";
			printStatement=printStatement + "<td>-</td>";
			printStatement=printStatement + "<td>-</td>";
			printStatement=printStatement + "</tr>";
			out.println(printStatement);
		    }
		    while (rs2.next()); 
		}
	    }
	    else{
		printStatement=("<b><c>There are no current auctions.</c></b>");
		out.println(printStatement);   
	    }
	    
	}catch(SQLException sqle){System.out.println("i am god:error sql");}
	out.println("</table>");
    }
    
    // generating page for query four(allauctions where user has placed bids)
    public static void queryFourPage(PrintWriter out, ResultSet rs){
	out.println("<html><head><title>Bids Placed</title></head>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	String printStatement;
	boolean checkInfo;
	try{
	    
	    if (rs==null)
		{checkInfo=false;System.out.println("test");}
	    else
		checkInfo=rs.next();

	    if (checkInfo){
		
		printStatement="<tr>";
		printStatement=printStatement+"<td><b>Product ID</b></td>";
		printStatement=printStatement+"<td><b>Product Name</b></td>";
		printStatement=printStatement+"<td><b>Location</b></td>";
		printStatement=printStatement+"<td><b>Closing Date</b></td>";
		printStatement=printStatement+"<td><b>Bid Amount</b></td>";
		printStatement=printStatement+"</tr>";
		out.println("<table width=\"100%\">");  
		out.println(printStatement);
		
		do{
		    printStatement="<tr>";
		    printStatement=printStatement + "<td><A href="+Config.servletUrl+"BidServlet?productId="+rs.getString(1)+">"+rs.getString(1)+"</A></td>";
		    printStatement=printStatement + "<td><A href="+Config.servletUrl+"BidServlet?productId="+rs.getString(1)+">"+rs.getString(2)+"</A></td>";
		    printStatement=printStatement + "<td>" + rs.getString(1) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(2) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(3) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(4) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(5) + "</td>";
		    printStatement=printStatement + "</tr>";
		    out.println(printStatement);
		}
		while (rs.next()) ;
	    }
	    else{
		printStatement=("<b><c>There are currently no bid placed on any item.</c></b>");
		out.println(printStatement);   
	    }
	}catch(SQLException sqle){}
	out.println("</table>");
    }
    
    // generating page for query five (all auctions won by a user)
    public static void queryFivePage(PrintWriter out, ResultSet rs, String userLogin){
	out.println("<html><head><title>Auctions Won</title></head>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	String printStatement, ratingStatus=null;
	boolean checkInfo;
	try{	    

	    if (rs==null)
		{checkInfo=false;System.out.println("test");}
	    else
		checkInfo=rs.next();

	    if (checkInfo){
		printStatement="<tr>";
		printStatement=printStatement+"<td><b>Product ID</b></td>";
		printStatement=printStatement+"<td><b>Product Name</b></td>";
		printStatement=printStatement+"<td><b>Bid Value</b></td>";
		printStatement=printStatement+"<td><b>Seller Login</b></td>";
		printStatement=printStatement+"<td><b>Seller Email</b></td>";
		printStatement=printStatement+"<td><b>Seller Address</b></td>";
		printStatement=printStatement+"</tr>";
		out.println("<table width=\"100%\">");  
		out.println(printStatement);
		
		do{
		    printStatement="<tr>";
		    printStatement=printStatement + "<td>" + rs.getString(1) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(2) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(3) + "</td>";
		    printStatement=printStatement + "<td>"+"<a href=\""+Config.servletUrl+"UserRatingServlet?userLogin="+rs.getString(4)+"\">"+ rs.getString(4)+"</a>" + "</td>";
		    //		    printStatement=printStatement + "<td>" + rs.getString(4) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(5) + "</td>";
		    printStatement=printStatement + "<td>" + rs.getString(6) + "</td>";
		    ratingStatus=(SharedObjects.qe).winnerRatedSellerAs(rs.getString(1));
		    if (!(ratingStatus.equals("noEntry") || ratingStatus.equals("notRated"))){
			printStatement=printStatement + "<td><span style=\"color:red\">You already rated</span></td>";
		    }
		    else if	(ratingStatus.equals("notRated")){
			printStatement=printStatement + "<td><A href="+Config.servletUrl+"UserFeedbackServlet?productId="+rs.getString(1)+"&sellerLogin="+rs.getString(4)+"&winnerLogin="+userLogin+"&toDo=update>Rate Seller</A></td>";
		    }
		    else{// when no enter for this product ID was in feedback table
			printStatement=printStatement + "<td><A href="+Config.servletUrl+"UserFeedbackServlet?productId="+rs.getString(1)+"&sellerLogin="+rs.getString(4)+"&winnerLogin="+userLogin+"&toDo=insert>Rate Seller</A></td>";
		    }
		    
		    printStatement=printStatement + "</tr>";
		    out.println(printStatement);
		}
		while (rs.next()); 
	    }
	    else{
		printStatement=("<b><c>There are currently no bid placed on any item.</c></b>");
		out.println(printStatement);   
	    }
	}catch(SQLException sqle){}
	out.println("</table>");
    }
    


    // when user enters some login while registering which has already been taken CHECKED!!!
    public static void feedbackForm(String productId, String sellerLogin, String winnerLogin, String login, String toDo, PrintWriter out){
	String feedbackType, userType;
	if (sellerLogin.equals(login)){
	    feedbackType="sellerRatedWinnerAs";
	    userType="Winner";
	}
	else{
	    userType="Seller";
	    feedbackType="winnerRatedSellerAs";
	}
					
	out.println("<html><head><title>Feedback Form</title></head>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<FORM ACTION=\""+Config.servletUrl+"UserFeedbackServlet\" method =\"POST\">");
	out.println("<input name=\"productId\" type=\"hidden\" value=\""+productId+"\">");
	out.println("<input name=\"winnerLogin\" type=\"hidden\" value=\""+winnerLogin+"\">");
	out.println("<input name=\"sellerLogin\" type=\"hidden\" value=\""+sellerLogin+"\">");
	out.println("<input name=\"toDo\" type=\"hidden\" value=\""+toDo+"\">");
	out.println("<table>");
	out.println("<tr>");
	out.println("<td> Product ID:</td>");
	out.println("<td>"+productId+"</td>");
	out.println("</tr>");

	out.println("<tr>");
	out.println("<td> Seller Login:</td>");
	out.println("<td>"+sellerLogin+"</td>");
	out.println("</tr>");

	out.println("<tr>");
	out.println("<td> Winner Login:</td>");
	out.println("<td>"+winnerLogin+"</td>");
	out.println("</tr>");

	out.println("Rate "+userType+":<br>");
	out.println("<input type=\"radio\" name=\""+feedbackType+"\" value=\"good\"> <strong>Good</strong><br>");
	out.println("<input type=\"radio\" name=\""+feedbackType+"\" value=\"neutral\" checked> <strong>neutral</strong><br>");
	out.println("<input type=\"radio\" name=\""+feedbackType+"\" value=\"bad\"> <strong>Bad</strong><br>");
	out.println("  <input type=\"submit\" name=\"Feedback\" value=\"submit\">");		
	out.println("</FORM>");
	out.println("</BODY></HTML>");
	out.close();
    }


    //generating rating table for a user
    public static void generalUserRatingTable(PrintWriter out, ResultSet rs1, ResultSet rs2){
	out.println("<html><head><title>User Current Auctions</title></head>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	int count1=0;
	int count2=0;
	String printStatement, goodString, badString, neutralString;
	System.out.println("page gen class now!!! final hurdle to cross");
	boolean checkInfo1, checkInfo2;
	try{	  
	    System.out.println("page gen class now!!! final hurdle to cross");
	    if (rs1==null)
		{checkInfo1=false;System.out.println("test");}
	    else
		checkInfo1=rs1.next();
	    
	    if (rs2==null)
		checkInfo2=false;
	    else
		checkInfo2=rs2.next();
	    
	    System.out.println("page gen class now!!! final hurdle to cross 3 then done");
	    if (checkInfo1 || checkInfo2){
		printStatement="<tr>";
		printStatement=printStatement+"<td><b>User Login</b></td>";
		printStatement=printStatement+"<td><b>Product Id</b></td>";
		printStatement=printStatement+"<td><b>Good</b></td>";
		printStatement=printStatement+"<td><b>Neutral</b></td>";
		printStatement=printStatement+"<td><b>Bad</b></td>";
		printStatement=printStatement+"</tr>";
		out.println("<table width=\"100%\">");  
		out.println(printStatement);
		
		if (checkInfo1){
		    do{
			goodString="-";
			neutralString="-";
			badString="-";
			printStatement="<tr>";
			printStatement=printStatement + "<td>" + rs1.getString(1) + "</td>";
			printStatement=printStatement + "<td>" + rs1.getString(2) + "</td>";
			if (rs1.getString(3).equals("good")){
			    goodString="*";
			}
			else if(rs1.getString(3).equals("neutral")){
			    neutralString="*";
			}
			else{
			    badString="*";
			}
			
			printStatement=printStatement + "<td><span style=\"color:red\">" + goodString + "</span></td>";
			printStatement=printStatement + "<td><span style=\"color:red\">" + neutralString + "</span></td>";
			printStatement=printStatement + "<td><span style=\"color:red\">" + badString + "</span></td>";
			printStatement=printStatement + "</tr>";
			out.println(printStatement);
		    }
		    while (rs1.next()) ;
		}
	    

		if (checkInfo2){
		    do{
			goodString="-";
			neutralString="-";
			badString="-";
			printStatement="<tr>";
			printStatement=printStatement + "<td>" + rs2.getString(1) + "</td>";
			printStatement=printStatement + "<td>" + rs2.getString(2) + "</td>";
			if (rs2.getString(3).equals("good")){
			    goodString="*";
			}
			else if(rs2.getString(3).equals("neutral")){
			    neutralString="*";
			}
			else{
			    badString="*";
			}
			
			printStatement=printStatement + "<td><center>" + goodString + "</center></td>";
			printStatement=printStatement + "<td><center>" + neutralString + "</center></td>";
			printStatement=printStatement + "<td><center>" + badString + "</center></td>";
			printStatement=printStatement + "</tr>";
			out.println(printStatement);
		    }
		    while (rs2.next()); 
		}
	    }
	    else{
		printStatement=("<b><c>This user has not yet been rated.</c></b>");
		out.println(printStatement);   
	    }
	    
	}catch(SQLException sqle){System.out.println("i am god:error sql..line no.783");}
	out.println("</table>");
    }
    
    
    
    // generates an error message in case of sql exception
    public static void sqlErrorMessage(PrintWriter out){
        out.println("<HTML><HEAD>");
	out.println("<TITLE>Connection Problem</TITLE>");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	out.print("<h3>There is some problem with the connection.</h3>");
	out.println("<h3>Try after some time.</h3>");
	out.println("</BODY></HTML>");
	// THIS WASN THERE IN LOGINASSIGNMENT
	out.close();
    }

    // user will be acknowledged after logging out
    public static void logoutUser(PrintWriter out){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>Logout</TITLE>");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>You Have Been Logged Out Successfully</h3>");
	out.println("</BODY></HTML>");	
	out.close();
    }


    // generates user page after he has logged in
    public static void userMainPage(PrintWriter out, String login){
	System.out.println("inside metyhod userMainpage");
	out.println("<html><head><title>User Main Page</title></head>");
	out.println("<body bgcolor=\"#fffff\">"); 
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>hi!<span style=\"color:red\"><i><b> " +login + "</b></i></span>. Welcome to your personal page.<h3><br>");
	out.println("<a href=\""+Config.servletUrl+"UserQueryServlet?queryNumber=1\">View All your successful auctions </a><br>");
	out.println("<a href=\""+Config.servletUrl+"UserQueryServlet?queryNumber=2\">View All your Unsuccessful auctions </a><br>");
	out.println("<a href=\""+Config.servletUrl+"UserQueryServlet?queryNumber=3\">View All your current auctions </a><br>");
	out.println("<a href=\""+Config.servletUrl+"UserQueryServlet?queryNumber=4\">View All auctions you have placed bid on </a><br>");
	out.println("<a href=\""+Config.servletUrl+"UserQueryServlet?queryNumber=5\">View All auctions you have won </a><br>");
	out.println("<a href=\""+Config.servletUrl+"UserProfileChangeServlet\">View and change your profile </a><br>");
	out.println("<a href=\""+Config.servletUrl+"BrowseServlet?whereFrom=browse&parentName=Product\">Bid on Products </a><br>");
	out.println("<a href=\""+Config.servletUrl+"BrowseServlet?whereFrom=sell&parentName=Product\">Place Auction </a><br>");
	out.println("<a href=\""+Config.servletUrl+"SearchServlet\">Search </a><br>");
	out.println("<a href=\""+Config.servletUrl+"LogoutServlet\">Logout </a><br>");
	out.println("</BODY></HTML>");	
	out.close();
    }

    // user will be acknowledged after logging out
    public static void profileSuccessfullyChanged(PrintWriter out){
	out.println("<HTML><HEAD>");
	out.println("<TITLE>Profile Changed</TITLE>");
	out.println("</HEAD>");
	out.println("<body bgcolor=\"#fffff\">");
	ProdHtmlGen.linksToPages(out);
	out.println("<h3>You profile have been successfully changed.</h3>");
	out.println("<A href=\""+Config.servletUrl+"UserMainServlet\">Click here</a> to go back to main page.");
	out.println("</BODY></HTML>");	
	out.close();
    }

}













