// -------------------------------------------------------------------------------
// File name			 : script.js
// Author				 : Bavanandan Govindan
// Created on		 : Friday, 20 February 2004
// -------------------------------------------------------------------------------
// Below are all client-side scripting functions used by Project Schedule.
// This file must be included in all the pages, whereever necessary.
// Copyright © 2005 Takata, Inc.
//#"Track Record History"
//*****************************************************************************************************************************************************************************************
//S.No     Date                 Developer         TR#(if any)             Change  
//*****************************************************************************************************************************************************************************************
//1.         07/27/06          Bava			       6683                      Modified the function EnterDigitOnly() to skip the backspace character.  
//2.			11/02/06			Bava					EIS-06153-2007		Modified all the show
//*****************************************************************************************************************************************************************************************

// Public error messages used across the script file
var INVALID_WBS = "Enter a valid WBS #.\nValid formats include:\n#          1\n#.#       1.1\n#.##     1.12\n#.#.#    2.0.1";
var INVALID_DISPLAYORDER = "Display Order must be a number between 0 and 99.";
var INVALID_TIMELINE = "Please select a Timeline.";
var DEFAULT_NON_NUMERIC = "Enter a valid number.";
var NO_DELETE_FEATURE = "Delete Event: \n This feature is not available when the current or other user as checked out the related Microsoft Project File.";
var NO_MULTIPLE_SELECT = "Please select at least one or more issues to Edit.";
var INVALID_REMAINDER_DAYS = "Remainder Days must be a number between 0 to 999.";
var INVALID_WARNING_DAYS = "Warning Days must be a number between 0 to 999.";
var INVALID_ALERT_DAYS = "Alert Days must be a number between 0 to 999.";
var NO_ADMINTYPE_SELECT = "Please select a Administration Type to continue.";
var NO_TEMPLATE_SELECT = 'Please select "Add New Template" or select an existing template to continue.';
var NO_TEMPLATE_EVENT_SELECT = 'Please select "Add New Template Event" or select an existing template event to continue.';
var NO_TEMPLATE_EVENT_DELETE = 'Please select a Template Event to delete.';
var NO_TEMPLATE_TYPE_SELECT = 'Please select "Add New Template Type" or select an existing template type to continue.';
var NO_SCHEDULE_TYPE_SELECT = 'Please select "Add New Schedule Type" or select an existing schedule type to continue.';
var INVALID_PROGRESS = 'Invalid progress value.\n\n An event progress should be greater than 0 and lesser than 100.\n\n Please enter a number between 0 and 100.';
var strTempStorage="0";
var INVALID_WBS_OR_EVENTCODE = 'Please enter either WBS # or Event Code to create an Event.';
var INVALID_EVENTCODE = 'Please enter a valid Event Code.';
var INVALID_EVENT_DESC = 'Please enter a valid Event Description';
var MSG_RE_OPEN = 'Do you want to reopen this Project Schedule ?\nPress "Ok" to continue or "Cancel" to return back.';
var MSG_NO_EVENTS_SELECTED = 'Warning!\n\nNo events selected for this revision.\n\nDo you want to continue?\n\nNote:\n1. Press "Ok" to continue creating an empty template.\n2.Press "Cancel" to return back.';
var MSG_NO_TARGET_PART_TYPES_SELECTED = 'Please select one or more Target Part types to continue.';
var MSG_NO_PLAN_DATES = "Please enter Plan From / Plan To date(s).";
var MSG_NO_PLAN_FROM_DATES = "Please enter Plan From date.";
var MSG_NO_PLAN_TO_DATES = "Please enter Plan To date.";
var MSG_NO_ACT_FROM_DATES = "Please enter Actual From date.";
var MSG_NO_ACT_TO_DATES = "Please enter Actual To date.";
var MSG_ACTUAL_ERR = 'Actual From date should be lesser than Actual To date.';
var MSG_PLAN_ERR = 'Plan From date should be lesser than Plan To date.';

//Check type browser this application is invoked from.
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
var is_ie7up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6);

//Generic function to create the popup window attributes.
function getPopupAttributes(pageW,pageH,resizeYesNo,scrollYesNo){
        var screenW = pageW;
        var screenH = pageH;
        var screenL = screenL = (screen.width - screenW) / 2;
        var screenT = screenT = (screen.height - screenH) / 2;
        var winattr = "toolbar=no,menubar=no,status=no,left=" + screenL + ",top=" + screenT + ",scrollbars=" + scrollYesNo + ", resizable=" + resizeYesNo  + ",width=" + screenW + ",height=" + screenH;
		return winattr;
}

//Closes the popup window and refreshes the parent window
function CloseMe()
{
	if (window.opener && !window.opener.closed)
	{
		opener.location.reload(true);
		window.close();
	}
	else
	{
		window.close();
	}
}

//Opens the url in a new window, with status bar
function OpenWin(url)
{
	window.open(url, "_blank", "statusbar=1, width=810,height=350");
}

//Opens the report url in a new window, with status bar
function OpenReport(url)
{
	window.open(url, "_blank", "statusbar=1,address=1,resizable=no");
}

//Opens the supporting documentation url in a new window, with no status bar
function openDocumentation(sURL)
{
	sURL = 'Documentation.aspx' + sURL
	var winAttr = getPopupAttributes(750,370,'no','yes');
	window.open(sURL,'Documentation',winAttr);
}

//Checks all the fields when check-all checkbox is clicked.
function CheckAllFields(theElement) {
	var theForm = theElement.form, z = 0;	
	for(z=0; z<theForm.length;z++){if(theForm[z].type == 'checkbox' && theForm[z].name != 'chkEditAllOpenIssues'){theForm[z].checked = theElement.checked;	}}
}

//Un-Checks the check-all checkbox, when any one checkbox is unchecked in the group.
function CheckIndividualFields(theElement){
	var theForm = theElement.form,x=0, z = 0,y=0;
	for(z=0; z<theForm.length;z++){if(theForm[z].type == 'checkbox' && theForm[z].name != 'chkEditAllOpenIssues'){	x++;	if(theForm[z].checked){y++;}}}
	if(theElement.checked && y==x){	document.getElementById('chkEditAllOpenIssues').checked = true;}else{	document.getElementById('chkEditAllOpenIssues').checked = false;	}
}

function QueryCheckAllFields(){
	if (document.forms[0].elements['chkAll'].checked)
	{
		document.forms[0].elements['chk'].checked = true;
	}
	else
	{
		document.forms[0].elements['chk'].checked = true;
	}
}

//Un-Checks the check-all checkbox, when any one checkbox 
//is unchecked in the group.
function QueryCheckIndividualFields() 
{
	if (document.forms[0].elements['chk0'].checked &&
		document.forms[0].elements['chk1'].checked)
		{
			document.forms[0].elements['chkAll'].checked = true;
		}
	else
		{
			document.forms[0].elements['chkAll'].checked = false;
		}
}

//Checks whether the input object is undefined value or not.
function isUndefined(obj) {if( typeof(obj) == "undefined" ) {return true;} else {return false;}}

//Additional confirmation before executing the actual function.
function verifyOperation(clientID,clientItemID,displayMsg)
{	
	if(confirm(displayMsg) == true)
	{
		__doPostBack(clientID,clientItemID);
	}
}

//Additional confirmation before executing the actual function.
function verifyCancel(clientID,clientItemID,displayMsg)
{	
	if(confirm(displayMsg) == false)
	{
		document.getElementById('hdnReturnVal').value = 'true';		
	}
		__doPostBack(clientID,clientItemID);
}

