/* javascript function to update form field
 *  field		form field that is being counted
 *  count		form field that will show characters left
 *  maxchars 	maximum number of characters
*/
function characterCount(field, count, maxchars) {
  var realchars = field.value.replace(/\t|\r|\n|\r\n/g,'');
  var excesschars = realchars.length - maxchars;
  if (excesschars > 0) {
		field.value = field.value.substring(0, maxchars);
		alert("Error:\n\n- You are only allowed to enter up to"+maxchars+" characters.");
	} else {
		count.value = maxchars - realchars.length;
	}
}

function upload_progress()
  {
    toggleLayer('divUpload');
    return true;
  }
  
  function upload_progress2()
  {
    toggleLayer('divUpload2');
    return true;
  }


function toggleLayer( whichLayer )
{  
	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
		elem = document.getElementById( whichLayer );  
	else if( document.all ) // this is the way old msie versions work      
		elem = document.all[whichLayer];  
	else if( document.layers ) // this is the way nn4 works   
		elem = document.layers[whichLayer]; 
	
	vis = elem.style;  
	// if the style.display value is blank we try to figure it out here  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
		
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function updateQty ( id, value )
{  	

	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
		elem = document.getElementById( id );  
	else if( document.all ) // this is the way old msie versions work      
		elem = document.all[id];  
	else if( document.layers ) // this is the way nn4 works   
		elem = document.layers[id]; 
	
	var curVal;
	curVal = parseInt(elem.innerText);
	
	if (value == "+1")
		curVal = curVal + 1;
	if (value == "-1")
		curVal = curVal - 1;

	if (curVal < 0) curVal = 0;
	elem.innerText = curVal;
	return false;
}

function updateQtyValue ( id, value )
{  	

	var elem, vis;  
	if( document.getElementById ) // this is the way the standards work    
		elem = document.getElementById( id );  
	else if( document.all ) // this is the way old msie versions work      
		elem = document.all[id];  
	else if( document.layers ) // this is the way nn4 works   
		elem = document.layers[id]; 
	
	var curVal; 
	var elemID;
	curVal = elem.value;
		
	var elemArray = new Array();
	elemArray = curVal.split(':');

	curVal = parseInt(elemArray[0]);
	elemID = elemArray[1];
	
	if (value == "+1")
		curVal = curVal + 1;
	if (value == "-1")
		curVal = curVal - 1;

	if (curVal < 0) curVal = 0;

	elem.value = curVal + ':' + elemID;
	return false;
}
