function changeFabric(partID,objId,fabricName,rollWidth,fabricPrice,patternRepeat,groupName,groupPart,groupId,liningColour){
	
	document.getElementById("fabric_partCode").value = partID;
	document.getElementById("fabric_id").value = objId;
	document.getElementById("fabric_name").value = fabricName;
	document.getElementById("fabric_fabricRollWidth").value = rollWidth;
	document.getElementById("fabric_fabricItemPrice").value = fabricPrice;
	document.getElementById("fabric_patternRepeat").value = patternRepeat;
	document.getElementById("fabric_groupName").value = groupName;
	document.getElementById("fabric_groupPartCode").value = groupPart;
	document.getElementById("fabric_groupId").value = groupId;
	document.getElementById("fabric_liningColour").value = liningColour;
			
			
	if(document.getElementById("actionprocess") != null){
		document.getElementById("actionprocess").value="";
	}
	 
	var doSubmit = true;
	/* check width 
	if(document.getElementById("widthField") != null){
		if(trim(document.getElementById("widthField").value) == 0){
			alert("Please enter a valid width measurement ");
			doSubmit = false;
		}
	}*/

	/* check drop 
	if(document.getElementById("dropField") != null){
		if(trim(document.getElementById("dropField").value) == 0 && doSubmit == true){
			alert("Please enter a valid measurement drop");
			doSubmit = false;
		}
	}*/
	
	/* check width 
	if(document.getElementById("measurements_width") != null){
		if(trim(document.getElementById("measurements_width").value) == 0 && doSubmit == true){
			alert("Please enter a valid width measurement ");
			doSubmit = false;
		}
	}*/

	/* check drop 
	if(document.getElementById("measurements_totalDrop") != null){
		if(trim(document.getElementById("measurements_totalDrop").value) == 0 && doSubmit == true){
			alert("Please enter a valid measurement drop");
			doSubmit = false;
		}
	}*/

	if(doSubmit){
		document.configForm.action=location.href;
		document.configForm.submit();
	}

}
function toggleExtras(varietyID,objContainer,prefix){

	var liningContainer = document.getElementById(objContainer);
	var extraFields = liningContainer.getElementsByTagName('div');
	
	for (i=0; i<extraFields.length; i++)	{
			
		var thisfield = extraFields[i];
		var selectedItem = prefix + varietyID;
		
		if(thisfield.className == prefix && thisfield.id != selectedItem){
				
			thisfield.style.display = "none";
		
		} else if (thisfield.id == selectedItem){
			
			thisfield.style.display = "block";
			
		}
		
	}

}
var trim = (function(){
    var ws = {},
        chars = ' \n\r\t\v\f\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
    for(var i = 0; i < chars.length; i++ )
        ws[chars.charAt(i)] = true;

    return function( str ){
        var s = -1,
            e = str.length;
        while( ws[str.charAt(--e)] );
        while( s++ !== e && ws[str.charAt(s)] );
        return str.substring( s, e+1 );
    };
})();
function getSelectedRadio(obj){
	var val = 0;
	var selectedItem = obj;
	
	for( i = 0; i < selectedItem.length; i++ )
	{
		if( selectedItem[i].checked == true ){
			val = selectedItem[i].value;
			break;
		}
	}	
	
	return val;
}

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function finalCalc(){

	/*var thePrice = document.getElementById("priceInt").firstChild.nodeValue;*/
	
	if(document.getElementById("actionprocess") != null){
		document.getElementById("actionprocess").value="";
	}

	thisUrl = window.location.href;
	thisUrl = thisUrl.split('?');

	document.configForm.action=thisUrl[0];
	document.configForm.submit();
	
/*
	var quantity = document.getElementById("config_requiredDropdown")[document.getElementById("config_requiredDropdown").selectedIndex].value;
	var quantity = quantity.split("|");

	finalTotal = (thePrice * quantity[0]);
	if(right(finalTotal.toFixed(2),2) != "00"){
		finalTotal = finalTotal.toFixed(2);
	}

	document.getElementById("totalPrice").value ="\u00A3" + finalTotal;
*/
}

function updateMeasurements(){

	actionProcess = document.getElementById("actionprocess");

}


checkMeasurements = function(){
	
	
	
	document.getElementById("configForm").onsubmit = function(){
		
		/* check width */
		if(document.getElementById("widthField") != null){
			if(trim(document.getElementById("widthField").value) == 0){
				alert("Please enter a valid width measurement ");
				return false;
			}
		}
	
		/* check drop */
		if(document.getElementById("dropField") != null){
			if(trim(document.getElementById("dropField").value) == 0){
				alert("Please enter a valid measurement drop");
				return false;
			}
		}
		
		/* check width */
		if(document.getElementById("measurements_width") != null){
			if(trim(document.getElementById("measurements_width").value) == 0){
				alert("Please enter a valid width measurement ");
				return false;
			}
		}
	
		/* check drop */
		if(document.getElementById("measurements_totalDrop") != null){
			if(trim(document.getElementById("measurements_totalDrop").value) == 0){
				alert("Please enter a valid measurement drop");
				return false;
			}
		}
		




		/* check cord pos */
		if(typeof(document.configForm.cordPos) == "object"){
			
			if(isSelected(document.configForm.cordPos, '\'Cord Position\' must be selected', 'radio')==false){
				return false;	
			}
			
		}

	}
}

addLoadEvent(checkMeasurements);

function updatePriceConfig(){
	if(document.getElementById("actionprocess") != null){
		document.getElementById("actionprocess").value="";
	}
	

	thisUrl = window.location.href;
	thisUrl = thisUrl.split('?');

	document.configForm.action=thisUrl[0];
}