$(document).ready(function() {
    $('#Button1').click(function() {
        location.reload(true);
    });
});

function requestCustomerInfo(sName,sEmail,sPhone,sSerial,sTicket) {  
 	var getEnteredData = document.getElementById("CustomerId").value;   // The input box data
    
    if (getEnteredData != "") {

	    var sName = getEnteredData; 
		var snamepat = /^\s*[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;  // The regex script
		if (snamepat.test(sName)) {   // The regex test
	    		var url = "GetCustomerName.php?name="; // The server-side script
	 		http.open("GET", url + escape(sName),  true); 
	  	} 

	  	var sEmail = getEnteredData;
	  	var emailpat = /^\s*.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;   // The regex script
		if (emailpat.test(sEmail)) {   // The regex test 			
	  		var url = "GetCustomerEmail.php?email="; // The server-side script 
	  		http.open("GET", url + escape(sEmail), true); 
		} 
 
	 	var sPhone = getEnteredData; 
	 	var phonepat = /^\s*\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;   // The regex script
	 	if (phonepat.test(sPhone)) {   // The regex test 
	 		var url = "GetCustomerPhone.php?phone="; // The server-side script
	 		http.open("GET", url + escape(sPhone), true); 
		}
           
		var sSerial = getEnteredData; 
		var serialpat = /^\s*[a-z|0-9]{10}$/;   // The regex script
	 	if (serialpat.test(sSerial)) {    // The regex test 
	 		var url = "GetProductSerialNumber.php?serial="; // The server-side script 
	 		http.open("GET", url + escape(sSerial), true);
		} 

		var sTicket = getEnteredData; 
		var ticketpat = /^\s*[0-9]{12,}$/;    // The regex script
	 	if (ticketpat.test(sTicket)) {    // The regex test 
	 		var url = "GetServiceTicket.php?ticket="; // The server-side script 
	 		http.open("GET", url + escape(sTicket), true);
		}   
   }
   
   http.onreadystatechange = handleHttpResponse; 
   http.send(null); 
}  

function handleHttpResponse() {    
    if (http.readyState == 4) { 
      if(http.status==200) { 
         var results=http.responseText; 
         document.getElementById('divCustomerInfo').innerHTML = results;  
		//alert(results);
      } 
   } 
}  

function getHTTPObject() { 
   var xmlhttp; 
   
   if(window.XMLHttpRequest){ 
        xmlhttp = new XMLHttpRequest(); 
   } 
   else if (window.ActiveXObject){ 
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
        if (!xmlhttp){ 
            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        } 
  } 
  return xmlhttp; 
} 

var http = getHTTPObject(); // We create the HTTP Object      


//var windowName = 'userConsole'; 
//if (popUp == null || typeof(popUp)=='undefined') {  
//  alert('Please disable your pop-up blocker and click the "Open" link again.'); 
//} 
//else {  
//  popUp.focus();
//}  


function displayAddNewCustomer() { 

  DispWin = window.open('addNewCustomer','New Customer', 'menubar=no, toolbar=no, statusbar=yes, location=no, resizable=no, width=383, height=470');
  name = document.addNewCustomer.name.value; 
  phone = document.addNewCustomer.phone.value;
  email = document.addNewCustomer.email.value; 

  address = document.addNewCustomer.address.value; 
  city = document.addNewCustomer.city.value;
  state = document.addNewCustomer.state.value;
  zip = document.addNewCustomer.zip.value;

  product = document.addNewCustomer.product.value;
  model = document.addNewCustomer.model.value; 
  serial = document.addNewCustomer.serial.value;
  computer = document.addNewCustomer.computer.value;
  os = document.addNewCustomer.os.value;
  docs = document.addNewCustomer.docs.value;
  cso = document.addNewCustomer.cso.value; 
  issue = document.addNewCustomer.issue.value;
 
  DispWin.document.write('<div style="color:#045FB4; font-size:22px"><b>Add New Customer</b></div><hr />');
  DispWin.document.write('<div style="color:#006600;">',cso,'</div><hr />'); 
  DispWin.document.write(name,"<br />");
  DispWin.document.write(phone,"<br />");
  DispWin.document.write(email,"<br />"); 
  DispWin.document.write(address,"<br />");
  DispWin.document.write(city,"<br />");
  DispWin.document.write(state,"<br />");
  DispWin.document.write(zip,"<br />"); 

  DispWin.document.write(product,"<br />");
  DispWin.document.write(model,"<br />");
  DispWin.document.write(serial,"<br />"); 

  DispWin.document.write(computer,"<br />");
  DispWin.document.write(os,"<br />");  

  DispWin.document.write(docs,"<br />");  
  DispWin.document.write(issue,"<br />");
  DispWin.document.write('<hr /><div class="winDisabled" style="color:#cc6600;">For demostration only the save function has been disabled for database security.</div><br />');    
  DispWin.document.write('<input type="button" style="float:right" onClick="window.close();" value="Close Window"/>');
} 


function displayAddNewTicket() { 
   
  DispWin = window.open('addNewTicket','New Ticket', 'menubar=no, toolbar=no, statusbar=yes, location=no, resizable=no, width=383, height=470'); 
  ticket =  document.addNewTicket.ticket.value; 
  name = document.addNewTicket.name.value; 
  phone = document.addNewTicket.phone.value;
  email = document.addNewTicket.email.value; 

  address = document.addNewTicket.address.value; 
  city = document.addNewTicket.city.value;
  state = document.addNewTicket.state.value;
  zip = document.addNewTicket.zip.value;

  product = document.addNewTicket.product.value;
  model = document.addNewTicket.model.value; 
  serial = document.addNewTicket.serial.value;
  
  computer = document.addNewTicket.computer.value;  
  os = document.addNewTicket.os.value;
  docs = document.addNewTicket.docs.value;
  issue = document.addNewTicket.issue.value;
  
  DispWin.document.write('<div style="color:#045FB4; font-size:22px"><b>Add New Service Ticket</b></div><hr />');
  DispWin.document.write('<div style="color:#006600;">',ticket,'</div><hr />');

  DispWin.document.write(name,"<br />");
  DispWin.document.write(phone,"<br />");
  DispWin.document.write(email,"<br />"); 
  DispWin.document.write(address,"<br />");
  DispWin.document.write(city,"<br />");
  DispWin.document.write(state,"<br />");
  DispWin.document.write(zip,"<br />");

  DispWin.document.write(product,"<br />");
  DispWin.document.write(model,"<br />");
  DispWin.document.write(serial,"<br />");  

  DispWin.document.write(computer,"<br />");
  DispWin.document.write(os,"<br />");

  DispWin.document.write(docs,"<br />");
  DispWin.document.write(issue,"<br />"); 
  DispWin.document.write('<hr /><div class="winDisabled" style="color:#cc6600;">For demostration only the save function has been disabled for database security.</div><br />');    
  DispWin.document.write('<input type="button" style="float:right" onClick="window.close();" value="Close Window"/>');
} 