function openDialog(sURL)
{
	var rc = new Array(0,0);
	sURL = 'Wizard.aspx' + sURL;
	if (is_ie7 && is_ie7up){
		rc= window.showModalDialog(sURL,'','dialogHeight:580px;dialogWidth:600px;scroll:no;status:no;edge:raised;center:yes;');
	}else	{
		rc= window.showModalDialog(sURL,'','dialogHeight:605px;dialogWidth:600px;scroll:no;status:no;edge:raised;center:yes;');
	}
	if(!isUndefined(rc)){
		if(rc[0]!=null)
		{
			document.getElementById('hdnReturnVal').value = rc[1];
			__doPostBack('lnkPopup','');
		}
	}
}

function openRevisionWizard(sURL)
{
	var rc = new Array(0,0);
	sURL = 'RevisionWizard.aspx' + sURL;
	if (is_ie7 && is_ie7up){
		rc= window.showModalDialog(sURL,'','dialogHeight:661px;dialogWidth:800px;scroll:no;status:no;edge:raised;center:yes;');
	}else	{
		rc= window.showModalDialog(sURL,'','dialogHeight:686px;dialogWidth:800px;scroll:no;status:no;edge:raised;center:yes;');
	}

	if(!isUndefined(rc)){
		if(rc[0]!=null)
		{
			document.getElementById('hdnReturnVal').value = rc[1];
			__doPostBack('lnkPopup','');
		}
	}
}

function openEditEventDialog(sURL){
	var rc = new Array(0,0);	
	sURL = getNums(sURL);	
	
	if (is_ie7 && is_ie7up){
		rc= window.showModalDialog(sURL,'','dialogHeight:587px;dialogWidth:700px;scroll:no;status:no;edge:raised;center:yes;');
	}else	{
		rc= window.showModalDialog(sURL,'','dialogHeight:610px;dialogWidth:700px;scroll:no;status:no;edge:raised;center:yes;');
	}
	if(!isUndefined(rc)){
		if(rc[0]!=null)
		{
			__doPostBack('lnkPopup','');
		}
	}
}

function openDeleteEventDialog(sURL){
	var rc = new Array(0,0);	
	sURL = getNums(sURL);
	if (is_ie7 && is_ie7up){
		rc= window.showModalDialog(sURL,'','dialogHeight:255px;dialogWidth:600px;scroll:no;status:no;edge:raised;center:yes;');
	}else	{
		rc= window.showModalDialog(sURL,'','dialogHeight:280px;dialogWidth:600px;scroll:no;status:no;edge:raised;center:yes;');
	}
	if(!isUndefined(rc)){
		if(rc[0]!=null)
		{
			__doPostBack('lnkPopup','');
		}
	}
}

function OpenModalessWindow(sURL){
	sURL = getNums(sURL);
   var winAttr = getPopupAttributes(640,420,'yes');
	window.open(sURL, '',winAttr);
}

function cancelEdit(vClientID){
    if(confirm('Are  you sure, you want to cancel the changes?'))
    {
		if(vClientID!=''){
			__doPostBack(vClientID,'');
		}
    }
}

function cancelChanges(){
    if(confirm('Are  you sure, you want to cancel the changes?'))
    {
        var ret=new Array(null,null) ;
		window.returnValue=ret;	 
		window.close();		
    } 
}

function openAdmin(sURL){
	sURL = getNums(sURL);
	sURL = 'Administration.aspx' + sURL;
	var winAttr = getPopupAttributes(600,710,'no');
	var rc= window.showModalDialog(sURL,'','dialogHeight:521px;dialogWidth:720px;scroll:no;status:no;edge:raised;center:yes;');	
}

function openSearch(sURL,clientID,clientItemID){
	var rc = new Array(0,0);
	sURL = getNums(sURL);
	sURL = 'SearchProjects.aspx' + sURL;
	if (is_ie7 && is_ie7up){
		rc= window.showModalDialog(sURL,'','dialogHeight:356px;dialogWidth:600px;scroll:no;status:no;edge:raised;center:yes;');
	}else	{
		rc= window.showModalDialog(sURL,'','dialogHeight:379px;dialogWidth:600px;scroll:no;status:no;edge:raised;center:yes;');
	}
	if(!isUndefined(rc)){
		if(rc[0]!=null)
		{
			document.getElementById('hdnReturnVal').value = rc[1];
			if(document.getElementById('hdnReturnVal').value != document.getElementById('hdnProjSchedID').value){
				__doPostBack(clientID,clientItemID);
			}
		}
	}
}

function sortEvent(clientID,sSortCol,sUID,sOrder){
	document.getElementById('hdnSortColumn_' + sUID).value = sSortCol;
	document.getElementById('hdnSortOrder_' + sUID).value = sOrder;
	__doPostBack(clientID,'');	
}

function openReport(sURL){
	sURL = sURL.replace('||',document.getElementById('txtSortColumn').value);
	sURL = getNums(sURL);
	sURL = 'ReportViewer.aspx' + sURL;
	window.open(sURL, '', "statusbar=1,address=1,resizable=yes");
}

function openSubReport(vOption,sURL){	
	sURL = getNums(sURL);
	if(vOption=='1'){		
		showProcessing(vOption);
		document.getElementById('hdnURL').value = sURL;
	}else{
		window.open(sURL, '', "statusbar=1,address=1,resizable=yes");
	}
}

function openTimeLineReport(){		
	var sURL = document.getElementById('hdnURL').value;
	var sTimeLineID = document.getElementById('lstTimeLine').selectedIndex;
	var sTimeLineName = "ALL";
	if(sURL!=''){
		cancelProcessing();
		if (document.getElementById('lstTimeLine').options[sTimeLineID].value=='0'){sTimeLineName= 'ALL';}else{
			sTimeLineName = document.getElementById('lstTimeLine').options[sTimeLineID].value;}
		var vURL = sURL.replace('OtherParams',sTimeLineName);
		window.open(vURL, '', "statusbar=1,address=1,resizable=yes");
	}else{
		alert(INVALID_TIMELINE);
	}
}

var searchterm = '';
var TRange=null;

function findinpage()
{
  var searchmsg = '';
  var firstSearch = false;
  
  if (TRange!=null)
  {
	searchmsg = 'Press OK to search for the next instance of this text, or enter a new word or phrase and press OK.';
  }  
  else
  {
    searchmsg = 'Enter the text that you want to find on this page and press OK';
  }
  
  str = window.prompt(searchmsg,searchterm);
  
  if (str == "" || str == null) return false;
  if (str != searchterm)   TRange=null;

  if (TRange==null) 
  {
    TRange = self.document.body.createTextRange();
	firstSearch = true;
  }
  else
  {
    TRange.collapse(false);
  }
  
  strFound=TRange.findText(str);
  if (strFound) 
  {
    try 
    {
		TRange.select();
	}
	catch (e) 
	{
	TRange = null;
	alert("Some text is hidden on the page, please expand/show all text on the page and search again.");
    return true
	}
	searchterm = str;
	findinpage();
  }
  else 
  {
	if(firstSearch)
	{
  	  alert("Could not find the term that you were searching for.");
	}
	else
	{
	  alert ("Finished searching the document.");
	}
	TRange = null;
  }
}

function hideElement(strDivName, strChangeName)
{
	var e = null
	var eImg = null

	e=document.getElementById(strDivName);
	if (e != null)	
	{
		eImg =document.getElementById(strChangeName);
		if (eImg != null)	
		{
			if (eImg.className == "ExpandImage")
			{
				eImg.className = "CollapseImage";
				e.className = "VisibleDiv";
				trackUIstate(strChangeName,1);
			}
			else
			{
				eImg.className = "ExpandImage";
				e.className = "HiddenDiv";
				trackUIstate(strChangeName,0);
			}
		}
	}
}

