// JavaScript Document
function ftn_trim(str, chars) {
    return ftn_ltrim(ftn_rtrim(str, chars), chars);
}

function ftn_ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function ftn_rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function ftn_setSelectedIndex(s, i)
{
	s.options[i-1].selected = true;
	return;
}



function ftn_print_mail_to_link(lhs,rhs)
{
   document.write("<a href=\"mailto");
   document.write(":" + lhs + "@");
   document.write(rhs + "\">" + lhs + "@" + rhs + "<\/a>");
}

function ftn_setSelectedValue(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
		var val=s.options[i].value;
        if (val==v) {
            s.options[i].selected = true;
            return;
        }
    }
}

function ftn_setSelectedIndex_wsplit(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
		var temp1=s.options[i].text.toLowerCase();
		var temp2=temp1.split(" - ");
        if (temp2[1]==v.toLowerCase() ) {
            s.options[i].selected = true;
            return;
        }
    }
}

function ftn_convertdatetoslash(datein)
{
       pieces = datein.split("-");
	   return (pieces[2]+"/"+pieces[1]+"/"+pieces[0]);
}

function ftn_convertdatetodash(datein)
{
       pieces = datein.split("/");
	   return (pieces[2]+"-"+pieces[1]+"-"+pieces[0]);
}

function ftn_setSelectedIndex_match(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

function ftn_AddDDLItem(ddl,Text,Value)
{
	// Create an Option object        
    var opt = document.createElement("option");
    
	// Add an Option object to Drop Down/List Box
    ddl.options.add(opt);

	// Assign text and value to Option object
	opt.text = Text;
	opt.value = Value;
}

function ftn_clearDDL(theDropDown) 
{
	var numberOfOptions = theDropDown.options.length
	for (i=0; i<numberOfOptions; i++)
	{
		//Note: Always remove(0) and NOT remove(i)
		theDropDown.remove(0)
	}
}

