function showLicense(aPlatform)
{
	var osName = {win:"Windows",linux:"Linux",mac:"MacOSX"};
	document.getElementById("installDiv").style.display = "block";
	document.getElementById("installTitle").innerHTML = "Abbeyphone Extension End User License Agreement (" + osName[aPlatform] + ")";
	gPlatform = aPlatform;
}

function install(aName, aType, aFileName, aPlatform)
{    
    try{
	    var xpi = new Object();
			if(aPlatform) gPlatform = aPlatform;
			xpi[aName] =  "installxpi.php?type=" + aType + "&name=" + aFileName + "&platform=" + gPlatform;
			gFileName = aFileName;
	    InstallTrigger.install(xpi, onInstallDone);
	}catch(e){alert("Your browser doesn't allow extensions!");}
}

function onInstallDone(name, result)
{
	if (result != 0) return;
	urchinTracker('/install/' + gFileName + '_' + gPlatform);
	location.href = "suggest.html#download";
}

function checkSuggestion()
{
	var email = document.getElementById("email").value;
	var comment = document.getElementById("comment").value;
	var submitItem = document.getElementById("sendBtn");
	submitItem.disabled = !(email.length && comment.length);
}

function sendSuggestion()
{
	var email = document.getElementById("email").value;
	var comment = document.getElementById("comment").value;
	document.getElementById("sendBtn").disabled = true;
	sendXMLHttpRequest("mail.php?email="+email+"&text="+parseString(comment));
}

function parseString(aString) {
		aString = aString.replace(/%/g,"%25"); // primo
		aString = aString.replace(/&/g,"%26");
    return aString.replace(/\+/g,"%2B");
}

function sendXMLHttpRequest(aURL) 
{    
    if (window.XMLHttpRequest) // native XMLHttpRequest object
    {
        req = new XMLHttpRequest();
        req.onreadystatechange = onRequestProgress;
        req.open("GET", aURL, true);
        req.send(null);
    
    }
    else if (window.ActiveXObject) // IE/Windows ActiveX version
    {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        req.onreadystatechange = onRequestProgress;
        req.open("GET", aURL, true);
        req.send();
    }
}

function onRequestProgress()
{
    if (req.readyState != 4) return; // 4 = complete
    if (req.status != 200) return; // "OK"
		if(req.responseText == "ok") location.href = "Firefox_Voip.html";
		else alert('Error sending email! Try again');
}

function addEngine()
{
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function"))
	{ 
		try
		{
			window.sidebar.addSearchEngine("http://labs.abbeyphone.com/firefox_search/abbeyphone.src", "http://labs.abbeyphone.com/firefox_search/abbeyphone.png", "Abbeynet Webphone", "VoIP")
		}
		catch(e) {alert('Cannot install search plugin');}
	}
}
