//constant
//dd amount indian Rs
var IndianSudentWithoutAccom = 300;
var IndianSudentWithAccom = 500;
var IndianNonSudent = 1000;
var IndianSponsered = 5000;
var IndianChildStudentBelow12 = 150;
var IndianChildNonStudentBelow12 = 500;
//dd amount  USD $
var AbroadSudentWithoutAccom = 50;
var AbroadSudentWithAccom = 60;
var AbroadNonSudent = 120;
var AbroadSponsered = 500;
var AbroadChildStudentBelow12 = 25;
var AbroadChildNonStudentBelow12 = 60;

//variables
var unitDDAmount = "";
var memberCount = 1;
var mFirstName;
var mMiddleName;
var mLastName;
var mAge;
var mEmailID;
var mOccupation;
var mDesignation;
var mOrganization;
var mCourse;
var mBranch;
var mInstitute;
var mRelation;
var mMbNo;
var mCategory;
var mAccommodation;
var mGender;
var mRegtype ="";
var mConfirmMsgSent =0;
var mPastConfDetails;
var mPayType = 'DD Amount';
var mmPayTypeInfo = 'DD';

var WindowObjectReference; 
function openFFPromotionPopup(filename,width,height)
{
	/* explanation: if the pointer to the window object
	in memory does not exist or
	if such pointer exists but the window was closed */

	if(WindowObjectReference == null || WindowObjectReference.closed)
	{
		WindowObjectReference = window.open(filename,"TaskInfo","location=0,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width="+width+",height="+height);
	}
	/* explanation: then create it. The new window will be created and
	will be brought on top of any other window. */
	else
	{	
	WindowObjectReference.close();
	WindowObjectReference = window.open(filename,"TaskInfo","location=0,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width="+width+",height="+height);
		/*if(WindowObjectReference.focus)
		{
			WindowObjectReference.focus();
		};*/
	};
}


function SelectedCategory()
{
	switch(document.f1.indu_category.value)
	{
			case "Student":
				document.getElementById("studentHidden").style.display="block";
				document.getElementById("nonStudentHidden").style.display="none";
				break;
			case "Non-Student":
			case "Sponsored":
				document.getElementById("nonStudentHidden").style.display="block";
				document.getElementById("studentHidden").style.display="none";
				break;
			default:
				document.getElementById("studentHidden").style.display="none";
				document.getElementById("nonStudentHidden").style.display="none";
	}
}

function MemSelectedCategory(id)
{
	
	mCategory = document.f1.elements["mcategory[]"];
	if(mCategory != null && mCategory.length >id)
	{
			switch(mCategory[id].value)
			{
					case "Student":
						document.getElementById("memStudentHidden"+id).style.display="block";
						document.getElementById("memNonStudentHidden"+id).style.display="none";
						break;
					case "Non-Student":
					case "Sponsored":
					
						document.getElementById("memNonStudentHidden"+id).style.display="block";
						document.getElementById("memStudentHidden"+id).style.display="none";
						break;
					default:
						document.getElementById("memStudentHidden"+id).style.display="none";
						document.getElementById("memNonStudentHidden"+id).style.display="none";
			}
	}
}

function limitText(limitField, limitNum) 
{
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
		alert("Maximum characters that can be entered in this field are " + limitNum);
	} 
}

function UnCheckAll(chk)
{
for (i = 0; i < chk.length-1; i++)
	chk[i].checked = false ;
}
function UnCheckNone(chk)
{
chk[chk.length-1].checked = false ;
}
function validateForm(){
	
    return false;
}

function clearForm()
{			
	if (confirm("Are you sure you want to clear form?")) 
	{
			document.f1.reset();
			document.getElementById('SingleReg').checked =	true;	
			UpdatepayDetails();		
			mConfirmMsgSent =0;
			//to remove group on reset
			document.getElementById("hidden1").style.display="none";
			document.getElementById("srcButtons").style.display="none";	
	}		
}

function loading()
{	
		document.getElementById('SingleReg').checked =	true;
		UpdatepayDetails();
		mConfirmMsgSent =0;
		//to remove group on reset
		document.getElementById("hidden1").style.display="none";
		document.getElementById("srcButtons").style.display="none";	
		SelectedCategory();
		//to clear the counter in firefox 
		document.getElementById('ctr').value =1;
		
}

