// Clientside JavaScript methods for InsideAnderson.com

//////////////////////////////////////////////
// CCH
// 04/03/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function validateAddEditUserForm(objForm)
{
	
	//Check First Name
	if (Trim(objForm.FirstName.value) == "")
	{
		alert("A valid First Name is required.");
		objForm.FirstName.focus();
		return false;
	}
	//Check Last Name
	if (Trim(objForm.LastName.value) == "")
	{
		alert("A valid Last Name is required.");
		objForm.LastName.focus();
		return false;
	}
	//Check UserName (aka Email) for valid email address format (a@b.c)
	if (!isEmail(Trim(objForm.Username.value)))
	{
		alert("A valid Email Address is required.");
		objForm.Username.focus();
		return false;
	}	
	//Check Password
	if (Trim(objForm.Password.value) == "")
	{
		alert("A valid Password is required.");
		objForm.Password.focus();
		return false;
	}
	//Check that Password is at least 6 characters
	if (Trim(objForm.Password.value).length < 6)
	{
		alert("For security purposes, the Password must be at least 6 characters in length.");
		objForm.Password.focus();
		objForm.Password.select();
		return false;
	}
	//Check that Password = Confirm Password
	if (Trim(objForm.Password.value) != Trim(objForm.ConfirmPassword.value))
	{
		alert("The passwords do not appear to match, please re-confirm your password.");
		objForm.ConfirmPassword.focus();
		objForm.ConfirmPassword.select();
		return false;
	}
	
	//Check Group selection and alert if no group and not admin
	var intIndex = objForm.Group.selectedIndex;
	if (Trim(objForm.Group.options[intIndex].value) == "" && !objForm.Admin.checked)
	{
		alert("You have not specified a group for this user and this user is not an Admin.  This combination will not allow the user to login.\n\nOnly administrators are allowed to not have a specific group.");
		objForm.Group.focus();
		return false;
	}
	
	//Verify Inside Anderson Administrator
	if (objForm.Admin.checked)
	{
		if (!confirm("You have chosen to make this user a website administrator for InsideAnderson.com.\n\nClick 'OK' to proceed, or 'Cancel' to go back."))
		{
			objForm.Admin.focus()
			return false;
		}
	}
	//Verify Inactive
	if (!objForm.Active.checked)
	{
		if (!confirm("You have chosen to Inactivate this user which will prevent them from using InsideAnderson.com.\n\nClick 'OK' to proceed, or 'Cancel' to go back."))
		{
			objForm.Active.focus()
			return false;
		}
	}
	
	return true;
}

//////////////////////////////////////////////
// CCH
// © 2004 NetOvation, LLC
//////////////////////////////////////////////

function Trim(rsString) 
{
	var lobjLeftSpacesRE = /^\s+/;
	var lobjRightSpacesRE = /\s+$/;

	rsString = rsString.replace(lobjLeftSpacesRE, '');
	rsString = rsString.replace(lobjRightSpacesRE, '');

	return rsString;
}


