//========================================================================
//             I N T E R N E T   C O N C E P T S (c) 2002
//========================================================================
//		Project : TriCord
//	Module Name : icScripts.js
//		 Author : Donall Burns
//	 Start Date : 27/10/2002
//========================================================================
//   Common Utility Javascript functions and constants
//========================================================================

var CONST_SUPPORT_PERSON = "WVIP";
function begintimer()
{

	var countdown = document.getElementById('icLogoffCounter');
	if (parselimit==1)
		window.location="LogOff.asp"
	else
		{ 
		parselimit-=1
		curmin=Math.floor(parselimit/60)
		cursec=parselimit%60
		if(cursec<10)
		{
			cursec="0" + cursec;
		}
		if (curmin!=0)
			curtime= curmin + ":" + cursec	
		else
			curtime="<font color=red>" + curmin + ":" + cursec + "</FONT>"
		countdown.innerHTML=curtime
		//window.status=curtime
		setTimeout("begintimer()",1000)
		}
}



var iHelpElOn=null;
var strOldColor='';
function doMouseOver(el)
{
	var iHelpDiv = document.getElementById("icHelpText")
	var iHelpDivSide = document.getElementById("icHelpTextSide")
	
	if(null!=iHelpDiv)
	{
		iHelpDiv.innerHTML = "&nbsp;"
		
	}
	
	if(null!=iHelpDivSide)
	{
		iHelpDivSide.innerHTML = "&nbsp;"
	}

	if(null!=iHelpElOn)
	{
		iHelpElOn.style.background='White';
	}
	
	if(null==el)
	{
		var iEl = window.event.srcElement;
	}
	else
	{
		var iEl = el;
	}
	
	if(null==iEl)
	{
		return;
	}
	
	if(iEl.disabled){return;}
	
	if(null==iEl.icShowHelpID)
	{
		return;
	}
	if(iEl.type=='checkbox' || iEl.type=='radio')
	{
		iHelpElOn = null;
	}
	else
	{
		iEl.style.background='#CDD8F7';
		iHelpElOn = iEl;
	}
	if(null!=iHelpDiv)
	{
		
		//iHelpDiv.innerHTML = iEl.icShowHelpID + ' - ' + vHelp[iEl.icShowHelpID];
		//iHelpDivSide.innerHTML = iEl.icShowHelpID + ' - ' + vHelp[iEl.icShowHelpID];
		iHelpDiv.innerHTML = vHelp[iEl.icShowHelpID];
	}
	if(null!=iHelpDivSide)
	{
		
		//iHelpDiv.innerHTML = iEl.icShowHelpID + ' - ' + vHelp[iEl.icShowHelpID];
		//iHelpDivSide.innerHTML = iEl.icShowHelpID + ' - ' + vHelp[iEl.icShowHelpID];
		iHelpDivSide.innerHTML = vHelp[iEl.icShowHelpID];
	}	
}

function getNewContactList(iEl)
{
	document.getElementById("nActionId").value = 99
	document.getElementById("icEditForm").submit();
}

function showInStatusBar(str)
{
		/*Sean Hasson added 2/12/2002*/
		/*clear status after 5.5 seconds...*/
		window.status = str;
		setTimeout("clearstatus()",5500);
}

function clearstatus()
{
		window.status = "";
}



function categoryPopup()
{
		var iCodes = document.icEditForm.con_tricord_category3;
		var strCodes = iCodes.value;
		window.showHelp;
		var pcdialogargs = "dialogHeight:370px;dialogWidth:500px;status:no;center: Yes; help: No; resizable: No;";
		var dialogWindow = showModalDialog("categoryPopup.asp?strCodes=" + strCodes,"",pcdialogargs );
		strCodes = '';
	
		if (dialogWindow != null) 
		{
			var vBig = dialogWindow.split("***");
			var strHTML = "";
			for (var i=0; i < vBig.length; i++) 
			{
				var vSmall = vBig[i].split("**");
				if(2==vSmall.length)
				{
					strHTML = strHTML + vSmall[1];
					if(i<vBig.length-1)
					{
						strHTML = strHTML + '<BR>';
					}
					if(0==i)
					{
						strCodes = vSmall[0];
					}
					else
					{
						strCodes = strCodes + ',' + vSmall[0];
					}
				}
			}
			iCodes.value = strCodes;
			var iDisplay = document.getElementById("icCategories");
			iDisplay.innerHTML = strHTML;
		}
}