function UpdatepayDetails()
{
//1-->DD Details 2-->Net Banking Details
	if(document.getElementById('DDPay').checked == true)
	{
		mPayType = 'DD Amount';
		document.getElementById('payDetails').innerHTML = 'DD Details';
		document.getElementById('ddNoText').innerHTML = 'DD No:<font color="Red">* </font></td>';
		//document.getElementById('amountText').innerHTML = 'DD Amount:';
		document.getElementById('ddDateText').innerHTML = 'DD Date:<font color="Red">* </font></td>';
	}
	else
	{
		mPayType = ' Amount';
		document.getElementById('payDetails').innerHTML = 'Net Banking Details <span style = "font-size: 12">(click <a style = "color:yellow; text-decoration:none" href=\"javascript:void(0)\" onclick="javascript:openFFPromotionPopup(\'netBankingDetails.php\',530,320);"> here </a>for account details to transfer fee and for other instructions)</span>';
		document.getElementById('ddNoText').innerHTML = 'Transaction No:<font color="Red">* </font></td>';
		//document.getElementById('amountText').innerHTML = 'Transaction Amount: ';
		document.getElementById('ddDateText').innerHTML = 'Transaction Date:<font color="Red">* </font></td>';
	}
	changeAmountType();
}


function showhide(val)
{	
		mRegtype = val;		
		if(val == "1"){			
			document.getElementById("hidden1").style.display="none";
			document.getElementById("srcButtons").style.display="none";
		} else {
			document.getElementById("hidden1").style.display="block";
			document.getElementById("srcButtons").style.display="block";
			MemSelectedCategory(1);
		}
		
}
 function removeText(ctrValue){
    var srcMembers = document.getElementById('hidden1');
	if (confirm("Are you sure you want to delete the group member?")) 
	{
			srcMembers.removeChild(document.getElementById(ctrValue));  
			memberCount--;
	}	
   
  }

function addMore(sel){
		var ctrValue = parseInt(document.getElementById('ctr').value) + 1; 		
		document.getElementById('ctr').value = ctrValue;
		if(memberCount < 10)
		{
			memberCount++;
			creatediv(ctrValue);  
		}
		else
		{
			alert(" Group registration is limited to 10 members only.");
		}
}
function creatediv(id) {
			var srcMembers = document.getElementById('hidden1');
		    var newdiv = document.createElement('div');    

		    newdiv.setAttribute('id', id);
			newdiv.innerHTML += textToAddinHTML(id);
			srcMembers.appendChild(newdiv);
		
		
}
	
