/* submit the form using tagName */
function submitTag(myform, tagName)
{
	mf=eval("document." + myform);
	mf.tag.value=tagName;
	mf.submit();
}

function submitSearchBy(myform, searchByValue)
{
	mf=eval("document." + myform);
	mf.search_by.value=searchByValue;
	mf.submit();
}

/* submit the form using tagName with an attachment key*/
function submitAttachmentKeyTag(myform, aKey, tagName)
{
	mf=eval("document." + myform);
	mf.attachment_key.value=aKey;
	mf.tag.value=tagName;
	mf.submit();
}

/* submit the form using tagName with an item_index */
function submitItemIndexTag(myform, itemIndex, tagName)
{
	mf=eval("document." + myform);
	mf.item_index.value=itemIndex;
	mf.tag.value=tagName;
	mf.submit();
}

/* submit the form using tagName with a product_key */
function submitProductKeyTag(myform, productKey, tagName)
{
	mf=eval("document." + myform);
	mf.product_key.value=productKey;
	mf.tag.value=tagName;
	mf.submit();
}


/* Prompt the user to confirm before submitting the form */
function confirmSubmitTag(msg, myform, tagName) {
	returnValue = confirm(msg);
	if (returnValue == true) {
		submitTag(myform, tagName);
	}
}

/* check if an item is selected in a list before submitting a form */
function checkListSubmitTag(myform, tagName, list, msg) {
	i = list.selectedIndex;
	if (i != -1 && list.options[i].value > "") {
		submitTag(myform, tagName);
	} else {
		alert(msg);	
	}
}

function submitTagWithBuf(myform, col, buf, tagName){
	sourceList = document.forms[myform].elements[col];
	val = "";
	for (i=0;i<sourceList.length;i++) {
		if (i!=0) { val += ","; }
		val += sourceList[i].value;
	} 

	mf=eval("document." + myform);
	buffer = document.forms[myform].elements[buf];
	buffer.value = val;
	mf.tag.value=tagName;
	mf.submit();
}


function moveUp(col) 
{
	sl = col.selectedIndex;
	if (sl != -1 && col.options[sl].value > "") {
    	oText = col.options[sl].text;
    	oValue = col.options[sl].value;
    	if (col.options[sl].value > "" && sl > 0) {
      		col.options[sl].text = col.options[sl-1].text;
      		col.options[sl].value = col.options[sl-1].value;
      		col.options[sl-1].text = oText;
      		col.options[sl-1].value = oValue;
      		col.selectedIndex--;
    	} 
	} else {
    	alert("Please select an item first");
	}
}

function moveDown(col) 
{
	sl = col.selectedIndex;
	if (sl != -1 && col.options[sl].value > "") {
		oText = col.options[sl].text;
		oValue = col.options[sl].value;
		if (sl < col.length-1 && col.options[sl+1].value > "") {
			col.options[sl].text = col.options[sl+1].text;
			col.options[sl].value = col.options[sl+1].value;
			col.options[sl+1].text = oText;
			col.options[sl+1].value = oValue;
			col.selectedIndex++;
		}
	} else {
		alert("Please select an item first");
	}
}

function viewNote(url) 
{
	/*
    attr="scrollbars=yes, resizable=yes, height=150, width=600"
    win = window.open(url, "_blank", attr);
	*/
	openWindow(url, 150, 600);
}

function openWindow(url, ht, wh) 
{
    attr="scrollbars=yes, resizable=yes";
	attr += " height=" + ht + ",";
	attr += " width=" + wh;
    win = window.open(url, "_blank", attr);
}

/* Determine image size and show it in proper size */
/* 12/02/02 hctu: this function is retired and is replaced
   by server size through com.ctu.crm.servlet.ImageUtil.
*/
function imageSize(path, srcFile, alt, minSize) {
    img = new Image();
    img.src = path+'/'+srcFile;

    var ht = img.height;
    var wh = img.width;
    if (ht>wh) base="w";
    else base="h";

    tmp="<img src=\"" + path + "/" + srcFile + "\"";
    if (base == "w" && wh > minSize) {
        newWidth=minSize;
        newHeight=ht*(newWidth/wh);
    } else if (base == "h" && ht > minSize) {
        newHeight = minSize;
        newWidth = wh * (newHeight/ht);
    } else {
        newWidth = wh;
        newHeight = ht;
    }
    /* The following is used when the image has not been
       fully loaded and the dimension is not available. */
    if (newWidth < 1 || newHeight < 1) {
        newWidth = minSize;
        newHeight = minSize;
        /* alert ("newWidth = minSize and newHeight = minSize"); */
    }

    tmp += " width=\"" + newWidth+ "\" height=\"" + newHeight + "\"";
    tmp += " border=0 alt=\"" + alt+"\">";
    /* alert ("ht="+ht+"   wh=" + wh + "  link=" + tmp); */
    document.write(tmp);
}





