// Formatting.js
//  Helper methods for text input
//
function confirmEmail(obj) {
    //alert("email confirmed, redirecting to: " + obj.value);
    window.location = "../" + obj.value;
}

function setPrimaryInfo()
{
    var fname = document.getElementById("ctl00_ContentPlaceHolder1_tbContactFName");
    var lname = document.getElementById("ctl00_ContentPlaceHolder1_tbContactLName");
        
    var fNameVal = fname.value;
    var lNameVal = lname.value;
    
    var mailname = document.getElementById("ctl00_ContentPlaceHolder1_tbMailName").value;
    if( mailname.length <= 0 )
        document.getElementById("ctl00_ContentPlaceHolder1_tbMailName").value = fNameVal + " " + lNameVal; 
        
    document.getElementById("ctl00_ContentPlaceHolder1_MEM1_FNAME").value = fNameVal;
    document.getElementById("ctl00_ContentPlaceHolder1_MEM1_LNAME").value = lNameVal;
}

function setExpandedBusTripDescription() {
    alert('set primary');
    var shortDesc = document.getElementById("ctl00_ContentPlaceHolder1_tbDestination");
    var date = document.getElementById("ctl00_ContentPlaceHolder1_txtDate");

    var shortDescVal = shortDesc.value;
    var dateVal = date.value;

    var fullDesc = document.getElementById("ctl00_ContentPlaceHolder1_tbFullDescription").value;
    if (fullDesc.length <= 0)
        document.getElementById("ctl00_ContentPlaceHolder1_tbFullDescription").value = shortDescVal + " - " + lNamdateValeVal;

}

//
//Restricts input to numeric values
//
function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else
	if (e)
		key = e.which;
	else
		return true;

	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
		(key==9) || (key==13) || (key==27) )
		return true;
	// numbers
	else
	if ((("0123456789-(). ").indexOf(keychar)> -1))
		return true;
	// decimal point jump
	else
	if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return false;
}
//
//Restricts input to numeric values
//
function charsonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event) {
	    key = window.event.keyCode;
	    //alert('key Code: ' + key);
	}
	else
	    if (e) {
	    key = e.which;
	    //alert('key which Code: ' + key);
	}
	else {
	    //alert('returning true');
	    return true;
	}

	keychar = String.fromCharCode(key);

	//alert('key Char: ' + keychar);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
		(key==9) || (key==13) || (key==27) )
		return true;
	// numbers
	else
	if ((("0123456789").indexOf(keychar)> -1))
		return false;
	// decimal point jump
	else
	if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return true;
}
//
// This function capitalizes the first character
//
function title_case(obj)
{
	var htext, nhtext;
    var str = obj.value;
    var htext=ltrim(rtrim( str ));

	htext=htext.toLowerCase();
	// Just in case they're all caps.

	j=htext.length;
	nhtext="";
	for(i=0; i < j;i++)
	{
		if(i==0)
		// To capitalize the first character.
		{
			nhtext=nhtext+htext.substr(i,1).toUpperCase();
		}
		else
		if(htext.charAt(i)==" ")
		{
			// Checks for the appearance of the space character.
			nhtext=nhtext+htext.substr(i,1);
			// Adds that space character to the string.
			nhtext=nhtext+htext.substr(++i,1).toUpperCase();
			// Capitalizes and adds the next character to the string.
		}
		else
		if(htext.charAt(i)=="-")
		{
			// Checks for the appearance of the newline character.
			nhtext=nhtext+htext.substr(i,1);
			// Adds the newline character to the string.
			nhtext=nhtext+htext.substr(++i,1).toUpperCase();
			// Capitalizes and adds the next character to the string.
		}
		else
		if(htext.charAt(i)=="")
		{
			// Checks for the appearance of the newline character.
			nhtext=nhtext+htext.substr(i,1);
			// Adds the newline character to the string.
			nhtext=nhtext+htext.substr(++i,1).toUpperCase();
			// Capitalizes and adds the next character to the string.
		}
		else
		{
			nhtext=nhtext+htext.substr(i,1);
			// Adds the character in a normal way.
		}
		//form.MemberLNAME.value=nhtext;
		obj.value = nhtext;
		// Done!!
	}
}
//
// Function that removes the leading spaces.
//
function ltrim(sent_str)
{
	var spaces = new String(" \t\r");
	var str = new String(sent_str);
	if(spaces.indexOf(str.charAt(0))!= -1)
	// This checks that there really leading blanks before the string.
	{
		var j=0, i=str.length;
		while(j<i && spaces.indexOf(str.charAt(j))!=-1)
		j++;
		// Keep iterating until you reach at a characterthat is not a space.
		str=str.substring(j,i);
		// Copy the rest of the string.
	}

	return str;
}

// Function that removes the trailing spaces.
// The explanation for this function is same as the
// above function, except for it moves backward.
function rtrim(sent_str)
{
	var spaces = new String(" \t\r");
	var str = new String(sent_str);
	if(spaces.indexOf(str.charAt(0))!=-1)
	{
		var i=str.length-1;
		while(i >= 0 && spaces.indexOf(str.charAt(i))!=-1)
		i--;
		str=str.substring(0, i+1);

	}
	return str;
}
//
// This function capitalizes the first character
//
function toCaps(obj)
{
	var htext;
    var str = obj.value;
    var htext=ltrim(rtrim( str ));

	htext=htext.toUpperCase();
	
    obj.value = htext;
}

function setAcceptButtonState()
{
    alert("in accept");
}
