
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
// 03/02/2010 Ciaran Moran
// The Affinity cookies were not working as they were being set with a path of /affinity/ 
// which did not then work site wide.
// What we need to do to fix this is to specify the cookie path as being "/". This makes the cookie 
// valid site wide.
//    document.cookie=c_name+ "=" +escape(value)+
//    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
	(";path=" +escape("/"));
}

function checkCookie(formName)
{
    var cookieVal = getTheMReference('mName');     
    if(cookieVal==""){      
        cookieVal=getCookie('mData');             
    }
else {
		setCookie('mData',cookieVal,365);  
	}

	// May be more than one form on a page which has the mRef hidden field
	if (document.getElementById(formName) != null){
		document.forms[formName].mRef.value=cookieVal;
	}
	else {
		document.getElementById('mRef').value=cookieVal;
}
	}

function checkForCookie(){
	// This function is included in a lot of body onload's throughout the web content 
	// The functionality that was in it is no longer needed but including here pending cleanup of all the pages
}

function getTheMReference( name ){  
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
    var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp( regexS );  
    var results = regex.exec( window.location.href );  
    if( results == null )    
    return "";  
    else    
    return results[1];
}
