function setItemNumber(tabindex){
	document.purchase.item_name_1.value += ": "+(ParseInt(tabindex) * 10)+" users";
}

function validate(){
	//This function takes any number of args. The first is a form object
	//That contains the fields named in the other args.
	var form = arguments[0];
	var popup = false;
	var ret_val = false;
	for(i = 1;i < arguments.length;i++){
		var type = eval("form."+arguments[i]+".type");
		temp = eval("form."+arguments[i]+".style.backgroundColor='#FFFFFF';");
		if(type == "select" || type=="select-one"){
			var select = eval("form."+arguments[i]);
			var empty = select.options[select.selectedIndex].value=="";

		} else {
			var empty = eval("form."+arguments[i]+".value=='' || form."+arguments[i]+".value=='00/00/00' || form."+arguments[i]+".value=='0.00' || form."+arguments[i]+".value=='0.00%' || form."+arguments[i]+".value=='$0.00' || form."+arguments[i]+".value=='0'");
		}
		if(empty==true){
			temp = eval("form."+arguments[i]+".style.backgroundColor='#FFDD77';");
			popup = true;
		}
	}
	if(popup == true){
		alert('One or more required fields were not filled in. Please check the highlighted field(s) for details.');
	} else {
		ret_val= true;
	}
	return ret_val;
}

