function rcmAddLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){oldonload();func();}}}
function makePOSTRequest(url,params){var http_request=false;if(window.XMLHttpRequest){http_request=new XMLHttpRequest();if(http_request.overrideMimeType){http_request.overrideMimeType('text/html');}}else if(window.ActiveXObject){try{http_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}}
if(!http_request){alert('Giving up :( Cannot create an XMLHTTP instance');return false;}
document.getElementById('DivRcm').setAttribute('align','center');document.getElementById('DivRcm').innerHTML=RcmPW+'<br />';document.getElementById('DivRcm').appendChild(RcmImg);document.getElementById('DivRcm').ajaxInProgress=true;http_request.onreadystatechange=function(){processContents(http_request);}
http_request.open('POST',url,true);http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');http_request.setRequestHeader("Content-length",params.length);http_request.setRequestHeader("Connection","close");http_request.send(params);}
function print_rcm_form(){var string='';if(InvalidEmail||(RcmToArrValue[0]!=""&&invalid_to_email())){string+="<font color=\""+RcmEC+"\">"+RcmI+"</font><br />";}
string+="<form name=\"rcmform\" id=\"rcmform\" method=\"post\" action=\"javascript:get(document.getElementById('rcmform'));\">"+"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";if(RcmUN=='1'){string+="<tr>"+"<td>"+RcmYN+"<br />"+"<div id=\"DivRcmFrom\"></div></td>"+"</tr>";}
string+="<tr>"+"<td nowrap=\"nowrap\">*&nbsp;"+RcmYE+"<br />"+"<div id=\"DivRcmEmail\"></div></td>"+"</tr>"+"<tr>"+"<td nowrap=\"nowrap\">*&nbsp;"+RcmFE+"<br />"+"<div id=\"DivRcmTo\"></div></td>"+"</tr>"+"<tr><td nowrap=\"nowrap\"><div align=\"right\" style=\"text-align: right\" id=\"DivRcmCmd\"></div></td></tr>"+"</tr>"+"</table>"+"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+"<tr><td nowrap=\"nowrap\"><div id=\"DivRcmMsg\"></div></td></tr>"+"<tr>"+"<td><input type=\"button\" name=\"send\" value=\""+RcmS+"\" class=\"button"+RcmMS+"\" onclick=\"get(this.parentNode);\" />&nbsp;"+"<input type=\"button\" name=\"cancel\" value=\""+RcmC+"\" class=\"button"+RcmMS+"\" onclick=\"rcm_cancel();\" /></td>"+"</tr>"+"</table>"+"</form>";document.getElementById('DivRcm').innerHTML=string;if(RcmUN=='1'){build_rcm_from_field();}
build_rcm_email_field();build_rcm_to_field();if(RcmAM=='1'){build_rcm_msg_field();}}
function build_rcm_to_field(){document.getElementById('DivRcmTo').innerHTML="";for(i=0;i<RcmToArrValue.length;i++){if(InvalidTo[i]==1){addstyle=" style=\"border-color:"+RcmEC+"\";";}else{addstyle="";}
document.getElementById('DivRcmTo').innerHTML+="<input type=\"text\" id=\"rcm_to_email_"+i+"\" name=\"rcm_to_email[]\" size=\""+RcmIS+"\" value=\""+RcmToArrValue[i]+"\" class=\"inputbox"+RcmMS+"\""+addstyle+" onchange=\"javascript: save_rcm_to_field (this.id, this.value)\" /><br />";}
if(RcmME=='1'){if(RcmToArrValue.length>1){document.getElementById('DivRcmCmd').innerHTML='<a href="javascript: void(0)" onclick="pop_rcm_to_field()">'+RcmSH+'</a> <a href="javascript: void(0)" onclick="push_rcm_to_field()">'+RcmEX+'</a>';}else{document.getElementById('DivRcmCmd').innerHTML='<a href="javascript: void(0)" onclick="push_rcm_to_field()">'+RcmEX+'</a>';}}}
function build_rcm_from_field(){document.getElementById('DivRcmFrom').innerHTML="<input type=\"text\" id=\"rcm_from_name\" name=\"rcm_from_name\" size=\""+RcmIS+"\" value=\""+
RcmFromValue+"\" class=\"inputbox"+RcmMS+"\""+" onchange=\"javascript: save_rcm_from_field (this.value)\" />";}
function build_rcm_email_field(){if(InvalidEmail){addstyle=" style=\"border-color:"+RcmEC+"\";";}else{addstyle="";}
document.getElementById('DivRcmEmail').innerHTML="<input type=\"text\" id=\"rcm_from_email\" name=\"rcm_from_email\" size=\""+RcmIS+"\" value=\""+
RcmEmailValue+"\" class=\"inputbox"+RcmMS+"\""+addstyle+" onchange=\"javascript: save_rcm_email_field (this.value)\" />";}
function push_rcm_msg_field(){document.getElementById('DivRcmMsg').innerHTML=RcmYM;if(RcmTE!='1'){document.getElementById('DivRcmMsg').innerHTML+=' <a href="javascript: void(0)" onclick="pop_rcm_msg_field()">'+RcmSH+'</a>';}
document.getElementById('DivRcmMsg').innerHTML+="<br />"+"<textarea id=\"rcm_text\" name=\"rcm_text\" class=\"inputbox"+RcmMS+"\" rows=\""+RcmTR+"\" cols=\""+RcmTC+"\" onchange=\"javascript: save_rcm_msg_field (this.value)\">"+
RcmMsgValue+"</textarea>";}
function pop_rcm_msg_field(){RcmMsgValue="";document.getElementById('DivRcmMsg').innerHTML=RcmYM;if(RcmTE!='1'){document.getElementById('DivRcmMsg').innerHTML+=' <a href="javascript: void(0)" onclick="push_rcm_msg_field()">'+RcmEX+'</a><br /><br />';}else{push_rcm_msg_field();}}
function processContents(http_request){if(http_request.readyState==4){document.getElementById('DivRcm').removeAttribute('align');if(http_request.status==200){document.getElementById('DivRcm').innerHTML=http_request.responseText;}else{document.getElementById('DivRcm').innerHTML='There was a problem with the request.';}}}
function get(obj){if(!ValidEmail(document.getElementById('rcm_from_email').value)){InvalidEmail=1;}else{InvalidEmail=0;}
for(i=0;i<RcmToArrValue.length;i++){if(!ValidEmail(RcmToArrValue[i])){InvalidTo[i]=1;}else{InvalidTo[i]=0;}}
if(InvalidEmail||invalid_to_email()){print_rcm_form();}else{var rcm_to_email=RcmToArrValue.join();var poststr='';if(document.getElementById('rcm_from_name')){poststr+='rcm_from_name='+encodeURI(document.getElementById('rcm_from_name').value)+'&';}
poststr+='rcm_from_email='+encodeURI(document.getElementById('rcm_from_email').value)+'&rcm_to_email='+encodeURI(rcm_to_email);if(document.getElementById('rcm_text')){poststr+="&rcm_text="+encodeURIComponent(document.getElementById('rcm_text').value);}
makePOSTRequest(RcmPath+'/mod_ajaxrecommend.php',poststr);}}
function push_rcm_to_field(){RcmToArrValue.push('');build_rcm_to_field();}
function pop_rcm_to_field(){if(RcmToArrValue.length>1){RcmToArrValue.pop();InvalidTo[RcmToArrValue.length]=0;build_rcm_to_field();}}
function save_rcm_to_field(id,str){pos=id.substring(13,id.length);RcmToArrValue[pos]=str;}
function save_rcm_from_field(str){RcmFromValue=str;}
function save_rcm_email_field(str){RcmEmailValue=str;}
function build_rcm_msg_field(){if(RcmMsgValue!=''){push_rcm_msg_field();}else{pop_rcm_msg_field();}}
function save_rcm_msg_field(str){RcmMsgValue=str;}
function rcm_cancel(){RcmFromValue='';RcmEmailValue='';RcmToArrValue=Array(0);RcmToArrValue.push("");InvalidEmail=0;InvalidTo=new Array(0);InvalidTo.push(0);RcmMsgValue='';print_rcm_form();}
function invalid_to_email(){flag=false;for(i=0;i<RcmToArrValue.length;i++){if(!ValidEmail(RcmToArrValue[i])){flag=true;break;}}
return flag;}
function ValidEmail (email) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=email.match(emailPat)
	if (matchArray==null) {
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
		    }
		  }
		return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>4) {
		return false
	}
	if (len<2) {
	   return false
	}
	return true;
}