function addonformsubmit()
{
	/*alert('go');
	var f = document.getElementsByTagName('form');
	f.onsubmit = function(){alert('help');}
	alert(f.onsubmit);
	*/
}
addonformsubmit();
function checkDOB(ddlDay, ddlMonth, ddlYear, isRequired){
	var day = document.getElementById(ddlDay);
	var month = document.getElementById(ddlMonth);
	var year = document.getElementById(ddlYear);
	var daySelected = SelectedValue(day);
	var monthSelected = SelectedValue(month);
	var yearSelected = SelectedValue(year);
	var noSelectionMade = (daySelected == '-' && monthSelected == '-' && yearSelected =='1900');
	var partSelectionMade = (daySelected == '-' || monthSelected == '-' || yearSelected =='1900');
	if(isRequired)
	{
		if(noSelectionMade)
		{
			/*DOB required and one not selected*/
			alert('You need to select a Date of Birth to continue.');
			return false;
		}
		else if(partSelectionMade)
		{
			alert('Incomplete Date of Birth: You need to select a Complete Date of Birth to continue.');
			return false;
		}
		else
		{
			return checkDaysInMonth(daySelected, monthSelected, yearSelected, "Date of Birth");
		}
	}
	else
	{
		if(noSelectionMade)
		{
			/*no DOB required and none selected*/
			return true;
		}
		else if(partSelectionMade)
		{
			alert('you have selected an incomplete Date of Birth.');
			return false;
		}
		else
		{
			return checkDaysInMonth(daySelected, monthSelected, yearSelected, "Date of Birth");
		}
	}
}
function SelectedValue(ddl){
	/* find if required value is same as selected value*/
	var selectedValue;
	for(i=0;i<ddl.length;i++)
	{
		if(ddl.options[i].selected)
		{
			selectedValue = ddl.options[i].value;
		}
	}
	return selectedValue;
}

function doUnload(){
	if(document.getElementById('isNav').value == 'false')
	{
		deleteCookie('ASP.NET_SessionId','/','');
	}
}

function setElementValue(pId, pValue)
{
	var element = document.getElementById(pId);
	element.value = pValue;
}

/* *** COOKIE CHECK FUNCTIONS START *** */
	function getCookie() {
		var strName = 'varCook';
		if (document.cookie.indexOf(strName) == -1) {
   			document.write('<span style="color: #f00; font: bold 8.5pt Verdana,sans-serif;">Sorry but you cannot use the MeOnTV Casting website unless cookies are accepted by your browser.\n\nRDF Media uses cookies primarily for authenticating members for entry to the Casting websites. This cookie allows access to the website without requiring re-entry of logins and passwords. At no time is any personal information stored in a cookie, nor is any information made available to others for any reason.</span>');
   			return false;
		} else {
		    var cookieStart = document.cookie.indexOf(strName);
		    var cookieValStart = (document.cookie.indexOf('=', cookieStart) + 1);
		    var cookieValEnd = document.cookie.indexOf(';', cookieStart);
		    if (cookieValEnd == -1) 	{cookieValEnd = document.cookie.length;	}
		    var cookieValue = document.cookie.substring(cookieValStart, cookieValEnd);
		}
		
		if (cookieValue == 'True') {return true;}
	}


	function setCookie(name, value, expires, path, domain, secure) {
		var strDNS = getDNS();
	    	document.cookie = name + '=' +escape(value) + ( (expires) ? ';expires=' + expires.toGMTString() + 1000*60*20 : '') + ( (path) ? ';path=' + path : '') + ( (domain) ? ';domain=' + strDNS : '') + ( (secure) ? ';secure' : '');
		    return true;
	}

	function deleteCookie(name, path, domain){
		{
			document.cookie = name + "=" +	( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) +	";expires=Thu, 01-Jan-1970 00:00:01 GMT";		
		}
	}


	function getDNS() {
		var cookieDomain = document.location.hostname;
	}

function IsCookiesEnabled() {			
    setCookie('varCook','True','','/','','');
    if (getCookie()){
        //alert('Cookies are enabled and you can properly use this website!');
    } else {		
        return false;	
    }	
    return true;	
}  
/* *** COOKIE CHECK FUNCTIONS END *** */

