var isIE, isNav;

agent = navigator.userAgent;
if (agent.indexOf('MSIE',0) != -1)
   isIE = true;
else
{
   if (agent.indexOf('Mozilla',0) != -1)
   {
      isNav = true;
      if ( (agent.indexOf('6.',0) != -1) || (agent.indexOf('7.',0) != -1) )
      {
         isNav = true;
         //isNav6 = true;
      }
   }
}

function saveStatuscall() {
	alert('Record sucessfully saved.');
}

function SetMarketing(obj) {
	//alert(obj.value);
	document.forms[0].txtMktRadioValue.value = obj.value;
}

function SetInstitution(obj) {
	//alert(obj.value);
	document.forms[0].txtItypeRadioValue.value = obj.value;
}

function SetEAS(obj) {
	//alert(obj.value);
	document.forms[0].txtEASRadioValue.value = obj.value;
}

function ValidateTitle() {
	//alert('validate');
	var bCan;
	bCan = true;
	with (document.forms[0]) {
		if (chkTitle1.checked || chkTitle2.checked) {
			if (chkTitle1.checked) {
				if (!chkTitle1Orig.checked && !chkTitle1Service.checked) {
					bCan = false;
					alert('You must specify a title1 activity.');	
				}
			}
			if (chkTitle2.checked) {
				if (!chkTitle2Orig.checked && !chkTitle2Service.checked) {
					bCan = false;
					alert('You must specify a title2 activity.');	
				}
			}
		} else {
			bCan = false
			alert('You must specify a title type.');
		}
		if (bCan) { SetDirection('FWD'); }
	}
}

function setField(e) {	
	//alert(document.forms[0][0].name);
	switch(document.forms[0][0].name) {
		case 'rNotify':
			break;
		case 'nPageNum':
			break;
		case 'exclude':
			break;
		default:	
			document.forms[0][0].focus();
			break;
	}
}

function doCancel() {
	document.forms[0].action = 'app_details.asp';
	document.forms[0].submit();
}

function doApp(app_id) {	
	document.forms[0].action = 'app_details.asp';
	document.forms[0].app_id.value = app_id;
	document.forms[0].submit();
	return;
}

function doEdit(arg){
	var tar;
	tar = 'edit_' + arg + '.asp';
	document.forms[0].action = tar;
	document.forms[0].submit();
}

function doAdd(arg){
	var tar;
	tar = 'add_' + arg + '.asp';
	document.forms[0].action = tar;
	document.forms[0].submit();
}

function doBack() {
	var tar;
	tar = 'app_listing.asp';
	document.location.replace(tar);
}

function doContact(o) {
	var id;
	id = o.value;
	document.forms[0].nContactId.value = id;
	document.forms[0].bContactSelected.value = 'Y';
	document.forms[0].submit();
}

function doPage(tab) {
	var url;
	switch (tab) {
		case 3:
			url = 'http://www.federalmortgagelicensing.com/FHA_HUD_License_Qualifications.asp';
			break;
		case 4:
			url = 'https://www.federalmortgagelicensing.com/FHA_HUD_Application_For_Obtaining_License.asp';
			break;
		default:
			url = 'http://www.federalmortgagelicensing.com/FHA_HUD_Licensing_Services.asp';
			break;
	}
	parent.document.location.reload(url);
}

function OnMouseOver() {

	if (!isIE) {return;}

	var n, o, sId, sClassName;
	e = window.event.srcElement;
	n = e.id;
	n = n.substring(1, n.length);
	sClassName = e.className;
				
	if (sClassName != 'TabLoaded' && sClassName != 'IELinkLoaded') {
		sId = 'T' + n;
		o = document.all(sId);
		with (o) {
			style.backgroundColor = '#4169e1';
			style.color = 'white';
			style.fontStyle = 'Italic';
		}
		sId = 'A' + n;
		o = document.all(sId);
		with (o) {
			style.backgroundColor = '#4169e1';
			style.color = 'white';
			style.fontStyle = 'Italic';
		}
	}
	o = null;
	e = null;
	return;
}

function OnMouseOut() {

	if (!isIE) {return;}

	var n, o, sId, sClassName;
	e = window.event.srcElement;
	n = e.id;
	n = n.substring(1, n.length);
	sClassName = e.className;
	
	if (sClassName != 'TabLoaded' && sClassName != 'IELinkLoaded') {
		sId = 'T' + n;
		o = document.all(sId);
		with (o) {
			style.backgroundColor = '#003aac';
			style.color = 'white';
			style.fontStyle = '';
		}
		sId = 'A' + n;
		o = document.all(sId);
		with (o) {
			style.backgroundColor = '#003aac';
			style.color = 'white';
			style.fontStyle = '';
		}
	}
	o = null;
	e = null;
	return;
}

