//'***************************************************************************
//' Comment History
//'***************************************************************************
//' STAMP			Date				Description
//'					Name
//'***************************************************************************
//' DD_27092005_1500	27-Sep-2005		Implementing Demo mode
//'						Dheeraj Dagliya
//'***************************************************************************

	function selDayclick(id , sFrmName)
	{
		eval("window.document." + String(sFrmName) + ".hidSelectedDay.value =  " + String(id));
		eval("window.document." + String(sFrmName) + ".submit()");
	}

	function doclick(str , sFrmName)
	{
		var nIndex=0;
		var nYear = eval("window.document." + String(sFrmName) + ".hidYear.value");
		
		nIndex= parseFloat(String(eval("window.document." + String(sFrmName) + ".hidMonth.value")));
		if(str=="prev")
			nIndex--;
		else
			nIndex++;
		if(nIndex<0)
		{
			eval("window.document." + String(sFrmName) + ".hidYear.value = " + String(parseInt(nYear)- parseInt(1)) );
//			window.document.frmCalendar.hidYear.value=parseInt(window.document.frmCalendar.hidYear.value)-1;
			nIndex=11;
		}
		else if(nIndex>11)
		{
			eval("window.document." + String(sFrmName) + ".hidYear.value = " + String(parseInt(nYear) + parseInt(1)) );
			nIndex=0;
		}
		eval("window.document." + String(sFrmName) + ".hidMonth.value= " + nIndex);
		eval("window.document." + String(sFrmName) + ".hidSelectedDay.value ='' ");
		eval("window.document." + String(sFrmName) + ".submit()");
	}




// This function is called on the click of the Hot prospects check box
///	-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/// COMMENT: JAK151220031708
///		THIRD PARAMETER sHpType ADDED IN ORDER TO
///		DETERMINE THE TYPE OF HP BEING REMOVED...
///
///		FOURTH PARAMETER sLayout ADDED IN ORDER TO
///		DETERMINE THE PRESENT LAYOUT OF HOME PAGE...
///	-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function fnValidateRL(sForm, sCntrl, sHpType, sLayout)
{
	sRetVal = "" // variable to get the no of check boxes clicked
	sSubmitPage = ""

	sRetVal = fnClickVal( sForm, sCntrl )
	
	var sModeValue = "";
	if(sHpType.toUpperCase() == "H")
		sModeValue = "RL";
	else
		sModeValue = "EM";

	if(sLayout == "O")
	{
		sSubmitPage = "Default.asp";
	}
	else
	{
		sSubmitPage = "Default1.asp";
		eval(sForm +".hidSubmitMode").value = "changepage";
		eval(sForm +".hidDiaryPageName").value = "5_off.gif";
	}

	if ( String(sRetVal) != "false" && parseInt( String(sRetVal).substr(0,1), 10) >= 1  )
	{
		eval(sForm + ".hidMode").value = sModeValue;
		eval(sForm + ".action = '"+ sSubmitPage +"'") 
		eval(sForm + ".submit()")
	}

	event.returnValue = false ;
	return false ;
}