/* *** JAVASCRIPT CHECK FUNCTIONS START *** */
function IsJavaScriptEnabled() {
    if(document.getElementById('JSCheck')) {
        if(document.getElementById('JSCheck').value == 'true') {
            return true
        }
    }
    return false;
}
/* *** JAVASCRIPT CHECK FUNCTIONS END *** */

/* *** BROWSER CHECK FUNCTIONS START *** */
function IsBrowserEnabled() {
    // set hidden field value
    if(document.getElementById('JSCheck')) {
        document.getElementById('JSCheck').value = 'true';
    }
  
  /*  
    if(!IsCookiesEnabled()) {
        document.write('<span style="color: #f00; font: bold 8.5pt Verdana,sans-serif;"><p>Access Denied: Cookies Disabled</p></span>');
        return false;
    }
    */
    
    if(!IsJavaScriptEnabled()) {
        document.write('<span style="color: #f00; font: bold 8.5pt Verdana,sans-serif;"><p>Access Denied: Javascript Disabled</p></span>');
        return false;
    }
    
   // if(IsCookiesEnabled() && IsJavaScriptEnabled()) {return true;} 
    if(IsJavaScriptEnabled()) {return true;} 
    
    return false;
}
/* *** BROWSER CHECK FUNCTIONS END *** */

/* *** HELPER FUNCTIONS START *** */

function encodeURL(strIn) {
	var strOut = "";
	
	for(i = 0; i<strIn.length; i++) {
		if (strIn.charAt(i) == " ") strOut += "+";
		else strOut += strIn.charAt(i);
	}
	
	return escape(strOut);
}


function setElementValue(strId, strValue) {
    if(document.getElementById(strId)) {
	    document.getElementById(strId).value = strValue;
	}
}

function switchRowColour(obj) {
    var currColour = obj.style.backgroundColor;
    var defaultColour = 'white';
    var highlightColour = 'wheat';
    
    if(currColour.toLowerCase() == defaultColour) {
        obj.style.backgroundColor = highlightColour;
    } else {
        obj.style.backgroundColor = defaultColour;
    }
}

function switchIconColour(obj) {
    var currColour = obj.style.backgroundColor;
    var defaultColour = '#996600';
    var defaultColourRGB = 'rgb(153, 102, 0)'; // for Mozilla
    var highlightColour = 'Orange';
    
    if(currColour == '') {currColour = defaultColour;}
    
    if((currColour.toLowerCase() == defaultColour.toLowerCase()) || (currColour.toLowerCase() == defaultColourRGB.toLowerCase())) {
        obj.style.backgroundColor = highlightColour;
    } else {
        obj.style.backgroundColor = defaultColour;
    }
}

function switchLinkColour(obj) {
    if(obj) {
        var currColour = obj.style.color;
        var defaultColour = 'White';
        var defaultColourRGB = 'rgb(255, 255, 255)'; // for Mozilla
        var highlightColour = 'Orange';
        
        if(currColour == '') {currColour = defaultColour;}
        
        if((currColour.toLowerCase() == defaultColour.toLowerCase()) || (currColour.toLowerCase() == defaultColourRGB.toLowerCase())) {
            obj.style.color = highlightColour;
        } else {
            obj.style.color = defaultColour;
        }
    }
}