function textToAddinHTML(idno)
{	
	var textadd = "<br><hr style = 'color: #B5B5B5' /><br><table align ='center' cellspacing =0; cellpadding = 0; border ='0' >" +
							"<tr><td >Category:<font color='Red'>* </font></td>" +
							"<td colspan ='3'><select name='mcategory[]' ONCHANGE=MemSelectedCategory(" + idno + ");><option value=''>-Select-</option><option value='Student'>Student</option> <option value='Non-Student'>Non-Student</option><option value='Sponsored'>Sponsored</option></select>" +
							"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accommodation Required:<font color='Red'>* </font>" +
							"&nbsp;<select name='maccomdation[]' ><option value=''>-Select-</option><option value='Yes'>Yes</option> <option value='No'>No</option></select>" +
							"</td></tr>" +
							"<tr><td width = '19%'><b></b> First Name: <font color='Red'>* </font></td>" +
							"<td ><input name='mfirstname[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='35' value='' type='textbox'> </td>" +
							"<td nowrap style = 'text-align:right;' >Middle Name:</td>" +
							"<td style = 'text-align:right;'><input name='mmiddlename[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='35' maxlength='25'  value='' type='textbox'>" +
							"</td></tr>" +
							"<tr><td>Last Name:<font color='Red'>* </font></td>" +
							"<td><input  name = 'mlastname[]'onkeyup=this.value=this.value.replace(/[']/g,'`'); size='35' maxlength='25'  value='' type='textbox'> </td>" +
							"<td colspan = '2' style = 'text-align:center;'>&nbsp;Gender:<font color='Red'>*</font><select name='mgender[]' ><option value=''>-Select-</option><option value='M'>Male</option> <option value='F'>Female</option></select>" +
							"&nbsp;&nbsp;&nbsp;&nbsp;Age:<font color='Red'>* </font><input  name = 'mage[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='4' value='' type='textbox'>" +
							"</td></tr>" +							
							"<tr><td colspan = '4' ><div  id = 'memNonStudentHidden" + idno + "' style='display:none' >" +
							"<table  cellspacing =0; cellpadding = 0;border ='0' >" +
							"<tr><td width = '19%'>Occupation:<font color='Red'>* </font> </td>" +
							"<td><input name='moccupation[]' size='35' maxlength='250' value='' type='textbox'></td> " +
							"<td nowrap style = 'text-align:right;'>Organization:<font color='Red'>* </font></td>" +
							"<td style = 'text-align:right;'><input  name='mOrgn[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='35' maxlength='250'value='' type='textbox'>" +
							"</td></tr><tr><td>Designation:<font color='Red'>* </font></td>" +
							"<td ><input name='mDesgn[]' size='35' maxlength='250' value='' type='textbox'></td><td colspan = '2'>&nbsp;your <b>designation/position</b> in your organization.</td>" +
							"</tr><tr><td></td><td colspan = '4' >(Professor/Director/ Manager/MS Student / PhD Student etc.)</td></tr>	</table></div></td></tr> "+
							"<tr><td colspan = '4'><div id = 'memStudentHidden" + idno + "' style='display:none' ><table  cellspacing =0; cellpadding = 0;border ='1' ><tr>" +
							"<td width = '19%'>Course:<font color='Red'>* </font> </td><td><input name='mCourse[]' size='35' maxlength='250' value='' type='textbox'>" +
							"</td><td nowrap style = 'text-align:right;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Branch:<font color='Red'>* </font> "+  
							"</td><td style = 'text-align:right;'><input  name='mBranch[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='35' maxlength='250'value='' type='textbox'>" +
							"</td></tr><tr><td colspan = '2' style = 'text-align:right;'>(BSc/BTech/MS/MBBS/MTech/MD/PhD/MSc etc)</td> "+
							"<td colspan = '2' style = 'text-align:right;' > (such as Mechanical Engg./ MSc in Math etc)</td></tr><tr>" +
							"<td>Institute:<font color='Red'>* </font></td><td colspan = '3'><input name='mInstitute[]' size='35' maxlength='250' value='' type='textbox'> Institute where studying "+
							"</td></tr></table></div></td></tr>"+
							"<tr><td>Relationship:<font color='Red'>* </font></td> " +
							"<td ><input  name = 'mrelation[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='35' value='' type='textbox'></td>" +
							"<td style = 'text-align:right;'>Mobile No:<font color='Red'>* </font></td>" +	
							"<td  style = 'text-align:right;'><input name='mmbNo[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='35' value='' type='textbox'></td></tr>" +							
							"<tr><td >Email ID:<font color='Red'>* </font></td>" +
							"<td colspan ='3'><input   name = 'memailId[]' onkeyup=this.value=this.value.replace(/[']/g,'`'); size='55' value='' type='textbox'>"+
							"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button'  name='m[]' value='   -   ' onClick=removeText(" + idno + "); >" +
							"</tr></table>";
	
	return textadd;
}

