/**
 * This Javascript file contains commonly HNL Magazine Site functions.
 *
 * @author   fuentesc
 * @history  02/14/2008  fuentesc  Created
 *
 */

// Hopefully not much more than this function will be needed
function popup(url, winname,  w, h, menu, resize, scroll, x, y) {
	if (winname == null) winname = "newWindow";
	if (w == null) w = 600;
	if (h == null) h = 600;
	if (resize == null) resize = 1;
	
	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";

	if (menu) menutype = "menubar";
	if (resize) resizetype = "resizable";
	if (scroll) scrolltype = "scrollbars";
	
	if (x == null || y == null) {
		cwin=window.open(url,winname, + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);
	}
	else {
		cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);
	}
	if (!cwin.opener) cwin.opener=self;
	
	cwin.focus();

	return cwin;
}

function popupFullWindow(url, winname,  w, h) {
	if (winname == null) winname = "newWindow";
	if (w == null) w = 600;
	if (h == null) h = 600;
	
	cwin=window.open(url,winname,"status,menubar,resizable,scrollbars,toolbar,location" + ",width=" + w + ",height=" + h);
	
	if (!cwin.opener) cwin.opener=self;
	cwin.focus();

	return;
}

function CheckPriceRange() {
	if (document.SearchCriteria.MinPrice.options[document.SearchCriteria.MinPrice.selectedIndex].value.length && document.SearchCriteria.MaxPrice.options[document.SearchCriteria.MaxPrice.selectedIndex].value.length) {
		if (parseInt(document.SearchCriteria.MinPrice.options[document.SearchCriteria.MinPrice.selectedIndex].value) > parseInt(document.SearchCriteria.MaxPrice.options[document.SearchCriteria.MaxPrice.selectedIndex].value)) {
			alert("Please select a max price greater than the min price you have chosen.");
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}

function ValueChangeSubmit(FormName,FieldName,Value) {
	var Form = document[FormName];
	var Field = Form[FieldName];
	Field.value = Value;
	Form.submit();
	return false;
}

//given a form checkbox name, this function will set all checkboxes of the name specified with the Status value specified
function CheckAll(CheckBox, Status) {
	if (CheckBox.length > 1) {
		for (var i=0; i < CheckBox.length; i++) {
			if (CheckBox[i].disabled == false) CheckBox[i].checked = Status;
	 	}
	} else {
		if (CheckBox.disabled == false) CheckBox.checked = Status;
	}
}

//if any checkboxes are checked, this function will return a true. Otherwise false.
function IsChecked(CheckBox) {
	if (CheckBox.length > 1) {
		for (var i=0; i < CheckBox.length; i++) {
			if (CheckBox[i].checked) {
				return true;
			}
	 	}
		return false;
	} else {
		if (CheckBox.checked) {
			return true;
		} else {
			return false;
		}
	}
}