//--------------------------------------------------------------------------------------------------------------------
// Author:	N/A
// Date:	N/A
// Purpose:	Javascript handler page for editing user properties
//--------------------------------------------------------------------------------------------------------------------
// REVISIONS
//
// #			Date		Developer		Reason
//--------------------------------------------------------------------------------------------------------------------
// 10.0.0.1		12/1/2006	MJR				Photo selection support/uploading as well
// 10.0.0.2		12/19/2006	MJR				Ability to clear the image
//--------------------------------------------------------------------------------------------------------------------
	
var requiredArr = new Array();
var selectedResourceArr = new Array();
var g_imageURLPath = "";

/*--------------------------------------------------------------------------------
 Page Specific Functions
--------------------------------------------------------------------------------*/
function showClearImageLink (bVisible)	// 10.0.0.2
{
	document.getElementById("clearImageLink").style.display = (bVisible ? "inline" : "none");
}

function clearImage () // 10.0.0.2
{
	if (confirm("Are you sure you want to clear your photo?"))
	{
		document.forms.detailsform.photoID.value = "";
		document.getElementById("userPhoto").src = "/images/nophotoimage.gif";
		showClearImageLink(false);
	}
}

function addPhoto_onClick (sessionID, imageURLPath)	// 10.0.0.1
{
	g_imageURLPath = imageURLPath;
	openexternalwindow("/comCenter/popup/comCenter_uploading.asp?sessionid=" + sessionID + "&imgonly=1", "uploadPhotoPopup",
		500, 500);
}

function setAttachmentIDs(imageIDs, fileNames) 
{    
	//window.alert(fileNames);
	if (imageIDs != null)
	{
		if (imageIDs > 0)
		{
			document.forms.detailsform.photoID.value = imageIDs;
			document.getElementById("userPhoto").src = g_imageURLPath + fileNames;
			showClearImageLink(true);
		}
	}
	//document.forms.detailsform.submit();
}

function submitForm(frm)  
{     	  
	var invalidSections = "";
	var cFMinLenghtValidation = true;
	var strInvalidMinLenghtDetail = '';
	
	invalidSections += (validateSection(frm,"userInfo") ? "" : "User Information, ");	
	
	//if (!ValidateUserDetails()) return false;
	
	for(var i=0; i<document.detailsform.length-1; i++){
	    for(var j=0; j<minLenArray.length; j++){	    	        
	         if(document.detailsform.elements[i].name == minLenArray[j][0] && document.detailsform.elements[i].value.length > 0 && document.detailsform.elements[i].value.length < parseInt(minLenArray[j][1])){	            
	            strInvalidMinLenghtDetail += minLenArray[j][2] + ' (' + minLenArray[j][1] + ' Characters)' + '<BR>';
                cFMinLenghtValidation = false;
	         }				    				    	        
	    }    
	}	
		
	if(cFMinLenghtValidation){			   
        if (document.getElementById('minFieldErrorMsg') != undefined)                    
	        document.getElementById('minFieldErrorMsg').style.display = 'none';		   
	    return evalSubmission(frm,invalidSections);	    		     
	 }else{	
	    document.getElementById('minFieldErrorMsg').style.display = 'block';	    
	    document.getElementById('minFieldErrorMsg').innerHTML = 'Minimum field requirement not met:<BR>' + strInvalidMinLenghtDetail;
	    return 0;
	 }	
}

function sectionErrors(frm,sectionID) 
{
	var errorStr = "";
	var blankErr = "";
	var invalidErr = "";

	switch (sectionID) {
		case "userInfo" :
			for (var index = 0; index < requiredArr.length; index++) {
				blankErr += checkBlankField(requiredArr[index][1],frm[requiredArr[index][0]]);
			}
			
			if (frm.UserName) {
			    blankErr += checkBlankField("Username", frm.UserName);
			    var tempStr = checkValidFieldSize("Username must be between " + intUserNameMinLength + ' and ' + intUserNameMaxLength + ' characters', frm.UserName, intUserNameMinLength, intUserNameMaxLength);
			    if (tempStr == "") tempStr = checkValidRegExp("Username " + strUserNamesAllowedPrompt, frm.UserName,"[^"+strUserNameAllowedCharacters+"]"); //shouldn't be allowed to type in invalid characters.  This is an extra check
			    invalidErr += tempStr;
			}
			break;
	}
	
	return evalErrors(blankErr,invalidErr);
}

//9.3.1
//Function to validate Username on OnBlur event.
function isValidUserName(obj, msg)
{
	if (obj.value.indexOf('\'') != -1)
	{
		alert(msg); 
		obj.focus();
	}
}