function validatedata()
{

	if(document.getElementById('SingleReg').checked == true)
		{
			mRegtype = 1;	
		}
	else if(document.getElementById('GroupReg').checked == true)
	{
			mRegtype = 2;
	}
	else
	{
		alert("Please select the registration type");
	}
	if (!document.f1.indu_category.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please select the category");  
		    document.f1.indu_category.focus();	
			return;
		}
	else if (!document.f1.indu_accomdation.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please select the proper option regarding accommodation.");  
		    document.f1.indu_accomdation.focus();	
			return;
		}	
	else if (!document.f1.firstname.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your first name");  
		    document.f1.firstname.select();	
		    document.f1.firstname.focus();	
			return;
		} 
	else if (!document.f1.lastname.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your last name");  
		    document.f1.lastname.select();
		    document.f1.lastname.focus();	
			return;
		} 
		
	else if (!document.f1.gender.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please select your gender");  
		    document.f1.gender.focus();	
			return;
		}
	else if (!document.f1.age.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your age");  
		    document.f1.age.focus();	
			return;
		}
	else if (checkNum(document.f1.age)==0)
	  	{  
			alert("Please enter your correct age");  
			document.f1.age.select();
		    document.f1.age.focus();	
			return;
		}
	else if (document.f1.age.value < 0 || document.f1.age.value > 200)
	  	{  
			alert("Please enter your correct age");  
			document.f1.age.select();
		    document.f1.age.focus();	
			return;
		}
	SelectedCategory();	
	switch(document.f1.indu_category.value)
	{
			case "Student":
				if (!document.f1.course.value.replace(/^\s*|\s*$/g,""))
				{  
					alert("Please enter your course of study.");  
					document.f1.course.select();
					document.f1.course.focus();	
					return;
				}			
				else if (!document.f1.branch.value.replace(/^\s*|\s*$/g,""))
				{  
					alert("Please enter your branch of study.");  
					document.f1.branch.select();
					document.f1.branch.focus();	
					return;
				}
			else if (!document.f1.institute.value.replace(/^\s*|\s*$/g,""))
				{  
					alert("Please enter the name of the institute where you are studying.");  
					document.f1.institute.select();
					document.f1.institute.focus();	
					return;
				}					
				break;
			case "Non-Student":
			case "Sponsored":
				if (!document.f1.occp.value.replace(/^\s*|\s*$/g,""))
				{  
					alert("Please enter your occupation.");  
					document.f1.occp.select();
					document.f1.occp.focus();	
					return;
				}			
				else if (!document.f1.orgn.value.replace(/^\s*|\s*$/g,""))
				{  
					alert("Please enter your organization.");  
					document.f1.orgn.select();
					document.f1.orgn.focus();	
					return;
				}
			else if (!document.f1.desgn.value.replace(/^\s*|\s*$/g,""))
				{  
					alert("Please enter your designation.");  
					document.f1.desgn.select();
					document.f1.desgn.focus();	
					return;
				}					
				break;
	}
	 if (!document.f1.address.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your address");  
			document.f1.address.select();
		    document.f1.address.focus();	
			return;
		}		
	else if (!document.f1.txtcountry.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please select your country");  
		    document.f1.txtcountry.focus();	
			return;
		}
	else if (!document.f1.txtstate.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your state");  
		    document.f1.txtstate.select();
		    document.f1.txtstate.focus();	
			return;
		}
	else if (!document.f1.txtcity.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your city / locality");  
		    document.f1.txtcity.select();	
		    document.f1.txtcity.focus();	
			return;
		}
	else if (!document.f1.txtzip.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your zip / postal code:");  
		    document.f1.txtzip.select();
		    document.f1.txtzip.focus();	
			return;
		}
	else if (!document.f1.mbno.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter your mobile No.");  
		    document.f1.mbno.select();
		    document.f1.mbno.focus();	
			return;
		}
	else if (checkNum(document.f1.mbno)==0)
	    {
	  		alert("Please enter your correct  mobile No.");  
	  		document.f1.mbno.select();
		    document.f1.mbno.focus();	
			return;
		}
		else if (checkPhoneNo(document.f1.contactno)==0)
	    {
	  		alert("Please enter your correct contact No.");  
	  		document.f1.contactno.select();
		    document.f1.contactno.focus();	
			return;
		}
	else if ((document.f1.emailId.value==null)||(document.f1.emailId.value=="")){
		alert("Please enter your email ID")
		document.f1.emailId.select();
		document.f1.emailId.focus();
		return false
	}
	else if (!ValidateemailID(document.f1.emailId))
	    {
			alert("Please enter your correct email ID")
	  		document.f1.emailId.select();
		    document.f1.emailId.focus();	
			return;
		}		
	else if(mRegtype == "2")
		{
			mFirstName = document.f1.elements["mfirstname[]"];
			mMiddleName = document.f1.elements["mmiddlename[]"];
			mLastName = document.f1.elements["mlastname[]"];
			mAge  = document.f1.elements["mage[]"];
			mEmailID  = document.f1.elements["memailId[]"];
			mOccupation  = document.f1.elements["moccupation[]"];
			mDesignation  = document.f1.elements["mDesgn[]"];
			mOrganization  = document.f1.elements["mOrgn[]"];
			mCourse  = document.f1.elements["mCourse[]"];
			mBranch  = document.f1.elements["mBranch[]"];
			mInstitute  = document.f1.elements["mInstitute[]"];
			mRelation  = document.f1.elements["mrelation[]"];
			mMbNo  = document.f1.elements["mmbNo[]"];
			mGender = document.f1.elements["mgender[]"];
			mCategory = document.f1.elements["mcategory[]"];
			mAccommodation = document.f1.elements["maccomdation[]"];
		    if(mFirstName != null)
			{
					for(i =1; i< mFirstName.length; i++)
					{
					
					
						if (!mCategory[i].value.replace(/^\s*|\s*$/g,""))
						{  
							alert("Please select the category of group member " + i ); 
							mCategory[i].focus();	
							return;
						}
						else if (!mAccommodation[i].value.replace(/^\s*|\s*$/g,""))
						{  
							alert("Please select the proper option regarding accommodation for group member " + i );  
							mAccommodation[i].focus();	
							return;
						}
						else if (!mFirstName[i].value.replace(/^\s*|\s*$/g,""))
						{  
							alert("Please enter the first name of group member " + i );  
						   mFirstName[i].select();	
						   mFirstName[i].focus();	
							return;
						}
						else if (!mLastName[i].value.replace(/^\s*|\s*$/g,""))
						{  
							alert("Please enter the last name of group member " + i );  
						    mLastName[i].select();	
						    mLastName[i].focus();	
							return;
						}
						else if (!mAge[i].value.replace(/^\s*|\s*$/g,""))
						{  
							alert("Please enter the age of group member " + i );  
						    mAge[i].select();	
						    mAge[i].focus();	
							return;
						}						
						else if (checkNum(mAge[i])==0)
						    {
						  		alert("Please enter the correct age of group member " + i ); 
							    mAge[i].select();	
							    mAge[i].focus();	
								return;
						    }
						else if (mAge[i].value < 0 || mAge[i].value > 200)
							{  
								alert("Please enter the correct age of group member " + i ); 
								mAge[i].select();	
							    mAge[i].focus();	
								return;
							}
						MemSelectedCategory(i);
						switch(mCategory[i].value)
						{
								case "Student":
									if (!mCourse[i].value.replace(/^\s*|\s*$/g,""))
									{  
										alert("Please enter the course of study of group member " + i );  
										mCourse[i].select();
										mCourse[i].focus();	
										return;
									}			
									else if (!mBranch[i].value.replace(/^\s*|\s*$/g,""))
									{  
										alert("Please enter the branch of study of group member " + i );  
										mBranch[i].select();
										mBranch[i].focus();	
										return;
									}
								else if (!mInstitute[i].value.replace(/^\s*|\s*$/g,""))
									{  
										alert("Please enter the institute of study of group member " + i ); 
										mInstitute[i].select();
										mInstitute[i].focus();	
										return;
									}					
									break;
									break;
								case "Non-Student":
								case "Sponsored":
									if (!mOccupation[i].value.replace(/^\s*|\s*$/g,""))
									{  
										alert("Please enter the occupation of group member " + i ); 
										mOccupation[i].select();
										mOccupation[i].focus();	
										return;
									}
									else if (!mOrganization[i].value.replace(/^\s*|\s*$/g,""))
									{  
										alert("Please enter the organization of group member " + i ); 
										mOrganization[i].select();
										mOrganization[i].focus();	
										return;
									}										
									else if (!mDesignation[i].value.replace(/^\s*|\s*$/g,""))
									{  
										alert("Please enter the designation of group member " + i );  
										mDesignation[i].select();
										mDesignation[i].focus();	
										return;
									}												
									break;
						}		
						if (!mRelation[i].value.replace(/^\s*|\s*$/g,""))
						{  
							alert("Please enter the relationship of group member" + i +" with first person (i.e. group leader)." );  
						    mRelation[i].select();	
						    mRelation[i].focus();	
							return;
						}
						else if ((mEmailID[i].value==null)||(mEmailID[i].value=="")){
							alert("Please enter the email ID of  group member " + i )
							mEmailID[i].select();
							mEmailID[i].focus();
							return;
						}
						else if (!ValidateemailID(mEmailID[i]))
					    {
							alert("Please enter the correct email ID of group member " + i )
					  		mEmailID[i].select();		
					  		mEmailID[i].focus();		
							return;
						}
						else if (!mGender[i].value.replace(/^\s*|\s*$/g,""))
						{  
							alert("Please select the gender of group member " + i );  
							mGender[i].focus();	
							return;
						}						
						else if (!mMbNo[i].value.replace(/^\s*|\s*$/g,""))
					   {  
						
							alert("Please enter the mobile no. of group member " + i );  
							mMbNo[i].select();
							mMbNo[i].focus();	
								return;
					   }
						else if (checkNum(mMbNo[i])==0)
						{
								alert("Please enter the correct  mobile no. of group member " + i );  
								mMbNo[i].select();
								mMbNo[i].focus();	
								return;
						}
						
						
					}		

				}
			
		}
	if(document.getElementById('DDPay').checked == true)
		{
			mPayTypeInfo = 'DD';	
		}
	else if(document.getElementById('netBankPay').checked == true)
	{
			mPayTypeInfo = 'transaction';	
	}
	else
	{
		alert("Please select fee payment type.");
	}
	 if (!document.f1.ddno.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter the "+ mPayTypeInfo +" no.");  
		    document.f1.ddno.select();	
		    document.f1.ddno.focus();	
			return;
		}
/*	else if (checkNum(document.f1.ddno)==0)
	    {
	  		alert("Please enter the correct "+ mPayTypeInfo +" no.");  
	  		document.f1.ddno.select();
		    document.f1.ddno.focus();	
			return;
		}	*/
	else if (!document.f1.ddamount.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter the "+ mPayTypeInfo +" amount");  
		    document.f1.ddamount.select();
		    document.f1.ddamount.focus();	
			return;
		}
	else if (checkNum(document.f1.ddamount)==0)
	    {
	  		alert("Please enter the correct "+ mPayTypeInfo +" amount");  
	  		document.f1.ddamount.select();
		    document.f1.ddamount.focus();	
			return;
		}
	else if (!document.f1.bkname.value.replace(/^\s*|\s*$/g,""))
	  	{  
			alert("Please enter the bank name");  
		    document.f1.bkname.select();
		    document.f1.bkname.focus();	
			return;
		}
	else 
		{
				var mChecked = false;
				mPastConfDetails  = document.f1.elements["prevConf[]"];
				for (i = 1; i < mPastConfDetails.length; i++)
				{
					if( mPastConfDetails[i].checked) 
					{
						mChecked = true;
						break;
					}
				}
				if(!mChecked)
				{
					alert("Please enter the details of past AISSQ conferences attended");
					mPastConfDetails[1].focus();
					return;	
				}		
		} 
	//check dd amount
	if(!ValidateDDAmount())
	{
		return;
	}
	
	
	if(mConfirmMsgSent == 0)
	{
			alert("Please check your email ID again. \n An invalid email ID will result in cancellation of your registration.")
			document.f1.emailId.select();
			document.f1.emailId.focus();
			mConfirmMsgSent =1;
	}
	else
	{
			//confirm message sent once
			if(mConfirmMsgSent)
			{
					document.f1.action = "Files/appadd.php";
					document.f1.submit();
			}
	}	   
}

