<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="windows-1255" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ODBC" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<script runat="server"> 

Public Dim UsersDBConnectionString As String = "Data Source=mysql281.secureserver.net;Database=ecusers;User ID=ecusers;Password=toto1X2;"
Public Dim SiteDBConnectionString As String = "Data Source=mysql273.secureserver.net;Database=ecsite;User ID=ecsite;Password=toto1X2;"


Sub Page_Template_Load (Sender As Object, E As EventArgs)
	Dim Lang as String
	Lang = Request.QueryString("lang")
	
	If (Lang = "") Then
		Lang = "heb"
	End If
	
	If Not Page.IsPostBack Then
		Dim SQLConnectString As String = SiteDBConnectionString
    	Dim mySQLConn As MySqlConnection = Nothing
		mySQLConn = New MySqlConnection(SQLConnectString)
        mySQLConn.Open()
		Dim Readme As MySqlDataReader = Nothing
        Dim cmd As New MySqlCommand("SELECT Type, Label, Link FROM MainMenu WHERE Lang='" & Lang & "' ORDER BY Serial ASC", mySQLConn)
		Readme = cmd.ExecuteReader()
		
		Dim menu_dt As DataTable 
		Dim dr As DataRow
    	Dim i As Integer
		
		menu_dt = New DataTable
    	menu_dt.Columns.Add(New DataColumn("MenuLink", GetType(String)))
	
		i = 0
		While Readme.Read()

			dr = menu_dt.NewRow()
			If Readme.GetString(0) = "Link" Then
				dr(0) = "<td class=""menucell""><a href=""" & Readme.GetString(2) & """ class=menu>"  & ReEncode(Readme.GetString(1)) & "</a></td>"
				menu_dt.Rows.Add(dr)
			End If
			If Readme.GetString(0) = "Label" Then
				dr(0) = "<td class=""menulabelcell""><span class=menulabel>" & ReEncode(Readme.GetString(1)) & "</span></td>"
				menu_dt.Rows.Add(dr)
			End If
			
	
		End While
				
		Readme.close()
		mySQLConn.Close()

		Repeater1.DataSource = New DataView(menu_dt)
		Repeater1.DataBind()

	End If
	
	If (Not Request.Cookies("UserName") Is Nothing) AndAlso _
		(Not Request.Cookies("UserName").Value Is Nothing) Then
		UserNameLabel.Text = Request.Cookies("UserName").Value
		LoginPanel.Visible = False
		UserPanel.Visible = True
	Else
		UserNameLabel.Text = "guest"
		LoginPanel.Visible = True
		UserPanel.Visible = False
	End If

End Sub

Sub SaveButton_Click(sender As Object, e As EventArgs)
	Dim UserName = UserNameTextBox.Text
	Dim PassHash = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(UserPassTextBox.Text,"SHA1").Substring(0,24).ToUpper()
	Dim LoginQuery = "SELECT PassHash, NickHash, Nick FROM UsersTable WHERE Email='" & UserName &"'"
	Dim connectString = UsersDBConnectionString
    Dim myConn As MySqlConnection = Nothing
	myConn = New MySqlConnection(connectString)
	Dim TableOutput As New MySqlCommand(LoginQuery, myConn)
    myConn.Open()
	Dim Readme As MySqlDataReader = TableOutput.ExecuteReader()
	If Readme.Read() then
		If PassHash = Readme.GetString(0).ToUpper() 
			Response.Cookies("UserName").Value = UserName
			Response.Cookies("UserName").Expires = System.DateTime.Now.AddDays(1000) 
			Response.Cookies("PassHash").Value = Readme.GetString(0)
			Response.Cookies("PassHash").Expires = System.DateTime.Now.AddDays(1000) 
			Response.Cookies("NickHash").Value = Readme.GetString(1)
			Response.Cookies("NickHash").Expires = System.DateTime.Now.AddDays(1000) 
		End If
	End If
	Response.AppendHeader("Refresh", "0")
End Sub

Sub DeleteButton_Click(sender As Object, e As EventArgs)
	Response.Cookies("UserName").Value = ""
	Response.Cookies("UserName").Expires = System.DateTime.Now.AddDays(-1)
	Response.Cookies("NickHash").Value = ""
	Response.Cookies("NickHash").Expires = System.DateTime.Now.AddDays(-1) 
	Response.Cookies("PassHash").Value = ""
	Response.Cookies("PassHash").Expires = System.DateTime.Now.AddDays(-1) 
	Response.AppendHeader("Refresh", "0")
End Sub	

Public Function ReEncode(S as String) As String
	Dim encode As Encoding
	encode = System.Text.Encoding.GetEncoding("windows-1255")	
	Dim unicodeBytes As Byte() = Encoding.Unicode.GetBytes(S)
	Dim RawBytes(unicodeBytes.Length/2) As Byte
	Dim j As Integer
	For j = 0 To (unicodeBytes.Length/2-1)
		RawBytes(j) = unicodeBytes(2*j)
	Next j
	Dim encodeChars(encode.GetCharCount(RawBytes, 0, RawBytes.Length-1)) As Char
	encode.GetChars(RawBytes, 0, RawBytes.Length-1, encodeChars, 1)
	Return (New String(encodeChars))
End Function

Public Function GetActiveMahzorID(Game as String) As String
	Dim connectString = UsersDBConnectionString
    Dim myConn As MySqlConnection = Nothing
	MyConn = New MySqlConnection(connectString)
	Dim TableOutput As New MySqlCommand("SELECT MAX(MahzorID) FROM MatchTable WHERE MahzorID LIKE '" & Game.SubString(0,2) & "%'", myConn)
	myConn.Open()
	Dim Readme As MySqlDataReader = TableOutput.ExecuteReader()
	Readme.Read()
	Dim CurrMahzor = Readme.GetString(0)
	Readme.close()
	MyConn.close()
	Return CurrMahzor
End Function
 
Function GetRecLink(MahId As String, NickHash As String, Lang As String, LinkText As String) As String
	Dim Ret As String
	If (Lang = "") Then
		Lang = "heb"
	End If
	Ret = "<a href=""ShowGuess.aspx?MahzorID=" & MahId & "&Nick=" & NickHash & "&Lang=" & Lang & """>" & LinkText & "</a>"
	Return Ret 
