//Check the maxlength property of a textarea.
function ClearMessage(){
	var messDiv = document.getElementById("outMessage");
	messDiv.innerHTML = "";
}
		
function MaxLengthBeforeEdit(selObject,maxlength)
{
	if(selObject.value.length>=maxlength)
	{
		selObject.value=selObject.value.slice(0, maxlength);
		return false;
	}
}

function MaxLength(selObject,maxlength)
{
	if(selObject.value.length>=maxlength)
	{
		event.keyCode = 0;
		return false;
	}
}

function openWindow(theURL,winName,features,twidth,theight) { //v2.0
  tleft=(screen.width - twidth)/2
  ttop=(screen.height - theight)/2;
  features=features+', width=' + twidth + ', height=' + theight + ', top=' + ttop + ', left=' + tleft;
  window.open(theURL,winName,features);
}

function popupWindow(theURL,winName,features,twidth,theight, postUrl) { //v2.0
	
	tleft=(screen.width - twidth)/2
	ttop=(screen.height - theight)/2;
	features=features+', dialogHeight: ' + theight +  'px; dialogWidth: ' + twidth +  'px; dialogTop: ' + ttop + ' px; dialogLeft: ' + tleft + ' px; edge: Raised; center: Yes; help: No; scroll: No; resizable: No; status: No;';
	
	var reval=0;
	var url=escape(theURL);
	reval = window.showModalDialog('PopUpWindow.aspx?src='+url,winName, features);
	if (reval != null) 
	{
		window.navigate(postUrl);	
	}
}

function ResetDropDownList(listid, arrayValue)
{
	var sourceList = document.getElementById(listid);
	
	//remove items.
	for(i = 0; i < sourceList.options.length; i++)
	{
		var option = sourceList.options[i];
		sourceList.options[i] = null;
		i--;
	}

	//reset items.
	for(i = 0; i < arrayValue.length; i++)
	{
		var option = arrayValue[i];
		sourceList.options[sourceList.options.length] = option;
	}
}


function MoveItem(source,destination,option){
	var source = eval("document." + source);
	var destination = eval("document." + destination);	
	if(option==0)
		while(source.length>0){
			newoption = new Option(source.options[0].text);
			destination.options[destination.length]=newoption;
			source.options[0]=null;
		}
	else
		for (i=0; i<source.length; i++){
			if(source.options[i].selected==true){
				newoption = new Option(source.options[i].text);
				destination.options[destination.length]=newoption;
				source.options[i]=null;
				i--;
			}
		}
}

function ListboxIsNotEmpty(sourceid)
{
	var val;
	val = document.getElementById(sourceid);
	if(val.length>0)
		return true;
	else
		return false;	 
}

function ListboxValidatorValidate(val) 
{    
	val.isvalid = true;
	if (val.enabled != false) {
		val.isvalid = ListboxIsNotEmpty(val.controltovalidate);
	}
	ValidatorUpdateDisplay(val);
}

function ValidateEmptyListbox(validatorid)
{
	//Check if listbox is empty.
	var val;
	val =  document.getElementById(validatorid);
	ListboxValidatorValidate(val);				
	
	//Much the same as the Page_ClientValidate function.
	ValidatorUpdateIsValid();    
	ValidationSummaryOnSubmit();
	Page_BlockSubmit = !Page_IsValid;
	return Page_IsValid;
}

function SetFocus(sourceid)
{
	var source = document.getElementById(sourceid);
	if(source) source.focus();
}

function deleteObject(confirmMsg, url){
	if(confirm(confirmMsg)){
		window.navigate(url);	
	}
}

function ValidateForm(){
		var messDiv = document.getElementById("outMessage");
		messDiv.innerHTML = "";
		//Much the same as the Page_ClientValidate function.
		ValidatorUpdateIsValid();    
		ValidationSummaryOnSubmit();
		Page_BlockSubmit = !Page_IsValid;
		return Page_IsValid;
}

function ChangeCheckboxAllItem(object,formname,itemname){
	var formname = eval("document." + formname);
	if (object.checked) change=eval("true"); else change=eval("false");
	for (var i=0; i<formname.elements.length; i++){
		if (formname.elements[i].name.indexOf(itemname)>=0) formname.elements[i].checked=change;
	}
}