//////////////////////////////////////////////
// CCH
// 06/29/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function isEmail (strEmail)
{   
	if (strEmail == "") 
		return false;  
    
    // There must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = strEmail.length;

    // look for @
    while ((i < sLength) && (strEmail.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (strEmail.charAt(i) != "@")) 
		return false;
    else 
		i += 2;

    // look for .
    while ((i < sLength) && (strEmail.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (strEmail.charAt(i) != ".")) 
		return false;
    else 
		return true;
}

//////////////////////////////////////////////
// CCH
// 04/03/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function confirmDeleteUser(intUserID, strUserInfo)
{	
	if (confirm("Are you sure you wish to delete user " + strUserInfo + "?\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = "deleteuser.asp?UserID=" + intUserID + "&UserInfo=" + strUserInfo;
}


//////////////////////////////////////////////
// CCH
// 04/03/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function confirmDeleteGroup(intGroupID, strGroupName)
{	
	if (confirm("Are you sure you wish to delete group " + strGroupName + "?\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = "deletegroup.asp?GroupID=" + intGroupID + "&GroupName=" + strGroupName;
}

//////////////////////////////////////////////
// CCH
// 07/07/04
// © 2004 NetOvation, LLC
//////////////////////////////////////////////
function textCounter(field, maxlimit) 
{
	if (field.value.length > maxlimit) //if the string has reached the maxlength, then lets trim it
		field.value = field.value.substring(0, maxlimit);
}


//////////////////////////////////////////////
// CCH
// 04/03/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function validateAddEditGroupForm(objForm)
{
	
	//Check Group Name
	if (Trim(objForm.Name.value) == "")
	{
		alert("A valid Group Name is required.");
		objForm.Name.focus();
		return false;
	}
	
	//Check Group Description
	if (Trim(objForm.Desc.value) == "")
	{
		alert("A valid Group Description is required.");
		objForm.Desc.focus();
		return false;
	}
	
	//Check Group Web Folder
	if (Trim(objForm.WebFolder.value) == "")
	{
		alert("A valid Web Folder is required.");
		objForm.WebFolder.focus();
		return false;
	}
	
	return true;
}


//////////////////////////////////////////////
// CCH
// 05/11/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function disablePressRoomFields(strType)
{
	if (strType == "Internal")
	{
		document.frmAddArticle.Title.disabled = false;
		document.frmAddArticle.Subtitle.disabled = false;
		document.frmAddArticle.Body.disabled = false;
		document.frmAddArticle.ExternalURL.disabled = true;
		
		document.frmAddArticle.Title.className = "InputText";
		document.frmAddArticle.Subtitle.className = "InputText"
		document.frmAddArticle.Body.className = "InputText"
		document.frmAddArticle.ExternalURL.className = "InputTextDisabled"
		
		document.frmAddArticle.ExternalURL.value = "";
		
		document.frmAddArticle.Title.focus();
	}
	else
	{
		document.frmAddArticle.Title.disabled = false;
		document.frmAddArticle.Subtitle.disabled = false;
		document.frmAddArticle.Body.disabled = true;
		document.frmAddArticle.ExternalURL.disabled = false;
		
		document.frmAddArticle.Title.className = "InputText";
		document.frmAddArticle.Subtitle.className = "InputText"
		document.frmAddArticle.Body.className = "InputTextDisabled"
		document.frmAddArticle.ExternalURL.className = "InputText"
		
		document.frmAddArticle.Body.value = "";
		
		document.frmAddArticle.Title.focus();
	}

}

//////////////////////////////////////////////
// CCH
// 05/11/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function confirmDeleteArticle(intPressRoomID, strTitle)
{	
	if (confirm("Are you sure you wish to delete the article:\n\n " + strTitle + "\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = "deletearticle.asp?PressRoomID=" + intPressRoomID + "&Title=" + strTitle;
}

//////////////////////////////////////////////
// CCH
// 05/11/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function confirmDeleteSearchLight(intSearchLightID, strTitle)
{	
	if (confirm("Are you sure you wish to delete the SearchLight:\n\n " + strTitle + "\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = "deletesearchlight.asp?SearchLightID=" + intSearchLightID + "&Title=" + strTitle;
}

//////////////////////////////////////////////
// CCH
// 05/12/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////

function validateAddEditArticleForm(objForm)
{
	
	//Check Title Name
	if (Trim(objForm.Title.value) == "")
	{
		alert("A valid Title is required.");
		objForm.Title.focus();
		return false;
	}
		
	//If INTERNAL ARTICLE
	if (objForm.ArticleType[0].checked)
	{		
		//Check Body
		if (Trim(objForm.Body.value) == "")
		{
			alert("A valid Body is required.");
			objForm.Body.focus();
			return false;
		}
	}
	else ////If EXTERNAL ARTICLE
	{		
		//Check ExtneralURL
		if (Trim(objForm.ExternalURL.value) == "")
		{
			alert("A valid External URL is required.");
			objForm.ExternalURL.focus();
			return false;
		}
	}
	
	return true;
}



//////////////////////////////////////////////
// CCH
// 05/15/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////
function confirmDeleteCurrentSearch(intCurrentSearchesID, strPosition)
{	
	if (confirm("Are you sure you wish to delete this current search for:\n\n " + strPosition + "\n\nTHIS ACTION CANNOT BE UNDONE!"))
		document.location.href = "deletecurrentsearch.asp?CurrentSearchesID=" + intCurrentSearchesID + "&Position=" + strPosition;
}

//////////////////////////////////////////////
// CCH
// 05/15/2006
// © 2006 NetOvation, LLC
//////////////////////////////////////////////

function validateAddEditCurrentSearch(objForm)
{
	
	//Check Position Name
	if (Trim(objForm.Position.value) == "")
	{
		alert("A valid Position is required.");
		objForm.Position.focus();
		return false;
	}
		
	//Check Client Description
	if (Trim(objForm.Description.value) == "")
	{
		alert("A valid Client Description is required.");
		objForm.Description.focus();
		return false;
	}
	
	//Check Industry selection
	var intIndex = objForm.Industry.selectedIndex;
	if (Trim(objForm.Industry.options[intIndex].value) == "")
	{
		alert("A valid Industry is required.");
		objForm.Industry.focus();
		return false;
	}
	
	return true;
}

