/**
 * jumpAttr
 *
 * Do the automatic redirection when the value of a select changes
 */
function jumpAttr (targ, selObj, restore) {
	eval (targ + ".location='../" + selObj.options[selObj.selectedIndex].value + "/1'");
	if (restore) selObj.selectedIndex=0;
}

function jumpBar (selObj, param) {
	var cLoc = self.location.toString();
	
	// Check for parameter "?"
	if (cLoc.indexOf('?') != -1) {
		cLoc = cLoc.substr(0, cLoc.lastIndexOf('?'));
	}

	// Check pagination to reset
	if (isNaN(cLoc.substr(cLoc.lastIndexOf('/') + 1)) == false) {
		cLoc = cLoc.substr(0, cLoc.lastIndexOf('/'));
	}
	
	// Check search_value
	if (param.indexOf('###') != -1) {
		var paramArray = param.split ("###");
		param = paramArray[0];
		search_value = paramArray[1];
		
		cLoc = cLoc.substr(0, cLoc.lastIndexOf ('/search'));
		cLoc += '/product/search/search_value/' + search_value + '/';
	}

	eval ("location='" + cLoc + "?" + param + "=" + selObj.options[selObj.selectedIndex].value + "'");
}

/**
 * filterByFamily
 *
 * Restrict the values of the field by the selectedFamily
 */
function filterByFamily (theFamily) {
	sel1 = document.getElementById("unassociated_product_has_attribute");
	sel2 = document.getElementById("associated_product_has_attribute");
	
	currentItems = Array ();
	
	// Delete all the values of the select		
	for (var i=sel1.length-1; i>=0; i--) {
		sel1.options[i] = null;
	}
	
	// Generate an array with the values selected
	for (var i=sel2.length-1; i>=0; i--) {
		currentItems.push(sel2.options[i].value);
	}

	attribs = theFamily.split ("#");
	
	attribs.sort();

	for (var i=0; i<attribs.length; i++) {
		attrib = attribs[i].split("-");
		
		inArray = false
		for (var j=0; j<currentItems.length; j++) {
			if (currentItems[j] == attrib[0]) {
				inArray = true;
			}
		}
		
		if (inArray == false) {
			addOption (sel1, attrib[1], attrib[0]);
		}
	}
}

/**
 * addOption
 *
 * Add the item to the select
 */
function addOption(theSel, theText, theValue) {
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}

/**
 * checkValueToSearch
 *
 * Check if is the default value and then replace for null
 */
function checkValueToSearch (theInput) {
	if (theInput.value.indexOf ('...') != -1) {
		theInput.value = '';
	}
}

/**
 * checkTerms
 *
 * Check if the user has checked the box with the shopping terms
 */
function checkTerms (theMessage) {
	if (document.validaForm.terms.checked) {
		return true;
	}
	else {
		alert (theMessage);
		return false;
	}
}
