function formatcurrency(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return "$" + s;
}

function getElement(element) {
	if (document.getElementById) {
		return document.getElementById(element);
	}	
	else if (document.all) {
		return document.all(element);
	}
	else if (document.layers){
		return document.layers[element];
	}
	else {
		return null;
	}
}

function getDocElement(doc, element) {
	if (doc.getElementById) {
		return doc.getElementById(element);
	}	
	else if (doc.all) {
		return doc.all(element);
	}
	else if (doc.layers){
		return doc.layers[element];
	}
	else {
		return null;
	}
}

function setSpanText(id, text) {
	var spanObj = getElement(id);
	spanObj.innerHTML = text;
}

function changeCountry(akey, aval, theform, prefix) {
	var elname = "document." + theform.name + "." + prefix + "state";
	var selobj = eval(elname);

	for(j=selobj.length; j >= 0; j--) {
		selobj.options[j] = null;
	}

	selobj.options.length = 0;
	for(i=0; i < akey.length; i++) {
		selobj.options[i] = new Option( aval[i], akey[i] );
	}
}

function borderit(which,color){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
		which.style.borderColor=color;
	}
}

function openwin(htmlFile, win_width, win_height) {
	thewin=open("","NewWindow","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width="+win_width+",height="+win_height);
	thewin.location = htmlFile;
}

function checkItemDetailForm(theform) {
    var haserror = false;
    var trackOptionGroup = [];
    
    for(i=0; i < theform.elements.length; i++) {
        if( theform.elements[i].name == "required" ) {
            ogroup = theform.elements[i].value;
            objMsg = getElement('MSG' + ogroup);
            objMsg.innerHTML='';
            objLabel = getElement('LABEL' + ogroup);
            optionValue = null;
            for(j=0; j < theform.elements.length; j++) {
                if( theform.elements[j].name == "option[" + ogroup + "]" ) {
                    optionValue = theform.elements[j].value;
                    if(optionValue=='')
                    {
                        labelValue= objLabel.innerHTML;
                        labelValue = labelValue.substr(0,labelValue.length-1);
                        objMsg = getElement('MSG' + ogroup);
                        objMsg.innerHTML='Specify some value for '+labelValue+' field.';
                        haserror = true;
                    }                    
                    //trackOptionGroup.push(optionValue); 
                    break;
                }
            }
        }
    }
    
    if(!haserror) {
        theform.submit();
    }
}
