var windowRef = window.opener;
upDateWindow();
function upDateWindow(){
document.getElementById('uid').value=windowRef.uid;
document.getElementById('AdId').childNodes[0].nodeValue=windowRef.id;
document.getElementById('cpy').childNodes[0].nodeValue=windowRef.cpy;
document.getElementById('sbj').value=windowRef.adType+" (List Id: " + windowRef.id+')';
document.getElementById('rcptEmail').value=windowRef.email;
document.getElementById('bid').value=windowRef.bid;}
function checkForm(){
if (document.getElementById('sbj').value.length<6) alert('Please enter a subject title, at least 6 characters long!');
else if (!emailCheck(document.getElementById('sndEm').value)) alert('Your return email appears incorrect!');
else if (document.getElementById('msg').value.length<20) alert('Please enter a meaningful message!');
else if (confirm('Send Message Now!')){
	removeapostrophes(document.getElementById('sbj'));
	removeapostrophes(document.getElementById('sndEm'));
	removeapostrophes(document.getElementById('msg'));
	removeapostrophes(document.getElementById('nm'));
	if (document.getElementById('nm').value.length >49) document.getElementById('nm').value= document.getElementById('nm').value.substring(0,48)
	
	return true;
	}
return false;
}
function removeapostrophes(s){
var i;
if (s.value.length > 0) s.value=s.value.split("'").join("''");
}
function emailCheck (emailStr){
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=emailStr.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){
	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>3)return false
if (len<2)return false
return true;
} 