// function to capture mouse position
function id7MouseMove(e)
{
	if (window.event)
	{
		iMouseX = parseInt(event.clientX + document.body.scrollLeft + 10);
		iMouseY = parseInt(event.clientY + document.body.scrollTop);
	}
	else
	{
		iMouseX = parseInt(e.pageX + 10);
		iMouseY = parseInt(e.pageY);
	}
}

// function to define text for message box
function id7MsgTxt(sTxt,sCls)
{
	var oMsg = document.getElementById("id7domMsg");
	
	oMsg.innerHTML = sTxt;
	oMsg.className = sCls;
	id7ShoMsg();
}

// function to define image for message box
function id7MsgImg(sSrc,sCls)
{
	var oMsg = document.getElementById("id7domMsg");
	
	oMsg.innerHTML = '<img src="' + sSrc + '" border="0">';
	oMsg.className = sCls;
	id7ShoMsg();
}

// function to show message box
function id7ShoMsg()
{
	try
	{
		var oMsg = document.getElementById("id7domMsg");
		
		oMsg.style.display = "inline";
		
		var iWinWidth = id7WinWidth();
		var iDiff = parseInt(iWinWidth) - iMouseX;
		var iOffset = oMsg.offsetWidth;
	
		if (iDiff <= iOffset)
		{
			iMouseX = iMouseX - iOffset - 10;
		}
		
		oMsg.style.left = iMouseX;
		oMsg.style.top = iMouseY;

	}
	catch(err){}
}

function id7CanMsg()
{
	var oMsg = document.getElementById("id7domMsg");
	
	oMsg.innerHTML = "";
	oMsg.style.display = "none";
}

// function to trim strings
function id7Trim(sVal)
{
	return sVal.replace(/^\s*|\s*$/g,"");
}

// function to test string as valid email
function id7ValidEmail(sEmail)
{
	var sEmailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (sEmailFilter.test(sEmail))
	{
		var sValidEmail = true;
	}
	else
	{
		var sValidEmail = false;
	}
	
	return sValidEmail;
}

// function to open window
function id7NewWin(sWinUrl,sWinName,sWinWidth,sWinHeight)
{
	// define window coords
	var sWinTop  = (screen.height - sWinHeight) / 2;
	var sWinLeft = (screen.width  - sWinWidth)  / 2;
	
	// define window features
	var sWinOpts = "resizable=yes, status=yes, width=" + sWinWidth + ",height=" + sWinHeight + ",top=" + sWinTop + ",left=" + sWinLeft;
	
	// close existing window
	try {id7jsvNewWin.close();} catch(err){}
		
	// open window
	id7jsvNewWin = window.open(sWinUrl, sWinName, sWinOpts);
	
	// set focus to window
	id7jsvNewWin.focus();
}

// function to confirm gui is loaded within its frame structure
function id7ChkFrame(sFrameStruct)
{
	if (window.parent.location.href.indexOf(sFrameStruct) == -1)
	{
		alert("The structure for this interface is incorrectly referenced. Press OK to correct.");
		
		// get the query string from the document url
		var sQryStr = document.location.href.split("?");
		
		if (sQryStr[1] == undefined)
		{
			// if query string undefined ignore in redirect url
			window.parent.location.href = sFrameStruct;
		}
		else
		{
			// if query string defined append to redirect url
			window.parent.location.href = sFrameStruct + "?" + sQryStr[1];
		}
	}
}

// function to determine value from measurement
function id7ValMeas(sValMeas,sReturn)
{
	// get length of value
	var sValMeasLen = sValMeas.length;
	
	// get character locations
	var iOneChar = sValMeasLen - 1;
	var iTwoChar = sValMeasLen - 2;
	var sOneChar = sValMeas.substring(iOneChar, sValMeasLen);
	var sTwoChar = sValMeas.substring(iTwoChar, sValMeasLen);
	
	// test whether measure is %
	if (sOneChar == "%")
	{
		var sValue = sValMeas.substring(0, iOneChar);
		var sMeasure = sOneChar;
	}
	
	else
	{
		var sValue = sValMeas.substring(0, iTwoChar);
		var sMeasure = sTwoChar;
	}
	
	// return required value
	if (sReturn == "value")
	{
		return sValue;
	}
	
	else
	{
		return sMeasure;
	}	
}

// function to strip position values from string
function id7StrVal(sVal,iStart,iEnd)
{
	// get length of value
	var sValLen = sVal.length;
	
	// get character locations
	var iLastChar = sValLen - iEnd;
	
	// get stripped value
	var sStripValue = sVal.substring(iStart, iLastChar);
	
	// return value
	return sStripValue;
}

// function to dynamically select value from select list
function id7SelOpt(sCtrl,sSelVal)
{
	// get control
	var oControl = document.getElementById(sCtrl);
	
	// loop to find value and select on control
	for (var i = 0; i < oControl.length; i++)
	{
		if (oControl.options[i].value == sSelVal)
		{
			oControl.options[i].selected = true;
			break;
		}
	}
}