function FloatDiv(divName, placement, startX, startY)
{
    e=document.getElementById(divName);
	if (e != null)	
	{
		var ns = (navigator.appName.indexOf("Netscape") != -1);
		var d = document;
		function ml(id)
		{
			var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
			if(d.layers)el.style=el;
			el.sP=function(x,y){this.style.left=x;this.style.top=y;};
			el.x = startX;
			if (placement==0)
			el.y = startY;
			else{
			el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			el.y -= startY;
			}
			return el;
		}
		window.stayTopLeft=function()
		{
			if (placement==0){
			var pY = ns ? pageYOffset : document.body.scrollTop;
			ftlObj.y += (pY + startY - ftlObj.y)/8;
			}
			else{
			var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			ftlObj.y += (pY - startY - ftlObj.y)/8;
			}
			ftlObj.sP(ftlObj.x, ftlObj.y);
			setTimeout("stayTopLeft()", 10);
		}
		ftlObj = ml(divName);
		stayTopLeft();
	}
}

function toggleLeftNav()
{
	var e = null
	e=document.getElementById("leftNavCell");
	if (e != null)	
	{
			if (e.className == "HiddenDiv")
			{
				e.className = "VisibleDiv";
				trackUIstate("leftNavCell",1,1);
				return 1
			}
			else
			{
				e.className = "HiddenDiv";
				trackUIstate("leftNavCell",0,1);
				return 0
			}
	}
}

function toggleLeftMenuWithFloatElement(floatElement, placement, hiddenX, hiddenY, showX, showY)
{
	
	if(toggleLeftNav()==0) 
	{
		FloatDiv(floatElement,placement,hiddenX,hiddenY);
	}
	else
	{
		FloatDiv(floatElement,placement,showX,showY);
	}
}

function trackUIstate(strElement, strOnOrOff, allRecords)
{
	var e = null
	if(allRecords==1)
	{
		e = document.forms[0].elements['hdnTrackAllRecordUIState']
	}
	else
	{
		e = document.forms[0].elements['hdnTrackRecordUIState']	
	}
	if(e != null)
	{
		var re = new RegExp("(.*" + strElement + "~)(.)(;.*)", "g");
		var strValue = e.value;

		if(strValue.match(re)) 
		{
			strValue = e.value.replace(re,"$1" + strOnOrOff + "$3");
		}
		else
		{
			strValue += strElement + "~" + strOnOrOff + ";";
		}
		e.value = strValue;
	}
}

function showErrorMsg1(vMessage){
	var vConstructError="<div id='divError' style='background:#ffffff;border:0px solid #000000;position:absolute;DISPLAY:block;left:171;top:70;width:830;'><table cellpadding='5' cellspacing='2' border='0' height='400px;width:100%;'><tr><td><span class='BodyTextBoldRed'>" + vMessage + "</span>.</td></tr><tr><td><span class='BodyTextBold'>For more information please contact the system administrator.</span></td></tr></table></div>";
	document.write(vConstructError);
}

function cancelProcessing(){
	var vCover = document.getElementById("divCoverup");
	var vElmt = document.getElementById("divChoose");
	vElmt.style.display = 'none';
	vCover.style.display = 'none';
	document.body.scroll='yes';
}

function showProcessing(vMsgText){
	var screenL = (screen.width - screen.availWidth /4 ) / 2;
	var screenT = (screen.height - screen.availWidth /4 ) / 2;				
	var vCover = document.getElementById("divCoverup");
	var vElmt = document.getElementById("divChoose");
	vCover.style.left = 0;	vCover.style.top = 0; 
	vCover.style.width = window.document.body.scrollWidth; vCover.style.height = window.document.body.scrollHeight;
	vCover.style.display = 'block';	vElmt.style.display = 'block';
	vElmt.style.left = screenL; vElmt.style.top=screenT;
	document.body.scroll='no';
}

function validateWBS(vCap){
	var vInput = document.getElementById(vCap);
	var vInputModified;
	if(vInput.value!=''){
		//Check and remove trailing periods
		vInput.value = TrimPrefix(TrimSuffix(vInput.value,"."),"0")		
		if(parseFloat(vInput.value)&&vInput.value.charAt(0)!="."){
			var expr = /(^[1-9]*|[1-9].*)\d$/;
			var reg = new RegExp(expr);	
			if (!vInput.value.match(reg)) {
				alert(INVALID_WBS); 
				if (strTempStorage.length>0) {vInput.value=strTempStorage;strTempStorage="";}
				return false;
			}
		}else{
			alert(INVALID_WBS); 
			if (strTempStorage.length>0) {vInput.value=strTempStorage;strTempStorage="";}
			return false;
		}
	}
	return true;
}

function doCheckInOut(){
	__doPostBack('lnkCheckOut','');
}

function validateNumeric(vCap,vMsg){
	switch(vMsg) {
		case '1': vMsg = INVALID_DISPLAYORDER;		break;
		case '2': vMsg = INVALID_PROGRESS;   				break;
		case '4': vMsg = INVALID_REMAINDER_DAYS;	break;
		case '5': vMsg = INVALID_WARNING_DAYS;		break;
		case '6': vMsg = INVALID_ALERT_DAYS;			break;		
		default:
	}
	var vInput = document.getElementById(vCap);
	if(vInput.value!=''){
		var expr = /(^[0-9]*)\d$/;
		var reg = new RegExp(expr);	
		if (!vInput.value.match(reg)) {
			alert(vMsg); 
			if (strTempStorage.length>0) {vInput.value=strTempStorage;strTempStorage="";}else{vInput.value=0;}
			vInput.focus();
			return false;
		}
	}/*else{
		
		vInput.value="0";
	}*/
	return true;
}

function cancelWizard(){window.close();}

function openNoFeature(vInput){
	switch (vInput){
	case 'DeleteEvent':
		alert(NO_DELETE_FEATURE);
		break;
	}
}

function openEditIssueDialog(sURL){
	sURL = getNums(sURL);
	var rc = new Array(0,0);
	document.getElementById("txtPopupHelper").value = '';	
	if (is_ie7 && is_ie7up){
		rc= window.showModalDialog(sURL,'','dialogHeight:540px;dialogWidth:720px;scroll:no;status:no;edge:raised;center:yes;');	
	}else	{
		rc= window.showModalDialog(sURL,'','dialogHeight:555px;dialogWidth:720px;scroll:no;status:no;edge:raised;center:yes;');	
	}
	if(!isUndefined(rc)){
		if(rc[0]!=null)
		{
			__doPostBack('lnkRefreshIssueList','');
		}
	}
}

function openDeleteIssueDialog(sURL){
	sURL = getNums(sURL);
	var rc = new Array(0,0);
	document.getElementById("txtPopupHelper").value = '';	
	if (is_ie7 && is_ie7up){
		rc = window.showModalDialog(sURL,'','dialogHeight:298px;dialogWidth:720px;scroll:no;status:no;edge:raised;center:yes;');
	}else	{
		rc = window.showModalDialog(sURL,'','dialogHeight:323px;dialogWidth:720px;scroll:no;status:no;edge:raised;center:yes;');
	}
	if(!isUndefined(rc)){
		if(rc[0]!=null)
		{
			__doPostBack('lnkRefreshIssueList','');
		}
	}
}

function CheckIfNameIsChanged(clientID,clientItemID,displayMsg){
	if(vIsNameChanged==true){
		if(confirm(displayMsg)){
			__doPostBack(clientID,clientItemID);
		}	
	} else{
		__doPostBack(clientID,clientItemID);
	}
}

