// JavaScript Document

// Show the popups.
function handsetPopup() {
	var handsetList = document.getElementById("handsetList");
	var hid = handsetList.options[handsetList.selectedIndex].value;
	if(hid != '') {
		globalPopUp('/mobile-phones/review.php?hid=' + hid,600,400);
	}
}

function retailerPopup() {
	var retailerList = document.getElementById("retailerList");
	var sid = retailerList.options[retailerList.selectedIndex].value;
	if(sid != '') {
		globalPopUp('/popups/tri-reviews.php?sid=' + sid,600,400);
	}
}

// Watch the buttons.
function handsetListWatch() {
   var handsetBtn = document.getElementById("handsetBtn");
   attachEventListener(handsetBtn, "click", handsetPopup, false);
}

function retailerListWatch() {
   var retailerBtn = document.getElementById("retailerBtn");
   attachEventListener(retailerBtn, "click", retailerPopup, false);
}

// Watch the selects if no buttons.
function handsetListWatch_select() {
   var handsetBtn = document.getElementById("handsetList");
   attachEventListener(handsetBtn, "change", handsetPopup, false);
}

function retailerListWatch_select() {
   var retailerBtn = document.getElementById("retailerList");
   attachEventListener(retailerBtn, "change", retailerPopup, false);
}


// Trigger the watch functions onload.
if(document.getElementById("handsetBtn")) {
	addLoadListener(handsetListWatch);
}else if(document.getElementById("handsetList")) {
	addLoadListener(handsetListWatch_select);
}

if(document.getElementById("retailerBtn")) {
	addLoadListener(retailerListWatch);
}else if(document.getElementById("retailerList")) {
	addLoadListener(retailerListWatch_select);
}