﻿var ReAjax = function()
{}
ReAjax.prototype.GetHttpRequest = function()
{
	var reObj="";
	if ( window.XMLHttpRequest ){
		reObj= new XMLHttpRequest() ;
	}
	else if ( window.ActiveXObject ){	
		try{
			reObj=new ActiveXObject("MsXml2.XmlHttp") ;
		}
		catch(e){
			reObj=new 	ActiveXObject("microsoft.XmlHttp")
		}
	}
	return reObj;
}

ReAjax.prototype.LoadUrl2 = function(urlToCall)
{	
	var oReAjax = this ;
	var oAjaxHttp = this.GetHttpRequest() ;
	oAjaxHttp.open( "GET", urlToCall, false) ;
	oAjaxHttp.send( null );
	var result=oAjaxHttp.responseText;
	return result;
}

function findObj(theObj, theDoc){  
	var p, i, foundObj;
	if(!theDoc) theDoc = document;  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)  {    theDoc = parent.frames[theObj.substring(p+1)].document;    theObj = theObj.substring(0,p);  }  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];  for (i=0; !foundObj && i < theDoc.forms.length; i++)     foundObj = theDoc.forms[i][theObj];  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)     foundObj = findObj(theObj,theDoc.layers[i].document);  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);    return foundObj;
}
var numLength = 0;
//生成行
function AddSignRow(){
	<!---读取最后一行的行号，存放在txtTRLastIndex文本框中---> 
	 var txtTRLastIndex = findObj("txtTRLastIndex",document);
	 var rowID = parseInt(txtTRLastIndex.value); 
	 var signFrame = findObj("FTabl",document);		
	 numLength = rowID + 3;	 	 
	 for (rowID; rowID<numLength;rowID++){
		 <!---//添加行--->
		 var newTR = signFrame.insertRow(signFrame.rows.length);
		 newTR.id = "FTablItem" + rowID; 
		 newTR.className="font11";
		 newTR.height="30";
		 
		 var newFullNameTDstr = newTR.insertCell(0);
		 newFullNameTDstr.innerHTML = "First Name:";
		 <!---//添加列:Full姓名--->
		 var newFullNameTD=newTR.insertCell(1);
		 <!---//添加列内容--->
		 newFullNameTD.innerHTML = "<input name='txtFullName" + rowID + "' id='txtFullName" + rowID + "' type='text' class='input' size='12' />"; 	
		 
		 var newFullNameTDstr = newTR.insertCell(2);
		 newFullNameTDstr.innerHTML = "Last Name:";
		 
		 var newLastNameTD=newTR.insertCell(3);	 
		 newLastNameTD.innerHTML = "<input name='txtLastName" + rowID + "' id='txtLastName" + rowID + "' type='text' class='input' size='12' />"; 
		
		 var newFullNameTDstr = newTR.insertCell(4);
		 newFullNameTDstr.innerHTML = "Email address:";
		
		 var newEmailTD=newTR.insertCell(5);	
		 newEmailTD.innerHTML = "<input name='txtEMail" + rowID + "' id='txtEmail" + rowID + "' type='text' class='input' size='20' />";
	}
	 
	 <!---//将行号推进下一行--->
	 txtTRLastIndex.value = (rowID).toString();
	}
	//验证邮件是否存在
	function checkMail(value){		
		var strResult = "";						
		var callUrl = "ajax/checkEmail.cfm?emailadd="+value;			
		strResult = ReAjax.prototype.LoadUrl2(callUrl);							
		return strResult;
	}
	//验证表单
	function checkForm(){
		var patrn=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
		if(findObj("txtRfullName",document).value == ""){
			alert("Please enter your FirstName");
			findObj("txtRfullName",document).focus();
			findObj("txtRfullName",document).className = "Error";
			return false;
		}else
			findObj("txtRfullName",document).className = "input";
			
		if(findObj("txtRlastName",document).value == ""){
			alert("Please enter your LastName");
			findObj("txtRlastName",document).focus();
			findObj("txtRlastName",document).className = "Error";
			return false;			
		}else
			findObj("txtRlastName",document).className = "input";
			
		if(findObj("txtRemail",document).value == ""){
			alert("Please enter your Email Address");
			findObj("txtRemail",document).focus();
			findObj("txtRemail",document).className = "Error";
			return false;
		}else
			findObj("txtRemail",document).className = "input";
			
		if(!patrn.exec(findObj("txtRemail",document).value)){
			alert("Please enter your valid Email Address");	
			findObj("txtRemail",document).focus();
			findObj("txtRemail",document).className = "Error";
			return false;
		}else					
			findObj("txtRemail",document).className = "input";		
			
		
		var txtTRIndex = findObj("txtTRLastIndex",document).value;			
		var f = 0;
		for(var i = 1;i < txtTRIndex; i++){	
			var fullName = "txtFullName"+i;
			var lastName="txtLastName"+i;
			var email="txtEMail"+i;	
			if(findObj(fullName,document).value != "" || findObj(lastName,document).value != "" || findObj(email,document).value != ""){		
				f = 1;
				if(findObj(fullName,document).value == ""){
					alert("Please enter your friends’ FirstName");
					findObj(fullName,document).className = "Error";
					findObj(fullName,document).focus();
					return false;
				}else
					findObj(fullName,document).className = "input";
					
				if(findObj(lastName,document).value == ""){
					alert("Please enter your friends’ LastName");
					findObj(lastName,document).className = "Error";
					findObj(lastName,document).focus();
					return false;			
				} else
					findObj(lastName,document).className = "input";
					
				if(findObj(email,document).value == ""){
					alert("Please enter your friends’ Email Address");
					findObj(email,document).className = "Error";
					findObj(email,document).focus();
					return false;
				}else if(findObj(email,document).value == findObj("txtRemail",document).value){
					alert("Are neither recommend their");
					findObj(email,document).className = "Error";
					findObj(email,document).focus();
					return false;
				}else if(!patrn.exec(findObj(email,document).value)){
					alert("Please enter your friends’ valid Email Address");	
					findObj(email,document).className = "Error";
					findObj(email,document).focus();
					return false;
				}else if(checkMail(findObj(email,document).value) == "false"){
					alert("E-mail address already exists");	
					findObj(email,document).className = "Error";
					findObj(email,document).focus();
					findObj(email,document).value = "";
					return false;
				}else
					findObj(email,document).className = "input";
			}			
		}
		if(f==0){
			alert("Please Enter your friends’ FirstName LastName and Email Address");
			findObj("txtFullName1",document).className = "Error";
			findObj("txtLastName1",document).className = "Error";
			findObj("txtEMail1",document).className = "Error";
			findObj("txtFullName1",document).focus();
			return false;
		}else{
			findObj("txtFullName1",document).className = "input";
			findObj("txtLastName1",document).className = "input";
			findObj("txtEMail1",document).className = "input";	
		}		
	}	



