// JavaScript Document

var url="http://skylife.ilvillage.it/skylife/sky_wap.jsp";

function chkForm() {
	if (document.getElementById('msisdn').value == '' || document.getElementById('msisdn').value == '+39' || document.getElementById('keyword').value == '') {
		alert("Completare tutti i campi!");
		return false;
	}

	//aggiunge +39 se manca
	if (document.getElementById('msisdn').value.substring(0,3) != '+39') document.getElementById('msisdn').value = '+39' + document.getElementById('msisdn').value;

	ajaxCall();

}

function ajaxCall() {
	//AJAX
	var strpost="msisdn=" + document.getElementById('msisdn').value + "&keyword=" + document.getElementById('keyword').value;
	//alert(url + '?' + strpost)
	var xmlReq = getHTTPObject(); // We create the HTTP Object
	xmlReq.onreadystatechange = function(){
		if (xmlReq.readyState == 4)
		{	
			if(xmlReq.status == 200) openPopup(1);
			else if(xmlReq.status == 400) openPopup(2);
			else openPopup(3);
		}
	}
	xmlReq.open("GET", url + '?' + strpost, true);
	xmlReq.send(null); 
}

function openPopup(p) {
	window.open('http://skylife.ilvillage.it/form/popup.html?res='+p,'risultato','left=300, top=250, width=300, height=300,toolbar=no, location=no,status=no,menubar=no,scrollbars=no,resizable=no');
}


//Restituisce oggetto HTTP
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }

  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

