
function addOrModifyNewUserDetails(formName, userID, action)
{
	var fullName, day, month, year, sex, education, monthlyIncome, totalSiblings, brothers, sisters, siblingsMartial, fatherName, motherName, contactName;
	var	landlineNumber, mobileNumber, contactAddress, emailID, password, cpassword, terms, height, complexion, profession, annualIncome, religion, prefAgeFrom, prefAgeTo, error = '', q = 0;
	var fatherProfession, motherProfession, fatherRetired, motherRetired;
	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
	obj = document.getElementById(formName);
		
	fullName = document.getElementById("fullName").value.trim();
	day = document.getElementById("dateSelect").value;
	month = document.getElementById("monthSelect").value;
	year = document.getElementById("yearSelect").value;
	sex = document.getElementById("sex").value;
	education = document.getElementById("education").value;
	monthlyIncome = document.getElementById("monthlyIncome").value;
	fatherName = document.getElementById("fatherName").value;
	motherName = document.getElementById("motherName").value;	
	fatherProfession = document.getElementById("fatherProfession").value;
	motherProfession = document.getElementById("motherProfession").value;
	fatherRetired = document.getElementById("fatherRetired").value;
	motherRetired = document.getElementById("motherRetired").value;	
	prefAgeFrom = document.getElementById("prefAgeFrom").value;
	prefAgeTo = document.getElementById("prefAgeTo").value;
	totalSiblings = document.getElementById("siblings").value;
	brothers = document.getElementById("brothers").value;
	sisters = document.getElementById("sisters").value;
	siblingsMartial = document.getElementById("siblingsMartial").value;
	contactName = document.getElementById("contactName").value;
	landlineNumber = document.getElementById("landlineNumber").value;
	mobileNumber = document.getElementById("mobileNumber").value;
	contactAddress = document.getElementById("contactAddress").value;
	height = document.getElementById("height").value;
	complexion = document.getElementById("complexion").value;
	profession = document.getElementById("profession").value;
	annualIncome = document.getElementById("annualIncome").value;
	religion = document.getElementById("religion").value;
			

	//validation for fullName--starts here
	if(fullName == '')		
		error = error +"- Enter Name \n";	

	if(fullName != '' && !alphanumericwithspacedot(fullName))
		error = error +"- Name can accept alphabets, numbers, dot & single space b/w two words Only \n";
	//validation for fullName--ends here
	
	//validation for day--starts here
	if(!isSelected(day) || !isSelected(month) || !isSelected(year))
		error = error +"- Select a valid DOB \n"; 	
	//validation for day--ends here	
	
	//validation for sex--starts here
	if(!isSelected(sex))
		error = error +"- Select a Sex \n";	
	//validation for sex--ends here	
	
	//validation for complexion--starts here
	if(!isSelected(complexion))
		error = error +"- Select a Complexion \n";	
	//validation for complexion--ends here	
	
	//validation for height--starts here
	if(!isSelected(height))
		error = error +"- Select a Height \n";	
	//validation for height--ends here	
	
	//validation for religion--starts here
	if(religion == '')		
		error = error +"- Enter Religion \n";	

	if(religion != '' && !alphawithspacehypendot(religion))
		error = error +"- Religion can accept alphabets, hypen, dot & single space b/w two words Only \n";
	//validation for religion--ends here		
	
	//validation for education--starts here
	if(!isSelected(education))
		error = error +"- Select a Education \n";	
	//validation for education--ends here	
	
	//validation for profession--starts here
	if(!isSelected(profession))
		error = error +"- Select a Profession Area \n";	
	//validation for profession--ends here
	
	//validation for monthlyIncome--starts here		
	if(monthlyIncome != '' && !numeric(monthlyIncome))
		error = error +"- Monthly Income can accept numbers Only \n";
	//validation for monthlyIncome--ends here
			
	//validation for fatherName--starts here	
	if(fatherName == '')		
		error = error +"- Enter Father Name \n";
		
	if(fatherName != '' && !alphanumericwithspacedot(fatherName))
		error = error +"- Father Name can accept alphabets, numbers, dot & single space b/w two words Only \n";
	//validation for fatherName--ends here
	
	//validation for motherName--starts here
	if(motherName == '')		
		error = error +"- Enter Mother Name \n";
			
	if(motherName != '' && !alphanumericwithspacedot(motherName))
		error = error +"- Mother Name can accept alphabets, numbers, dot & single space b/w two words Only \n";
	//validation for motherName--ends here	
	
	//validation for siblings--starts here		
	if(totalSiblings > 0)
	{
		var tempSiblings = parseInt(brothers) + parseInt(sisters);
		
		if(!isSelected(brothers) && !isSelected(sisters) && !isSelected(siblingsMartial))
			error = error +"- Select a brother(s) or sister(s) and their martial status \n";
		
		if((brothers > 0 || sisters >0) && totalSiblings != tempSiblings)
			error = error +"- Invalid brother(s) or sister(s) selected count \n";
			
		if((brothers > 0 || sisters >0) && !isSelected(siblingsMartial))
			error = error +"- Select siblings martial status \n";
	}	
	//validation for siblings--ends here	
	
	//validation for fatherRetired--starts here	
	if(fatherRetired != '-1' && fatherProfession == '-1')
		error = error +"- Select a Father Profession \n";	
		
	if(fatherRetired != '-1' && fatherProfession == '27')
		error = error +"- Select a different father profession or unselect retired option \n";	
	//validation for fatherRetired--ends here
	
	//validation for motherRetired--starts here
	if(motherRetired != '-1' && motherProfession == '-1')
		error = error +"- Select a Mother Profession \n";
		
	if(motherRetired != '-1' && motherProfession == '27')
		error = error +"- Select a different mother profession or unselect retired option \n";	
	//validation for motherRetired--ends here	
	
	//validation for prefAgeFrom--starts here		
	if(prefAgeFrom != '' && !numeric(prefAgeFrom))
		error = error +"- My preference from age can accept numbers Only \n";
	//validation for prefAgeFrom--ends here
	 
	//validation for prefAgeTo--starts here		
	if(prefAgeTo != '' && !numeric(prefAgeTo))
		error = error +"- My preference to age can accept numbers Only \n";
	//validation for prefAgeTo--ends here
	
	//validation for prefAge--starts here		
	if(prefAgeFrom > prefAgeTo)
		error = error +"- My preference to age should be greater than from age \n";
	//validation for prefAge--ends here
	
	//validation for contactName--starts here
	if(contactName == '')		
		error = error +"- Enter Contact Name \n";
			
	if(contactName != '' && !alphanumericwithspacedot(contactName))
		error = error +"- Contact Name can accept alphabets, numbers, dot & single space b/w two words Only \n";
	//validation for contactName--ends here
	
	//validation for landlineNumber--starts here
	if(landlineNumber == '')		
		error = error +"- Enter Phone \n";
		
	if(landlineNumber != '' && !numericwithhypen(landlineNumber))
		error = error +"- Phone can accept numbers Only \n";
	//validation for landlineNumber--ends here
	
	//validation for mobileNumber--starts here
	if(mobileNumber == '')		
		error = error +"- Enter Mobile \n";
		
	if(mobileNumber != '' && !numericwithhypen(mobileNumber))
		error = error +"- Mobile can accept numbers Only \n";
	//validation for mobileNumber--ends here
	
	//validation for contactAddress--starts here
	if(contactAddress == '')		
		error = error +"- Enter Contact Address \n";
	//validation for contactAddress--ends here	
	
	
	if(userID == 0)
	{
		emailID = document.getElementById("emailID").value;
		password = document.getElementById("accountPassword").value;	
		cpassword = document.getElementById("confirmPassword").value;	
		terms = document.getElementById("terms").checked;
	
		//validation for emailID--starts here
		if(emailID == '')		
			error = error +"- Enter EmailID \n";
			
		if(emailID != '' && !checkMailId(emailID))
			error = error +"- Enter Valid Email ID \n";
		//validation for emailID--ends here
		
		//validation for password--starts here
		if(password == '')	
			error = error +"- Enter Password \n";
		//validation for password--ends here
			
		//validation for cpassword--starts here
		if(cpassword == '')	
			error = error +"- Enter Confirm Password \n";
		//validation for password--ends here
			
		//validation for password and cpassword--starts here
		if ((password != '' && (password.length < 6) || (password.length > 15)))
	       error = error + "- Password only accepts from 6-15 characters \n";  
	       
		if(password!='' && cpassword!='' &&  password != cpassword) 
		   error = error +"- Your passwords did not match. Please retype.\n";	 	  
		//validation for password and cpassword--ends here	
		
		//validation for terms--starts here
		if(terms == false)	
			error = error +"- Select Terms & Conditions \n";
		//validation for terms--ends here	
	}	

	if(error!=null && error!='')
			alert(error);	
	else	
	{			
		if(userID !=null && userID != '')
		{
			obj.methodId.value = "1006";
			obj.docID.value = userID;
		}
		else
			obj.methodId.value = "1003";
			
		obj.formAction.value = action;
		
		if(action == 'editProfile')
		{
			obj.page.value = "UserRegistration";
			obj.viewmethodId.value = "1005"; 
			obj.submit();
			alert('Your profile has been updated successfully.');  
		}
		else if(action == 'newRegistration')
		{
			obj.page.value = "Thanks";
			obj.viewmethodId.value = "1019"; 
			obj.submit();			
		}
		else
		{
			obj.page.value = "UsersList";
			obj.viewmethodId.value = "1001";
			obj.submit();
		}						
	}	
}