function OnMouseClick() {
	
	if (!isIE) {return;}

	var e, sUrl, n; 
	e = window.event.srcElement;
	n = e.id;
	n = n.substring(1, n.length);
		
	switch (n) {
		case '1':
			sUrl = 'FHA_HUD_Approval_Specialists.asp';
			break;
		case '2':
			sUrl = 'FHA_HUD_Licensing_Services.asp';
			break;
		case '3':
			sUrl = 'FHA_HUD_License_Qualifications.asp';
			break;
		case '4':
			sUrl = 'FHA_HUD_Application_For_Obtaining_License.asp';
			break;
		case '5':
			sUrl = 'Federal Mortgage Licensing, Inc. Account Access.asp';
			break;
		default:
			sUrl = 'FHA_HUD_Approval_Specialists.asp';
			break;
	}
	
	//alert(sUrl);
	
	parent.window.location.replace(sUrl);
	e = null;
	return;
}

function CheckDigitCount(sName) {
	return true;
}

function CheckKeyPress(type) {
	var key;
	var ok;
	var elem;
	
	if (!isIE) {return;}
	
	key = window.event.keyCode;
	
	//alert(key);
	switch(type) {
		case 'number':
			if (key < 48 || key > 57) {ok = false;} else {ok = true;}
			break;
		case 'phone':
			if (key < 48 || key > 57) {ok = false;} else {ok = true;}
			break;
		case 'decimal':
			if (key == 46) {
				ok = true;
			}
			else {
				if (key < 48 || key > 57) {ok = false;} else {ok = true;}
			}
			break;
		case 'date':
			if ((key < 48 || key > 57) && (key != 47)) {ok = false;} else {ok = true;}
			break;
		default:
			break;
	}
	window.event.returnValue = ok;
}

function CheckSelection()
{
	var isChecked = false;
	for(i=0;i<document.forms[0].rAppType.length;i++)
	{
		//alert(document.forms[0].rAppType[i].checked);
		if(document.forms[0].rAppType[i].checked)
		{
			isChecked = true;
			break;
		}
	}
	if(isChecked)
		SetDirection('FWD');
	else
		alert("You must select a service first.        ");
}

function SetDirection(sDir) {
	var o;
	
	if (isIE) {
		o = window.event.srcElement;
		if (o.id == 'btnDone') {
			o.disabled = true;
		}
		o = null;
	}	
	
	document.forms[0].Direction.value = sDir;
	document.forms[0].submit();
}

function DoAdd() {
	document.forms[0].bAdd.value = 'Y';
	document.forms[0].submit();
}

function DoNext() {
	document.forms[0].submit();
}

function DoSubmit() {
	document.forms[0].action = 'app3.asp';
	document.forms[0].submit();
}

function OnNotify() {
	var e;
	if (isIE) {
		e = window.event.srcElement;
		if (e.value == 'Other') {
			document.forms[0].eNotifyOther.focus();
		}
		e = null;
	}
}

function CheckIsSameAddress() {
	if (document.forms[0].chkSame.checked) {
		with (document.forms[0]) {
			txtMailAttention.value = txtCorpAttention.value;
			txtMailStreetAddress.value = txtCorpStreetAddress.value;
			txtMailCity.value = txtCorpCity.value;
			lstMailState.value = lstCorpState.value;
			zMailZip.value = zCorpZip.value;
			txtMailCounty.value = txtCorpCounty.value;
		}
	} else {
		with (document.forms[0]) {
			txtMailAttention.value = '';
			txtMailStreetAddress.value = '';
			txtMailCity.value = '';
			lstMailState.value = '';
			zMailZip.value = '';
			txtMailCounty.value = '';
		}
	}
}

function CheckIsSameLendAddress() {
	if (document.forms[0].chkLendSame.checked) {
		with (document.forms[0]) {
			txtLendContactAttention.value = txtLendAttention.value;
			txtLendContactStreetAddress.value = txtLendStreetAddress.value;
			txtLendContactCity.value = txtLendCity.value;
			lstLendContactState.value = lstLendState.value;
			zLendContactZip.value = zLendZip.value;
			txtLendContactCounty.value = txtLendCounty.value;
		}
	} else {
		with (document.forms[0]) {
			txtLendContactAttention.value = '';
			txtLendContactStreetAddress.value = '';
			txtLendContactCity.value = '';
			lstLendContactState.value = '';
			zLendContactZip.value = '';
			txtLendContactCounty.value = '';
		}
	}
}