function fnClickVal( sForm, sCntrl )
{
	var iCtr							// variable for the loop variable
	var iFound = "0"				// variable for found variable
	var sVal = ""					// checked box value

	if (  eval( "String(" + sForm + "." + sCntrl + ") == 'undefined' " ) )
	{
		return false ;
	}
	if ( eval( "String(" + sForm + "." + sCntrl + ".length) == 'undefined' " ) )
	{
		if ( eval( "String(" + sForm + "." + sCntrl + ".disabled) == 'false' " )  )		
		{
			if ( eval( "String(" + sForm + "." + sCntrl + ".checked) == 'false' " )  )
			{
				return false ;
			}
			else
				return "1" + eval( "String(" + sForm + "." + sCntrl + ".value)" ) ;
		}
		else
		{
			return false ;
		}
	}
	else
	{
		for ( iCtr=0;iCtr < eval( sForm + "." + sCntrl + ".length" ) ; iCtr++ )
		{
	
			if ( eval( sForm + "." + sCntrl + "(" + iCtr + ").checked == true" ) && ( eval( sForm + "." + sCntrl + "(" + iCtr + ").disabled == false" ) ) )
			{
				if (String(sVal) == ""  )
					sVal = eval( sForm + "." + sCntrl + "(" + iCtr + ").value" ) ;
				else
					sVal = sVal + "," + eval( sForm + "." + sCntrl + "(" + iCtr + ").value" ) ; 
			
				iFound++ ;
			}

		}
		
		if ( iFound == 0 )
		{
			return false ;
		}
		else
		{	
			return String(iFound) + String(sVal) ;
		}

	}

}
// This function is called on the click of Edit Upcoming Seminar
function fnConfirmEdit( sForm, sCntrl )
{
	sRetVal = "" // variable to get the no of check boxes clicked

	sRetVal = fnClickVal( sForm, sCntrl )
	
	if ( String(sRetVal) != "false" && parseInt( String(sRetVal).substr(0,1), 10) > 1  )
	{
		alert ( "You can edit one seminar at a time. ")
		fnUnCheckAll( sForm, sCntrl )
	}
	else if ( parseInt( String(sRetVal).substr(0,1), 10) == 1 )
	{
		eval( sForm + ".hidJobId.value = '" + String(sRetVal).substr(1) +"'" )
		//alert ( eval( sForm + ".hidJobId.value" ) )
		eval( sForm + ".hidMode.value = 'E'" )
		eval( sForm + ".action = 'Default1.asp'" ) 
		eval( sForm + ".submit()" )
	}
	event.returnValue = false ;
	return false ;



}
function fnConfirmThank( sForm, sCntrl )
{
	sRetVal = "" // variable to get the no of check boxes clicked

	sRetVal = fnClickVal( sForm, sCntrl )
	
	if ( String(sRetVal) != "false" && parseInt( String(sRetVal).substr(0,1), 10) > 1  )
	{
		alert ( "You can edit one seminar at a time. ")
		fnUnCheckAll( sForm, sCntrl )
	}
	else if ( parseInt( String(sRetVal).substr(0,1), 10) == 1 )
	{
		eval( sForm + ".hidJobId.value = '" + String(sRetVal).substr(1) +"'" )
		window.open('db/seminarlist.asp','Preview','width=350,height=400,directories=yes,location=yes,menubar=no,scrollbars=yes,status=yes,toolbar=yes,resizable=yes,left=0,top=0,screenX=10,screenY=10')
		//eval( sForm + ".submit()" )
	}
	event.returnValue = false ;
	return false ;
}

function fnConfirmSave(sForm, sCntrl,sCardTyp)
{

	if(! IsAllowedInDemo('DEMO_GUEST,DEMO_SPECIAL') )
	{
		event.returnValue =false ;
		return false ;
	}

	sRetVal = "" // variable to get the no of check boxes clicked

	sRetVal = fnClickVal( sForm, sCntrl )
	if ( String(sRetVal) != "false" )
	{
		eval( sForm + ".hidClientIds.value = '" + String(sRetVal).substr(1) +"'" )
		eval( sForm + ".hidMailGroupType.value = '" + String(sCardTyp) +"'" )
		//alert ( eval( sForm + ".hidMailGroupType.value" ) )
		//alert ( eval( sForm + ".hidClientIds.value" ) )
		//alert ( eval( sForm + ".hidClientIds.value" ) )
		eval( sForm + ".action = '/crmSuite/products/EasySend.asp'" ) 
		eval( sForm + ".submit()" )
	}
	event.returnValue = false ;
	return false ;
}

function fnUnCheckAll( sForm, sCntrl )
{
	if (  eval( "String(" + sForm + "." + sCntrl + ") == 'undefined' " ) )
	{
		return false ;
	}
	if ( eval( "String(" + sForm + "." + sCntrl + ".length) == 'undefined' " ) )
	{
		eval( sForm + "." + sCntrl + ".checked = false " ) ;
	}
	else
	{
		for ( iCtr=0;iCtr < eval( sForm + "." + sCntrl + ".length" ) ; iCtr++ )
		{
	
			eval( sForm + "." + sCntrl + "(" + iCtr + ").checked = false " ) ;
			

		}
	}
}
// This function is called on Body Load and flashes a message if any
function fnOnLoad()
{
	if ( String( sVarDec ) != "undefined" && String( sVarDec ) != "" )
	{
		var bWithChanges = 	window.showModalDialog("db/template/continuedialogue.stm", sVarDec, "status:no;resizable:no;status=no;scroll:no;center: yes;dialogWidth:420px;dialogHeight:150px")
		// Include Code to open to create a new Job 
		alert ( bWithChanges )
	}

}