function changeAmountType()
{	
	
	if(document.f1.txtcountry.value == "India")
	{
		document.getElementById("netBankPay").disabled = false;	
document.getElementById("netBankingText").innerHTML = "Net Banking (only for Indian participants)";		
		document.getElementById("amountText").innerHTML = mPayType +" (in Rs):<font color='Red'>* </font>";
		unitDDAmount = "Rs ";
	}
	else
	{			
		document.getElementById("netBankPay").disabled = true;
		document.getElementById("netBankingText").innerHTML = "<span style ='color:gray'>Net Banking (only for Indian participants)</span>";
		document.getElementById("DDPay").checked = true;
		mPayType = 'DD Amount';
		document.getElementById('payDetails').innerHTML = 'DD Details';
		document.getElementById('ddNoText').innerHTML = 'DD No:';
		document.getElementById('ddDateText').innerHTML = 'DD Date:';
		document.getElementById("amountText").innerHTML = mPayType +" (in US $):<font color='Red'>* </font>";
		unitDDAmount = "$(USD) ";
	}
}

//return false if wrong amount
function ValidateDDAmount()
{

	mInvAmount = 0;	
	if(document.f1.txtcountry.value == "India")
	{
	//indivi
		switch (document.f1.indu_category.value) 
		{
				case "Student" : 
					if(document.f1.indu_accomdation.value == "Yes")
					{
						//with accomdation amount 
						mInvAmount =  IndianSudentWithAccom;
					}
					else
					{
						//without accomdation amount 
						mInvAmount =  IndianSudentWithoutAccom;
					}
					break;
				case "Non-Student":  mInvAmount = IndianNonSudent; break;
				case "Sponsored": mInvAmount = IndianSponsered;
		}
		//check for group
		if(mRegtype == "2")
		{
			mGroupMemAmont = 0;
			mFirstName = document.f1.elements["mfirstname[]"];
			mMiddleName = document.f1.elements["mmiddlename[]"];
			mLastName = document.f1.elements["mlastname[]"];
			mAge  = document.f1.elements["mage[]"];
			mEmailID  = document.f1.elements["memailId[]"];
			mOccupation  = document.f1.elements["moccupation[]"];
			mRelation  = document.f1.elements["mrelation[]"];
			mMbNo  = document.f1.elements["mmbNo[]"];
			mGender = document.f1.elements["mgender[]"];
			mCategory = document.f1.elements["mcategory[]"];
			mAccommodation = document.f1.elements["maccomdation[]"];
		    if(mFirstName != null)
			{
					for(i =1; i< mFirstName.length; i++)
					{
						if(mAge[i].value < 12)
						{
						//child < 12
							switch (mCategory[i].value) 
							{
									case "Student" :										
											mGroupMemAmont =  IndianChildStudentBelow12;
										
										break;
									default:  mGroupMemAmont = IndianChildNonStudentBelow12; break;
							}
						}
						else
						{
						
							switch (mCategory[i].value) 
							{
									case "Student" : 
										if(mAccommodation[i].value == "Yes")
										{
											
											mGroupMemAmont =  IndianSudentWithAccom;
										}
										else
										{
											
											mGroupMemAmont =  IndianSudentWithoutAccom;
										}
										break;
									case "Non-Student":  mGroupMemAmont = IndianNonSudent; break;
									case "Sponsored": mGroupMemAmont = IndianSponsered;
							}
							
						}
						
						mInvAmount = mInvAmount + mGroupMemAmont;
					}//for
			}
		}
	}
	else
	{//abroad
		//indiv
		switch (document.f1.indu_category.value) 
		{
				case "Student" : 
					if(document.f1.indu_accomdation.value == "Yes")
					{
						//with accomdation amount 
						mInvAmount = AbroadSudentWithAccom;
					}
					else
					{
						//without accomdation amount 
						mInvAmount =  AbroadSudentWithoutAccom;
					}
					break;
				case "Non-Student":  mInvAmount = AbroadNonSudent; break;
				case "Sponsored": mInvAmount = AbroadSponsered;
		}
		//check for group
		if(mRegtype == "2")
		{
			mGroupMemAmont = 0;
			mFirstName = document.f1.elements["mfirstname[]"];
			mMiddleName = document.f1.elements["mmiddlename[]"];
			mLastName = document.f1.elements["mlastname[]"];
			mAge  = document.f1.elements["mage[]"];
			mEmailID  = document.f1.elements["memailId[]"];
			mOccupation  = document.f1.elements["moccupation[]"];
			mRelation  = document.f1.elements["mrelation[]"];
			mMbNo  = document.f1.elements["mmbNo[]"];
			mGender = document.f1.elements["mgender[]"];
			mCategory = document.f1.elements["mcategory[]"];
			mAccommodation = document.f1.elements["maccomdation[]"];
		    if(mFirstName != null)
			{
					for(i =1; i< mFirstName.length; i++)
					{
						if(mAge[i].value < 12)
						{
							//child < 12
							switch (mCategory[i].value) 
							{
									case "Student" : 
										
											mGroupMemAmont =  AbroadChildStudentBelow12;
										
										break;
									default:  mGroupMemAmont = AbroadChildNonStudentBelow12; break;
							}
						}
						else
						{
						
							switch (mCategory[i].value) 
							{
									case "Student" : 
										if(mAccommodation[i].value == "Yes")
										{
											
											mGroupMemAmont =  AbroadSudentWithAccom;
										}
										else
										{
											
											mGroupMemAmont =  AbroadSudentWithoutAccom;
										}
										break;
									case "Non-Student":  mGroupMemAmont = AbroadNonSudent; break;
									case "Sponsored": mGroupMemAmont = AbroadSponsered;
							}
							
						}
						//alert(mGroupMemAmont);
						mInvAmount = mInvAmount + mGroupMemAmont;
					}//for
			}
		}
	}
	
	if(document.f1.ddamount.value != mInvAmount)
	{
		alert("The "+ mPayTypeInfo +" amount should be "+ unitDDAmount + mInvAmount);
		document.f1.ddamount.select();
		document.f1.ddamount.focus();
		return false;
	}
	return true;	
}