//Capitalise the first letter of each word
function titleCaps(obj) {
    var strIn = Trim(obj.value).toLowerCase();
    strIn = strIn.replace(' - ', '-');
    var strOut = '';
    
    if (strIn.length > 0) {
    
        // create an array, delimited by line breaks		
		var arrLines = new Array();
		
		// create an array, delimited by spaces		
		var arrInLine = new Array();
		
		// create an array, delimited by hyphen
		var arrWords = new Array();
		
		arrLines = strIn.split('\n');	
		var strTmpLine = '';
		
		for(var k = 0; k < arrLines.length; k++) {

		    strIn = arrLines[k];
		    arrInLine = strIn.split(' ');	
		    strOut = '';
		    var strTmp = '';
		    var strTmpInner = '';
		    var strTmpState = '';		    
    			
		    for(var i = 0; i < arrInLine.length; i++) {
			    strTmp = '';
			    // remove double spaces
			    if(arrInLine[i].length > 0) {
    				
				    // This might be a hyphenated name
				    arrWords = arrInLine[i].split('-');	
    							
				    for(var j = 0; j < arrWords.length; j++) {
					    // if this is a special case (Mc, Mac, *'*, *-*)
					    if(arrWords[j].substring(0,2).toUpperCase() == 'MC') {
						    strTmp = arrWords[j].substring(0,2).toLowerCase() + arrWords[j].substring(2,3).toUpperCase() + arrWords[j].substring(3,arrWords[j].length) + ' ';
						    // capitalise like mcCartney
					    } else if (arrWords[j].substring(0,3).toUpperCase() == 'MAC') {
						    // capitalise like macIntyre
						    strTmp = arrWords[j].substring(0,3).toLowerCase() + arrWords[j].substring(3,4).toUpperCase() + arrWords[j].substring(4,arrWords[j].length) + ' ';
					    } else if (arrWords[j].substring(1,2) == '\'') {
						    // capitalise like o'Toole
						    strTmp = arrWords[j].substring(0,1).toLowerCase() + arrWords[j].substring(1,2) + arrWords[j].substring(2,3).toUpperCase() + arrWords[j].substring(3,arrWords[j].length) + ' ';					
					    } else {
						    strTmp = arrWords[j];
					    }
    					
					    // capitalise first letter
					    strTmp = strTmp.substring(0,1).toUpperCase() + strTmp.substring(1,arrInLine[i].length);

					    // update array
					    arrWords.splice(j, 1, strTmp);
					    strTmpState = strTmp;
					    strTmp = '';
				    }	
    				
				    // re-compile hyphenated names
				    if(arrWords.length > 1) {
					    for(j = 0; j < arrWords.length; j++) {
						    if(j < arrWords.length-1) {
							    strTmp += arrWords[j] + '-';
						    } else {
							    strTmp += arrWords[j];
						    }
					    }
					    // clear non-hyphenated text
					    strTmpState = '';
				    }
    						
				    if(i < arrInLine.length-1)	{
					    strOut += strTmp + strTmpState + ' ';
				    } else {
					    strOut += strTmp + strTmpState;
				    }
			    }			    
		    }
		    strTmpLine += strOut+'\n';
		}
        obj.value = strTmpLine;
    } 
    return true;
}

// TRIM FUNCTIONS START
function Trim(strIn, intNoise) {
    if(strIn.length < 1) {
        return '';
    }
    
    strIn = rightTrim(strIn);
    strIn = leftTrim(strIn);
    strIn = multiTrim(strIn);
    strIn = commaCancel(strIn);
    switch (intNoise)
    {
	case 1: //this is for the interview
		strIn = noiseCancel(strIn);
	case 2://this is for the first name noise words remain cancel and final s not removed
		break;
	case 3://this is for the surname, final s is removed before doing search
	if (strIn.length > 0){
			strIn = takeOffFinalS(strIn);
		}
	}
    strIn = rightTrim(strIn);
    
    if(strIn == '') {
        return '';
    } else {
        return strIn;
    }
}
/*
// get rid of noise words. Called from function trim
*/
function trim(stringToTrim){
	stringToTrim = stringToTrim.replace(/^\s+|\s+$/g,'');
	return stringToTrim;
}

function trimDoubleSpace(stringToTrim){
	stringToTrim = stringToTrim.replace(/\s{2,} /g, ' ');
	return stringToTrim;
}