End Function

Function GetHomePageLink(NickHash As String, LinkText As String) As String
	Dim Ret As String
	Ret = "<a href=""HomePage.aspx?Nick=" & NickHash & """ >" & LinkText & "</a>"
	Return Ret 
End Function


</script>



<script runat="server"> 

Public Dim NickHash As String
Public Dim ToNickHash As String
Public Dim IsSelf As Boolean

Sub Details_Load (Sender As Object, E As EventArgs)

	'Verifying User
	Dim connectString = UsersDBConnectionString
    Dim myConn As MySqlConnection = Nothing
	MyConn = New MySqlConnection(connectString)
	myConn.Open()
	Dim TableOutput As MySqlCommand
	Dim Readme As MySqlDataReader
	
	ToNickHash = ""
	TableOutput = New MySqlCommand("SELECT Nick FROM UsersTable WHERE NickHash='" & Request.QueryString("To") & "'", myConn)
	Readme = TableOutput.ExecuteReader()
	If Readme.Read() Then
		ToNickHash = Request.QueryString("To")
		ToLabel.Text = ReEncode(Readme.GetString(0))
	Else
		Exit Sub
	End If
	
	Readme.Close()
	
	If (Not Request.Cookies("NickHash") Is Nothing) AndAlso _
		(Not Request.Cookies("NickHash").Value Is Nothing) Then
		
		TableOutput = New MySqlCommand("SELECT Nick, NickHash, PassHash FROM UsersTable WHERE NickHash='" & Request.Cookies("NickHash").Value & "'", myConn)
		Readme = TableOutput.ExecuteReader()
		If Readme.Read() Then 
			If (Readme.GetString(2) = Request.Cookies("PassHash").Value) Then
				NickHash = Request.Cookies("NickHash").Value
				FromLabel.Text = ReEncode(Readme.GetString(0))
			End If
		End If
		Readme.Close()
		
		
	Else
		MyConn.Close()
		Response.Redirect("YardHome.aspx")
		Exit Sub
	End If
		
	myConn.Close()

End Sub

Sub Page_Load (Sender As Object, E As EventArgs)
	Page_Template_Load(Sender, E)
	Details_Load(Sender, E)
End Sub
</script>


<head>
<meta http-equiv="Content-Type" content="text/html" charset=windows-1255>



<title>המלצות טוטו - מאגר המלצות לניחוש טוטו וטוטו עולמי</title>

<meta name="KEYWORDS" content="טוטו, ווינר, וינר, טוטו עולמי, מילוי טוטו, המלצות טוטו, מומחים, צמצום, צימצום, תוכנת טוטו, כדורגל, הימורים, סטטיסטיקה, סטטיסטיקות טוטו, ליינים, יחסי הימור, שערי הימור">

<meta name="DESCRIPTION" content="מאגר המלצות טוטו פתוח, המלצות מהמרים, סטטיסטיקות על משחקי המחזור, ההמלצות נבדקות ומדורגות על פי הניחוש הנכון בטוטו.">




<style type="text/css">
<!--
.style2 {font-family: Arial}
.menu {
	color: #000000; font-size: 14px; font-weight: bold; text-decoration: none;
}
.menu:visited {
	color: #000000; font-size: 14px; font-weight: bold; text-decoration: none;
}
.menu:hover {
	color: #0000CC; font-size: 14px; font-weight: bold; text-decoration: none;
}

.menulabel {font-size: 16px; font-weight: bold; color:#000099;}

.tipster {font-size: 15px; font-weight: bold;}

.menucell { vertical-align: bottom; padding: 3px; }

.menulabelcell { vertical-align: middle; border: 2px solid red; padding: 1px; text-align: center; }

.style6 {font-size: 12px}

.style7 {font-size: 10px}

.style9 {font-size: 24px; font-weight: bold; font-style: italic; color:#3300FF}

.guesscell {font-size: 16px; font-weight: bold; border: 1px solid black; background-color:#FFFF99; vertical-align:middle;} 

.freetextcell {font-size: 12px; border: 1px solid black; background-color:#FFFFCC; vertical-align:middle; text-align: right;}  

.gamecell {font-size: 12px; border: 1px solid black; vertical-align:middle; text-align: right;}  

.game {
	border-bottom: 2px solid black; vertical-align: middle;
}

.gametable {
	border-collapse: collapse;
}

.gametabletitle {background-color:#FFFF99; font-weight: bold; font-size: 12px;}

.linestriplet {
	border-collapse: separate;
}

.linestd {
	border: 1px solid red;
}

.summarytd {
	border: 1px solid red; background-color:#FFFFFF;
}

.summarytdtop {
	background-color: #FFFFCC; font-size: 10px; font-weight: bold; border: 1px solid black;  
}

-->
</style>


</head>
<form runat="server"> 
 
<body class="style2" dir=rtl>
<table width="780" height="78" background="/images/yardtitle.gif" hspace="0" vspace="0" align="center" style="border-collapse: separate">
    <tr> 
		<td height="76" width="780"></td>
    </tr>
</table>
  
  <table width="780" border="1" align="center" bordercolor="#6699FF">
    <tr>
      <td width="140px" valign="top">
	  <div style="vertical-align: top; width:135px;">
	  	<BR>
		<asp:Panel id="UserPanel" 
        style="Z-INDEX: 101; vertical-align: top;" 
        runat="server" 
        Height="80px" 
        Width="130px">
		<span class="style6">מחובר<BR>
		<b>
		<asp:Label ID="UserNameLabel" Runat="server" EnableViewState="False"></asp:Label><BR></b></span>
		<asp:Button id="DeleteButton" runat="server" Text="התנתק" Font-Size="9" Width="50px" OnClick="DeleteButton_Click"></asp:Button>
		</asp:Panel>
		
		  <asp:Panel id="LoginPanel" 
        style="Z-INDEX: 102; vertical-align: top;" 
        runat="server" 
        Height="80px" 
        Width="130px">
		<div align="center">
		    <span class="style7">
			<table border="0">
			<tr>
			<td>אימייל</td><td>
		    <asp:TextBox id="UserNameTextBox" runat="server" Font-Size="9" Columns="14" MaxLength="40"></asp:TextBox></td>
			</tr><tr><td>
		    סיסמה</td><td>
		    <asp:TextBox id="UserPassTextBox" TextMode="Password" runat="server" Columns="14"  Font-Size="9" MaxLength="8"></asp:TextBox></td>
			</tr><tr><td colspan="2">
		    <asp:Button id="SaveButton" runat="server" Text="היכנס" Font-Size="9" Width="40px" OnClick="SaveButton_Click"></asp:Button>
			<a href="sitereg.php" style="font-size: 10px">משתמש חדש</a></td>
			</tr>
			</table>
		    </span></div>
	      </asp:Panel>  	    
		
	  	<asp:Repeater id="Repeater1" runat="server">
				<HeaderTemplate><table width="100%" style="border-collapse: separate;"></HeaderTemplate> 
				<ItemTemplate>
					<tr width="100%">
					<%#DataBinder.Eval(Container.DataItem, "MenuLink")%>
					</tr>
				</ItemTemplate>
				<FooterTemplate></table></FooterTemplate>
		  </asp:Repeater>
		</div>
	  </td>

	  <td width="640" valign="top">
	  
	  
	  
		<table bgcolor="#99CCFF" width="100%"><tr><td align="center">
		<b>מאת:</b>&nbsp;<asp:Label id="FromLabel" runat="server"
		Font-Size="14" Font-Bold="true" Font-Italic="True" Font-Name="Arial" text=""></asp:Label>
		</td></tr></table>
		<br>
		<b>אל:&nbsp;</b><asp:Label id="ToLabel" runat="server"></asp:Label><br>
		<br>
		<br>
		</form>
		<script language="javascript">
	 		function sendform() {
	  			document.myform.submitbutton.disabled = true;
				document.myform.submit();
				}
		</script>
		<form name="myform" action="sendmsg.php" method=POST>
		<input type="hidden" name="FromNickHash" value="<%= NickHash %>">
		<input type="hidden" name="FromNick" value="<%= FromLabel.Text %>">
		<input type="hidden" name="ToNickHash" value="<%= ToNickHash %>">
		כותרת:<br> <textarea rows="1" cols="70" name="Subject"></textarea><br><br>
		תוכן ההודעה:<br> <textarea rows="10" cols="70" name="Message"></textarea><br><br>
		<center><input type="submit" name="submitbutton" value="שלח הודעה" onClick="sendform()"></center>
		
       </td>
    </tr>
    <tr>
      <td height="15" width="780" colspan="2" align="center" valign="middle">
	  <a href="index.html"><img src="/images/extra1x2_add.gif" border="0"></a> 
	       <center><iframe src="http://dealme.org/show_ad.php?t=1&s=2&p=1059&cat_id=0&width=728&height=90&ref=" width="728px" height="90px" scrolling="no" frameborder="0"></iframe></center>
	  
	  
	  </td></a>
    </tr>
  </table>
</body>
</form>

</html>