// This function is called on links of contacts From Hot Prospects and Upcoming events
function fnVwContact(sForm, nCntId)
{
	// DD_27092005_1500 : BEGIN
	if( ! IsAllowedInDemo( "DEMO_GUEST" , false , "Contact details are not editable from here in Demo Version." ) )
    {
		return false;  
		window.event.returnValue = false ;
    }
	// DD_27092005_1500 : END
//	alert(sForm + ".contactId.value = " + nCntId );		//added by Ashish Chauhan 11032004_17:20 
	eval(sForm + ".contactId.value = " + nCntId );
//	eval(sForm + ".action= '/Contacts/ShowContacts.asp'" )
	eval(sForm + ".submit()" );
}

//This function is called on the click of the NLOM image
// Change made by maithily for issue 2280 Default.asp Advertisement
function frmsub(sVal,sPage,iMailProductId)
{
	sUser=String(window.document.mainForm.hidUser.value)
	iProducerId=String(window.document.mainForm.hidProducer.value)
	sVal = String ( sVal )
	
	//alert(sUser);alert(iProducerId);
	AddACTLParameter("sMailingType",sVal)
	AddACTLParameter("sUser",sUser)
	AddACTLParameter("iProducerId",iProducerId)
	AddACTLParameter("iMailProductId",iMailProductId)
	//alert(sVal);alert(iMailProductId)
	mainForm.hidClient.value=GetACTLParameterString()
	
	window.mainForm.action=sPage
	mainForm.Mode.value = "N"
	event.returnValue = false
	window.mainForm.submit()
		
}



///////////////////////////////////////////////////////////////////////////////
// Author  : Mahendra Parmar
// Date    : April 17, 2003
// FUNCTION: To show enhancements

function showEnhanceMents()
{
	//*************************************************************//
	//CHANGED BY SANDEEP SHRIVASTAVA ON 26/08/2003 ISSUE ID 4072
	//window.mainForm.action = "/crmSuite/products/v31PubEnhance.asp";
	window.mainForm.action = "/crmSuite/products/PubEnhance.asp";
	//*************************************************************//

	event.returnValue = false
	window.mainForm.submit();
}
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Author  : Jay A. Khimani
// Date    : November 10, 2003
// Function: To show toold tip for the appointments
function fnShowTip(bShowTip, sTip)
{
	var oDiv = window.document.all.divTip;
	if(bShowTip)
	{
		oDiv.style.left = window.event.x  + window.document.body.scrollLeft + 10;
		oDiv.style.top = window.event.y + window.document.body.scrollTop;
		oDiv.innerHTML = sTip //+"<br/>ele: "+window.document.body.scrollTop;
		oDiv.style.display = "block";
	}
	else
	{
		oDiv.innerHTML = "";
		oDiv.style.display = "none";
	}
}

/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
///	COMMENT: JAK111120031530
///		ON CLICK OF PREFERENCES...
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function fnOpenPref()
{
	var sRetValue = String(window.showModalDialog('SetPrefHomePage.asp','','dialogWidth:470px;status:no;center:yes;'));
	if(sRetValue.toLowerCase() != "undefined")
	{
		if(sRetValue.toLowerCase() == "no session")
		{
		/// ISSUE: 4488 - JAK301220031616
		///		IF SESSION HAS EXPIRED, SHOW APPROPRIATE MESSAGE AND
		///		SEND USER BACK TO LOGIN PAGE....
			window.location.href = "/Diary/Default.asp?error=You%20are%20no%20longer%20logged%20in.%20Please%20log%20back%20in.";
		}
		else
		{
		/// WHEN SAVE BUTTON CLICKED ON NEW APPOINTMENT MODAL DIALOG...
			window.document.mainForm.hidUserPreferences.value=sRetValue;
			window.document.mainForm.submit();
		}
	}
}