function catchFKeys() { 
	document.onkeydown=catchFKeys;
	f5key=116;
	f1key=112; 
	if (window.event && window.event.keyCode == f1key) {
		alert("Help section")
		window.event.keyCode = 0;
	}
	if (window.event && window.event.keyCode == f5key) {
		alert("Help section")
		window.event.keyCode = 0;
	}				
	if (window.event && window.event.keyCode == 0) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return false;
	}
}

function imposeMaxLength(Object, Caption, MaxLen){
var strText;
var strMessage = Caption + " as exceeded the maximum limit of " + MaxLen + ". \nSystem will truncate the value to the maximum limit.\nDo you want to continue?";
strText = Object.value;
 if(Object.value.length > MaxLen) {
	if(confirm(strMessage)){
		Object.value = Object.value.substring(0, MaxLen);
		return true;
	}else{
		Object.focus();
		return false;		
	 }  
  } 
}

function EditAllChecked(sURL){
	var vInput=document.getElementsByTagName("input");
	sURL = getNums(sURL);
	var k=0; var strOut=''; var rc = new Array(0,0);
	var vCheck = new Array()
	for(var n=0;n<vInput.length;n++){if(vInput[n].type=="checkbox"){if(vInput[n].checked){if(vInput[n].value!='on'){vCheck[k]=vInput[n].value;k++;}}}}
	
	if(vCheck.length>0){strOut = vCheck.join("|");}else{strOut='';}	
	if(strOut!=''){
		if(vCheck.length>0 && vCheck.length<2){
			sURL = sURL.replace('EditAllChecked','Edit');
			strOut = strOut.replace(',','&ActionID=');
		}
		sURL = sURL.replace('OtherParams',strOut);
		if (is_ie7 && is_ie7up){
			rc= window.showModalDialog(sURL,'','dialogHeight:540px;dialogWidth:720px;scroll:no;status:no;edge:raised;center:yes;');	
		}else	{
			rc= window.showModalDialog(sURL,'','dialogHeight:555px;dialogWidth:720px;scroll:no;status:no;edge:raised;center:yes;');	
		}
		if(!isUndefined(rc)){if(rc[0]!=null){	__doPostBack('lnkIssues','');}	}
	}else{alert(NO_MULTIPLE_SELECT);	return;}
}

function EnterDigitOnly(e,vOption,vObject){
	switch(vOption) {
		case '1':		vMsg = INVALID_WBS;						break;
		case '2': 	vMsg = INVALID_DISPLAYORDER; 		break;
		case '3':		vMsg = INVALID_PROGRESS;				break;
		case '4':		vMsg = INVALID_REMAINDER_DAYS;	break;
		case '5':		vMsg = INVALID_WARNING_DAYS;		break;
		case '6':		vMsg = INVALID_ALERT_DAYS;			break;		
		default: 	vMsg = DEFAULT_NON_NUMERIC;
	}	
	if (document.layers) Key = e.which; else 	Key = window.event.keyCode;
	if (vOption=='1') {
		if ((Key > 45 && Key < 58) || Key == 8 ){return true;}else{return false;}
	} else{
		if ((Key > 47 && Key < 58) || Key == 8 ){return true;}else{return false;}
	}
}

function checkOrUnCheckItem(itemID,thisID){
	document.getElementById(itemID).checked = document.getElementById(thisID).checked			
}	

function changeProperties(){
	var screenL = screenL = (screen.width - 620) / 2;
	var screenT = screenT = (screen.height - 605) / 2;
	if(window.screen){window.moveTo(screenL,screenT);window.resizeTo(620,605);}
}

function validateAdminType(){
	var bCheck = false;
	var rdoButton = document.getElementsByName("rdoAdminType");
	if(rdoButton!=null){
		if(isUndefined(rdoButton.length)){
			if(rdoButton.checked){bCheck=true;}}
		else{
			for(var i=0;i<rdoButton.length;i++){if(rdoButton[i].checked){bCheck = true;}}}
		if(bCheck)
			__doPostBack('lnkNextMain','');				
		else
			alert(NO_ADMINTYPE_SELECT);
	}else{
		alert(NO_ADMINTYPE_SELECT);
	}
}		

function validateSelected(vID){
	var bCheck = false;
	var rdoButton;
	if (vID=='1') rdoButton = rdoButton = document.frmTemplateAdmin.rdoTemplateID; else rdoButton = document.frmTemplateAdmin.rdoTemplateEventID;
					
	if(rdoButton!=null){
		if(isUndefined(rdoButton.length)){
			if(rdoButton.checked){bCheck=true;}
		}else{
			for(var i=0;i<rdoButton.length;i++){if(rdoButton[i].checked){bCheck = true;}}
		}
		if(bCheck){
			if (vID=='1') 
				__doPostBack('lnkNextList','');		
			else if(vID=='2')
				__doPostBack('lnkNextEdit','');				
			else if(vID=='3')
				__doPostBack('lnkDelete','');							
		}else{
			if (vID=='1')
				alert(NO_TEMPLATE_SELECT);
			else if(vID=='2')
				alert(NO_TEMPLATE_EVENT_SELECT);
			else if(vID=='3')
				alert(NO_TEMPLATE_EVENT_DELETE);
		}
	}else{
			if (vID=='1')
				alert(NO_TEMPLATE_SELECT);
			else
				alert(NO_TEMPLATE_EVENT_SELECT);
	}
}	

function progressRange(){
	var vProgress = document.getElementById("txtProgress");
	var vSeperator = document.getElementById("hdnDateSep").value;
	var vFormat = document.getElementById("hdnDateFormat").value;
	if((vProgress.value>=0&&vProgress.value<=100) && vProgress.value !=''){
		if(document.getElementById("txtPlanFrom").value.length> 0 && document.getElementById("txtPlanTo").value.length>0){		
			if(document.getElementById("txtActualTo").value.length==0 && document.getElementById("txtPlanTo").value.length > 0){
				if(vProgress.value==100)
					document.getElementById("txtActualTo").value = document.getElementById("txtPlanTo").value;
			}else{
				document.getElementById("txtPlanTo").value = document.getElementById("txtActualTo").value;
				document.getElementById("txtProgress").value = '100';
			}
			if(document.getElementById("txtActualFrom").value.length==0 && document.getElementById("txtPlanFrom").value.length>0){
				if(vProgress.value>0)
					document.getElementById("txtActualFrom").value = document.getElementById("txtPlanFrom").value;
			}else{
				document.getElementById("txtPlanFrom").value = document.getElementById("txtActualFrom").value;
			}
		}else if(vProgress.value>0 && vProgress.value<100){
			if(document.getElementById("txtActualFrom").value.length >0)
				document.getElementById("txtPlanFrom").value = document.getElementById("txtActualFrom").value;
			else{
				if(document.getElementById("txtPlanFrom").value.length>0){
					document.getElementById("txtActualFrom").value = document.getElementById("txtPlanFrom").value;						
				}else{
					alert(MSG_NO_PLAN_FROM_DATES);
					return false;
				}
			}
			if(document.getElementById("txtActualTo").value.length >0)
				document.getElementById("txtPlanTo").value = document.getElementById("txtActualTo").value;
			else{
				if(document.getElementById("txtPlanTo").value.length>0){
					document.getElementById("txtActualTo").value = document.getElementById("txtPlanTo").value;						
				}else{
					alert(MSG_NO_PLAN_TO_DATES);
					return false;
				}
			}	
			if(document.getElementById("txtActualFrom").value.length>0 && document.getElementById("txtActualTo").value.length>0){
				document.getElementById("txtProgress").value='100';
				document.getElementById("txtPlanFrom").value = document.getElementById("txtActualFrom").value;
				document.getElementById("txtPlanTo").value = document.getElementById("txtActualTo").value;
			}
		}else if(document.getElementById("txtActualTo").value.length>0){
			document.getElementById("txtProgress").value = '100';
			document.getElementById("txtPlanTo").value = document.getElementById("txtActualTo").value;			
			if(document.getElementById("txtActualFrom").value.length >0)
				document.getElementById("txtPlanFrom").value = document.getElementById("txtActualFrom").value;
			else{
				if(document.getElementById("txtPlanFrom").value.length>0){
					document.getElementById("txtActualFrom").value = document.getElementById("txtPlanFrom").value;						
				}else{
					alert(MSG_NO_PLAN_FROM_DATES);
					return false;
				}
			}
		}else if(vProgress.value==100){
			if(document.getElementById("txtActualFrom").value.length >0)
				document.getElementById("txtPlanFrom").value = document.getElementById("txtActualFrom").value;
			else{
				if(document.getElementById("txtPlanFrom").value.length>0){
					document.getElementById("txtActualFrom").value = document.getElementById("txtPlanFrom").value;						
				}else{
					alert(MSG_NO_PLAN_FROM_DATES);
					return false;
				}
			}
			if(document.getElementById("txtActualTo").value.length >0)
				document.getElementById("txtPlanTo").value = document.getElementById("txtActualTo").value;
			else{
				if(document.getElementById("txtPlanTo").value.length>0){
					document.getElementById("txtActualTo").value = document.getElementById("txtPlanTo").value;						
				}else{
					alert(MSG_NO_PLAN_TO_DATES);
					return false;
				}
			}	
		}
	}else{
		alert(INVALID_PROGRESS);
		if (strTempStorage.length>0) {vProgress.value=strTempStorage;strTempStorage="";}
		return false;
	}
	return true;
}

