var isNav4, isNav6, isIE4;

// AUTHOR:			Jason Noftall
// DATE:			Aug. 19, 2003
// DESCRIPTION:		Validates User Profile text fields for content.
// PARAMETERS:		1. frm = reference to the user profile form.
//					2. ctlpreface = a string representing the leading name of all controls.
//					3. current_username = current username (will content a string for User Edit and empty for User Add).
// RETURNS:			<none>, submits the specified form if the specified text fields contain data.
function ValidateUser(frm, ctlpreface, current_username)
{
	var doc = window.document;
	
	// Only check for Username/Passwords for "Add New User"...
	if (current_username.length == 0)
	{
		var username = doc.getElementById(ctlpreface + "user");
		var password = doc.getElementById(ctlpreface + "pass");
		 if (trimString(username.value).length == 0)
		{
			alert("Please specify your Username.");
			username.focus();
			return;
		}
		else if (trimString(password.value).length == 0)
		{
			alert("Please specify your Password.");
			password.focus();
			return;
		}
	}
		
	var firstname = doc.getElementById(ctlpreface + "fName");
	var lastname = doc.getElementById(ctlpreface + "lName");

var email = doc.getElementById(ctlpreface + "email");
		
		if (trimString(email.value).length == 0)
		{
			alert("Please specify your email address.");
			email.focus();
			return;
		} else
	if (trimString(firstname.value).length == 0)
	{
		alert("Please specify your First Name.");
		firstname.focus();
		return;
	}
	else if (trimString(lastname.value).length == 0)
	{
		alert("Please specify your Last Name.");
		lastname.focus();
		return;
	}

	frm.submit();
}

// AUTHOR:			Jason Noftall
// DATE:			Aug. 19, 2003
// DESCRIPTION:		Validates User Profile text fields for content.
// PARAMETERS:		1. frm = reference to the user profile form.
//					2. ctlpreface = a string representing the leading name of all controls.
//					3. current_username = current username (will content a string for User Edit and empty for User Add).
// RETURNS:			<none>, submits the specified form if the specified text fields contain data.
function ValidateMailingList(frm)
{
	var email = frm.email.value;
	if( email.length == 0 )
	{
		frm.email.focus();
		alert("Please enter an email address.");
		return;
	}
	
	frm.submit();
}

// AUTHOR:			Jason Noftall
// DATE:			Nov. 7, 2003
// DESCRIPTION:		Validates Contact Us text fields for content.
// PARAMETERS:		1. frm = reference to the user profile form.
//					
// RETURNS:			<none>, submits the specified form if the specified text fields contain data.
function ValidateContactUs(frm)
{
	//name="_ctl0:_ctl5:name" id="_ctl0__ctl5_name"
	//_ctl0:_ctl5name
	
	//_ctl0__ctl5_name
	//_ctl0__ctl5_name

	//var name = document.getElementById(ctlPreface + "_NameFrom");
	var name = document.getElementById("NameFrom");
	var email = document.getElementById("EmailFrom");

	if (trimString(name.value).length == 0)
	{
		alert("Please provide your name.");
		name.focus();
		return;
	}
	else if ((trimString(email.value).length == 0) || (!IsValidEmail(email.value)))
	{
		alert("You must provide a valid E-mail address.");
		email.focus();
		return;
	}
	
	frm.submit();
}

// AUTHOR:			Melissa Whalen
// DATE:			Jan. 4, 2007
// DESCRIPTION:		Validates Change of Address text fields for content.
// PARAMETERS:		1. frm = reference to the user profile form.
//					
// RETURNS:			<none>, submits the specified form if the specified text fields contain data.

