// JavaScript Document
//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = 'img/false.png';
var imgTrue = 'img/true.png';

function changeimg(orig, dest){
	dest.src = orig;
}

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
	replaceChecks();
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(mylink,windowname,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=500,top=100,left=100");

return false;
}

function replaceChecks() {
	
	//get all the input fields on the page
	inputs = document.getElementsByTagName('input');

	//cycle trough the input fields
	for(var i=0; i < inputs.length; i++) {

		//check if the input is a checkbox
		if(inputs[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputs[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImage'+i;
			//set image 
			img.onclick = new Function('checkChange('+i+')');
			//place image in front of the checkbox
			inputs[i].parentNode.insertBefore(img, inputs[i]);
			
			//hide the checkbox
			inputs[i].style.display='none';
		}
	}
}

//change the checkbox status and the replacement image
function checkChange(i) {

	if(inputs[i].checked) {
		inputs[i].checked = '';
		document.getElementById('checkImage'+i).src=imgFalse;
	} else {
		inputs[i].checked = 'checked';
		document.getElementById('checkImage'+i).src=imgTrue;
	}
}
window.onload = function() {
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop 
	if (!document.getElementsByTagName) {
		return false; 
	} 
	// create an array of objects of each link in the document 
	var popuplinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
	for (var i=0; i < popuplinks.length; i++) {	
		// if the link has a class of "popup"...	
		if (popuplinks[i].getAttribute("class") == "popup") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			popuplinks[i].onclick = function() {	
			openPopUp(this.getAttribute("href"));	
			return false; 	
			} 	
		}
	} 
} 

function changeValue()
{
        var indice = document.AdsChange.Country.selectedIndex;


        if(document.AdsChange.Country.options[indice].value=="U.S.A." || document.AdsChange.Country.options[indice].value=="Canada")
        {
                document.AdsChange.State.disabled=false;
        }
        else
        {
                document.AdsChange.State.disabled=true;
                document.AdsChange.State.value="X";
        }
}

function ConfirmDelete (Tag)
{
agree = confirm("You are about to delete the address tagged as <"+Tag+">: are you sure?");
return agree;
}
function swap(num) {
			var im1 = "img/stars-"+num+"-0.gif"
			//alert(im1);
						document.zstar.src = "img/stars-"+num+"-0.gif";
						document.forms['rForm'].starrating.value = num;
						return true;
			}
			function RConfirm(f, sentence){
						if (confirm(sentence)){
						f.submit();
						}
						else {
						return false;
						}
			}
	
	function abh(fvalue, fvalue2, tnum){
		document.forms['bsearch'].TWhere.value = fvalue2;
		document.forms['bsearch'].TWhere2.value = fvalue;
		document.forms['bsearch'].SType.value = tnum;
		return document.forms['bsearch'].submit();
	}

window.onload = init;