function deleteSelectedUsers(formName)
{
	obj = document.getElementById(formName);
	var flag = false;
	for (var i=0; i<obj.elements.length; i++)
	{
		if(obj.elements[i].checked == true)
			flag=true;
	}	 
		
	if(!flag)
		alert("Select a user(s) to Delete");
	else
	{
		var agree = confirm("Are you sure wish to Delete?");
		if(agree)
		{		 
			obj.methodId.value = "1004";
			obj.page.value = "UsersList";					
			obj.viewmethodId.value = "1001";  
			obj.submit();	   	
		}
		else
			return;
	}		
}

//show or hide siblings details
function siblingsChage(selectedValue)
{
	if(selectedValue > 0)
		document.getElementById('siblingsDetails').style.display = 'block';
	else
		document.getElementById('siblingsDetails').style.display = 'none';

}

function cancelRegistration(formName)
{	
	obj = document.getElementById(formName);
	obj.methodId.value = "1001";
	obj.page.value = "UsersList";
	obj.formAction.value = "cancelReg";					
	obj.submit();	 
}

function getUserDetailsById(formname, userID)
{	
	obj = document.getElementById(formname);
	obj.methodId.value = "1005";
	obj.page.value = "UserRegistration";
	obj.docID.value = userID;
	obj.submit();
}

function userActivateOrDeactivate(formName, action, isActive)
{
	obj = document.getElementById(formName);
	var flag = false;
	for (var i=0; i<obj.elements.length; i++)
	{
		if(obj.elements[i].checked == true)
			flag=true;
	}	 
		
	if(!flag)
	{
		if(action == 'activate')
			alert("Select a user(s) to Activate");
		if(action == 'deactivate')
			alert("Select a user(s) to Deactivate");
	}
	else
	{
		var agree = '';
		if(action == 'activate')
			agree = confirm("Are you sure wish to Activate?");
		if(action == 'deactivate')
			agree = confirm("Are you sure wish to Deactivate?");

		if(agree)
		{		 
			obj.methodId.value = "1007";
			obj.activateOrDeactivate.value = isActive;
			obj.page.value = "UsersList";					
			obj.viewmethodId.value = "1001";   
			obj.submit();	   	
		}
		else
			return;
	}		
}

function doAction(page, methodId)  
{
	href= "controlservlet";	
	document.getElementById('usersListForm').action = href;
	document.getElementById('usersListForm').page.value = page;
	document.getElementById('usersListForm').methodId.value = methodId;		
	document.getElementById('usersListForm').submit();

}

function newRegistrationPage(formName, page, methodId, formaction)  
{	
	document.getElementById(formName).page.value = page;
	document.getElementById(formName).methodId.value = methodId;	
	document.getElementById(formName).formAction.value = formaction;	
	document.getElementById(formName).actionPage.value = "NewRegistrationPage";	
	document.getElementById(formName).submit();
}

function redirectToWelcomePage(formName)
{	
	obj = document.getElementById(formName);
	obj.methodId.value = "1014";
	obj.page.value = "Welcome";
	obj.formAction.value = "gotoWelcome";					
	obj.submit();	 		
}

function doPagingAction(pageno, pagingaction) 
{ 
	var pageNo, error = '';
	if(pagingaction == 'goToPage')
	{
		String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
		pageNo = document.getElementById("pageNumber").value.trim();
		
		if(pageNo == '')
			error = error +"- Enter Page No";  
		if(pageNo != '' && !numeric(pageNo))
			error = error +"- Page No can accept numbers only";
	}
	
	if(error!=null && error!='')
			alert(error);		
	else
	{
		href= "controlservlet";	
		document.getElementById('usersListForm').action = href;
		document.getElementById('usersListForm').page.value = "UsersList";
		document.getElementById('usersListForm').methodId.value = "1001";		
		document.getElementById('usersListForm').pageNo.value = pageno;
		document.getElementById('usersListForm').formAction.value = pagingaction;
		document.getElementById('usersListForm').submit();    
	}
}

function fetchListBy(formName)
{
	obj = document.getElementById(formName);	
	if(isSelected(document.getElementById("fetchBy").value))
	{		
		obj.methodId.value = "1001";
		obj.formAction.value = "fetchBy";	
		obj.page.value = "UsersList";						
		obj.submit();   			
	}	
}

function profileIDSearchEnterKeyPressed(event)
{
	if(event.keyCode==13)			
		searchByProfileID('usersListForm');		
}

function searchByProfileID(formname)
{	 
	var error = '', profileID;
	
	profileID = document.getElementById("profileID").value; 
	
	//validation for profileID--starts here
	if(profileID == '')		
		error = error +"- Enter Profile ID \n";
		
	if(profileID != '' && !numeric(profileID))
		error = error +"- Profile ID can accept Numbers Only \n";
	//validation for profileID--ends here
	
	if(error!=null && error!='')
			alert(error);		
	else		
		getUserDetailsById(formname, profileID);	
}