﻿var xmlHttp;


function checkMobile()
{
	
	
	
	var num = escape(document.getElementById("phonenum").value);
	var agree= document.getElementById("checkbox1").checked;
	

	
	
	
	if( isNaN(num)==true) { 
				document.getElementById("txtHint2").innerHTML="Ο αριθμός πρέπει να περιέχει μόνο ψηφία [0-9].";   
				document.getElementById("phonenum").focus();  
				document.getElementById("phonenum").select();
		} 
	else if(num.length>0 && num.length<10){ 
				document.getElementById("txtHint2").innerHTML="Ο αριθμός πρέπει να έχει 10 ψηφία.";
				document.getElementById("phonenum").focus();  
				document.getElementById("phonenum").select();
		} 
	else if(num.length==0) { 
				document.getElementById("txtHint2").innerHTML="Δεν έχετε εισάγει αριθμό."; 
				document.getElementById("phonenum").focus();  
				document.getElementById("phonenum").select();
		} 
	else if (num[0]!= 6 || num[1]!=9) { 
				document.getElementById("txtHint2").innerHTML="O αριθμός πρέπει να ξεκινάει απο 69.";  
		 		document.getElementById("phonenum").focus();  
				document.getElementById("phonenum").select();
		} 
	
	else{
		if(agree){
			insert(num);
			document.getElementById("phonenum").value="";
                       document.getElementById("txtHint2").innerHTML="Παρακαλώ πολύ περιμένετε...";


		}
		else //not agree
		alert("Πρέπει να αποδεχθείτε τους όρους!");
		

	}
	



}


function insert(num)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
//var num = escape(document.getElementById("phonenum").value);
var url="sms_news.php";
url=url+"?phonenum="+num;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



function stateChanged2() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint2").innerHTML=xmlHttp.responseText;
 } 
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

