/* 
 * Opens a window to edit data for a selected row.
 */
function openEdit(sURL, iHeight, iWidth)
{
	var iTop = (screen.height - iHeight)/2;
	var iLeft = (screen.width - iWidth)/2;
	
	window.open(sURL, "_blank", "toolbar=0,scrollbars=1,resizable=0,status=1,height=" + iHeight + ",width=" + iWidth + ",top=" + iTop + ",left=" + iLeft);
}

/* 
 * Opens a full screen window
 */
function openFullscreen(sURL, iHeight, iWidth, iFullscreen)
{
	var iTop = (screen.height - iHeight)/2;
	var iLeft = (screen.width - iWidth)/2;
	
	window.open(sURL, "_blank", "toolbar=0,scrollbars=1,resizable=0,status=1,fullscreen=" + iFullscreen + ",height=" + iHeight + ",width=" + iWidth + ",top=" + iTop + ",left=" + iLeft);
}

/* 
 * Opens a modal dialog to edit data for a selected row.
 */
function openModalDialog(sURL, iWantReturnVal, iHeight, iWidth, sControlId)
{
	var sStyleString = "toolbar:0;resizable:0;status:0;dialogHeight:" + iHeight + "px;dialogWidth:" + iWidth + "px;centered:1";
	var sRetVal = window.showModalDialog(sURL, "", sStyleString);
	
	if((sRetVal == null) ||
		(sRetVal == "cancel"))
	{
		sRetVal = "";
	}

	if(sRetVal != "")
	{
		if(iWantReturnVal == "1")
		{
			var iControlId = document.getElementById(sControlId);
			iControlId.value = sRetVal;
			Form1.submit();
		}
	}
}

/* 
 * Opens a modal dialog to edit data for a selected row.
 */
function openModalDialogForWebControl(sURL, sTextToPass, iWantReturnVal, iWebControlId, iWebControlType)
{
	var sRetVal = window.showModalDialog(sURL, sTextToPass, "toolbar:0;resizable:0;status:0;dialogHeight:600px;dialogWidth:900px;centered:1");
	
	if((sRetVal == null) ||
		(sRetVal == "cancel"))
	{
		sRetVal = "";
	}
	
	if(sRetVal != "")
	{
		if(iWantReturnVal == "1")
		{
			if((iWebControlType == "1") ||
				(iWebControlType == "2")) // Means text or image
			{
				iWebControlType += "&*^*&" + iWebControlId + "&*^*&" + sRetVal;
				Form1.hdnWindowReturnValueId.value = iWebControlType;
				Form1.submit();
			}
		}
	}
	else
	{
		Form1.hdnWindowReturnValueId.value = "";
		Form1.submit();
	}
}


function setWebControlValue()
{
	alert("in");
	//Form1.hdnWindowReturnValueId.value = "test value";
	//Form1.submit();
}

/* 
 * Opens a modal dialog to edit data for a selected row.
 */
function openModalDialogWithSubmit(sURL, iHeight, iWidth)
{
	var sStyleString = "toolbar:0;resizable:0;scroll:no;status:0;dialogHeight:" + iHeight + "px;dialogWidth:" + iWidth + "px;centered:1";
	var sRetVal = window.showModalDialog(sURL, "", sStyleString);
	
	Form1.submit();
}

/* 
 * Opens a modal dialog to edit data for a selected row.
 */
function openModalDialogWithSubmitScroll(sURL, iHeight, iWidth)
{
	var sStyleString = "toolbar:0;resizable:0;scroll:yes;status:0;dialogHeight:" + iHeight + "px;dialogWidth:" + iWidth + "px;centered:1";
	var sRetVal = window.showModalDialog(sURL, "", sStyleString);
	
	Form1.submit();
}


/* 
 * Opens a modal dialog to edit data for a selected row.
 */
function setClearSelection(sWebControlId, sStringToSet)
{
	if(confirm("Are you sure you want to clear the selection?"))
	{
		sWebControlId += "&*^*&" + sStringToSet;
		
		Form1.hdnClearSelectionId.value = sWebControlId;
		Form1.submit();
	}
}

/* 
 * closes a window leaving a return value for the opener window
 */
function closeWindow(sRetVal)
{
	window.returnValue = sRetVal;
	window.close();
}

/* 
 * Contents of the folder are shown.
 */
function showFolderContents(iCheckBoxId)
{
	var arrCheckBoxes = document.getElementsByTagName("input");

	for (i=0; i< arrCheckBoxes.length; i++)
	{
		if (arrCheckBoxes[i].id == iCheckBoxId)
		{
			Form1.hdnFolderId.value = iCheckBoxId;
			Form1.submit();
			break;
		}
	}
}

