
function DeleteConfirmSubmit() {
	var doc = document.forms[0];	
	var msg = "Are you sure to delete the record(s)?";	
	if (confirm(msg)) {
		doc.submit();	
	} else {
		return false;	
	}
}

function SaveConfirmSubmit() {
	var doc = document.forms[0];	
	var msg = "Are you sure to save the record(s)?";	
	if (confirm(msg)) {
		doc.submit();	
	} else {
		return false;	
	}
}

function DiscardConfirmSubmit() {
	var doc = document.forms[0];	
	var msg = "Your input has not been saved.\r\nDiscard your input?";	
	if (confirm(msg)) {
		doc.submit();	
	} else {
		return false;	
	}
}

function document.onkeydown() {
	// alt+left and alt+right
	if ((window.event.altKey)&&((window.event.keyCode==37)||(window.event.keyCode==39)))
	{
		event.returnValue=false;
	}
	// F5 or Ctrl+R
	else if ((event.keyCode==116)||(event.ctrlKey&&event.keyCode==82))
	{
		event.keyCode=0;
		event.returnValue=false;
	}
	// Ctrl+N
	else if ((event.ctrlKey)&&(event.keyCode==78))
	{
		event.returnValue=false;						
	}
	// Shift+F10
	else if ((event.shiftKey)&&(event.keyCode==121))
	{
		event.returnValue=false;
	}
	else
	{
		event.returnValue=true;
	}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function SetDivHeight(divID) {
	document.all(divID).style.height = document.body.offsetHeight - 50;
}

function PhoneCheck(strSelfID, strNextID, num) {
  if (document.all(strSelfID).value.length > num-1) {
    document.all(strNextID).focus();
  }
}

var setFrame = false;
var setFrame1 = false;
var setFrame2 = false;
function FramesetTransfer(TopFrame2URL, Frameset_1, Frameset_2, CaseEditURL, CaseTabURL, CaseGridURL) {
	ClickMenu(1);
	top.topFrame2.window.location.href = TopFrame2URL + "&ToCase=1";
	
	setFrame = false;
	setTimeout("Frameset2Trans('" + Frameset_1 + "','" + Frameset_2 + "')", 500);
	
	setFrame1 = false;
	setFrame2 = false;
	setTimeout("Frameset3Trans('" + Frameset_2 + "','" + CaseEditURL + "','" + CaseTabURL + "','" + CaseGridURL + "')", 500);
}

function Frameset2Trans(pageURL1, pageURL2) {
	if (!setFrame) {
		if (top.mainFrame.window.location.href.indexOf(pageURL1) >= 0) {
			top.mainFrame.main.window.location.href = pageURL2 + "?ShowCase=1";
			setFrame = true;
		} else {
			setTimeout("Frameset2Trans('" + pageURL1 + "','" + pageURL2 + "')", 500);
		}
	}
}

function Frameset3Trans(frameSetURL, pageURL1, pageURL2, pageURL3) {
	if (!setFrame1) {
		if (setFrame) {
			if (top.mainFrame.main.window.location.href.indexOf(frameSetURL) >= 0) {
				top.mainFrame.document.all("Frame1").rows = "0,*";
				top.mainFrame.main.Edit.window.location.href = pageURL1 + "?GotoCase=1";
				top.mainFrame.main.tab.window.location.href = pageURL2;
				setTimeout("Frameset4Trans('" + pageURL1 + "','" + pageURL3 + "')", 500);
				setFrame1 = true;
			} else {
				setTimeout("Frameset3Trans('" + frameSetURL + "','" + pageURL1 + "','" + pageURL2 + "','" + pageURL3 + "')", 500);
			}
		} else {
			setTimeout("Frameset3Trans('" + frameSetURL + "','" + pageURL1 + "','" + pageURL2 + "','" + pageURL3 + "')", 500);
		}
	}
}

function Frameset4Trans(pageURL1, pageURL3) {
	if (!setFrame2) {
		if (!setFrame || !setFrame1) {
			setTimeout("Frameset4Trans('" + pageURL1 + "','" + pageURL3 + "')", 500);
		} else {
			if (top.mainFrame.main.Edit.window.location.href.indexOf(pageURL1) >= 0) {
				top.mainFrame.main.grid.window.location.href = pageURL3;
				setFrame2 = true;
			} else {
				setTimeout("Frameset4Trans('" + pageURL1 + "','" + pageURL3 + "')", 500);
			}
		}
	}
}

function MsgPageOnLoad() {
	parent.up.ReLoad();
	parent.document.all("Frame1").rows = "315,*";
}

var controlName = new Array();
var controlID = new Array();
var controlLen = new Array();
function CheckCharLength(controlName, controlID, controlLen) {
	var i = 0;
	for (i=0; i<controlID.length; i++) {
		if (document.all(controlID[i]).value.length > controlLen[i]) {
			document.all(controlID[i]).focus();
			alert(controlName[i] + "length must be less than " + controlLen[i]);
			return false;
		}
	}
	
	return true;
}

function AlignFileBox(strFile, strButton) {
	if (document.all(strFile) != null) {
		document.all(strFile).style.position = "relative";
		document.all(strFile).style.filter = "alpha(opacity=0)";
		document.all(strFile).style.width = "60px";
		document.all(strFile).style.posTop = document.all(strButton).style.posTop;
		document.all(strFile).style.posLeft = document.all(strButton).style.posLeft - 85;
	}
}

function CheckNotesLength(objNotes, strLength) {
	if (objNotes.value.length > strLength) {
		alert("Length of Notes must be less than " + strLength + ".");
		//objNotes.value = objNotes.value.substring(0, strLength);
		//objNotes.focus();
		return false;
	} else {
		return true;
	}
}

function CheckUDFNotesLength(objNotes, strLength, strObjName) {
	if (objNotes.value.length > strLength) {
		alert("Length of " + strObjName + " must be less than " + strLength + ".");
		//objNotes.value = objNotes.value.substring(0, strLength);
		//objNotes.focus();
		return false;
	} else {
		return true;
	}
}

function readCookie(name) 
{ 
	var cookieValue = ""; 
	var search = name + "="; 
	if(document.cookie.length > 0) 
	{ 
		offset = document.cookie.indexOf(search);
		if (offset != -1) 
		{ 
			offset += search.length; 
			end = document.cookie.indexOf(";", offset); 
			if (end == -1) end = document.cookie.length; 
			cookieValue = unescape(document.cookie.substring(offset, end));
		} 
		return cookieValue; 
	} else {
		return "";
	}
}

function writeCookie(name, value, hours) 
{ 
	var expire = ""; 
	expire = new Date((new Date()).getTime() + hours * 3600000);
	expire = "; expires=" + expire.toGMTString(); 
	document.cookie = name + "=" + escape(value) + expire;
}


function ShowHelpCaseSearch() {
	var cWidth = top.document.body.clientWidth - 20;
	window.open("../help/help1.html", "Help", "toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no, width=" + cWidth + ", height=300, top=10, left=10");
}

function ShowHelpCaseInd() {
	var cLeft = top.document.body.clientWidth - 350;
	var cHeight = top.document.body.clientHeight - 20;
	window.open("../help/help2.html", "Help", "toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no, width=350, height=" + cHeight + ", top=10, left=" + cLeft);
}

function ShowHelpCaseAddr() {
	var cLeft = top.document.body.clientWidth - 350;
	var cHeight = top.document.body.clientHeight - 20;
	window.open("../help/help3.html", "Help", "toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no, width=350, height=" + cHeight + ", top=10, left=" + cLeft);
}

function BodyKeyDown() {
	if(event.keyCode==13) {
		return event.srcElement.tagName=='TEXTAREA';
	}else if (event.keyCode==8) {
		return event.srcElement.tagName=='TEXTAREA' || (event.srcElement.tagName=='INPUT' && (event.srcElement.type=='text' || event.srcElement.type=='password') && event.srcElement.readOnly==false);
	}
	return true;
}

function strIndexOf(strSub, strContent) {
	var len = strSub.length;
	if (strContent.length < len) {
		return -1;
	}
	for (var i = 0; i<strContent.length; i++) {
		if (i>=strContent.length - len) {
			return -1;
		}
		var strTmp = strContent.substring(i, len + i);
		if (strTmp == strSub) {
			return i;
		}
	}
}

document.write("<div style='position:absolute; left:0px; top:0px; width:0px; z-index:-1; background-color: #FFFFFF; layer-background-color: #FFFFFF; visibility: hidden; border: 1px none #FFFFFF;'><object ID='WebBrowser1' WIDTH='0' HEIGHT='0' CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object></div>");
