/*-------------------------------------------------------------------------------------------------
editError()
Reposition an error flag
Top and Left is the absolute position - not an addition or subtraction
-------------------------------------------------------------------------------------------------*/
function editError(id,error,direction,top,left,autolocate) {

	// If given a direction...
	if(direction != "") {
		// If given left as a direction, switch the classes
		if(direction == "left") {
			parent.document.getElementById(id + "_error").className = "errorTab";
		}
		// Else switch the classes to right
		else {
			parent.document.getElementById(id + "_error").className = "errorTab errorTabRight";
		}
	} 
	
	// If given a top position, move it there
	if(top != "") {
		parent.document.getElementById(id + "_error").style.top  = top + "px"; 
	}
	
	// If given a left position, move it there
	if(left != "") {
		parent.document.getElementById(id + "_error").style.left = left + "px";
	} 
	
	// THIS ISN'T BEING USED RIGHT NOW BUT WOULD BE GOOD TO ONE DAY
	if(autolocate == true) {
				
		obj = parent.document.getElementById(id);
				
		// These position functions are being called from generic_functions
		var posX = findPosX(obj); 
		var posY = findPosY(obj);
		
		// If its a right tab, move it to the right of the obj
		if(obj.className == "errorTab errorTabRight") {
			var widthOfInput = parseInt(obj.style.width);
			var errorX = poxX + widthOfInput + 5;
		}
		// Otherwise if its a left tab, move it to the left of the obj
		else {
			var errorX = posX - 155; // 165 is about the width of a tab
		}
		
		var errorY = posY - 8;
	
		parent.document.getElementById(id + "_error").style.left = errorX + "px";
		parent.document.getElementById(id + "_error").style.top  = errorY + "px";
	}
	
	
	// If given an error, change the message
	if(error != "") {
		parent.document.getElementById(id + "_errorText").innerHTML = error
	}
	
}




/*-------------------------------------------------------------------------------------------------
errorField()
Throw an error field
-------------------------------------------------------------------------------------------------*/
function errorField(id,pass,newError,background,autolocate){

	fade = true;
	
	// If passed a newError message, use it
	if(newError != "" && newError != undefined) {
		editError(id,newError,"","","");
	}
	
	if(autolocate == true) {
		editError(id,"","","","",true);
	}
	
	// TURN ON ERROR
	if(pass == false) {	

		parent.document.getElementById(id + "_error").style.display = "block";
	
		// Only change backgrounds on text input
		if(parent.document.getElementById(id + "_input")) {
			if(parent.document.getElementById(id + "_input").type == "text" && background == 1) {
				parent.document.getElementById(id + "_input").style.background = 'url(/store/checkout/images/field-status-pink.jpg)';
			} 
		}
	
		// Find out what the opacity of the error is...if its already full opacity, don't try to fade it in again
		opacityIs = parent.document.getElementById(id + "_error").style.opacity;
		
		
		
		if(fade == false) {
			parent.document.getElementById(id + "_error").style.opacity = "100";
		}
		else {
			if(opacityIs != 0.990099) {
				opacity(id + "_error", 0, 100, 500); // Fade in error				
				
				//var attributes = {  opacity: {from: 0, to: 1 }  }	
				//var ani = new YAHOO.util.Anim(id + '_error' , attributes, 0, YAHOO.util.Easing.easeNone);
			}
		}
	}
	// TURN OFF ERROR
	else {

		parent.document.getElementById(id + "_error").style.display = "none";
		parent.document.getElementById(id + "_input").style.background = '';
		
		if(parent.document.getElementById(id + "_error").style.opacity < 100) {
			currentOpac = parent.document.getElementById(id + "_error").style.opacity * 100;
		}
		
		if(fade == false) {
			parent.document.getElementById(id + "_error").style.opacity = "0";
		}
		else {
			if(currentOpac >= 99.0099) {
				opacity(id + "_error", 100, 0, 500); // Fade out error
				//var attributes = {  opacity: {from: 1, to: 0 }  }	
				//var ani = new YAHOO.util.Anim(id + '_error' , attributes, 0, YAHOO.util.Easing.easeNone);
			}
		}
	}
}