/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
///	COMMENT: JAK13120031610
///		MANAGE LIST OF THE DISPLAYED NOTES AND ENTRY FOR NEW NOTES SECTION...
///		CALLED WHEN AN EXISTING NOTES IS CLICKED TO EDIT OR 
///		NEW ICON IS PRESSED TO ADD NEW NOTES...
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


/// WILL CONTAIN THE ID OF THE NOTE/BDAY/ANNI
/// WHICH WILL BE USED TO UPDATE THE DATA.... 
var sRecordId = "new";


function fnOpenNotes(sStatus, sId, sTitle, sNotes, sLayout)
{
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-
/// if sStatus == N -- NEW NOTES BUTTON CLICKED...
///			   == e -- EXISTING NOTE CLICKED FOR UPDATION...
///
///	sId == "" FOR sTatus = N
///		== id OF THE NOTE BEING UPDATED...
///
/// sNotes == "" FOR sStatus = 0 AND 1...
///		   == ACTUAL NOTES TEXT, OF THE NOTE BEING UPDATED...
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-
	var oForm = window.document.mainForm;
	if(sStatus == "N")
	{
	/// NEW NOTES BUTTON/IMAGE CLICKED...
		window.open("SpecifyNotes.asp?sStatus=N&nId="+ sId +"&sLayout="+ sLayout, "Preview", "width=500,height=450,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,left=0,top=0,screenX=10,screenY=10");
	}
	else
	{
	/// EXISTING NOTE CLICKED FOR CONTENT UPDATION...
//		oForm.hidDiaryNotesTitle.value = String(window.event.srcElement.innerText);
		oForm.hidDiaryNotesTitle.value = String(sTitle);
		oForm.hidDiaryNotesDesc.value = sNotes;
		window.open("SpecifyNotes.asp?sStatus=E&nId="+sId +"&sLayout="+ sLayout, "Preview", "width=500,height=450,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,left=0,top=0,screenX=10,screenY=10");
	}
}


/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
///	COMMENT: JAK181120031048
///		ON CLICK OF NEW TO-DO OR ON EXISTING TO-DO...
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function fnOpenToDo(nStatus, sId, sTitle, sStartDt, sEndDt, sPrioId, sStatusId, sNotes)
{
	var oForm = window.document.mainForm;
	
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/// COMMENT: JAK100120041131 - ISSUE# 4496
///		FOR NEW TODOS, DATE SHOULD BE PREFILLED
///		AS PER THE DATE SELECTED IN THE CALENDAR ON LEFT SIDE...
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	//alert ( window.document.mainForm.hidCalDate.value );
	var aDate = String(window.document.mainForm.hidCalDate.value).split("-");
	var sAppDate = AddZero(aDate[1])+"/"+AddZero(aDate[2])+"/"+AddZero(aDate[0]);


	if(nStatus == "N")
	{
		window.open('SpecifyToDo.asp?sStatus='+ nStatus +'&nId='+ sId + "&appDate=" + sAppDate,'Preview','width=500,height=450,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,left=0,top=0,screenX=10,screenY=10');
		return false; 
	}
	else
	{
		oForm.hidDiaryToDoNotesDesc.value = sNotes;
		var sQstring = 'sStatus='+ nStatus +'&nId='+ sId +'&sTitle='+ sTitle +'&sStartDt='+ sStartDt+'&sEndDt='+ sEndDt +'&sPrioId='+ sPrioId +'&sStatusId='+sStatusId

		window.open('SpecifyToDo.asp?'+sQstring + "&appDate=" + sAppDate,'Preview','width=500,height=450,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,left=0,top=0,screenX=10,screenY=10');
	}
}

function AddZero(nInptVal)
{
///Created by Sandeep Shrivastava on 20/05/2002
	var cRetVal = "";
	if (parseFloat(nInptVal) < 10)
	{
		cRetVal = "0" + String(nInptVal)
	}
	else
	{
		cRetVal =  String(nInptVal)
	}
	return cRetVal;
}				