function rc(evnt){
	//alert(navigator.appName);
	if (navigator.appName.toUpperCase().match(/NETSCAPE/) != null){
		if (evnt.which >= 2){
			//alert("Operation not allowed");
			return false;
		}
	}else{
		if (event.button>=2){
			alert("Operation not allowed");
		}
	}
}

function doOfficerCheck(elem) {
	var num;
	var sObj;
	var obj;
	num = document.forms[0].txtOfficerNum.value;
	
	for (i = 1; i <= num; i++) {
		sObj = "document.forms[0].chkOfficerInCharge_" + i;
		obj = eval(sObj);
		obj.checked = false;
	}
	elem.checked = true;	
}

function doDisclaimer() {
	var features, sTop, sLeft, sUrl;
	sTop = '20px';
	sLeft = '20px';
	sUrl = 'disclaimer.asp';
	features = 'height=380px,width=500px,status=yes,toolbar=no,menubar=yes,scrollbars=yes,location=yes,resizable=no,top=' + sTop + ',left=' + sLeft;
	window.open(sUrl,'legal', features, '');
}

function doPayment(custid, invoice, amt) {
	var features, sTop, sLeft, sUrl;
	sTop = '20px';
	sLeft = '20px';
	sUrl = 'payment.asp?custid=' + custid + '&invoice=' + invoice + '&amt=' + amt;
	features = 'height=700px,width=500px,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=yes,resizable=no,top=' + sTop + ',left=' + sLeft;
	window.open(sUrl,'payment', features, '');
}

function doAppCreate(row_guid,location) {
		
	var features, sTop, sLeft, sUrl;
	sTop = '0px';
	sLeft = '0px';
	if(location == 'local')
	{
		sUrl = 'http://localhost/opps/hud11701a.asp?row_guid=' + row_guid;
	}
	else
	{
		sUrl = 'http://www.federalmortgagelicensing.com/hud11701a.asp?row_guid=' + row_guid;
	}
	features = 'height=700px,width=900px,scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,top=' + sTop + ',left=' + sLeft;
	window.open(sUrl,'application', features, '');
}

function doAppCreateNoPopUp(app_code,row_guid,location)
{
	window.document.forms[0].app_guid.value = row_guid;
	window.document.forms[0].app_location.value = location;
	window.document.forms[0].app_code.value = app_code;
	window.document.forms[0].action = "hud_fha_11701.asp";
	window.document.forms[0].submit();
}

function doDownloadApp(row_guid)
{
	window.document.forms[0].app_guid.value = row_guid;
	window.document.forms[0].action = "app_download.asp";
	window.document.forms[0].submit();
}

var ElementWindow = closed;

	function doOpenQcWiz(row_guid,location) 
	{
		var url;
		
		if(location == 'local')
		{
			url = 'http://twolf.gotdns.com/services/QcWiz.aspx?row_guid=' + row_guid;
		}
		else
		{
			url = 'http://www.federalmortgagelicensing.com/services/QcWiz.aspx?row_guid=' + row_guid;
		}
		
		url = 'http://twolf.gotdns.com/services/QcWiz.aspx?row_guid=' + row_guid;
						
		var l = 0;
		var t = 0;
		var w = 650;
		var h = 700;
	
		if (screen) 
		{
			l = (screen.width / 2) - (w/2);
			t = (screen.height / 2) - (h/2);
		}
		if(ElementWindow == closed)
		{
			//alert('about to open');
			ElementWindow = window.open(url,'WinName','width='+w+',height='+h+',left='+l+',top='+t+',scrollbars=auto,resizable=no')
		}
		else
		{
			//alert('about to focus');
			ElementWindow.focus();	
		}
	}

function doAppDetail(app_id) {
	
	//document.forms[0].app_id.value = app_id;
	//alert(document.forms[0].app_id.value);
	//document.forms[0].submit();
	
	var features, sTop, sLeft, sUrl;
	sTop = '100px';
	sLeft = '100px';
	sUrl = 'edit_app_details.asp?app_id=' + app_id;
	features = 'height=300px,width=600px,status=yes,toolbar=no,menubar=no,location=no,resizable=no,top=' + sTop + ',left=' + sLeft;
	window.open(sUrl,'application', features, '');
}

function ToggleDisclaimer(chkBox)
{
	var btnDone;
	btnDone = document.forms[0].btnDone;
	//alert(btnDone.disabled);	
	if(chkBox.checked)
	{
		btnDone.disabled = false;
	}
	else
	{
		btnDone.disabled = true;
	}
}

//document.onmousedown=rc;
//if (document.layers)window.captureEvents(Event.MOUSEDOWN);window.onmousedown=rc;