/* 
 This file was generated by Dashcode.  
 You may edit this file to customize your widget or web page 
 according to the license.txt file included in the project.
 */

//
// Function: load()
// Called by HTML body element's onload event when the web application is ready to start
//
function load() {
    dashcode.setupParts();
    document.getElementById("results").style.display = "none";
}

function getResults(event) {
    var phone = document.getElementById("phoneNum").innerHTML;
    var feedURL = "http://www.telephonenumber.com/iphone/reverse.php?phone=" + phone;
    var onloadHandler = function() { 
        xmlLoaded(xmlRequest);
    };

    var xmlRequest = new XMLHttpRequest();
    xmlRequest.onload = onloadHandler;
    xmlRequest.open("GET", feedURL);
    xmlRequest.setRequestHeader("Cache-Control", "no-cache");
    xmlRequest.send(null);
}


function xmlLoaded(xmlRequest) {
	if (xmlRequest.status == 200) {
		var textAreaValue = document.getElementById("results");
        document.getElementById("keypad").style.display = "none";
        textAreaValue.style.display = "inline";
        textAreaValue.innerHTML = xmlRequest.responseText;
    }
	else {
		alert("Error fetching data: HTTP status " + xmlRequest.status);
	}
}

function keypadIn(val) {

    var phoneNum = document.getElementById("phoneNum").innerHTML;
    if(val == 10) phoneNum = phoneNum + "-";
    else if(val == 99) {
        var last = phoneNum.length;
        phoneNum = phoneNum.substring(0, last - 1);
    }
    else phoneNum = phoneNum + val;
    document.getElementById("phoneNum").innerHTML = phoneNum;    
}

function showKeypad(event) {
    document.getElementById("results").style.display = "none";
    document.getElementById("keypad").style.display = "inline";
    document.getElementById("phoneNum").innerHTML = "";
}
