/*Javascript for My-InTouch specific needs*/

var nfiles1 = 1;

function fxNameOnly(theField,theField2){
  theValue = theField.value;
  if (theValue != ""){
   	for (i = 0; i < theValue.length; i++) {
	  if (theValue.substr(i,1) == "\\"){
	     theTemp = theValue.substr(i+1,100);
	  }
   	}
	theField2.value = document.InTouchReg.photoPath.value + theTemp
  }
}

function fxSelectNav(theNav){
	l_dontsubmit = true;
	document.ITContacts.action="/fdtcgi/wc.dll?FDProcess~fxRepGen";
	if(isNull(document.ITContacts.classno2)){
		strClass = "";
	}else{
		strClass = document.ITContacts.classno2.checked;
		if(strClass){
		 	strClass = "and nextaction = ''";
		}else{
		 	strClass = "and nextaction <> 'Closed'";
		}
	}
	var strWhere1 = "username='"+document.ITContacts.username.value+"' and password='"+document.ITContacts.password.value+"' ";
	strWhere = strWhere1 + strClass;
	document.ITContacts.cReportType.value='';

//alert(theNav);
	switch(theNav){
		case "Contact":
			document.ITContacts.action="/it-contact.asp";
			break;
		case "Profile":
			document.ITContacts.action="/fdtcgi/wc.dll?FDProcess~SaveTokens";
			document.ITContacts.TemplateX1.value="intouch\\it-profile";
			break;
		case "EmailLog":
//			var strWhere = "";
			document.ITContacts.cSelectWhere.value = strWhere1;
			document.ITContacts.creport.value="IT-Email";
			document.ITContacts.cSelectOrder.disabled=true;
			document.ITContacts.cnextpage.value = "/contactmassemail"+document.ITContacts.cnextpage1.value;
			break;
		case "Daily":
			var dDate = new Date();
			var DOW = dDate.getDay()*1;
			var Sunday = 7-DOW
			strDays = document.ITContacts.callreport.value;
			switch(strDays){
				case "today": dtRange = "d_followup = date()"; break;
				case "tomorrow": dtRange = "d_followup = date()+1"; break;
				case "yesterday": dtRange = "d_followup = date()-1"; break;
				case "thisweek": dtRange = "d_followup > date()-"+DOW+" and d_followup < date()+"+Sunday; break;
				case "lastweek": dtRange = "d_followup > date()-7-"+DOW+" and d_followup < date()-7+"+Sunday; break;
				case "lastmonth": dtRange = "d_followup > date()-30 and d_followup < date()"; break;
			}
			strWhere = strWhere + " and " + dtRange;
			document.ITContacts.cSelectWhere.value = strWhere;
			document.ITContacts.creport.value='ITFollowup';
			break;
		case "General":
			document.ITContacts.cSelectWhere.value = strWhere;
			document.ITContacts.creport.value='ITFollowup';
			break;
		case "ReDate":
			strField = document.ITContacts.cField.value;
			strWord = document.ITContacts.cWord.value
			var dDate = new Date();
			var DOW = dDate.getDay()*1;
			var Sunday = 7-DOW
			strDays = document.ITContacts.callreport.value;
			switch(strDays){
				case "today": dtRange = "d_followup = date()"; break;
				case "yesterday": dtRange = "d_followup = date()-1"; break;
				case "thisweek": dtRange = "d_followup > date()-"+DOW+" and d_followup < date()+"+Sunday; break;
				case "lastweek": dtRange = "d_followup > date()-7-"+DOW+" and d_followup < date()-7+"+Sunday; break;
				case "lastmonth": dtRange = "d_followup > date()-30 and d_followup < date()"; break;
			}
			strWhere = strWhere + " and " + dtRange;
			document.ITContacts.cSelectWhere.value = strWhere;
//			document.ITContacts.cSelectWhere.value = strWhere + " and lower('" + strWord + "') $ lower(" + strField + ")";
			document.ITContacts.creport.value='IT-ReDate';
			document.ITContacts.cnextpage.value = "/fdtcgi/maintenance/GoBack2.html";
			break;
		case "Advanced":
			strField = document.ITContacts.cField.value;
			strWord = document.ITContacts.cWord.value
			document.ITContacts.cSelectWhere.value = strWhere + " and lower('" + strWord + "') $ lower(" + strField + ")";
			document.ITContacts.creport.value='ITFollowup';
			break;
		case "Mass":
			strField = document.ITContacts.cField.value;
			strWord = document.ITContacts.cWord.value;
			if (strWord == ""){
				document.ITContacts.cSelectWhere.value = strWhere;
			}else{
//				alert(strWord);
				document.ITContacts.cSelectWhere.value = strWhere + " and lower('" + strWord + "') $ lower(" + strField + ")";
			}
			document.ITContacts.creport.value="ITMassEmail";
//			document.ITContacts.cSelectOrder.value = "first_name";
			document.ITContacts.cSelectWhere.value = document.ITContacts.cSelectWhere.value + " and !empty(email) and !'Removed from E-mail' $ notes01 and !'Undeliverable' $ notes02";
			break;
		case "Export":
			strField = document.ITContacts.cField.value;
			strWord = document.ITContacts.cWord.value
			if (strWord == ""){
				document.ITContacts.cSelectWhere.value = strWhere;
			}else{
				document.ITContacts.cSelectWhere.value = strWhere + " and lower('" + strWord + "') $ lower(" + strField + ")";
			}
			document.ITContacts.creport.value='ITExport';
			document.ITContacts.cReportType.value='CommaDelimited';
			break;
		case "BizCards":
			document.ITContacts.action="/fdtcgi/wc.dll?FDProcess~SaveTokens";
			document.ITContacts.TemplateX1.value="intouch\\bc-nav01";
			break;
		case "NewCard":
			fxSetCooky('ITBizCard',document.ITContacts.username.value+'/'+document.ITContacts.password.value+'/',false);
			document.ITContacts.action="/BCCreateCard.asp";
//			l_dontsubmit = false;
			break;
		case "EditBizCards":
			document.ITContacts.cSelectWhere.value = strWhere;
			document.ITContacts.cReport.value='IT_BizCards';
			break;
	}
	if(l_dontsubmit) {
//alert(document.ITContacts.action);
document.ITContacts.submit();
}
}


function fxApprove(){
	if(document.ITBizCard.l_approve.checked)
	{
		document.ITBizCard.Done.disabled=false;
	}else{
		document.ITBizCard.Done.disabled=true;
	}
}

function fxRegister(){
	var a = "Hello "+document.InTouchReg.agnt_name.value+",";
	var u = document.InTouchReg.strMsgu.value+document.InTouchReg.username.value;
	var p = "Your Password is: "+document.InTouchReg.password.value;
	var c = document.InTouchReg.strMsgc.value;
	document.InTouchReg.strMessage.value = a+u+"\n"+p+c;
}

function fxAction(theField){
	switch(theField){
		case "Remove":
			fxDT(document.ITContacts.notes01,"Removed from E-mail List"); break;
		case "Undeliverable":
			fxDT(document.ITContacts.notes02,"E-mail Undeliverable"); break;
		case "Closed":
			fxDT(document.ITContacts.notes02,"Record Closed"); 
			document.ITContacts.l_delete[0].checked = true;
			break;
	}
}
