/* Add Item Specific */
/* Change the Price Input-Select Combo */
function changePriceComboValue(spPrice, priceID, curSignSelID){
	var pIn = document.getElementById(priceID);
	pIn.value = spPrice[1];
	cSelOpt = document.getElementById(curSignSelID).options;
	for(x=0; x<cSelOpt.length; x++) {
		if(cSelOpt[x].value== spPrice[0]) {
			cSelOpt.selectedIndex = x;
		}
	}
}
/* Change the Price Input-Select Combo and Preview */
function changePriceComboAndPreviewValue(spPrice, priceID, curSignSelID, textNodeID){
	changePriceComboValue(spPrice, priceID, curSignSelID);
	var Val = '';
	if(spPrice[0]=='EUR') {
		Val = "€" + spPrice[1];
	} else if(spPrice[0]=='GBP') {
		Val = "£" + spPrice[1];
	} else if(spPrice[0]=='JPY') {
		Val = "¥" + spPrice[1];
	} else if(spPrice[0]=='USD') {
		Val = "$" + spPrice[1];
	 } else {
		Val = spPrice[0] + " $" + spPrice[1];
	}	 
	addOrChangeTextNode(textNodeID, Val);
}

/* Do the Price from pIn */
function updatePriceAllFromPriceInput(pIn, curSignSelID, textNodeID){
	var cSelOpt = document.getElementById(curSignSelID).options;
	var spPrice = new Array();
	spPrice[0] = cSelOpt[cSelOpt.selectedIndex].value;
	spPrice[1] = pIn.value;
	changePriceComboAndPreviewValue(spPrice, pIn.id, curSignSelID, textNodeID);
}
/* Do the Price from cSel */
function updatePriceAllFromCurrencySelect(priceID, curSignSel, textNodeID){
	var cSelOpt = curSignSel.options;
	var spPrice = new Array();
	spPrice[0] = cSelOpt[cSelOpt.selectedIndex].value;
	spPrice[1] = document.getElementById(priceID).value;
	changePriceComboAndPreviewValue(spPrice, priceID, curSignSel.id, textNodeID);
}

/* for Image on Load */
function resizeImgAndChangeHiddenValues(daImg, maxW, maxH, hidWID, hidHID) {
	resizeIMG(daImg, maxW, maxH);
	changeHiddenValue(hidWID, daImg.width);
	changeHiddenValue(hidHID, daImg.height);
}

/* Do Price Select Logic */
function doPriceSelectLogic(daselect, priceID, curSignSelID, textNodeID) {
	//get Value from Select
	var selVal = daselect.options[ daselect.options.selectedIndex ].value;
	//Split Value.
	var spPrice = selVal.split(':');
	changePriceComboAndPreviewValue(spPrice, priceID, curSignSelID, textNodeID);
	changeDisplay(daselect.id);
}

/* Select the image from Img */
function doImgFromImgLink(val, ContainerID, inputID, imgID, hidWID, hidHID){
	document.getElementById(inputID).value = val;
	changeDisplay(ContainerID);
	changeAndResizeIMG(imgID, val);
	changeHiddenValue(hidWID, document.getElementById(imgID).width);
	changeHiddenValue(hidHID, document.getElementById(imgID).height);
}
/* to simplify */
function doImg(val) {
	doImgFromImgLink(val, 'imageSelect', 'PhotoURL', 'previewImg', 'imgW', 'imgH');
	return false;
}

/* Check the Price Value */
function checkPriceValidate(theForm) {
	if (validate(theForm)) {
 	//Form is allright.
	 	if (!document.getElementById('Price').value) {
		//But Price has not been filled. We Confirm.
			var tR = confirm('Are you sure you want to leave the Price Field Empty?\nSelect CANCEL to fill it in manually.\nSelect OK to add Item to the list without price anyway.');
		} else {
			//Price has been filled. 
			var tR = true;
		}
	} else {
	//Form is not right.
	tR = false;
	}
	return tR;
}