// function to dynamically add value to select list
function id7AddOpt(sCtrl,sAddVal,sAddTxt,iPos)
{
	// get control
	var oControl = document.getElementById(sCtrl);
	
	var oOpt = new Option(sAddTxt,sAddVal);
	oControl.options[iPos] = oOpt;

}

// function to dynamically remove value/s from select list
function id7DelOpt(sCtrl,sDelVal)
{
	// get control
	var oControl = document.getElementById(sCtrl);
	
	// loop to find value and remove from control
	for (var i = 0; i < oControl.length; i++)
	{
		if (sDelVal != "@@@ALL@@@" && oControl.options[i].value == sDelVal)
		{
			oControl.remove(i);
			break;
		}
		else
		{
			if (sDelVal == "@@@ALL@@@")
			{
				oControl.remove(i);
			}
		}
	}
}

// function to convert rgb color to hex
function id7GetHex(iRed,iGreen,iBlue)
{
	if (isNaN(iRed) || isNaN(iGreen) || isNaN(iBlue)) {return;}
	
	// define hex array
	var aHexValues = new Array(256);

aHexValues[0]="00";aHexValues[1]="01";aHexValues[2]="02";aHexValues[3]="03";aHexValues[4]="04";aHexValues[5]="05";aHexValues[6]="06";aHexValues[7]="07";aHexValues[8]="08";aHexValues[9]="09";aHexValues[10]="0A";aHexValues[11]="0B";aHexValues[12]="0C";aHexValues[13]="0D";aHexValues[14]="0E";aHexValues[15]="0F";aHexValues[16]="10";aHexValues[17]="11";aHexValues[18]="12";aHexValues[19]="13";aHexValues[20]="14";aHexValues[21]="15";aHexValues[22]="16";aHexValues[23]="17";aHexValues[24]="18";aHexValues[25]="19";aHexValues[26]="1A";aHexValues[27]="1B";aHexValues[28]="1C";aHexValues[29]="1D";aHexValues[30]="1E";aHexValues[31]="1F";aHexValues[32]="20";aHexValues[33]="21";aHexValues[34]="22";aHexValues[35]="23";aHexValues[36]="24";aHexValues[37]="25";aHexValues[38]="26";aHexValues[39]="27";aHexValues[40]="28";aHexValues[41]="29";aHexValues[42]="2A";aHexValues[43]="2B";aHexValues[44]="2C";aHexValues[45]="2D";aHexValues[46]="2E";aHexValues[47]="2F";aHexValues[48]="30";aHexValues[49]="31";aHexValues[50]="32";aHexValues[51]="33";aHexValues[52]="34";aHexValues[53]="35";aHexValues[54]="36";aHexValues[55]="37";aHexValues[56]="38";aHexValues[57]="39";aHexValues[58]="3A";aHexValues[59]="3B";aHexValues[60]="3C";aHexValues[61]="3D";aHexValues[62]="3E";aHexValues[63]="3F";aHexValues[64]="40";aHexValues[65]="41";aHexValues[66]="42";aHexValues[67]="43";aHexValues[68]="44";aHexValues[69]="45";aHexValues[70]="46";aHexValues[71]="47";aHexValues[72]="48";aHexValues[73]="49";aHexValues[74]="4A";aHexValues[75]="4B";aHexValues[76]="4C";aHexValues[77]="4D";aHexValues[78]="4E";aHexValues[79]="4F";aHexValues[80]="50";aHexValues[81]="51";aHexValues[82]="52";aHexValues[83]="53";aHexValues[84]="54";aHexValues[85]="55";aHexValues[86]="56";aHexValues[87]="57";aHexValues[88]="58";aHexValues[89]="59";aHexValues[90]="5A";aHexValues[91]="5B";aHexValues[92]="5C";aHexValues[93]="5D";aHexValues[94]="5E";aHexValues[95]="6F";aHexValues[96]="60";aHexValues[97]="61";aHexValues[98]="62";aHexValues[99]="63";aHexValues[100]="64";aHexValues[101]="65";aHexValues[102]="66";aHexValues[103]="67";aHexValues[104]="68";aHexValues[105]="69";aHexValues[106]="6A";aHexValues[107]="6B";aHexValues[108]="6C";aHexValues[109]="6D";aHexValues[110]="6E";aHexValues[111]="6F";aHexValues[112]="70";aHexValues[113]="71";aHexValues[114]="72";aHexValues[115]="73";aHexValues[116]="74";aHexValues[117]="75";aHexValues[118]="76";aHexValues[119]="77";aHexValues[120]="78";aHexValues[121]="79";aHexValues[122]="7A";aHexValues[123]="7B";aHexValues[124]="7C";aHexValues[125]="7D";aHexValues[126]="7E";aHexValues[127]="7F";aHexValues[128]="80";aHexValues[129]="81";aHexValues[130]="82";aHexValues[131]="83";aHexValues[132]="84";aHexValues[133]="85";aHexValues[134]="86";aHexValues[135]="87";aHexValues[136]="88";aHexValues[137]="89";aHexValues[138]="8A";aHexValues[139]="8B";aHexValues[140]="8C";aHexValues[141]="8D";aHexValues[142]="8E";aHexValues[143]="8F";aHexValues[144]="90";aHexValues[145]="91";aHexValues[146]="92";aHexValues[147]="93";aHexValues[148]="94";aHexValues[149]="95";aHexValues[150]="96";aHexValues[151]="97";aHexValues[152]="98";aHexValues[153]="99";aHexValues[154]="9A";aHexValues[155]="9B";aHexValues[156]="9C";aHexValues[157]="9D";aHexValues[158]="9E";aHexValues[159]="9F";aHexValues[160]="A0";aHexValues[161]="A1";aHexValues[162]="A2";aHexValues[163]="A3";aHexValues[164]="A4";aHexValues[165]="A5";aHexValues[166]="A6";aHexValues[167]="A7";aHexValues[168]="A8";aHexValues[169]="A9";aHexValues[170]="AA";aHexValues[171]="AB";aHexValues[172]="AC";aHexValues[173]="AD";aHexValues[174]="AE";aHexValues[175]="AF";aHexValues[176]="B0";aHexValues[177]="B1";aHexValues[178]="B2";aHexValues[179]="B3";aHexValues[180]="B4";aHexValues[181]="B5";aHexValues[182]="B6";aHexValues[183]="B7";aHexValues[184]="B8";aHexValues[185]="B9";aHexValues[186]="BA";aHexValues[187]="BB";aHexValues[188]="BC";aHexValues[189]="BD";aHexValues[190]="BE";aHexValues[191]="BF";aHexValues[192]="C0";aHexValues[193]="C1";aHexValues[194]="C2";aHexValues[195]="C3";aHexValues[196]="C4";aHexValues[197]="C5";aHexValues[198]="C6";aHexValues[199]="C7";aHexValues[200]="C8";aHexValues[201]="C9";aHexValues[202]="CA";aHexValues[203]="CB";aHexValues[204]="CC";aHexValues[205]="CD";aHexValues[206]="CE";aHexValues[207]="CF";aHexValues[208]="D0";aHexValues[209]="D1";aHexValues[210]="D2";aHexValues[211]="D3";aHexValues[212]="D4";aHexValues[213]="D5";aHexValues[214]="D6";aHexValues[215]="D7";aHexValues[216]="D8";aHexValues[217]="D9";aHexValues[218]="DA";aHexValues[219]="DB";aHexValues[220]="DC";aHexValues[221]="DD";aHexValues[222]="DE";aHexValues[223]="DF";aHexValues[224]="E0";aHexValues[225]="E1";aHexValues[226]="E2";aHexValues[227]="E3";aHexValues[228]="E4";aHexValues[229]="E5";aHexValues[230]="E6";aHexValues[231]="E7";aHexValues[232]="E8";aHexValues[233]="E9";aHexValues[234]="EA";aHexValues[235]="EB";aHexValues[236]="EC";aHexValues[237]="ED";aHexValues[238]="EE";aHexValues[239]="EF";aHexValues[240]="F0";aHexValues[241]="F1";aHexValues[242]="F2";aHexValues[243]="F3";aHexValues[244]="F4";aHexValues[245]="F5";aHexValues[246]="F6";aHexValues[247]="F7";aHexValues[248]="F8";aHexValues[249]="F9";aHexValues[250]="FA";aHexValues[251]="FB";aHexValues[252]="FC";aHexValues[253]="FD";aHexValues[254]="FE";aHexValues[255]="FF";
	
	// convert rgb to hex
	var sHexCode = "#" + aHexValues[iRed] + aHexValues[iGreen] + aHexValues[iBlue];
	
	// return value
	return sHexCode;
}

// function to show color of form control in border
function id7CtrlBrdCol(sCtrl)
{
	// define default border color
	var sBorderColor = "1px solid #7F9DB9";
	
	// get selected color value
	var sSelColor = document.getElementById(sCtrl).value;
	
	if (sSelColor.length > 1)
	{
		// check for # symbol at start of string
		var sFirstChar = sSelColor.charAt(0);
		if (sFirstChar != "#") {document.getElementById(sCtrl).value = "#" + sSelColor;}
	
		// convert color hex value to uppercase
		var sSelColor2 = document.getElementById(sCtrl).value;
		document.getElementById(sCtrl).value = sSelColor2.toUpperCase();
	
		// check color string
		if (sSelColor2.length != 7)
		{
			document.getElementById(sCtrl).style.border = sBorderColor;
			return;
		}
		try
		{
			// show selected color
			document.getElementById(sCtrl).style.border = "1px solid " + sSelColor2;
		}	
		catch(err)
		{
			alert("The value entered is not a valid color.");
			document.getElementById(sCtrl).value = "";
			document.getElementById(sCtrl).style.border = sBorderColor;
			return;
		}
	}	
	else
	{
		document.getElementById(sCtrl).style.border = sBorderColor;
	}	
}

