
function fGetValueFromResonseXml(xmlNode,ajaxRequest){

	return (ajaxRequest.responseXML.documentElement.getElementsByTagName(xmlNode)[0].childNodes[0].data);
}
 

 function isAuthenticated(ajaxRequest){
 
	  var userStatus = 'invalid';
	  if ( fGetValueFromResonseXml("failureCode",ajaxRequest) == 1 ){ 
			var pluckCookieValue = fGetValueFromResonseXml("atCookie",ajaxRequest);
			var erightsCookieVal = fGetValueFromResonseXml("erightsSessionID",ajaxRequest);
			var userIdCookieVal = fGetValueFromResonseXml("uid",ajaxRequest);

			if (!(""+erightsCookieVal == ""+null)){
				setCookie( erightsCookie, erightsCookieVal, cookieDomain, cookiePath, erightsCookieValidity);  	
				setCookie( userIdCookie , userIdCookieVal, cookieDomain, cookiePath, erightsCookieValidity);
				if (!(""+pluckCookieValue == ""+null)){
					setCookie( pluckCookie, pluckCookieValue, cookieDomain, cookiePath, atCookieValidity);
					userStatus = 'valid';
				}
				else{
					userStatus = 'genregOnly';
				}	  
			}
	  }
	  return userStatus;
 }
 
 function fGetDisplayName(ajaxRequest){
	 var displayName = '';
	 
	 var fName = fGetValueFromResonseXml("firstName",ajaxRequest);
	
	 var lName = fGetValueFromResonseXml("lastName",ajaxRequest);

	 if(!(""+fName == ""+null)){
		displayName+= fName; 
	 }
	 if(!(""+lName == ""+null)){
		displayName+= ' '+lName; 
	 }
	return displayName; 
 }
 
 function fGetValidationOutput(ajaxRequest){
	 var isValid = fGetValueFromResonseXml("failureCode",ajaxRequest);
	 
	 return isValid;
 }
 
 function fGetRegistrationOutput(ajaxRequest){
	 var isValid = fGetValueFromResonseXml("failureCode",ajaxRequest);
	 var message = fGetValueFromResonseXml("statusCode",ajaxRequest);
	 
	 return isValid;
 }
 
function setCookie(cookieName,cookieValue,cookieDomain,cookiePath,nDays) {

   var today = new Date();
   var expire = new Date();
   if ( nDays == null || nDays==0 )
   { 
        nDays=1;
   }
   expire.setTime(today.getTime() + 3600000*24*nDays);
   document.cookie = cookieName+"="+cookieValue
	                 + "; expires="+expire.toGMTString()
	                 + "; path="+cookiePath
	                 + "; domain="+cookieDomain;
}


function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return false;
	}
	if ( start == -1 ) return false;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


function fCommentLogout(){

	deleteCookie(erightsCookie,cookiePath,cookieDomain);
	deleteCookie(pluckCookie,cookiePath,cookieDomain);
	deleteCookie(userIdCookie,cookiePath,cookieDomain);
}