/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/// COMMENT: JAK251120031031
///		ON CLICK OF VARIOUS TABS OF DIARY...
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function fnChangeDiaryPage()
{
//	var sImg = String(window.event.srcElement.src);
	var sImg = String(window.event.srcElement.diary_index);
//	alert(sImg);
	var oForm = window.document.mainForm;

	sImg = sImg.substr(sImg.lastIndexOf("/") + 1);
//	alert(sImg);
	oForm.hidSubmitMode.value = "changepage";
	oForm.hidDiaryPageName.value = sImg;

	oForm.method = "post";
	oForm.action = "Default1.asp";
	oForm.submit();
}


/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/// COMMENT: JAK261120031812
///		THIS FUNCTION IS CALLED WHEN ANY DATE IS CLICKED
///		FROM ONE OF THE CALENDARS ON THE DIARY'S CALENDAR TAB...
/// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function fnDiaryCalDayClicked(nDay)
{
	window.open("CalDiary.asp?sCalDate="+nDay, "Preview","width=500,height=450,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,left=0,top=0,screenX=10,screenY=10");
}

function fnSetAppTodo()
{

	var oForm = window.document.mainForm;
	/*
	var oRdSrc = window.event.srcElement;
	var oRd = oForm.rdoAppTo;
	var oChe;
	
	if(oRd[0].checked)
		oChe = oRd[0];
	else
		oChe = oRd[1];

	alert(oRdSrc.value +" -- "+oRdSrc.value.length +"\n" + oChe.value +" --- "+oChe.value.length);
	if(oRdSrc.value != oChe.value)
	{*/
		oForm.hidSubmitMode.value = "toggle";
		oForm.action = "Default.asp";
		oForm.submit();
//	}
}

function fnSaveToDoFilterText()
{



	var oForm = window.document.mainForm;
	var oOp = oForm.selToDoFilter.options;

	if(typeof(oForm.selPageRange_ToDo) == "object")
		oForm.selPageRange_ToDo.value = 1;

	for(i=0; i<oOp.length; i++)
		if(oOp[i].selected)
			oForm.hidFilterText.value = String(oOp[i].innerText);

	oForm.submit();
}

///	-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
/// COMMENT: JAK241220031823
///		THIS FUNCTION CALLED WHEN THE PAGING COMBO
///		ON BDAY, ANNI OR AR DIARY TAB...
///	-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function fnChangePageBdAnniAr()
{
	var oForm = window.document.mainForm;
	oForm.hidSubmitMode.value = "changepage";
	oForm.hidSamePage.value = "samepage";
	oForm.submit();
}

/// -=-=-=--=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-
/// COMMENT: JAK311220031122
///		WILL SET THE DATE TO CURRENT/TODAY'S DATE...
/// -=-=-=--=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-
function fnShowToday()
{
	var oForm = window.document.mainForm;
	oForm.hidMonth.value = "undefined";
//	oForm.hidSelectedDay.value = new Date().getDate();
	oForm.hidTodayClicked.value = "today";
	oForm.submit();
}


function ShowHideCal( objectId )
{

//	alert( objectId );
	var obj = eval("window.document.all." + objectId );
	//alert( obj );
	
	if ( String ( obj ) == '[object]')
	{
		//alert( 'style' + 	obj.style.display );

		if ( obj.style.display == 'none')
		{
			obj.style.display = 'block';
		}
		else
		{
			obj.style.display = 'none';
		}

						
		if ( objectId == "divMyCal" )
		{
			window.document.mainForm.hidMyCalState.value = obj.style.display ;
		}

		if ( objectId == "divHotProspect" )
		{
			window.document.mainForm.hidHotProspectState.value = obj.style.display ;
		}

		if ( objectId == "trUBId" )
		{
			window.document.mainForm.hidUBStatus.value = obj.style.display ;
		}

		if ( objectId == "trUAStatus" )
		{
			window.document.mainForm.hidUAStatus.value = obj.style.display ;
		}

		if ( objectId == "trARStatus" )
		{
			window.document.mainForm.hidARStatus.value = obj.style.display ;
		}
	}
}
