
	function limitText(limitField, limitCount, limitNum) {
		if (limitField.value.length > limitNum) {
			limitField.value = limitField.value.substring(0, limitNum);
		} else {
			limitCount.value = limitNum - limitField.value.length;
		}
	}

	function retain_reqired() {
		if (document.getElementsByName("v_trs_conf_contact_option").length > 0) {
			var oRadios = document.LOGIN.v_trs_conf_contact_option;
//alert(document.getElementsByName("v_trs_conf_contact_option").length);
			for (var r=0;r<oRadios.length;r++) {
				if (oRadios[r].checked) {
					if ((r == 2) || (r == 3)) {
						document.all.contact_email.innerHTML = '<b><font color="red">*</font>&nbsp;Email Address: <b>';
					}
				break;
				}
			}
		}
	}

/*
	function affiliateswitch_old(which,name) {

		document.getElementById('v_affiliate_option').value=which;
		document.getElementById('v_affiliate_name').value=name;

		switch(which) {
			case '1':
//alert(document.getElementById('checkinfo').style.display);
				document.getElementById('checkinfo').style.display='none';
				document.getElementById('v_check_option').value='1';
//alert(document.getElementById('checkinfo').style.display);
				break;
			case '2':
//alert(document.getElementById('checkinfo').style.display);
				document.getElementById('checkinfo').style.display='inline';
//alert(document.getElementById('checkinfo').style.display);
				break;
			case '3':
//alert(document.getElementById('checkinfo').style.display);
				document.getElementById('checkinfo').style.display='inline';
//alert(document.getElementById('checkinfo').style.display);
				break;
			case '9':
//alert(document.getElementById('checkinfo').style.display);
				document.getElementById('checkinfo').style.display='inline';
//alert(document.getElementById('checkinfo').style.display);
				break;
		}
	}
*/
	function affiliateswitch(which,name) {
	/*alert(document.getElementById('v_affiliate_option').value);*/

		document.getElementById('v_affiliate_option').value=which;
		document.getElementById('v_affiliate_name').value=name;

		switch(which) {
			case '1':
//alert(document.getElementById('affiliateinfo').style.display);
				document.getElementById('affiliateinfo').style.display='none';
//alert(document.getElementById('checkinfo').style.display);
				break;
			case '2':
//alert(document.getElementById('affiliateinfo').style.display);
				document.getElementById('affiliateinfo').style.display='inline';
//alert(document.getElementById('affiliateinfo').style.display);
				break;
			case '3':
//alert(document.getElementById('affiliateinfo').style.display);
				document.getElementById('affiliateinfo').style.display='inline';
//alert(document.getElementById('affiliateinfo').style.display);
				break;
			case '9':
//alert(document.getElementById('affiliateinfo').style.display);
				document.getElementById('affiliateinfo').style.display='inline';
//alert(document.getElementById('affiliateinfo').style.display);
				break;
		}
	}
	function checkinfoswitch(which) {
	/*alert(document.getElementById('v_check_option').value);*/

		document.getElementById('v_check_option').value=which;

		switch(which) {
			case '1':
				document.getElementById('v_check_name').disabled=true;
				break;
			case '9':
				document.getElementById('v_check_name').disabled=false;
				break;
		}
	}


	function fill_contact(which) {

	if (which == 1) {
/*
		document.LOGIN.v_trs_conf_contact_salutation.value = document.LOGIN.v_trs_contact_salutation.value;
		document.LOGIN.v_trs_conf_contact_title.value = document.LOGIN.v_trs_contact_title.value;
		document.LOGIN.v_trs_conf_contact_first_name.value = document.LOGIN.v_trs_contact_first_name.value;
		document.LOGIN.v_trs_conf_contact_last_name.value = document.LOGIN.v_trs_contact_last_name.value;
		document.LOGIN.v_trs_conf_contact_email.value = document.LOGIN.v_trs_contact_email.value;
		document.LOGIN.v_trs_conf_contact_phone.value = document.LOGIN.v_trs_phone.value;
		//document.all.fl_trs_conf_contact_email.innerHTML = "Email Address: "
*/
		document.getElementById("v_conf_contact_title").style.display="none";
		document.getElementById("v_conf_contact_name").style.display="none";
		document.getElementById("v_conf_contact_email").style.display="none";
		document.getElementById("v_conf_contact_phone").style.display="none";

		document.getElementById("v_trs_conf_contact_salutation").value = "";
		document.getElementById("v_trs_conf_contact_title").value = "";
		document.getElementById("v_trs_conf_contact_first_name").value = "";
		document.getElementById("v_trs_conf_contact_last_name").value = "";
		document.getElementById("v_trs_conf_contact_email").value = "";
		document.getElementById("v_trs_conf_contact_phone").value = "";
		}

	if (which == 2) {
/*
		document.LOGIN.v_trs_conf_contact_salutation.value = document.LOGIN.v_trs_other_contact_salutation.value;
		document.LOGIN.v_trs_conf_contact_title.value = document.LOGIN.v_trs_other_contact_title.value;
		document.LOGIN.v_trs_conf_contact_first_name.value = document.LOGIN.v_trs_other_contact_first_name.value;
		document.LOGIN.v_trs_conf_contact_last_name.value = document.LOGIN.v_trs_other_contact_last_name.value;
		document.LOGIN.v_trs_conf_contact_email.value = document.LOGIN.v_trs_other_contact_email.value;
		document.LOGIN.v_trs_conf_contact_phone.value = document.LOGIN.v_trs_other_contact_phone.value;
		//document.all.fl_trs_conf_contact_email.innerHTML = 'Email Address: ';
*/
		document.getElementById("v_conf_contact_title").style.display="none";
		document.getElementById("v_conf_contact_name").style.display="none";
		document.getElementById("v_conf_contact_email").style.display="none";
		document.getElementById("v_conf_contact_phone").style.display="none";

		document.getElementById("v_trs_conf_contact_salutation").value = "";
		document.getElementById("v_trs_conf_contact_title").value = "";
		document.getElementById("v_trs_conf_contact_first_name").value = "";
		document.getElementById("v_trs_conf_contact_last_name").value = "";
		document.getElementById("v_trs_conf_contact_email").value = "";
		document.getElementById("v_trs_conf_contact_phone").value = "";
		}
/*
	if (which == 3) {
		document.all.fl_trs_conf_contact_email.innerHTML = '<b><font color="red">*</font>&nbsp;Email Address: <b>';
		}
*/
	if (which == 4) {
//		alert(document.getElementById("conf_contact_title"));
/*
		alert(document.getElementById("v_conf_contact_title").style.display);
		alert(document.getElementById("v_conf_contact_name").style.display);
		alert(document.getElementById("v_conf_contact_email").style.display);
		alert(document.getElementById("v_conf_contact_phone").style.display);
*/
		document.getElementById("v_conf_contact_title").style.display="block";
		document.getElementById("v_conf_contact_name").style.display="block";
		document.getElementById("v_conf_contact_email").style.display="block";
		document.getElementById("v_conf_contact_phone").style.display="block";
/*
		document.LOGIN.v_trs_conf_contact_salutation.value = "";
		document.LOGIN.v_trs_conf_contact_title.value = "";
		document.LOGIN.v_trs_conf_contact_first_name.value = "";
		document.LOGIN.v_trs_conf_contact_last_name.value = "";
		document.LOGIN.v_trs_conf_contact_email.value = "";
		document.LOGIN.v_trs_conf_contact_phone.value = "";
*/
		//document.all.fl_trs_conf_contact_email.innerHTML = '<b><font color="red">*</font>&nbsp;Email Address: <b>';
		}

	}


	function highlightCheckConfirm(elem) {
		//alert(elem.value);
/*
trs_address
trs_phone

*/
		if( elem.checked == true) {
			document.getElementById(elem.value).style.background="#97DB97";
		} else {
			document.getElementById(elem.value).style.background="#FFFFFF";
		}
	}

	function othercontactswitch(elem) {

		if( elem.checked == true) {
			document.getElementById('v_trs_other_contact_pending').value='1';
			document.getElementById('trs_other_contact_section').style.display='none';
/*
			if( document.getElementById('r_trs_conf_contact_option2').checked == true) {
				document.getElementById('r_trs_conf_contact_option1').checked=true;
				document.getElementById('v_trs_conf_contact_option').value=1;
			}

			document.getElementById('r_trs_conf_contact_option2').disabled=true;

			if( document.getElementById('c_trs_other_contact').checked == true) {
				document.getElementById('c_trs_contact').checked=true;
				document.getElementById('v_trs_contact').value=1;
			}

			document.getElementById('v_trs_other_contact').value=0;
			document.getElementById('c_trs_other_contact').checked=false;
			document.getElementById('c_trs_other_contact').disabled=true;
*/
		} else {

			document.getElementById('v_trs_other_contact_pending').value='0';
/*
			document.getElementById('r_trs_conf_contact_option2').disabled=false;
			document.getElementById('c_trs_other_contact').disabled=false;
*/
			if( window.external) {
				document.getElementById('trs_other_contact_section').style.display='block';
			} else {
				document.getElementById('trs_other_contact_section').style.display='table-row';
			}
		}

		return(true);

	}

	function confcontactswitch(elem) {

		switch( elem.id.toLowerCase()) {
			case "r_trs_conf_contact_option1":
				document.getElementById('v_trs_conf_contact_option').value='1';
/*
				document.getElementById('v_trs_conf_contact').value=0;
				document.getElementById('c_trs_conf_contact').disabled=true;
				document.getElementById('v_trs_other_contact').value=0;
				document.getElementById('c_trs_other_contact').disabled=true;
*/
				document.getElementById('trs_your_contact_section').style.display='none';
				break
			case "r_trs_conf_contact_option2":
				document.getElementById('v_trs_conf_contact_option').value='2';
/*
				document.getElementById('v_trs_conf_contact').value=0;
				document.getElementById('c_trs_conf_contact').disabled=true;
				document.getElementById('c_trs_other_contact').disabled=false;
*/
				if( window.external) {
					document.getElementById('trs_your_contact_section').style.display='block';
				} else {
					document.getElementById('trs_your_contact_section').style.display='table-row';
				}
				break
			case "r_trs_conf_contact_option4":
				document.getElementById('v_trs_conf_contact_option').value='4';
/*
				document.getElementById('v_trs_other_contact').value=0;
				document.getElementById('c_trs_conf_contact').disabled=false;
				document.getElementById('c_trs_other_contact').disabled=true;
*/
				if( window.external) {
					document.getElementById('trs_your_contact_section').style.display='block';
				} else {
					document.getElementById('trs_your_contact_section').style.display='table-row';
				}
				break
		}

		return(true);

	}

	function heardswitch(elem) {
          if( elem.value == "Other") {
            document.getElementById("v_heard_other").style.display="block";
				document.getElementById("v_spec_other").style.display="block";
          } else {
            document.getElementById("v_heard_other").style.display="none";
				document.getElementById("v_spec_other").style.display="none";
          }
        }

	function searchparam(param) {
//alert(location.search.indexOf(param + "="));
		var start = location.search.indexOf(param + "=");
		if( start == -1) {
			return("");
		} else {
//alert(location.search.indexOf("&",start));
			var end = location.search.indexOf("&",start);
			if( end == -1) {
				return(location.search.substring(start+(param + "=").length));
			} else {
//alert(location.search.substring(start+(param + "=").length,end));
				return(location.search.substring(start+(param + "=").length,end));
			}
		}
	}

	function getinputtypes(type) {
		var elem,arr,i;
		i=0;
		arr = new Array();
//alert(document.getElementsByTagName("input").length);
		for( elem in document.getElementsByTagName("input")) {
//alert(document.getElementsByTagName("input")[elem].name);
			if( document.getElementsByTagName("input")[elem].type == type) {
//alert(document.getElementsByTagName("input")[elem].name);

				arr[i]=document.getElementsByTagName("input")[elem].name;
				i++;
			}
		}
//alert(arr.length);
/*
for( var x=0;x<arr.length;x++) {
	document.writeln(arr[x]);
}
*/
		return(arr.sort());
	}

	function defaults() {
/*
alert("hello");
alert(searchparam("ref").toUpperCase());
*/
		switch(searchparam("ref").toUpperCase()) {
			case "PTR-EML":
				try {
					document.getElementById('v_trs_conf_contact_option').value=2;
				} catch(err) {
					document.getElementById('h_trs_conf_contact_option').value=2;
				}

				try {
						document.getElementById('v_trs_other_contact').value=1;
				} catch(err) {
						document.getElementById('h_trs_other_contact').value=1;
				}

				try {
						document.getElementById('v_trs_contact').value=0;
				} catch(err) {
						document.getElementById('h_trs_contact').value=0;
				}

				try {
						document.getElementById('v_attn_to_option').value=2;
				} catch(err) {
						document.getElementById('h_attn_to_option').value=2;
				}

				try {
						document.getElementById('v_trs_other_contact_pending').value=0;
				} catch(err) {
						document.getElementById('h_trs_other_contact_pending').value=0;
				}

//alert(searchparam("cmd").toLowerCase());
//alert(document.getElementById('r_confirmcontact_option2').checked);
				if( searchparam("cmd").toLowerCase() == "xpnext") {
					document.getElementById('r_trs_conf_contact_option2').checked=true;
					document.getElementById('r_trs_conf_contact_option1').disabled=true;
					document.getElementById('r_trs_conf_contact_option4').disabled=true;
					document.getElementById('c_trs_other_contact').checked=true;
					document.getElementById('c_trs_other_contact').disabled=true;
					document.getElementById('c_trs_contact').disabled=true;
					document.getElementById('c_trs_conf_contact').disabled=true;
					document.getElementById('c_trs_other_contact_pending').disabled=true;
				} else if( searchparam("cmd").toLowerCase() == "xpress" && searchparam("prvc").length == 0) {
					//document.getElementById('r_attn_to_option2').checked=true;
					document.getElementById('r_confirmcontact_option2').checked=true;
					document.getElementById('v_confirmcontact_option').value=2;
				}
//alert(document.getElementById('r_confirmcontact_option2').checked);
//alert(document.getElementById('h_confirmcontact_option').value);
				break
			default:
				//alert(searchparam("ref").toUpperCase());
				break
		}

		return(true);
	}

function opensrmconsole(vrt) {
	return(window.open(vrt+'/admin/trs_manager/'+location.search,'_blank','directories=no,top=5,left=5,location=no,menubar=no,resizable=no,scrollbars=no,toolbar=no,width=630,height=460'));
}

function getRadioGroupValue(radios){
	var radiogrouparray=document.getElementsByName(radios);
	var retval=null;
	for(var i=0;i<radiogrouparray.length;i++){
//alert(radiogrouparray[i].checked)
		if(radiogrouparray[i].checked){
			retval=radiogrouparray[i].value;
		}
	}
	return retval;
}


//top javascript functions
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

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 null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

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';
}

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}