/* 
 * Confirms before deleting any item.
 */
function confirmDeleteItem(iConfirmationMessage, iItemToDelete)
{
	if(confirm(iConfirmationMessage))
	{
		Form1.hdnItemToDeleteId.value = iItemToDelete;
		Form1.submit();
	}
}

/* 
 * Confirms before deleting any item.
 */
function confirmDeleteFolder(iConfirmationMessage, iItemToDelete)
{
	if(confirm(iConfirmationMessage))
	{
		Form1.hdnFolderToDeleteId.value = iItemToDelete;
		Form1.submit();
	}
}

/* 
 * Confirms before selecting any item.
 */
function confirmSelection(iConfirmationMessage, iItemSelected)
{
	if(confirm(iConfirmationMessage))
	{
		window.returnValue = iItemSelected;
		window.close();
	}
}

/* 
 * Confirms before creating a new version for the existing item.
 */
function confirmCreateVersionItem(iConfirmationMessage, iItemToDelete)
{
	if(confirm(iConfirmationMessage))
	{
		Form1.hdnCreateVersionId.value = iItemToDelete;
		Form1.submit();
	}
}

/* 
 * Shows the confirmation message and then sets the control with the value passed
 */
function showConfirmationMessage(sConfirmationMessage, sValueToSet, sControlId)
{
	if(confirm(sConfirmationMessage))
	{
		var iControlId = document.getElementById(sControlId);
		iControlId.value = sValueToSet;
		Form1.submit();
	}
}

/* 
 * Opens a window that can be resize.
 */
function openWindowResize(sURL, iHeight, iWidth)
{
	var iTop = (screen.height - iHeight)/2;
	var iLeft = (screen.width - iWidth)/2;
	
	window.open(sURL, "_blank", "toolbar=0,scrollbars=1,resizable=1,status=1,height=" + iHeight + ",width=" + iWidth + ",top=" + iTop + ",left=" + iLeft);
}

///<summery>
///Opens a modal dialog to edit information, force off scrolling.
///<summery>
function openModalDialogForReport(sURL, sTextToPass, iWantReturnVal, iWebControlId, iWebControlType)
{
	var sRetVal = window.showModalDialog(sURL, sTextToPass, "toolbar:0;resizable:0;status:0;scroll=no;dialogHeight:600px;dialogWidth:900px;centered:1");
	//var sRetVal = window.open(sURL);
	if((sRetVal == null) ||
		(sRetVal == "cancel"))
	{
		sRetVal = "";
	}
	
	if(sRetVal != "")
	{
		if(iWantReturnVal == "1")
		{
			if((iWebControlType == "1") ||
				(iWebControlType == "2") || (iWebControlType == "3") ) // Means text, image or Report
			{
				//iWebControlType += "&*^*&" + iWebControlId + "&*^*&" + sRetVal;
				Form1.TextBox1.value = sRetVal;
				//Form1.hdnReportId.value = sRetVal;
				alert(Form1.TextBox1.value);
				Form1.submit();
			}
		}
	}
	else
	{
		Form1.hdnReportId.value = "";
		Form1.submit();
	}
}

/* 
 * Set id of personalised items to be removed from personalisation object
 */
function setRemovePersonaliseId(sConfirmationMessage, sValueToSet, sControlId)
{
	//if(confirm(sConfirmationMessage))
	//{
		var iControlId = document.getElementById(sControlId);
		iControlId.value = sValueToSet;
		//alert(iControlId.value);
		Form1.submit();
	//}
}

/* 
 * method called to submit form in order to refresh web page
 */
function submitForm()
{
	Form1.submit();	
}

/*
 *set values on/off to textbox according to status of checkbox to enable postback 
 *use in cms_report
 */
function setCheckBox(selectedCheckBox)
{
	//get the textbox assciated with checkbox
	var vTBControlName = selectedCheckBox.name.replace("CBparams", "params");				
	var vTBControl = document.getElementById(vTBControlName);
	
	if (vTBControl != null)
	{
		if(selectedCheckBox.checked == true)
			vTBControl.value = "on";					
		else	
			vTBControl.value = "off";
	}
}

/* 
 * Shows the confirmation message and then sets the control with the value passed
 */
function viewConfirmationMessage(sConfirmationMessage, sValueToSet, sControlId)
{
	if(confirm(sConfirmationMessage))
	{
		var iControlId = document.getElementById(sControlId);
		iControlId.value = sValueToSet;
		Form1.submit();
	}
}

/* 
 * Shows the confirmation message and then sets the control with the value passed
 */
function showCustomInformationMessage(sMessage)
{
	alert(sMessage);
}