var blNAR=true;
var blA3O4P=false;


function fob(n, d){
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length){
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=fob(n,d.layers[i].document);
	return x;
}

function show_choose(html){
	var win = null;
	if(win==null||win.closed)
		{
			win = window.open("about:blank","choose_window","width=400,height=450,scrolling=no");
		}
		else
		{
			win.document.close();						
		}	
		win.document.write(html);	
		win.focus();
}

function vdf() {
	var i,p,q,nm,t,num,min,max,e='',a=vdf.arguments;

	with(document.submit_form)
	{
		strHomePhone1.value = strHomePhone1_1.value + strHomePhone1_2.value + strHomePhone1_3.value;
		strHomePhone2.value = strHomePhone2_1.value + strHomePhone2_2.value + strHomePhone2_3.value;
		strHomePhone3.value = strHomePhone3_1.value + strHomePhone3_2.value + strHomePhone3_3.value;
		strHomePhone4.value = strHomePhone4_1.value + strHomePhone4_2.value + strHomePhone4_3.value;
		strDayPhone1.value = strDayPhone1_1.value + strDayPhone1_2.value + strDayPhone1_3.value;
		strDayPhone2.value = strDayPhone2_1.value + strDayPhone2_2.value + strDayPhone2_3.value;
		strDayPhone3.value = strDayPhone3_1.value + strDayPhone3_2.value + strDayPhone3_3.value;
		strDayPhone4.value = strDayPhone4_1.value + strDayPhone4_2.value + strDayPhone4_3.value;
	}
	
	for (i=0; i<(a.length-2); i+=3) {
		t=a[i+2];
		val=fob(a[i]);
		val1=val.value;
		
		if(a[i+2]=="checkRadio")
		{
			if(a[i]=="strNAR" && !blNAR)
			{
				i+=100;
			}
			if(a[i]=="strA3O4P" && !blA3O4P)
			{
				i+=100;
			}
		}
		
		if (val) {
			nm=a[i+1];
			if ((val=val.value)!="") {
				if (t.indexOf('len') != -1) {
					p=t.indexOf(':');
					l=t.substring(p+1);
					if (val1.length<l) e+='<tr><td>'+nm+'</td><td class=td1>Length false.</td></tr>';
				}
	
				if (t.indexOf('mail')!=-1) {
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) e+='<tr><td>'+nm+'</td><td class=td1>Email address is false.</td></tr>';
				}
	
				if (t.indexOf('num')!=-1) {
					num = parseFloat(val);
					cond = val.indexOf('.')!=-1;
					if (val!=''+num && cond){
						e+='<tr><td>'+nm+'</td><td class=td1>Invalid Format.</td></tr>';
					}else{
						if (val!=''+num) e+='<tr><td>'+nm+'</td><td class=td1>Invalid Format.</td></tr>';
						if (cond) e+='<tr><td>'+nm+'</td><td class=td1>Do not input the decimal point.</td></tr>'
					}
				}

				if (t.indexOf('phone')!=-1) {
					phone = parseFloat(val);
					if (val!=''+phone) e+='<tr><td>'+nm+'</td><td class=td1>Invalid phone number.</td></tr>';
				}
	
				if (t.indexOf('inRange') != -1) {
					num = parseFloat(val);
					p=t.indexOf(':');
					min=t.substring(1,p);
					max=t.substring(p+1);
					if (t.indexOf('Z') != -1) {
						if (num<min || max<num || val!=''+num && val!='0'+num) e+='<tr><td>'+nm+'</td><td class=td1>Invalid.</td></tr>';
					}else{
						if (num<min || max<num || val!=''+num) e+='<tr><td>'+nm+'</td><td class=td1>Invalid.</td></tr>';
					}
				}
	
				if (t.indexOf('year') != -1) {
					num = parseFloat(val);
					now = new Date();
					year = now.getYear();
					min=1900;
					if (a[i]=='strExpYear'){
						max=year;
					}else{
						max=year-10;
					}
					if (num<min || max<num || val!=''+num) e+='<tr><td>'+nm+'</td><td class=td1>Invalid year.</td></tr>';
				}
			} else {
				if (t.charAt(0) == 'R') e+='<tr><td>'+nm+'</td><td class=td1>Required Field.</td></tr>';
			}
		}
	}
	if (e!='') {
		var html='<html><head><title>Error page!</title><style><!--.td1{color:#ff0000}--></style></head><body bgcolor=#E0EEF7><table border="0" cellspacing="0" cellpadding="0" align="center" style="font-family:Arial;font-size=13px;"><tr><th height=40 colspan=2>Please check error below:</th>'+e+'</tr><tr><td colspan=2 align=center height=40><a onClick=opener.focus();window.close() style=cursor:hand><b><u>Please click here go back!</u></b></a></td><tr></table></body></html>';
		show_choose(html);
		document.vdfValue=(e=='');
	}
	return(e=='');
}


function checkRadio(obj)
{
	if(obj.id.indexOf("strNAR")>-1 && obj.id.indexOf("1")>-1)
	{
		blNAR = true;
	}
	else if(obj.id.indexOf("strNAR")>-1 && obj.id.indexOf("2")>-1)
	{
		blNAR = false;
	}
	else if(obj.id.indexOf("strA3O4P")>-1 && obj.id.indexOf("1")>-1)
	{
		blA3O4P = true;
	}
	else
	{
		blA3O4P = false;
	}
}