function postcodePopup(strItem, strAddress1, strTown, strCounty)
{
	var iPostcode = document.getElementById(strItem);
	var strPostcode = iPostcode.value;
	var nLenBefore = strPostcode.length;
	var strWithoutSpaces = strPostcode.replace(/\ /g, '');
	var nLenAfter =  strWithoutSpaces.length;
	
	if(nLenAfter==nLenBefore)
	{
		if(6==nLenBefore)
		{
			strPostcode = strPostcode.substr(0,3) + ' ' + strPostcode.substr(3);
		}
		if(7==nLenBefore)
		{
			strPostcode = strPostcode.substr(0,4) + ' ' + strPostcode.substr(4);
		}
	}
	var strPage = "icPostcodePopup.asp?strPostcode=" + escape(strPostcode);
	var pcdialogargs = "dialogHeight: 200px; dialogWidth: 500px; center: Yes; help: No; resizable: No; status: No;";
	var arr = showModalDialog(strPage,"",pcdialogargs );
	if (arr != null) 
	{
		var vAddress=arr.split("**");
		var iAddress1 = document.getElementById(strAddress1);
		var iTown = document.getElementById(strTown);
		var iCounty = document.getElementById(strCounty);
		
		iAddress1.value=vAddress[0];
		iAddress1.focus();
		iTown.value=vAddress[1];
		var strCounty = vAddress[2];
		strCounty = strCounty.toUpperCase();
		iCounty.value=strCounty.substr(0,3);
		iPostcode.value=vAddress[3];
		
		var iCountySelect = document.getElementById("icCountySelect");
		var iCountyOther = document.getElementById("icCountyOther");
		
		if((null!=iCountyOther) && (null!=iCountySelect))
		{
			iCountySelect.style.display = '';
			iCountyOther.style.display = 'none';
			iCountyOther = document.getElementById("con_county_other");
			
			if(null!=iCountyOther)
			{
				iCountyOther.value = '';
			}
		}
	}	
}

function setDisabledChildren(strParent, bDisabled)
{
	var iParent = document.getElementById(strParent);
	if(null!=iParent)
	{
		var iCol = iParent.all.tags("INPUT");
		if(iCol.length>0)
		{
			for(var i=0;i<iCol.length;i++)
			{
				var iChild = iCol.item(i);
				iChild.disabled = bDisabled;
			}
		}
	}
		
}

function getRadioValue(strName, nDefault)
{
	var iGroup = document.getElementById(strName);
	
	if(null!=iGroup)
	{
		alert(iGroup.value);
		for(var i=0; i<iGroup.length;i++)
		{
			alert(iGroup.item(i).value);
		}
	}
	
	return nDefault;
}

function setDisabledTextarea(strName, bDisabled)
{
	var iTextarea = document.getElementById(strName);
	if(null!=iTextarea)
	{
		iTextarea.disabled = bDisabled;
		
		if(bDisabled)
		{
			iTextarea.className = "icTextAreaDisabled";
		}
		else
		{
			iTextarea.className = "icTextArea";
		}
	}
}

function checkFeedbackForm()
{
	var strReason = '';
	
	for(var i=1;i<6;i++)
	{
		if(document.getElementById("bQuestion2_" + i).checked)
		{
			strReason = strReason + '1';
		}
		else
		{
			strReason = strReason + '0';
		}
	}
	
	document.icEditForm.fb_reason.value = strReason;
	
	return true;
}

function checkForPostcode()
{
	nError = 0;
	var strError='';
	strError = strError + checkValueExists(document.icQuarterForm3.strPostcode, "Postcode");
	
	if(nError>0)
	{
		showErrorWindow(nError, strError);
	}
	else
	{
		document.icQuarterForm3.submit();
	}
		
}

function checkAddDelegateForm()
{
	nError = 0;
	var strError='';

	strError = strError + checkValueExists(document.icQuarterForm1.strForename, "Forename");
	strError = strError + checkValueExists(document.icQuarterForm1.strSurname, "Surname");
	strError = strError + checkValueExists(document.icQuarterForm1.strPostcode, "Postcode");
	
	if(nError>0)
	{
		showErrorWindow(nError, strError);
	}
	else
	{
		document.icQuarterForm1.submit();
	}
		
}

function checkValueExists(iEl, strField)
{
	if(null!=iEl)
	{
		if(''==iEl.value)
		{
			nError++;
			return "<LI>A value must be specified for " + strField + ".";
		}
	}
}

function myScroll(strScroll)
{
	var oDiv = document.getElementById("divVisit");
	oDiv.doScroll(strScroll);
}