function validateScheduleTypeSelected(){
	var bCheck = false;
	var rdoButton = document.frmScheduleTypeAdmin.rdoScheduleTypeID;
	if(rdoButton!=null){
		if(isUndefined(rdoButton.length)){
			if(rdoButton.checked){bCheck=true;}
		}else{
			for(var i=0;i<rdoButton.length;i++){if(rdoButton[i].checked){bCheck = true;}}
		}
		if(bCheck)
			__doPostBack('lnkNextFinish','');				
		else
			alert(NO_SCHEDULE_TYPE_SELECT);
	}else{
		alalert(NO_SCHEDULE_TYPE_SELECT);
	}
}

function validateTemplateTypeSelected(){
	var bCheck = false;
	var rdoButton = document.frmTemplateTypeAdmin.rdoTemplateTypeID;
	if(rdoButton!=null){
		if(isUndefined(rdoButton.length)){
			if(rdoButton.checked){bCheck=true;}
		}else{
			for(var i=0;i<rdoButton.length;i++){if(rdoButton[i].checked){bCheck = true;}}
		}
		if(bCheck)
			__doPostBack('lnkNext','');				
		else
			alert(NO_TEMPLATE_TYPE_SELECT);
	}else{
		alert(NO_TEMPLATE_TYPE_SELECT);
	}
}

function showCheckOut(){
	var screenL = (screen.width - 400) /2; var screenT = (screen.height) /4;
	var vCover = document.getElementById("divCoverup"); var vChoose = document.getElementById("divCheckInOut");
	vCover.style.display = 'block'; vCover.style.left = 0; vCover.style.top = 0;
	vCover.style.width = window.document.body.scrollWidth; vCover.style.height = window.document.body.scrollHeight;
	vChoose.style.display = 'block'; vChoose.style.left = screenL; vChoose.style.top = screenT;
	document.body.scroll = 'no';
}

function closeCheckOut(vType){
	var vChoose = document.getElementById('divCheckInOut');
	vChoose.style.display = 'none';
	document.body.scroll='yes';
	if(vType=='1'){
		doCheckInOut();
	}else if(vType=='2'){
		__doPostBack('lnkEvents','');
	}
}

function validateData(){			
	var isValidToSubmit=true;
	if(isValidToSubmit && (imposeMaxLength(document.getElementById('txtIssue'),'Issue',500)==false ||
											imposeMaxLength(document.getElementById('txtCause'),'Cause',500)==false ||
											imposeMaxLength(document.getElementById('txtCounterMeasure'),'Counter Measure',500)==false ||
											imposeMaxLength(document.getElementById('txtComments'),'Comments',1000)==false)){
		isValidToSubmit = false;
	}
	
	if(isValidToSubmit){				
		__doPostBack('lblFinish','');
	}
}

//---------------------------------------------------------------------------------------
// Trim functions
// Returns string with whitespace trimmed or a specified value to trim
//---------------------------------------------------------------------------------------
function LTrimString(vIn,vFind){
	if (vIn==null){return null;}
	for(var i=0;vIn.charAt(i)==vFind;i++);
	return vIn.substring(i,vIn.length);
}
function RTrimString(vIn, vFind){
	if (vIn==null){return null;}
	for(var i=vIn.length-1;vIn.charAt(i)==vFind;i--);
	return vIn.substring(0,i+1);
}
function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
}
function Trim(str){return LTrim(RTrim(str));}
function LTrimAll(str) {
	if (str==null){return str;}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
}
function RTrimAll(str) {
	if (str==null){return str;}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
}
function TrimAll(str) {	return LTrimAll(RTrimAll(str));}
function TrimPrefix(vIn,vFind){
	var vOut = vIn;
	if(vIn==null||vIn=="") return vIn;
	for(var i=0;i<vIn.length;i++){if(vIn.substring(0,1)==vFind){vOut = vIn.substring(1,vIn.length);vIn = vOut;	}else{vIn = vOut;break;}}
	return vOut;
}
function TrimSuffix(vIn,vFind){
	var vOut=vIn,j=0;
	if(vIn==null||vIn=="") return vIn;
	for(var i=vIn.length-1;i>0;i--){if(vIn.substring(vIn.length,i)==vFind){	vOut = vIn.substring(0,vIn.length-1); vIn = vOut;}else{	vIn = vOut;	break;	}}
	return vOut;
}

function validateTemplateEventDesc(vEventDescId,vClientItemID,vWBSId,vPartTypes){
	var vEventDesc = document.getElementById(vEventDescId);
	var vWBS = document.getElementById(vWBSId);
	
	if(TrimAll(vEventDesc.value).length==0){
		alert(INVALID_EVENT_DESC);
	}else{
		if(vWBS.value!=''){
			if(validateWBS(vWBSId)){
				if(validateTargetPartSelection(vPartTypes)){
					__doPostBack(vClientItemID,'');
				}else{
					alert(MSG_NO_TARGET_PART_TYPES_SELECTED);					
				}				
			}		
		}else{
			if(validateTargetPartSelection(vPartTypes)){
				__doPostBack(vClientItemID,'');
			}else{
				alert(MSG_NO_TARGET_PART_TYPES_SELECTED);					
			}	
		}
	}
}

function validateEventSubmission(vWBSId,vClientItemID,vRequired,vSend){
	var vIsRequired = document.getElementById(vRequired);
	var vChecked = document.getElementById(vSend).checked;
	if(vIsRequired.value=='True'){
		var vWBS = document.getElementById(vWBSId);
		if(vWBS.value!=''){
			if(validateWBS(vWBSId)){		
				if(progressRange()==true){
					if(!vChecked){
						__doPostBack(vClientItemID,'');
					}else{
						if(multiEmail(document.getElementById('txtAddNotifAddress').value)==true){
							__doPostBack(vClientItemID,'');
						}
					}
				}
			}
		}else{
			if(progressRange()==true){
				if(!vChecked){
					__doPostBack(vClientItemID,'');
				}else{
					if(multiEmail(document.getElementById('txtAddNotifAddress').value)==true){
						__doPostBack(vClientItemID,'');
					}
				}
			}
		}
	}else{
		if(progressRange()==true){			
			if(!vChecked){
				__doPostBack(vClientItemID,'');
			}else{
				if(multiEmail(document.getElementById('txtAddNotifAddress').value)==true){
					__doPostBack(vClientItemID,'');
				}
			}
		}
	}
}