function ValidateAddressChange(frm)
{
	var fname = document.getElementById("fName");
	var lname = document.getElementById("lName");
	var local = document.getElementById("local");
	var address = document.getElementById("address1");
	var city = document.getElementById("city");
	var postalCode = document.getElementById("postalCode");
	var homePh = document.getElementById("homePh");
	var email = document.getElementById("email");
	
	if (trimString(fname.value).length == 0)
	{
		alert("Please provide your first name.");
		fname.focus();
		return;
	}
	else if ((trimString(lname.value).length == 0)) 
	{
		alert("Please provide your last name.");
		lname.focus();
		return;
	}
	else if (trimString(local.value).length == 0)
	{
		alert("Please provide your union local.");
		local.focus();
		return;
	}
	else if (trimString(address.value).length == 0)
	{
		alert("Please provide your address.");
		address.focus();
		return;
	}
	else if (trimString(city.value).length == 0)
	{
		alert("Please provide your city.");
		city.focus();
		return;
	}
	else if (trimString(postalCode.value).length == 0)
	{
		alert("Please provide your postal code.");
		postalCode.focus();
		return;
	}
	else if (trimString(homePh.value).length == 0)
	{
		alert("Please provide your home phone number.");
		homePh.focus();
		return;
	}	
	
	if (trimString(email.value).length > 0)
	{
		if (!IsValidEmail(email.value))
		{
			alert("Please provide a valid email address.");
			email.focus();
			return;
		}
	}
		
	frm.submit();
}

// AUTHOR:			Melissa Whalen
// DATE:			Jan. 4, 2007
// DESCRIPTION:		Validates Forgot Password email field for content.
// PARAMETERS:		1. frm = reference to the user profile form.
//					
// RETURNS:			<none>, submits the specified form if the specified text fields contain data.

function ValidateForgotPassword(frm)
{

	var email = document.getElementById("email");

	if ((trimString(email.value).length == 0) || (!IsValidEmail(email.value)))
	{
		alert("You must provide a valid E-mail address.");
		email.focus();
		return;
	}

	frm.submit();
}

// AUTHOR:			Scott MacDonald
// DATE:			Oct. 22, 2003
// DESCRIPTION:		Forwards the page to the given URL.
// PARAMETERS:		1. strURL = URL to forward to.
// RETURNS:			<none>, loads the URL passed in
function GotoURL(strURL)
{
	window.document.location = strURL
}


// AUTHOR:			Scott MacDonald
// DATE:			Jan 19, 2004
// DESCRIPTION:		Submits a workflow step request. Some fields from the form are set in the 
//					page itself using onchange or onblur.
// PARAMETERS:		frm - the form being submitted
//					CurrentOwnerId - the ID of the current content owner
//					CurrentOwnerIdHidden - the hidden field to set in the post collection
//					WFStepId - the workflow step id (review request, etc)
//					WFStepIdHidden - the hidden field...
//					LiveContentId - the id of the live content id
//					LiveContentIdHidden - the hidden field...
//					ReplacementContentId - the replacement content id
//					ReplacementContentIdHidden - the hidden field...
// RETURNS:			<none> submits the form
function WFStepSubmit( frm, 
	CurrentOwnerId, CurrentOwnerIdHidden, 
	WFStepId, WFStepIdHidden,	
	LiveContentId, LiveContentIdHidden, 
	ReplacementContentId, ReplacementContentIdHidden )
{
	// assign the values to the hidden fields
	CurrentOwnerIdHidden.value = CurrentOwnerId;
	WFStepIdHidden.value = WFStepId;
	LiveContentIdHidden.value =  LiveContentId;
	ReplacementContentIdHidden.value = ReplacementContentId;
	
	// submit the form
	frm.submit();
}  

function setSizeDiv(typelist) 
{
	switch( typelist[typelist.selectedIndex].value ) {
		case '2': case '3': case '5': case '6':
			setIdProperty( "sizeDiv", "display", "inline" );
			break; 
		default:
			setIdProperty( "sizeDiv", "display", "none" );
			break;
	} 
	return;
}

/*
 *
 * Given an id and a property (as strings), set
 * the given property of that id to the value provided.
 *
 * The property is set directly on the tag, not in the
 * stylesheet.
 *
 */
function setIdProperty( id, property, value )
{
    if (isNav6)
    {
	    
	alert( "isNav6" );
	    
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
    }
    else if (isNav4)
    {
    	alert( "isNav4" );
        document[id][property] = value;
    }
    else if (isIE4)
    {
    	alert( "isIE4" );
        document.all[id].style[property] = value;
    }
    else
    {
       	
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
		styleObject = styleObject.style;
	        styleObject[ property ] = value;
        }
    }
}