function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function radio_button_checker(f,text) {
	// set var radio_choice to false
	var radio_choice = false;
	
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < f.elements.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (f.elements[counter].checked)
		radio_choice = true; 
	}
	
	if (!radio_choice) {
		// If there were no selections made display an alert box 
		alert(text)
		return (false);
	} else {
		return (true);
	}
}

function confDelete(f,text) {
	if(confirm(text)){
		return true;
	} else {
		// untick the messages
		for (i = 0; i < f.length; i++) {
		f[i].checked = false; }
		return false;
	}
}

function checkAll(theForm, cName, allNo_stat) {
	var n=theForm.elements.length;
	for (var i=0;i<n;i++){
		if (theForm.elements[i].className.indexOf(cName) !=-1){
			if (allNo_stat.checked) {
				theForm.elements[i].checked = true;
			} else {
				theForm.elements[i].checked = false;
			}
		}
	}
}

var popWin;

// Add a handler to the popup link on loading the page to cause the popup to open
// Thanks Dan!
/*
function preparePopup() {
	var link = document.getElementById('photopopup');
	if (link) {
		link.onclick = function() {
			popWin  = window.open(this.href,'ImageWindow','width=540,height=640,resizable=yes,scrollbars=yes,menubar=no,statusbar=no,toolbar=no');
			return (!popWin);
		}
	}
}
*/

// popup for photos
function photopopup(user_id){
	url = '/photo-popup.php?user_id='+user_id;
	
	popWin = window.open(url,'ImageWindow','width=540,height=550,resizable=yes,scrollbars=yes,menubar=no,statusbar=no,toolbar=no');
	return (!popWin);
}

// popup for send to friend
function sendtofriend(user_id,city,listing_type,title) {

	url = '/sendtofriend.php?user_id='+user_id+'&city='+city+'&listing_type='+listing_type+'&title='+title;

	popWin  = window.open(url,'ImageWindow','width=600,height=430,resizable=yes,scrollbars=yes,menubar=no,statusbar=no,toolbar=no');
	return (!popWin);
}


// window.onload = preparePopup;

// close the popup when navigating away from parent
function winCloser()
{
 if (popWin)
 {
  popWin.close();
 }
}

window.onunload = winCloser;
