//###
//###Dec:			Javascript Lib for QuickPlace functions
//###File: 			Neo_QPToolLib.js
//###Ver: 			2.0
//###Resposible: 	mwa
//###
//###Use libs:		Neo_Ajax.js for some functions
//###
//###(c) Opus Neo 2006
//###


//@Disabled by MWA 2010-06-22 for confligt with Quickr buildind function
function xD_DatePickerHTML(fieldName) {
//Do not use this function - is only for support fo old function's call

	return neo_DatePicker(fieldName);
}

function neo_DatePicker(fieldName) {
 //alert('Neo_DatePicker()');
 /*
 #Promp a dialobox with a date calander#
 fieldName = the fieldname og the field to return the date to.
 */
 
 //Alt text
 var AltText = "Click to select a date"; 
 hr="javascript:fieldSetCalendarVal(self, \'" + fieldName + "\', theForm." + fieldName +".value, true)";
 om="window.status=\'" + AltText + "\'; return true;";
 mo="window.status=\' \'; return true;";
 if (getPageMode() == "e") {
   im='<img align="ABSMIDDLE" height="14" src="../../../$resources.nsf/h_ResourcesByName/calpopicon2.gif/$FILE/calpopicon2.gif?OpenElement" width="14" border="0" alt="' + AltText + '">';
   document.write('<a href="' + hr + '" onMouseOver="' + om + '" onMouseOut ="' + mo + '">' + im + '</a>');
 }
 return true; 
}

function getPlaceName() {
//Do not use this function - is only for support fo old function's call

	return neo_GetPlaceName();
}

function neo_GetPlaceName() {
 //alert('Neo_getPlaceName()');
 /*
 #Return the placename of the current place#
 */
 
 //Var
 var hs = "";
 var qp = "";
 var i = 0;
 
 //Get href
 hs = window.location.href;
  
 //Get placename
 qp = hs.toLowerCase();
 i = qp.indexOf("/quickplace/");
 qp = qp.substring(i + 12 ,qp.length);
 i = qp.indexOf("/");
 qp = qp.substring(0 ,i );
 
 //return placename
 return qp;

}

function neo_GetlocalGroupsForUser() {

	return neo_GetValueByAgent("../../GetLocalGroupsForUser?OpenAgent&username=" + escape(REMOTE_USER),"", "return",false);

}

function isMemberOfLocalGroup(groupName) {
//Do not use this function - is only for support fo old function's call
 
	return neo_IsMemberOfLocalGroup(groupName)
}
 
function neo_IsMemberOfLocalGroup(groupName,groupList) {
 //alert('Neo_isMemberOfLocalGroupV2()');
 /*
 #Return true if user is member of groupName#
 groupName = 	the groupName to test for if user is member of.
 groupList = 	text list of groups user is member of sep. by ",".
 				If not set it is set by the function Neo_GetlocalGroupsForUser
 */	

 	var groupS;
	var groupArray;
	
 	if ( typeof(groupList) == "undefined" || groupList == "") {
		groupS = neo_GetlocalGroupsForUser();
	} else {
		groupS = groupList;
	}
	
	var groupArray = groupS.split(",")
	
	 //loop thro all entryes in groupList
 	for (i=0 ; i < groupArray.length; i++) {
		if ( groupArray[i].toLowerCase() == groupName.toLowerCase() ) {
			//if groupName found in GroupList return true
			return true;
		}
	 }

 	return false;

}


function isMemberOfLocalGroup_Old_v1(groupName) {
 //alert('isMemberOfLocalGroup()');
 /*
 #Return true if user is member of groupName#
 groupName = the groupName to test for if user is member off.
 */
 
 //Var
 var longGroupName = "";
 var currentGroupName = "";
 var i = 0;
 var qpName = "";
 
 //get PlaceName
 qpName = getPlaceName();
 //alert('qpName=' + qpName);
  
 //set longGroupName
 longGroupName = "CN=" + groupName + "/OU=" + qpName + "/OU=QP";
 longGroupName = longGroupName.toLowerCase();
 //alert('longGroupName=' + longGroupName);
 
 if( (typeof(groupsForUser) == "undefined") ) {
    //if groupsForUser not defined return false
    return false;
 }
 
 //loop thro all entryes in groupsForUser
 for (i=0 ; i < groupsForUser.length; i++) {
    
	//set current group name
    currentGroupName = groupsForUser[i];
	currentGroupName = currentGroupName.toLowerCase();
	//alert('currentGroupName=' + currentGroupName);
	
    if (currentGroupName.indexOf(longGroupName) > -1 ) {
	    //if groupName found in GroupsForUser return true
		return true;
	}
 }
 
 return false;
 
}