function querystring(key) { 
	var value = null; 
	for (var i=0;i<querystring.keys.length;i++){ 
		if (querystring.keys[i]==key){ 
			value = querystring.values[i]; 
			break; 
		} 
	} 
	return value; 
} 
querystring.keys = new Array(); 
querystring.values = new Array(); 

function querystring_Parse(){ 
	var query = window.location.search.substring(1); 
	var pairs = query.split("&"); 
	for (var i=0;i<pairs.length;i++){ 
		var pos = pairs[i].indexOf('='); 
		if (pos >= 0){ 
			var argname = pairs[i].substring(0,pos); 
			var value = pairs[i].substring(pos+1); 
			querystring.keys[querystring.keys.length] = argname; 
			querystring.values[querystring.values.length] = value; 
		} 
	} 
} 

function openAdminFromTAS(sURL){
	querystring_Parse(); 
	var adminURL = querystring('URL');
	var adminCpy = querystring('Company');
	adminURL = adminURL + '&Company=' + adminCpy
	var winAttr = getPopupAttributes(720,573,'no');
	sURL = getNums(sURL);
	window.open(adminURL, '',winAttr);
	window.opener = null;
	window.close();
	return false;
}

function showCodes(){
	var vElementID = document.getElementById('pnlShowCustomerCodes');
	vElementID.style.visibility = 'visible';
	document.getElementById('lblWizardFinish').disabled = true;
	document.getElementById('lblWizardFinish').style.cursor = 'none';
}

function hideCodes(){
	var vElementID = document.getElementById('pnlShowCustomerCodes');
	vElementID.style.visibility = 'hidden';
	document.getElementById('lblWizardFinish').disabled = false;
	document.getElementById('lblWizardFinish').style.cursor = 'hand';
}

function verifyIssueOkCancel(clientID,clientItemID,displayMsg)
{	
	if(confirm(displayMsg) == true){
		document.getElementById('hdnReturnVal').value = 'True';	
		__doPostBack(clientID,clientItemID);
	}else{
		if(clientItemID=='cmdCancel'){
			document.getElementById('hdnReturnVal').value = 'False';
			__doPostBack(clientID,clientItemID);
		}		
	}		
}

function enableNotificationList(vCheckItem,vServer){	
	if(document.getElementById(vCheckItem).checked){	
		document.getElementById('txtAddNotifAddress').disabled = false;
		document.getElementById('lnkAddNotifAddress').disabled = false;
		document.getElementById('lnkAddNotifAddress').href = "javascript:openEmailWizard('http://" + vServer + "/EmailWizard/EmailSelect.aspx?EmailID=txtAddNotifAddress&Email_Lang=hdnEmailLang');";
		document.getElementById('lnkAddNotifAddress').style.cursor = 'hand';
	}else{
		document.getElementById('txtAddNotifAddress').disabled = true;
		document.getElementById('lnkAddNotifAddress').disabled = true;		
		document.getElementById('lnkAddNotifAddress').href = "#";
		document.getElementById('lnkAddNotifAddress').style.cursor = 'default';
	}
}

//Opens the email notification wizard popup window.			
function openEmailWizard(sURL){
	sURL = getNums(sURL);
    var winAttr = getPopupAttributes(470,409,'no');            
	window.open(sURL, "Email", winAttr);					
}	

//Reset Search
function resetSearch(){
	__doPostBack('lnkReset','');
}

//ReOpen ProjectSchedule
function reOpenSchedule(){
	if(confirm(MSG_RE_OPEN)){
		__doPostBack('lnkReOpen','');
	}
}

//Email Validation
var vEmailValidMsg = '';
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
		if (db) vEmailValidMsg = 'Email address is mandatory';
			return false;
	}
	
	var invalidChars = '\/\'\\ ":?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
		if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
			if (db) vEmailValidMsg = 'Email address(' + addr + ') contains invalid characters.';
				return false;
		}
	}
	
	for (i=0; i<addr.length; i++) {
		if (addr.charCodeAt(i)>127) {
			if (db) vEmailValidMsg = 'Email address(' + addr + ') contains non ascii characters.';
				return false;
		}
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
		if (db) vEmailValidMsg = 'Email address(' + addr + ') must contain an @.';
			return false;
	}
	if (atPos == 0) {
		if (db) vEmailValidMsg = 'Email address(' + addr + ') must not start with @.';
			return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
		if (db) vEmailValidMsg = 'Email address(' + addr + ') must contain only one @.';
			return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
		if (db) vEmailValidMsg = 'Email address(' + addr + ') must contain a period in the domain name.';
			return false;
	}
	if (addr.indexOf('@.',0) != -1) {
		if (db) vEmailValidMsg = 'Period must not immediately follow @ in email address(' + addr + ').';
			return false;
	}
	if (addr.indexOf('.@',0) != -1){
		if (db) vEmailValidMsg = 'Period must not immediately preceed @ in email address(' + addr + ').'; 
			return false;
	}
	if (addr.indexOf('..',0) != -1) {
		if (db) vEmailValidMsg = 'Two periods must not be adjacent in email address(' + addr + ').';
			return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
		if (db) vEmailValidMsg = 'Invalid primary domain in email address(' + addr + ').';
			return false;
	}
	return true;
}

function multiEmail(email_field) {
	if (email_field !=''){
		var email = email_field.split(';');			
		for (var i = 0; i < email.length; i++) {
			if (email[i]!=''){
				if (!validateEmail(email[i], document.getElementById('chkSendNotification').checked, 1)) {
					if(vEmailValidMsg.length>0){alert('Additional Notification Address: \n' + vEmailValidMsg); vEmailValidMsg='';}else alert('One or more email addresses entered is invalid.\n(' + email_field + ')');
					return false;
				}
			}
		}
	}
	return true;	
} 

//Checks all the fields when check-all checkbox is clicked.
function selectAllEvents(theElement,chkBoxName) {
	var theForm = theElement.form, z = 0;	
	for(z=0; z<theForm.length;z++){if(theForm[z].type == 'checkbox' && theForm[z].name == chkBoxName){theForm[z].checked = theElement.checked;}}
}

//Un-Checks the check-all checkbox, when any one checkbox is unchecked in the group.
function selectIndividualFields(theElement,parentChkBoxName,chkBoxName){
	var theForm = theElement.form,x=0, z = 0,y=0;
	for(z=0; z<theForm.length;z++){if(theForm[z].type == 'checkbox' && theForm[z].name == chkBoxName){	x++;	if(theForm[z].checked){y++;}}}
	if(theElement.checked && y==x){document.forms[theForm.id].item(parentChkBoxName).checked = true;}else{document.forms[theForm.id].item(parentChkBoxName).checked = false;}
}