function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0 || year < 2009 || year > 2010) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, No error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if No error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      //alert("Date is incorrect!");
      //DateField.select();
	  //DateField.focus();
	  return 0;
   }
}

//validate integer data
function checkNum(x)
{
   var s_len=x.value.length ;
   var s_charcode = 0;
     for (var s_i=0;s_i<s_len;s_i++)
     {
     s_charcode = x.value.charCodeAt(s_i);
      if(!((s_charcode>=48 && s_charcode<=57)))
       { 
           x.value='';
         x.focus();
         return false;
       }
     }
     return true;
}

//validate integer data
function checkPhoneNo(x)
{
   var s_len=x.value.length ;
   var s_charcode = 0;
     for (var s_i=0;s_i<s_len;s_i++)
     {
     s_charcode = x.value.charCodeAt(s_i);
      if(!((s_charcode>=48 && s_charcode<=57)) && s_charcode != 45)
       { 
           x.value='';
         x.focus();
         return false;
       }
     }
     return true;
}

var bugchars = '!#$^&*()+|}{[]?><~%:;/,=`"\'';
function CharsInBag(s)
{   var i;
var lchar="";
    // Search through string's characters one by one.
    // If character is not in bag.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
		if(i>0)lchar=s.charAt(i-1)
        if (bugchars.indexOf(c) != -1 || (lchar=="." && c==".")) return false;
    }
    return true;
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is not a number.
        var c = s.charAt(i);
        if ((c >= "0") && (c <= "9") && (c != ".")) return false;
    }
    // All characters are numbers.
    return true;
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var lastdot=str.lastIndexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert("Invalid E-mail ID")
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.substring(lastdot+1)==""){
		    //alert("Invalid E-mail ID")
		    return false;
		}
		 
		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		   // alert("Invalid E-mail ID")
		    return false;
		 }
		if(CharsInBag(str)==false){
		    //alert("Invalid E-mail ID")
		    return false;
		 }
		 var arrEmail=str.split("@")
		 var ldot=arrEmail[1].indexOf(".")
		 if(isInteger(arrEmail[1].substring(ldot+1))==false){
		    //alert("Invalid E-mail ID")
		    return false;
		 }
 		 return true;					
	}
	
	
	function ValidateemailID(emailID){
	
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }
