// 
// Filename : AllJavaScript.js
// Author : Han Hanafi
// Just for validation



function CheckingWhitespaces(inString)
{
	var theLength = inString.length;
	var count = 0;
	if (theLength == 0) {
		return false;
	}
	
	if (theLength > 0) {
		for (var i = 0; i < theLength; i++) {			
			if (inString.charAt(i) == " ") {
				count++;
			}
		}

		if (count == theLength) {
			return false;
		}
	}
	
	return true;
}//CheckingWhitespaces


function validateLength(inString, inLimit)
{
	var theLength = inString.length;
	if (theLength < inLimit) {
		return false;
	}

	return true
}//validateLength



function validateEmailAddress(inString)
{
	var theLength = inString.length;

	if (theLength == 0) {
		return false;
	}

	if (theLength > 0) {
		var findAt = inString.indexOf("@");
		var findDot = inString.indexOf(".");
		
		if (findAt == -1 || findDot == -1) {
			return false;
		}
	}
	
	return true;	
}//validateEmailAddress


function ValidateAll()
{
	var GenericString = document.Registration.first.value;
	var response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out Your First Name!");

		document.Registration.first.focus();
		
		return false;
	}

	GenericString = document.Registration.last.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out Your Last Name!");

		document.Registration.last.focus();
		
		return false;
	}

	GenericString = document.Registration.title.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Enter Your Title!");

		document.Registration.title.focus();
		
		return false;
	}

	GenericString = document.Registration.email.value;
	response = validateEmailAddress(GenericString);
	if (response == false) {
		alert("Please Provide Us a Valid Email Address!");

		document.Registration.email.focus();
		
		return false;
	}

	GenericString = document.Registration.company.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Enter Your Company Name!");

		document.Registration.company.focus();
		
		return false;
	}

	GenericString = document.Registration.address1.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete Your Address!");

		document.Registration.address1.focus();
		
		return false;
	}

	GenericString = document.Registration.city.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete the City of Your Address");

		document.Registration.city.focus();
		
		return false;
	}

	GenericString = document.Registration.state.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete the State of Your Address");

		document.Registration.state.focus();
		
		return false;
	}

	GenericString = document.Registration.zip.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete the Zip of Your Address");

		document.Registration.zip.focus();
		
		return false;
	}

	GenericString = document.Registration.phone.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete Your Phone Number");

		document.Registration.phone.focus();
		
		return false;
	}

	GenericString = document.Registration.fax.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete Your Fax Number");

		document.Registration.fax.focus();
		
		return false;
	}

	GenericString = document.Registration.username.value;
	response = ValidateUserName(GenericString);
	if (response == false) {
		alert("Please Fill Your Username Name With At least 6 characters!" + 
		"\nYou can use letters, digits, and others but NOT spaces!");
		
		document.Registration.username.focus();
		return false;
	}

	GenericString = document.Registration.password.value;	
	response = ValidateUserName(GenericString);
	if (response == false) {
		alert("Please Fill Your Password With At least 6 characters!" + 
		"\nYou can use letters, digits, and others but NOT spaces!");
		
		document.Registration.password.focus();
		return false;
	}
	
	var Reconfirmpass = document.Registration.repassword.value;		
	if (GenericString != Reconfirmpass) {
		alert("Please Retype Your Password Exacly the Same as Your Password Above!");

		document.Registration.repassword.focus();
		return false;
	}


	return true;
}//ValidateAll


function validateNumber(inString)
{	
	if (isNaN(inString)) {
		
		return false;
	}

	return true;	
}//validateNumber


function ValidateUserName(inString)
{
	var theLength = inString.length;
	var count = 0;

	if (theLength < 6) {
		return false;
	}

	var findSpc = inString.indexOf(" ");
	if (findSpc != -1) {
		return false;
	}

	return true;
}//ValidateUserName


function ValidatePro()
{
	var GenericString = document.Registration.first.value;
	var response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out Your First Name!");

		document.Registration.first.focus();
		
		return false;
	}

	GenericString = document.Registration.last.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out Your Last Name!");

		document.Registration.last.focus();
		
		return false;
	}

	var SelectedIndex = document.Registration.BestPosition.selectedIndex;
	GenericString = document.Registration.BestPosition.options[SelectedIndex].value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Select the Best Position to Describe About Yourself for us!");
		document.Registration.BestPosition.focus();			
		return false;
	}

	
	if (GenericString == "Appraiser") {
		GenericString = document.Registration.license.value;
		response1 = CheckingWhitespaces(GenericString);
		response2 = GenericString.length;
		if (response1 == false) {
			alert("Since you are an Appraiser, please enter your valid License No!");
			document.Registration.license.focus();

			return false;
		}

		//check the expiration
		GenericString = document.Registration.LicExpiration.value;
		response1 = CheckingWhitespaces(GenericString);
		response2 = GenericString.length;
		response = ValidateDate(GenericString)
		if (response == false || response1 == false || response2 < 6) {
			alert("Please Enter valid Expiration Date of your License, e.g 12/30/09!");
			document.Registration.LicExpiration.focus();

			return false;
		}

	} 
	

	GenericString = document.Registration.ssn.value;
	response = CheckingWhitespaces(GenericString);
	response1 = validateNumber(GenericString);
	var response2 = validateLength(GenericString, 9);//min length, which is from SSN
	if (response == false || response1 == false || response2 == false) {
		alert("Please Enter Your Valid Social Security Or Tax ID Number!\n (Number Only; no dash, space, etc)");

		document.Registration.ssn.focus();
		
		return false;
	}

	GenericString = document.Registration.homephone.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete Your Home Phone Number");

		document.Registration.homephone.focus();
		
		return false;
	}

	GenericString = document.Registration.officephone.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete Your Office Phone Number");

		document.Registration.officephone.focus();
		
		return false;
	}

	GenericString = document.Registration.officefax.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete Your Office Fax Number");

		document.Registration.officefax.focus();
		
		return false;
	}


	GenericString = document.Registration.email.value;
	response = validateEmailAddress(GenericString);
	if (response == false) {
		alert("Please Provide Us a Valid Email Address!");

		document.Registration.email.focus();
		
		return false;
	}

	GenericString = document.Registration.company.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Enter Your Company Name!");

		document.Registration.company.focus();
		
		return false;
	}

	/****
	GenericString = document.Registration.taxID.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Enter Your Company Tax ID!");

		document.Registration.taxID.focus();
		
		return false;
	}
	****/


	GenericString = document.Registration.address1.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete Your Company Address!");

		document.Registration.address1.focus();
		
		return false;
	}

	GenericString = document.Registration.city.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete the City of Your Office Address");

		document.Registration.city.focus();
		
		return false;
	}

	GenericString = document.Registration.state.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete the State of Your Office Address");

		document.Registration.state.focus();
		
		return false;
	}

	GenericString = document.Registration.zip.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Complete the Zip Code of Your Office Address");

		document.Registration.zip.focus();
		
		return false;
	}

	response1 = document.Registration.paymentindividual.checked;
	response2 = document.Registration.paymentcompany.checked;
	if (response1 == false && response2 == false) {

		alert("Please select of how the payment should be made to!");
		document.Registration.paymentindividual.focus();

		return false;
	}
	

	GenericString = document.Registration.username.value;
	response = ValidateUserName(GenericString);
	if (response == false) {
		alert("Please Fill Your Username Name With At least 6 characters!" + 
		"\nYou can use letters, digits, and others but NOT spaces!");
		
		document.Registration.username.focus();
		return false;
	}

	GenericString = document.Registration.password.value;	
	response = ValidateUserName(GenericString);
	if (response == false) {
		alert("Please Fill Your Password With At least 6 characters!" + 
		"\nYou can use letters, digits, and others but NOT spaces!");
		
		document.Registration.password.focus();
		return false;
	}
	
	var Reconfirmpass = document.Registration.repassword.value;		
	if (GenericString != Reconfirmpass) {
		alert("Please Retype Your Password Exacly the Same as Your Password Above!");

		document.Registration.repassword.focus();
		return false;
	}
}//ValidatePro



function ValidateDate(inString)
{

	var theArrayVal = inString.split("/");

	if (theArrayVal.length < 3) {
		return false;
	} else {
		if (isNaN(theArrayVal[0]+theArrayVal[1]+theArrayVal[2]) == true ||
			parseInt(theArrayVal[0]) > 12 || parseInt(theArrayVal[1]) > 31) {// || parseInt(theArrayVal[2]) < 6) {
			return false;
		} else {
			return true;
		}
	}



}//DateCheck



function CancelRegistration()
{
	if (confirm("Please take a note. \nBy clicking cancel, it will delete your submitted data! \n Are you sure you want to cancel your registration?")) {
		document.Questionaire.eflag.value = 13;

		document.Questionaire.submit();
	}
}//CancelRegistration


function ValidateQuestionaire()
{
	var response;
	var theString;
	//alert(document.Questionaire.yesexp_noexp[0].value + " and " + document.Questionaire.yesexp_noexp[1].value);
	if (document.Questionaire.yesexp_noexp[0].checked) {		
		theString = document.Questionaire.howlongperform.value;
		response1 = CheckingWhitespaces(theString);
		response2 = validateNumber(theString);
		if (response1 == false || response2 == false) {
			alert("Please enter with valid digit indicating how long you've been performing these services!");
			document.Questionaire.howlongperform.focus();

			return false;
		}

		theString = document.Questionaire.howlonglicence.value;
		response1 = CheckingWhitespaces(theString);
		response2 = validateNumber(theString);
		if (response1 == false || response2 == false) {
			alert("Please enter with valid digit indicating how long you've been with the licence!");
			document.Questionaire.howlonglicence.focus();

			return false;
		}
	}

	if (document.Questionaire.yesno_resume[0].checked == false && 
		document.Questionaire.yesno_resume[1].checked == false) {
		alert("Please indicate whether you have a resume or not!");

		return false;
	}


	return true;

}//ValidateQuestionaire



function showform()
{
	var IndexSelection = document.BPO_Deal.bpo_selection.selectedIndex;
	var SelectionVal = document.BPO_Deal.bpo_selection.options[IndexSelection].value
	if (SelectionVal != 0) {
		document.BPO_Deal.submit();
	}
}//showform






//============== Order validation ===============
function ValidateOrders(inOrderType)
{
	var GenericString = document.OrderForm.orderduedate.value;
	var response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out the Due Date of Order!");

		document.OrderForm.orderduedate.focus();
		
		return false;
	}

	
	/******** UNUSED 5/18/00
	GenericString = document.OrderForm.propertysaledate.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out the Due Date of Order!");

		document.OrderForm.propertysaledate.focus();
		
		return false;
	}
	********/

	var SelectedIndex = document.OrderForm.Purpose.selectedIndex;
	GenericString = document.OrderForm.Purpose.options[SelectedIndex].value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Select the Purpose of Your Order!");

		document.OrderForm.Purpose.focus();
		
		return false;
	}

	GenericString = document.OrderForm.clientdealnumber.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out the Client Deal Number Or Name! \n (used by us to refer to your portfolio)");

		document.OrderForm.clientdealnumber.focus();
		
		return false;
	}


	GenericString = document.OrderForm.contactname.value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Fill Out the Contact Name! \n (used by us as the identity name to assign to his or her portfolio)");

		document.OrderForm.contactname.focus();
		
		return false;
	}

	if (inOrderType == 1) {
		//order BPO
		SelectedIndex = document.OrderForm.BpoScale.selectedIndex;
		GenericString = document.OrderForm.BpoScale.options[SelectedIndex].value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Select Any one of the BPO's!");

			document.OrderForm.BpoScale.focus();
			
			return false;
		}
	} else if (inOrderType == 3) {

		//order Appraisal
		SelectedIndex = document.OrderForm.AppraisalScale.selectedIndex;
		GenericString = document.OrderForm.AppraisalScale.options[SelectedIndex].value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Select Any one of the Appraisals!");

			document.OrderForm.AppraisalScale.focus();
			
			return false;
		}
		
	} else {
		//do nothing
	}



	SelectedIndex = document.OrderForm.qty.selectedIndex;
	GenericString = document.OrderForm.qty.options[SelectedIndex].value;
	response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please Select the Quantity of Property You about to Do With ASG!");

		document.OrderForm.qty.focus();
		
		return false;
	}

	if (GenericString == "1") {

		GenericString = document.OrderForm.address1.value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Fill Out Address of the Property!");

			document.OrderForm.address1.focus();
			
			return false;
		}

		
		GenericString = document.OrderForm.city.value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Fill Out the City of Property Address!");

			document.OrderForm.city.focus();
			
			return false;
		}
		

		SelectedIndex = document.OrderForm.state.selectedIndex;
		GenericString = document.OrderForm.state.options[SelectedIndex].value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Select the State!");

			document.OrderForm.state.focus();
			
			return false;
		}


		GenericString = document.OrderForm.zip.value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Fill Out the Zip Code!");

			document.OrderForm.zip.focus();
			
			return false;
		}

		GenericString = document.OrderForm.borrowername.value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Fill Out the Borrower Name!");

			document.OrderForm.borrowername.focus();
			
			return false;
		}

		GenericString = document.OrderForm.loannumber.value;
		response = CheckingWhitespaces(GenericString);
		if (response == false) {
			alert("Please Fill Out the Borrower Name!");

			document.OrderForm.loannumber.focus();
			
			return false;
		}
	}

	return true;
}//ValidateOrders