function JumpMenu(selObj,restore){ //v3.0
  eval("location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function DeleteObjectCollection(checkboxName, confirmMsg)
{
	var frm = document.forms[0];
	var item = frm.elements[checkboxName];
	var idList = "";
	var result = false;
	
	if(item!=null)
	{
		if (item.length !=null)
			for (var i=0; i<item.length; i++)
			{
				if (item[i].checked)
					idList += ";" + item[i].value;
			}
		else if(item.checked)	
				idList += ";" + item.value;
		
		if (idList != "")
		{
			result = confirm(confirmMsg);
		}
		else
		{
			alert("Please select at least one item to delete.");
		}
	}
	
	return result;	
}

function ConfirmDeletion(){
	return confirm("The navigation associated with the page changes to 'Pending' and other pages linking to it may not display properly. Do you want to continue?");
}

function ConfirmDeletionGlossary(){
	return confirm("Do you want to delete the selected Glossary?");
}

function ConfirmDeletionAsset(){
	return confirm("The navigation associated with the asset changes to 'Pending'. Do you want to continue?");
}
function ConfirmDeletionCategory(){
	return confirm("Do you want to delete the selected category?");
}
function ConfirmDeletionImage(){
	return confirm("Do you want to delete the selected image?");
}
function ConfirmDeletionPressRelease(){
	return confirm("Do you want to delete the selected Press release?");
}
function ConfirmDeletionFAQ(){
	return confirm("Do you want to delete the selected FAQ?");
}

function ConfirmDeletionDivision(){
	return confirm("Do you want to delete the selected Division?");
}

function BlockDeletionDivision(){
	alert("This division is currently in use by underwriters or at least one class of business and cannot be deleted.")
	return false;
}

function ConfirmDeletionUnderwriter(){
	return confirm("Do you want to delete the selected Underwriter?");
}

function ConfirmDeletionUnderwriterType(){
	return confirm("Do you want to delete the selected Underwriter Type?");
}

function BlockDeletionUnderwriterType(){
	alert("This underwriter type is currently in use by underwriters or at least one class of business and cannot be deleted.")
	return false;
}

function ConfirmDeletionClassOfBusiness(){
	return confirm("Do you want to delete the selected Class Of Business?");
}

function BlockDeletionClassOfBusiness(){
	alert("This class of business is currently in use by at least one underwriter and cannot be deleted.")
	return false;
}

function ConfirmDeletionBoxLocator(){
	return confirm("Do you want to delete the selected Box Locator?");
}

function BlockDeletionBoxLocator(){
	
	alert("This Box Location image is currently in use by underwriters and cannot be deleted.")
	return false;
}


function ConfirmDeletionCaseStudy(){
	return confirm("Do you want to delete the selected Case study?");
}

function ConfirmParaDeletion(){
	return confirm("Do you want to delete the selected Paragraph?");
}

function ConfirmDeleteUser(){
	return confirm("Do you want to delete the selected CMS User?");
}

function ConfirmDeleteNavigation(){
	return confirm("Deleting this navigation will also delete all sub navigation levels associated. Are you sure you want to delete it?");
}

function ConfirmDeletionCodeSnippet(){
	return confirm("Do you want to delete the selected Code snippet?");
}
function ConfirmDeletionDownloadItem(){
	return confirm("Do you want to delete the selected Download item?");
}
function doNothing()
{
}

function ConfirmDeleteMsg(msg)
{
	return confirm(msg);
}

function WhenPublish()
{
	if(associatedPublished){
		return true;
	}
	
	if(!associatedLive){
		alert("Please make sure that its associated item is live.");
		return false;	
	}
	else
	{
		if(!confirm("The associated item is not published, would you like to publish it?"))
			return false;
		else
			return true;
	}
}

function WhenSuspend()
{
	return confirm("Suspend this navigation will delete the navigation in live site and all sub navigations associated. Are you sure you want to suspend it?");
}

function DefineField_CheckboxClick(checkbox,validator)
{
	validator.enabled = checkbox.checked;
	if (validator.enabled ==false) {validator.isvalid = true;
	validator.style.display = "none";
	}
	
}

function QuarterlyPage_CheckboxClick(checkbox,validator)
{
	validator.enabled = !checkbox.checked;
	if (validator.enabled ==false) {validator.isvalid = true;
	validator.style.display = "none";
	}
	
}
/*
function OpenUserList(obj) 
{	
			var pos = calcBelowPosition(obj,1,190,220);	
			var w = 550;
			var h = 350;
			lpos=(screen.width - w)/2
			tpos=(screen.height - h)/2		
			var reval;
			var sFeature = 'scrollbars=yes,top=' + tpos.toString() + ',left=' + lpos.toString() + ',width=' + w.toString() + ',height=' + h.toString();
			reval = window.open('QuarterlyUserList.aspx',"UserList", sFeature);//,"edge: Raised; center: Yes; help: No; resizable: No; status: No;")
					
			if (reval != null) {
				return true;
			}
			return false;
		}*/
		function OpenQuarterlyReport(obj,username,completeddate) {						
			var w = screen.width - 100;
			var h = screen.height - 100;
			var reval;
			var url=escape('QuarterlyReportResult.aspx?username=' + username.value + '&completedDate=' + completeddate.value);			
			reval = window.showModalDialog('ShowDialog.aspx?src='+url,"AccessRight","edge: Raised; center: Yes; help: No; resizable: No; status: No;dialogWidth:" + w.toString() + "px;dialogHeight:" + h.toString()+"px;")
			//reval = window.open('QuarterlyReportResult.aspx?username=' + username.value + '&completedDate=' + completeddate.value,"Result");
			if (reval != null) {
				return true;
			}
			return false;
		}
		function fillDataIntoQuarterlyForm(strValue)
		{
			window.opener.document.all['txtUser'].value = strValue;
			window.close();
		}
		