function validate_bgt(){
	//This function makes sure they have "cycle" if "amt" is filled in
	var form = arguments[0];
	var popup = false;
	var ret_val = false;
	form.bgt_cycle.style.backgroundColor='#FFFFFF'
	form.bgt_day1.style.backgroundColor='#FFFFFF'
 	form.bgt_day2.style.backgroundColor='#FFFFFF'
	form.bgt_amt.style.backgroundColor='#FFFFFF'
	form.bgt_pmnt_dt.style.backgroundColor='#FFFFFF'
 	form.bgt_name.style.backgroundColor='#FFFFFF'

	if(form.SaveButton.value == 'Save Changes'){

		if(form.bgt_name.value == ''){
			form.bgt_name.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(parseInt(form.bgt_amt.value) == 0 || form.bgt_amt.value == ''){
			form.bgt_amt.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(form.bgt_cycle.value == ""){
			form.bgt_cycle.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(form.bgt_cycle.value == "Semi-Monthly"){
			if(parseInt(form.bgt_day1.value) < 1 || form.bgt_day1.value == ''){
				form.bgt_day1.style.backgroundColor='#FFDD77'
				popup = true;
			}
			if(parseInt(form.bgt_day2.value) < 1 || form.bgt_day2.value == ''){
				form.bgt_day2.style.backgroundColor='#FFDD77'
				popup = true;
			}
		}
		if(form.bgt_pmnt_dt.value == "00/00/00" || form.bgt_pmnt_dt.value == ''){
			form.bgt_pmnt_dt.style.backgroundColor='#FFDD77'
			popup = true;
		}
	}
	if(popup == true){
			alert('One or more required fields were not filled in. Please check the highlighted field(s) for details.');
	} else {
			ret_val= true;
	}
	return ret_val;
}

function validate_vip(){
	//This function makes sure they have "cycle" if "amt" is filled in
	var form = arguments[0];
	var popup = false;
	var ret_val = false;

	form.bgt_cycle.style.backgroundColor='#FFFFFF'
	form.bgt_day1.style.backgroundColor='#FFFFFF'
	form.bgt_day2.style.backgroundColor='#FFFFFF'
	form.bgt_Loanamt.style.backgroundColor='#FFFFFF'
	form.bgt_term.style.backgroundColor='#FFFFFF'
	form.bgt_IntRt.style.backgroundColor='#FFFFFF'
	form.bgt_pymnts.style.backgroundColor='#FFFFFF'
	form.bgt_startDt.style.backgroundColor='#FFFFFF'

	if(form.SaveButton.value == 'Save Changes'){

		if(form.bgt_cycle.value == ""){
			form.bgt_cycle.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(form.bgt_cycle.value == "Semi-Monthly"){
			if(parseInt(form.bgt_day1.value) < 1 || form.bgt_day1.value == ''){
				form.bgt_day1.style.backgroundColor='#FFDD77'
				popup = true;
			}
			if(parseInt(form.bgt_day2.value) < 1 || form.bgt_day2.value == ''){
				form.bgt_day2.style.backgroundColor='#FFDD77'
				popup = true;
			}
		}
		if(parseInt(form.bgt_Loanamt.value) == 0 || form.bgt_Loanamt.value == ''){
			form.bgt_Loanamt.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(parseInt(form.bgt_term.value) == 0 || form.bgt_term.value == ''){
			form.bgt_term.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(parseInt(form.bgt_IntRt.value) == 0 || form.bgt_IntRt.value == ''){
			form.bgt_IntRt.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(parseInt(form.bgt_pymnts.value) == 0 || form.bgt_pymnts.value == ''){
			form.bgt_pymnts.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(form.bgt_startDt.value == "00/00/00" || form.bgt_startDt.value == ''){
			form.bgt_startDt.style.backgroundColor='#FFDD77'
			popup = true;
		}
	}
	if(popup == true){
		alert('One or more required fields were not filled in. Please check the highlighted field(s) for details.');
	} else {
		ret_val= true;
	}
	return ret_val;
}

function validate_rup(){
	//This function makes sure they have "cycle" if "amt" is filled in
	var form = arguments[0];
	var popup = false;
	var ret_val = false;

	form.bgt_name.style.backgroundColor='#FFFFFF'
	form.bgt_Loanamt.style.backgroundColor='#FFFFFF'
	form.bgt_IntRt.style.backgroundColor='#FFFFFF'
	form.bgt_pmnt_dt.style.backgroundColor='#FFFFFF'

	//if(form.SaveButton.value == 'Save Changes'){

		if(form.bgt_name.value == ""){
			form.bgt_name.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(parseInt(form.bgt_Loanamt.value) == 0 || form.bgt_Loanamt.value == ''){
			form.bgt_Loanamt.style.backgroundColor='#FFDD77'
			popup = true;
		}
		if(parseInt(form.bgt_IntRt.value) == 0 || form.bgt_IntRt.value == ''){
			form.bgt_IntRt.value='.00001'
		}
		if(form.bgt_pmnt_dt.value == "00/00/00" || form.bgt_pmnt_dt.value == ''){
			form.bgt_pmnt_dt.style.backgroundColor='#FFDD77'
			popup = true;
		}
	//}
	if(popup == true){
		alert('One or more required fields were not filled in. Please check the highlighted field(s) for details.');
	} else {
		ret_val= true;
	}
	return ret_val;
}

function printTextArea(text){
	var div = document.getElementById('printDiv');
	div.innerHTML=text.replace(/\r\n/g,/<br \/>/);
	window.print();
}

function expand_div(div){
	document.getElementById(div).style.display='';
}

function collapse_div(div){
	document.getElementById(div).style.display='none';
}

function activate(link){
	var navbar = document.getElementById('navbarlinks');
	var links = navbar.getElementsByTagName('a');
	var numlinks = links.length;
	for(i=0;i<numlinks;i++){
		links[i].setAttribute('class','nonactive_link');
	}
	link.setAttribute('class','active_link');
}

function activatetwo(link){
	var navbar = document.getElementById('links');
	var links = navbar.getElementsByTagName('a');
	var numlinks = links.length;
	for(i=0;i<numlinks;i++){
		links[i].setAttribute('class','nonactive_link');
	}
	link.setAttribute('class','active_link');
}

function setInactive(user,level){
	//this method will send an ajax call to 4D to set fields to blank
	//will also enable the relevant disabled fields.
	level = parseInt(level);
	if(level<3){
		if(confirm('ARE YOU SURE? This will clear all existing data and reset this license so it can be re-used!!')){
			if(confirm('CLEAR ALL USER DATA NOW?')){
				var url = "/4DACTION/WEB_ClearThisUserData"
				var data = "Refno="+user;
				//simple ajax post - since we don't care what comes back
				//param 1 - the url to request
				//param 2 - the post data to send
				//param 3 - asynchronus or not (Firefox sometimes locks up if this is set to false
				send_ajax_post(url,data,true);	

				//At this point we need to blank the fields and set them to accept input
				var form = document.frmAgentEditUser;
				var elements = form.elements;
				var type="";
				for(i=0;i<elements.length;i++){
					type = elements[i].type;
					if(type != "hidden"){
						elements[i].value="";
						elements[i].disabled = false;
					}
				}
			} else {
				document.frmAgentEditUser.ck1[0].checked = true;
			}
		} else {
			document.frmAgentEditUser.ck1[0].checked = true;
		}
	} else {
		alert('Sorry. This user has purchased a complete mortgage paydown system. You cannot turn thus user to inactive status.');
	}
}

function setEnabledOnLoad(){
	//this method will set disabled to true on the relevant fields
	// if the field is inactive
	var form = document.frmAgentEditUser;
	var elements = form.elements;
	var type="";
	for(i=0;i<elements.length;i++){
		type = elements[i].type;
		if(type != "hidden" && type != "radio" && type !="button"){
			elements[i].disabled = true;
		}
	}
}

function checkUserName(name,userType,UID){
	//this will be an ajax call back to 4D to see it the username
	//exists or not.
	var URL = '/4DAction/WEB_CheckUserName';
	var data = 'LoginName='+name+'&userType='+userType+'&RefNo='+UID;
	var val= send_ajax_post_return_only_var(URL,data,true);
	if(error==true){
		alert('Sorry. The username you entered already exists.');
		document.frmEditData.LoginName.style.backgroundColor='#FFDD77';
		document.frmEditData.LoginName.value='';
		document.frmEditData.PWD.value='';
		error = false;
	} else {
		document.frmEditData.LoginName.style.backgroundColor='#FFFFFF';
	}
}

function destroy_session(location){
      var today = new Date();
      var cookieExpires = today.toGMTString();
     document.cookie = "CS_cookie=~CS_cookieEND;path=/;expires="+cookieExpires+";;";
     window.location=location;
}

function checkUsernameExists(username,userType){
	var URL = '/4DAction/WEB_CheckUserName';
	var data = 'LoginName='+username+'&userType='+userType;
	var val= send_ajax_post_return_only_var(URL,data,true);
	if(error==true){
		alert('Sorry. The username you entered does not exist.');
		document.frmLogin.LoginName.style.backgroundColor='#FFDD77';
		document.frmLogin.LoginName.value='';
		document.frmLogin.PWD.value='';
		error = false;
	} else {
		document.frmLogin.LoginName.style.backgroundColor='#FFFFFF';
	}
}

function SetClickNum(variable, value, formname){
	var form = document.getElementById(formname)
	eval('form.'+variable+'.value = '+value);
}

function writeYear(){
	var today = new Date();
	document.write(today.getFullYear().toString());
}

function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.tabindex) newObject.size = oldObject.tabindex;
  if(oldObject.maxlength) newObject.size = oldObject.maxlength;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}

function getCurMgtBal(CurDate,RefNum){
	//ajax call back to 4D to get cur mortgage balance based on date from amortization
	var URL = '/4DAction/WEB_getCurMgtBalance';
	var data = 'CurDate='+CurDate+'&RefNo='+RefNum;
	var val= send_ajax_post_field_return(URL,data,document.frmMontlyChng.mgt_CurrPrinBalance,true);
}