//************************************************************************************
//File:		/NR/System/WBC/PopUp/Cross-Browser/ResourceBrowser/Management/ResourceProperties.js
//Author:	Microsoft Corporation.
//Purpose:	Display functions used for resource properties saving
//
//*************************************************************************************

var g_strResName;
var g_strResDispName;
var g_strResDesc;
var g_pPropertiesForm;
var g_bCanSetProperties;

// ---- [Public] This function initialize the default value for detecting update changes
function WBC_onLoadHandler(bCanSetProperties) {

//	Initialize variables
	g_bCanSetProperties = bCanSetProperties;
	g_pPropertiesForm = window.document.NC_PropertiesForm;

//	If user can set properties
	if (g_bCanSetProperties) {
	
		//	Store original page properties values
		g_strResName = g_pPropertiesForm.NC_intxtName.value;
		g_strResDispName = g_pPropertiesForm.NC_intxtDisplayName.value;
		g_strResDesc = g_pPropertiesForm.NC_intxtDescription.value;
	}
	
}

	
// ---- [Public] This function chk for properties form data validation
//               If OK, form will submit and data will be written to the db
function WBC_onOkayHandler(strActionURL) {

	if ((!g_bCanSetProperties)  ||
	    ((g_strResName == g_pPropertiesForm.NC_intxtName.value) && (g_strResDispName == g_pPropertiesForm.NC_intxtDisplayName.value) &&
		(g_strResDesc == g_pPropertiesForm.NC_intxtDescription.value)))
	{
		window.close();
		return;
	}
		 
	if (!WBC_validateProperties()){
		return;
	}

	g_pPropertiesForm.action = strActionURL;
	g_pPropertiesForm.submit();
	
}
	




// ---- [Private] This function verifies the display text property of an attachment
function WBC_verifyResDispText(strDispText) {
	
	return strDispText;

}


// ---- [Public] This function validates resource and its properties.  Use when no file uploading is required
function WBC_validateProperties() {


	if (WBC_verifyResDispText(document.NC_PropertiesForm.NC_intxtDisplayName.value) == null) 
	{
			alert(IDS_INVALID_DISP_TEXT);
			return false;
	}
	
	var strName;
	strName = g_pPropertiesForm.NC_intxtName;
	
	if (!WBC_verifyInputName(strName))
	{
			alert(IDS_INVALID_NAME);
			return false;
	}
	return true;

}


// ---- [Public] This function validates resource and its properties.  Use by Add/Replace new resource
//               
function WBC_validateResource(bValidateDisplayText) {

	if (bValidateDisplayText) {
		if (WBC_verifyResDispText(document.NC_LocalForm.NC_intxtDisplayName.value) == null) {
			alert(IDS_INVALID_DISP_TEXT);
			return false;
		}
	}
	return WBC_validateLocalPath(IDS_RESTYPE_ATTACHMENT);
}