function checkValidPostCode(postcode){
	var fullPostCodePattern = new RegExp("^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$");
	var areaCodePattern = new RegExp("^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]?$");
	var isValid = (fullPostCodePattern.test(postcode) || areaCodePattern.test(postcode));
	if(!isValid){alert('the postcode entered does not seem to be a valid UK Postcode. Type in either the first part or the whole of your postcode with a space between the two parts.');}
	return postcode;
}
function noiseCancel(strIn) {

	strIn = strIn.toLowerCase();
	var blnFlag = false;
	var strOut = '';
	var arrInLine = strIn.split(' ');
	var arrClean = new Array(1);
	var arrNoise = new Array('about', '1', 'after', '2', 'all', 'also', '3', 'an', '4', 'and', '5', 'another', '6', 'any', '7', 'are', '8', 'as', '9', 'at', '0', 'be', '$', 'because', 'been', 'before', 'being', 'between', 'both', 'but', 'by', 'came', 'can', 'come', 'could', 'did', 'do', 'does', 'each', 'else', 'for', 'from', 'get', 'got', 'has', 'had', 'he', 'have', 'her', 'here', 'him', 'himself', 'his', 'how', 'if', 'in', 'into', 'is', 'it', 'its', 'just', 'like', 'make', 'many', 'me', 'might', 'more', 'most', 'much', 'must', 'my', 'never', 'now', 'of', 'on', 'only', 'or', 'other', 'our', 'out', 'over', 're', 'said', 'same', 'see', 'should', 'since', 'so', 'some', 'still', 'such', 'take', 'than', 'that', 'the', 'their', 'them', 'then', 'there', 'these', 'they', 'this', 'those', 'through', 'to', 'too', 'under', 'up', 'use', 'very', 'want', 'was', 'way', 'we', 'well', 'were', 'what', 'when', 'where', 'which', 'while', 'who', 'will', 'with', 'would', 'you', 'your', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
	arrInLine.reverse(); // reverse array because when put into arrClean, goes in "backwards"
	while(arrInLine.length >0){

		for(var j=0; j<arrNoise.length; j++){
			if (arrInLine[0].toString() == arrNoise[j].toString()){
				blnFlag = true;
			}
		}
			if (blnFlag == false){
				arrClean.splice(0,0, arrInLine[0]);
			}
			blnFlag = false;
			arrInLine.splice(0,1);
	}
	strOut = arrClean.join(' ');

	return strOut;
}
function takeOffFinalS(strIn)//takes off final s off a string. Used for the surname in the search page
{
	var intLastLetter = strIn.length - 1;
	var intPenultimate = intLastLetter;

	if (strIn.charAt(intLastLetter) == 's'){
	strIn = strIn.substring(0,intPenultimate);
}
return strIn;
}

function commaCancel(strIn){
	while (strIn.search(/,/) != -1){
		strIn = strIn.replace(/,/,"");
	}
	return strIn; 
}
    
function rightTrim(strIn){
    var spaceChar = String.fromCharCode(32);
    var intStringLength = strIn.length;
    var strOut = '';
    
    if(intStringLength < 0){
        return '';
    }
    
    var i = intStringLength - 1;
    
    while(i > -1){
        if(strIn.charAt(i) != spaceChar) {
            strOut = strIn.substring(0, i +1);
            break;
        }
        i--;
    } 
    return strOut;
}
 

function leftTrim(strIn){
    var spaceChar = String.fromCharCode(32);
    var intStringLength = strIn.length;
    var strOut = '';
    
    if(intStringLength < 1) {
        return '';
    }    
    
    var i = 0;
    
    while(i < intStringLength) {
        if(strIn.charAt(i) != spaceChar){
            strOut = strIn.substring(i,intStringLength);
            break;
        }        
        i++;
    } 
    return strOut;
} 

// This function removes sequences of multiple spaces
function multiTrim(strIn) {
	var strOut = '';
	var arrInLine = strIn.split(' ');
	
	if(arrInLine.length > 1) {
		for(var i=0; i < arrInLine.length; i++) {
			if(arrInLine[i].length > 0) {
				if(i < arrInLine.length -1) {
					strOut += arrInLine[i] + ' ';
				} else {
					strOut += arrInLine[i];
				}
			}
		}
	} else {
		strOut = strIn;
	}
	
	return strOut;
}
// TRIM FUNCTIONS END

//put Postcodes into upper case
function allUpper(str) {
	str = str.toUpperCase();
	return str;
}

//put Email addresses into lower case
function allLower(obj) {
	obj.value = Trim(obj.value.toLowerCase());
}

function stripTags() {
	//replaces < and > with &lt; and &gt; for any input in text boxes.
	//however, this isn't needed - better to use Server.htmlencode() to do this job server side
    for(var i=0;i<document.forms[0].elements.length;i++) {
        if (document.forms[0].elements[i].type) {
            if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "textarea") {
                    if (document.forms[0].elements[i].value.indexOf("<") >= 0) {
                        do {
                            document.forms[0][i].value = document.forms[0].elements[i].value.replace("<","&lt;")
                        }
                        while (document.forms[0].elements[i].value.indexOf("<") >= 0); 
                    }
                    
                    if (document.forms[0].elements[i].value.indexOf(">") >= 0) {     
                        do {
                            document.forms[0][i].value = document.forms[0].elements[i].value.replace(">","&gt;")
                        }
                        while (document.forms[0].elements[i].value.indexOf(">") >= 0);
                    }
            }
        }
    }
}