//On changing the Actual From Date , Actual To Date or Plan From , Plan To
function onActualChange(vSeperator, vFormat, vIsActualOrPlan){	
	if(vIsActualOrPlan=='1'){ //Actual
		var pActualFrom = document.getElementById('txtActualFrom').value;		
		var pActualTo = document.getElementById('txtActualTo').value;
		var sActualFrom = new Date(extractDate(pActualFrom, vSeperator, vFormat));
		var sActualTo = new Date(extractDate(pActualTo, vSeperator, vFormat));	
		if(sActualTo < sActualFrom){
			alert(MSG_ACTUAL_ERR);
			document.getElementById('txtActualFrom').value = pActualFrom;
			document.getElementById('txtActualTo').value = pActualTo;
		}else{
			if(document.getElementById('txtActualFrom').value.length>0)
				document.getElementById('txtPlanFrom').value = document.getElementById('txtActualFrom').value
			if(document.getElementById('txtActualTo').value.length>0){
				document.getElementById('txtPlanTo').value = document.getElementById('txtActualTo').value
				document.getElementById('txtProgress').value = '100';	
			}	
		}
	}else if(vIsActualOrPlan=='2'){ // Plan
		var sPlanFrom = new Date(extractDate(document.getElementById('txtPlanFrom').value, vSeperator, vFormat));
		var sPlanTo = new Date(extractDate(document.getElementById('txtPlanTo').value, vSeperator, vFormat));
		if(sPlanTo < sPlanFrom){
			alert(MSG_PLAN_ERR);
		}
	}	
}

//Extract Date by Dateformat and DateSeperator
function extractDate(sDate,sSep,sPattern){
	var vDay, vMonth,vYear, rDate;
	if(sDate.length>0){
		if(sPattern!='' && sSep!=''){
			var vPatternType = sPattern.substring(0,1);	
			var vDate = sDate.split(sSep);
			if(vPatternType=='M' ||vPatternType=='m'){
				vDay = vDate[1];vMonth = vDate[0];vYear = vDate[2];
			}else if(vPatternType=='D' ||vPatternType=='d'){
				vDay = vDate[0];vMonth = vDate[1];vYear = vDate[2];
			}else if(vPatternType=='Y' ||vPatternType=='y'){
				vDay = vDate[2];vMonth = vDate[1];vYear = vDate[0];
			}
			return vMonth + '/' + vDay + '/' + vYear;		
		}else{
			return '';
		}		
	}else{
		return '';
	}	

}

function getNums(sURL){
	var numberString = "";
	for (var i=0;i<4;i++){
		var randomNum = Math.round(Math.random()*9);
		var intRnd = randomNum + 65;
		randomNum = randomNum.toString();
		numberString += randomNum + complement(String.fromCharCode(intRnd));
	}
	return sURL + '&DId=' + numberString;
}

function complement(s) {
  var sResult = ""; var i = 0; var d = 0;  
  for (i = 0; i < s.length; i++) {
    d = s.charCodeAt(i);
	if ((d >= 65) && (d <= 90)) {
	  d = 90 - (d -65);
    }
	sResult += String.fromCharCode(d);
  }
  return sResult;
}

function openTPPEvents(sURL)
{
	var vURL = 'ShowTPPEvents.aspx' + sURL;
	var rc;
	if (is_ie7 && is_ie7up){
		rc= window.showModalDialog(vURL,'','dialogHeight:550px;dialogWidth:800px;scroll:no;status:no;edge:raised;center:yes;');
	}else	{
		rc= window.showModalDialog(vURL,'','dialogHeight:577px;dialogWidth:800px;scroll:no;status:no;edge:raised;center:yes;');	
	}
}
// TIR METHODS BEGIN
//Opens the modify concern category Window.
function OpenConcernCategories(url)
{
	var winAttr = getPopupAttributes(641,220,'yes');          
	window.open(url, "", winAttr);
}
//Opens the rank popup window.
function OpenRank(url)
{
   var winAttr = getPopupAttributes(940,750,'yes');
	window.open(url, '',winAttr);
}
//Opens the nuisance popup window.
function OpenNuisance(url)
{
   var winAttr = getPopupAttributes(641,341,'yes');
	window.open(url, '',winAttr);
}
//Opens the incident  window from incident query page.
function OpenIncident(url,title)
{
	window.open(url, title);
}
//Functions for image handling in occurrence and corrective action pages - Start
function showRemove(sFrom){
	if(sFrom=="occur"){
		document.getElementById("pnlOccurButton").style.visibility = "visible";										
		document.getElementById("pnlOccurFile").style.visibility = "hidden";
		document.getElementById("imgOccurance").src = '';
		document.getElementById("imgOccurance").src = "images/noimage.gif";
		document.getElementById("imgOccurance").src = document.getElementById("txtOccurFile").value;
		document.getElementById("txtOccurImgFileName").value = document.getElementById("txtOccurFile").value;
	} else if(sFrom=="corr"){
		document.getElementById("pnlCorrButton").style.visibility = "visible";										
		document.getElementById("pnlCorrFile").style.visibility = "hidden";
		document.getElementById("imgCAImage").src = '';
		document.getElementById("imgCAImage").src = "images/noimage.gif";
		document.getElementById("imgCAImage").src = document.getElementById("txtCorrImgFile").value;
		document.getElementById("txtCorrImgFileName").value = document.getElementById("txtCorrImgFile").value;	
	}
}
function doRemove(sFrom){
	if(sFrom=="occur"){
		document.getElementById("pnlOccurButton").style.visibility = "hidden";										
		document.getElementById("pnlOccurFile").style.visibility = "visible";
		document.getElementById("imgOccurance").src = '';
		document.getElementById("imgOccurance").src = "images/noimage.gif";
		document.getElementById("txtOccurImgFileName").value = "1";
	}
	else if(sFrom=="corr"){
		document.getElementById("pnlCorrButton").style.visibility = "hidden";										
		document.getElementById("pnlCorrFile").style.visibility = "visible";
		document.getElementById("imgCAImage").src = '';
		document.getElementById("imgCAImage").src = "images/noimage.gif";
		document.getElementById("txtCorrImgFileName").value = "1";		
	}
}
//Opens the email notification wizard popup window.
function OpenNotify(url)
{        
	var winAttr = getPopupAttributes(485,493,'no');                    
	window.open(url, "Alert", winAttr);
}
//Refreshes the page to check whether the Email is sent or not.
function setEmailNotifyReturn(returnVal)
{
	document.forms[0].txtEmailNotify.value = returnVal;
	document.forms[0].submit();
}
//Refreshes the page to update the concern categories list with new list, if changes exist.
function setConcernLevelReturn(returnVal)
{
	document.forms[0].txtConcernVal.value = returnVal;
	document.forms[0].submit();
}
//no idea what it is need to check and delete later.
function popUpRteHistory(url)
{
   sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=800,height=400,top=0,left=0');
}
 //Opens  the add new status popup window
function AddStatus(url)
{
    var winAttr = getPopupAttributes(500,235,'no');
	window.open(url, '',winAttr);
}
//Opens  the add new sort popup window
function AddSort(url)
{
    var winAttr = getPopupAttributes(500,275,'no');
	window.open(url, '',winAttr);
}
//Opens  the add new claim popup window
function AddWarranty(url)
{
    var winAttr = getPopupAttributes(500,546,'no');
	window.open(url, '',winAttr);
}
//Opens  the add new task popup window
function AddTask(url)
{
    var winAttr = getPopupAttributes(500,365,'no');    
	window.open(url, '',winAttr);
}
//Opens  the delete popup window
function OpenDeleteWin(url)
{    
    var winAttr = getPopupAttributes(500,275,'no');        
	window.open(url, '',winAttr);
}
//Opens  the popup window for selecting the type details.
function OpenTypeDetail(url)
{
    var winAttr = getPopupAttributes(300,145,'no');            
	window.open(url, '',winAttr);
}
//TIR METHOID ENDS

//MessagingPortal Javascript Function Start
function NewWindow(mypage, myname) 
{
    win = window.open(mypage, myname)

    if (parseInt(navigator.appVersion) >= 4) { 
        win.window.focus(); 
    }
}