function ValidateUpload(inObject)
{
	var GenericString = document.DataTransmitter.FILE1.value;
	var response = CheckingWhitespaces(GenericString);
	if (response == false) {
		alert("Please attach your file to be transfered by clicking Browse button!");

		return false;
	}


	
	if (inObject == 1) {
		//must be pdf or doc format
		GenericString = document.DataTransmitter.FILE1.value;	
		var upto = GenericString.length;
		var startfrom = upto - 4;	
		response = GenericString.substring(startfrom, upto);
		
		if ((response.toLowerCase() != ".pdf") && (response.toLowerCase() != ".doc")) {
			alert("Please attach your completed appraisal file to be transfered in PDF or DOC format!");

			return false;
		}
	}

	return true
}//ValidateUpload


function ValidateImagefiles()
{

	for (var i=1; i<9; i++) {
		var RawObj = eval("document.ImageTransmitter.FILE" + i);
		var GenericString = RawObj.value;
		var upto = GenericString.length;
		var startfrom = upto - 4;	
		var response = GenericString.substring(startfrom, upto);
		
		if (response.length > 1 && (response.toLowerCase() != ".jpg") && (response.toLowerCase() != ".gif")) {
			alert("Please attach your image files to be transfered in JPG or GIF format!");

			RawObj.focus();
			RawObj.style.backgroundColor = "#FFA6A6";
			return false;
		}
	}

	/****** modified 8/19/2007
	var GenericString = document.ImageTransmitter.FILE1.value;	
	var upto = GenericString.length;
	var startfrom = upto - 4;	
	var response = GenericString.substring(startfrom, upto);
	
	if ((response.toLowerCase() != ".jpg") && (response.toLowerCase() != ".gif")) {
		alert("Please attach your image files to be transfered in JPG or GIF format!");

		return false;
	}

	GenericString = document.ImageTransmitter.FILE2.value;	
	upto = GenericString.length;
	startfrom = upto - 4;	
	response = GenericString.substring(startfrom, upto);
	
	if ((response.toLowerCase() != ".jpg") && (response.toLowerCase() != ".gif")) {
		alert("Please attach your image files to be transfered in JPG or GIF format!");

		return false;
	}
	*/
	return true;
}//ValidateImagefiles




function ValidatePreferenceAdmin()
{
	var GenericString = document.AdminPreference.username.value;
	var response = ValidateUserName(GenericString);
	if (response == false) {
		alert("Please Fill Your Username Name With At least 6 characters!" + 
		"\nYou can use letters, digits, and others but NOT spaces!");
		
		document.AdminPreference.username.focus();
		return false;
	}
	
	GenericString = document.AdminPreference.email.value;
	response = validateEmailAddress(GenericString);
	if (response == false) {
		alert("Please Provide Us a Valid Email Address!");

		document.AdminPreference.email.focus();
		
		return false;
	}

	GenericString = document.AdminPreference.password.value;	
	response = ValidateUserName(GenericString);
	if (response == false) {
		alert("Please Fill Your Password With At least 6 characters!" + 
		"\nYou can use letters, digits, and others but NOT spaces!");
		
		document.AdminPreference.password.focus();
		return false;
	}
	
	var Reconfirmpass = document.AdminPreference.repassword.value;		
	if (GenericString != Reconfirmpass) {
		alert("Please Retype Your Password Exacly the Same as Your Password Above!");

		document.AdminPreference.repassword.focus();
		return false;
	}	

	return true;
}//ValidatePreferenceAdmin


function modifyForm(inObj, inIndex)
{
	//alert(document.OrderForm.qty.value);	
	if (inObj.qty.value == "1+") {
		document.getElementById(inIndex).style.display='none';
	} else {
		document.getElementById(inIndex).style.display='block';
	}
}//modifyForm


function ConfirmNow(inVal)
{
	if (confirm("Do you really want to delete this record permanently?")) {
		return true;
	}

	return false;
}//ConfirmNow


function PoppyWindow(inInfoPath)
{
	var popWin = window.open(inInfoPath,"ASGBPO",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');//,width=160,height=136');
	popWin.focus();
}//PoppyWindow


/****** DELETE 

*****/