/* *** HELPER FUNCTIONS END *** */

/* *** VALIDATION FUNCTIONS START *** */

function promptFinish() {
    if(!confirm('Clicking on the \'OK\' button means that you are happy with your application and do not want to add or change anything in it.\n\nIf you want to go back to your application now to change something click \'Cancel\'.\n\nIf you want to submit your finished application to us click \'OK\'.\n')) {
        return false;
    } else {
        return true;
    }
    return true;
}

function validateAge(obj) {

    if(obj.value.length > 0) {
        if(obj.value > 150) {
            alert('Ages cannot be greater than 150 years!');
            obj.focus();
            obj.select();
            return false;
        }
        
        if(obj.value < 0) {
            alert('Ages cannot be less than 0 years!');
            obj.focus();
            obj.select();
            return false;
        }
    } else {
        //alert('Please enter your age');
        obj.focus();
        obj.select();
        return false;
    }
    
    return true
}

/*
	This function validates Date form fields
*/
function validateDate(obj) {
	
	if(obj) {
	
	    if(obj.value.length <= 0 || obj.value == '') { // if there is no input
	        //alert('Please enter your date of birth.');		
		    obj.focus();
		    obj.select();
		    return false;
	    }
	    
	    // Declare valid date regular expression
	    var regEx = /\b(0?[1-9]|[12][0-9]|3[01])\/(1[0-2]|0?[1-9])\/\d\d\d\d$/;
    	
	    // Declare variables for the current date, year and month
	    var now = new Date();
	    var thisYear = now.getYear();
	    if(thisYear < 2000) {thisYear = thisYear + 1900;}
	    var thisMonth = now.getMonth()+1;
	    var thisDay = now.getDate();
	    var blnIsFuture = false;
	    var minYear = thisYear - 150;
	    var dateArr = obj.value.split('/');
	    var inputDay = dateArr[0];
	    if(inputDay.indexOf('0') == 0) {inputDay = inputDay.substring(1)};
	    var inputMonth = dateArr[1]; 
	    if(inputMonth.indexOf('0') == 0) {inputMonth = inputMonth.substring(1)};
	    var inputYear = dateArr[2]; 
	    var strDay = thisDay.toString();
	    var strMonth = thisMonth.toString();
	    if(strDay.length == 1) {strDay = '0'+strDay}
	    if(strMonth.length == 1) {strMonth = '0'+strMonth}
	    var strToday = strDay+'/'+strMonth+'/'+thisYear.toString();

	    if(!regEx.test(obj.value)) {
		    alert('The date must be in the format \'dd/mm/yyyy\'\nPlease re-enter the date.');	
		    obj.focus();
		    obj.select();
		    return false;
	    }	

	    if(parseInt(inputYear) > parseInt(thisYear)) {
		    blnIsFuture = true;		
	    } else {
		    if(parseInt(inputYear) == parseInt(thisYear) && parseInt(inputMonth) > parseInt(thisMonth)){
			    blnIsFuture = true;			
		    } else {
			    if(parseInt(inputYear) == parseInt(thisYear) && parseInt(inputMonth) == parseInt(thisMonth) && parseInt(inputDay) > parseInt(thisDay)) {
				    blnIsFuture = true;				
			    }
		    }
	    }
    	
	    if(blnIsFuture) {
		    alert('The date cannot be later than today!\nPlease re-enter the date.');		
		    obj.focus();
		    obj.select();
		    return false;
	    }
    	
	    if(parseInt(inputYear) <= parseInt(minYear)) {
		    alert('The date cannot be more than 150 years in the past!\nPlease re-enter the date.');		
		    obj.focus();
		    obj.select();
		    return false;
	    }
	    
	    switch(parseInt(inputMonth)) {
	        case 9:
	        case 4:
	        case 6:
	        case 11:
	            if(parseInt(inputDay) > 30) {
	                alert('This month only has 30 days!\nPlease try again.');
	                obj.focus();
		            obj.select();
	                return false;
	            }
	            break;
	        case 2:
	            if((parseInt(inputYear)%4 == 0 && (parseInt(inputYear)%100 != 0)) || (parseInt(inputYear)%400 == 0)) {
	                if(parseInt(inputDay) > 29) {
	                    alert('This month only has 29 days!\nPlease try again.');
                        obj.focus();
                        obj.select();
	                    return false;
	                }
	            } else {
	                if(parseInt(inputDay) > 28) {
	                    alert('This month only has 28 days!\nPlease try again.');
                        obj.focus();
                        obj.select();
	                    return false;
	                }
	            }
	            break;
	    }
	    
	    return true;
	} else {
	    return false;
	}
}