//Opens a popup window to show the 'Check-in/out File Wizard'
function FileCheckInOut(url)
{
	window.open(url, "FileCheckInOut", "statusbar=1, width=490,height=337");
}

//Opens a popup window to show the 'Add WorkGroup Wizard'
function AddWorkGroup(url)
{
	window.open(url, "AddWorkGroup", "statusbar=1, width=490,height=337");
}

//Opens a popup window to show the 'Update WorkGroup Wizard'
function UpdateWorkGroup(url)
{
	window.open(url, "UpdateWorkGroup", "statusbar=1, width=490,height=337");
}

//Opens a popup window to show the 'Delete WorkGroup Wizard'
function DeleteWorkGroup(url)
{
	window.open(url, "DeleteWorkGroup", "statusbar=1, width=490,height=337");
}
//Opens a popup window to show the 'Add Message Wizard'
function AddMessage(url)
{
	//window.open(url, "AddMessage", "statusbar=1, width=490,height=400");
	window.open(url, "AddMessage", "statusbar=1, width=510,height=441");
}

//Opens a popup window to show the 'Add File Wizard'
function AddFile(url)
{
	window.open(url, "AddFile", "statusbar=1, width=495,height=467");
	
}

//Opens a popup window to show the 'Add WorkGroup Metric Wizard'
function AddWorkGroupMetric(url)
{
	window.open(url, "AddWorkGroupMetric", "statusbar=1, width=490,height=337");
	
}
//Opens a popup window to show the 'Update WorkGroup Metric Wizard'
function UpdateWorkGroupMetric(url)
{
	window.open(url, "UpdateWorkGroupMetric", "statusbar=1, width=490,height=337");
	
}
//Opens a popup window to show the 'Delete WorkGroup Metric Wizard'
function DeleteWorkGroupMetric(url)
{
	window.open(url, "DeleteWorkGroupMetric", "statusbar=1, width=490,height=337");
	
}

//Opens a popup window to show the 'Add WorkGroup Category  Wizard'
function AddWorkGroupCategory(url)
{
	window.open(url, "AddWorkGroupCategory", "statusbar=1, width=490,height=337");
	
}
//Opens a popup window to show the 'Update WorkGroup Category Wizard'
function UpdateWorkGroupCategory(url)
{
	window.open(url, "UpdateWorkGroupCategory", "statusbar=1, width=490,height=337");
	
}
//Opens a popup window to show the 'Delete WorkGroup Metric Wizard'
function DeleteWorkGroupCategory(url)
{
	window.open(url, "DeleteWorkGroupCategory", "statusbar=1, width=490,height=337");
	
}

//Opens a popup window to show the 'Update Message Wizard'
function UpdateMessage(url)
{
	window.open(url, "UpdateMessage", "statusbar=1, width=510,height=441");
	
}

//Opens a popup window to show the 'Update File Wizard'
function UpdateFile(url)
{
	//window.open(url, "UpdateFile", "statusbar=1, width=485,height=450");
	window.open(url, "UpdateFile", "statusbar=1, width=485,height=485");
}

//Opens a popup window to show the 'Delete / Restore Message Wizard'
function DeleteRestore(url)
{
	window.open(url, "DeleteRestore", "statusbar=1, width=441,height=336");
}

//Opens the 'Send Email' popup window
function SendMail(url)
{
	window.open(url, "SendMail", "statusbar=1, width=525,height=525");
}

//Opens the 'Compose Email' popup window
function ComposeMail(url)
{
	window.open(url, "ComposeMail", "statusbar=1, width=575,height=337");
}

//Goto FileDetail page to ViewFileHistory
function ViewFileHistory(url)
{
	window.location.href="FileDetail.aspx?" + url
}

//Goto FileDetail page to ViewItemDetail
function ViewItemDetail(url)
{
	window.location.href="FileDetail.aspx?" + url
}

//Initiates a download
function DownloadFile(url)
{
	window.open("FileDownload.aspx?" + url);
}

//Closes the popup window and refreshes the parent window
function CloseMe(url) {
	if (window.opener && !window.opener.closed){
		opener.location.href = "Workgroup.aspx?" + url;
		window.close();
	}
	else{
		window.close();
	}
}

//Closes the popup WorkGroup window and refreshes the parent window
function CloseWrkGrp(url) {
	if (window.opener && !window.opener.closed){
		if (url == 'ADDNEWUSER'){
			window.opener.location.href = window.opener.location.href;
		}
		else {
			window.opener.location.href = "Main.aspx";
		}
		window.close();
	}
	else{
		window.close();
	}
}

//Expand or Collapse a node
function OpenClose(sNode) {
	if (document.all) {
		var oObject = document.all("item" + sNode);
		var oSubObject = document.all("subitem" + sNode);
		var oImg = document.all('img' + sNode);
	}
	else {
		var oObject = document.getElementById("item" + sNode);
		var oSubObject = document.getElementById("subitem" + sNode);
		var oImg = document.getElementById('img' + sNode);
	}
	if (oSubObject.style.display == 'none') {
		oSubObject.style.display = 'block';
		oObject.className = 'NodeItemStyle';
		oSubObject.className = 'NodeSubItemStyle';		
		oImg.src = "images/collapse.gif";
		oImg.alt = 'Collapse';
	} else {
		oSubObject.style.display = 'none'
		oObject.className = '';
		oImg.src = "images/expand.gif";
		oImg.alt = 'Expand'
	}
}

//Opens a popup window to show the 'Delete User Wizard'
function DeleteUser(url)
{
	window.open(url, "DeleteUser", "statusbar=1, width=441,height=336");
}


//Update the workgroup information section
function DisplayWkgpInfo(strWkgpData)
{
  	var arrValues = strWkgpData.split("|");
    document.getElementById('lblSelectWkgpName').innerText = arrValues[1];
    document.getElementById('lblSelectWkgpStatus').innerText = arrValues[3];
    document.getElementById('lblSelectWkgpDivision').innerText = arrValues[5];
    document.getElementById('lblSelectWkgpDepartment').innerText = arrValues[6];
    document.getElementById('hlkWkgpEdit').href = "javascript:UpdateWorkGroup('AddWrkGrp.aspx?WGID=" + arrValues[0] + "')";
	document.getElementById('hlkWkgpDelete').href = "javascript:DeleteWorkGroup('DeleteWrkGrp.aspx?ID=" + arrValues[0] + "&Deleted=False')";
}

//Go to the workgroup home page
function DisplayWkgpDetail(strWkgpData)
{
	var arrValues = strWkgpData.split("|");
	window.location.href = "Workgroup.aspx?WGID=" + arrValues[0];
}

//Split a string with a delimiter
function SplitValues(strValues, delimiter)
{
    //var delimiter = "|";
    var i, intStart, intIndex, intLen;
    var arrValues = new Array();
    intStart = 0;
    intIndex = 0;
    //strValues = "0123|567|9|1";
    //alert(strValues);
    for(i = 0, intIndex = strValues.indexOf(delimiter, intStart); intIndex >= 0; i++)
    {
      arrValues[i] = strValues.substring(intStart, intIndex);
      //alert(i + " - " + intIndex + " - " + arrValues[i]);
      intStart = intIndex + 1;
      intIndex = strValues.indexOf(delimiter, intStart);
      //alert(i + " - " + intStart + " - " + intIndex);
    }
    intLen = strValues.length;
    if (intStart <= intLen)
    {  arrValues[i] = strValues.substring(intStart); }
    //for(i = 0; i < arrValues.length; i++)
    //{  alert(i + " - " + arrValues[i]); }
    return arrValues;
}
//MessagingPortal Javascript Function End