// Check that the minimum Contact Details have been entered
function validateContactDetails() {
	if(document.getElementById('_ctl0_txtContactName') && document.getElementById('_ctl0_txtContactSurname')) {
	
		if(document.getElementById('_ctl0_txtContactName').value == ''){			
			alert('Please enter your first Name');
			document.getElementById('_ctl0_txtContactName').focus();
			return false;
		}
		
		if(document.getElementById('_ctl0_txtContactSurname').value == ''){			
			alert('Please enter your Surname');
			document.getElementById('_ctl0_txtContactSurname').focus();
			return false;
		}
		
		if(document.getElementById('_ctl0_txtPhoneHome').value == '' && document.getElementById('_ctl0_txtPhoneMobile').value == '' && document.getElementById('_ctl0_txtPhoneWork').value == ''){			
			alert('Please enter at least one Phone Number');
			document.getElementById('_ctl0_txtPhoneHome').focus();
			return false;
		}

		if(document.getElementById('_ctl0_txtContactDoBYears').value == '0')
		{
			alert('You must input your age before continuing.');
			return false;
		}
	} else {
		return false;
	}	
	return true;
}

function validateEmail(obj) {
    // Declare valid email regular expression
	var regEx = /(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9\+\-\_]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}/;
	if(obj.value.length > 0) {
	    if(!regEx.test(obj.value)) {
		    alert('Sorry but your email address \''+obj.value+'\' is not in a valid format!\nA valid format should be something like \'username@domainname.com\' or \'firstname.surname@domainname.co.uk\'\nPlease re-enter your email address, making sure it contains no spaces.');	
		    obj.select();
		    return false;
	    }
	} else {
	    alert('Please enter your email address.');	
		obj.select();
	    return false;
	}
	return true;
}

/* *** VALIDATION FUNCTIONS END *** */


/**** IMAGE GALLERY FUNCTIONS START */

function highlightImage(obj) {
    // switch off any highlighted images (there are a maximum of 12)
    for(var i=1;i<=12;i++) {
        if(document.getElementById('_ctl0_img'+i)) {
            document.getElementById('_ctl0_img'+i).className = 'defaultImg';
        }
    }
    
    // highlight the selected image
    if(obj) {
        obj.className = 'highlightImg';
    }
}

function fullsizeImage(imageURL) {

    if (document.all && window.print) {//if ie5+ use a modal window
        window.showModalDialog(imageURL,'Argument #1','help:0;resizable:1;dialogWidth:1024px;dialogHeight:768px');
    } else {
        window.open(imageURL,'','status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=auto, height=768px, width=1024px');
    }

}

/**** IMAGE GALLERY FUNCTIONS END */