/***
 * This javascript file contains function which is called when the Add/Edit form is submitted for validating the field values.
 * @author     		MediTab Software Inc. 
 * @copyright  		1997-2005 The MediTab Software Inc.
 * @license    		http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version   	 	Release: 1.0
 * @PHP version  	5.x
*/

var strSourceDestValues   =	'disabled="disabled",slt_source_table,hid_activity_count,slt_destination_table,selected="selected",Taara_note,hid_row_id';
var arrSourceDestValues	=	strSourceDestValues.split(",");

var strConversionFilesVar   =	'disabled="disabled",slt_type,Taara_path,Taara_description,hid_source_file_id,selected="selected"';
var arrConversionFilesVar	=	strConversionFilesVar.split(",");

var strOnClickConvTbl	=	 'tb_show(null,"index.php?file=med_misc_common&strModuleTypeFrmPopup=Source Table&strControlPopup=ELEMENT_NAME&strMiscType=IMS_TABLE&TB_iframe=true&height=200&width=400&modal=true",null)' ;
		

var divStyle
var isSubmitForm = false;
/** This method is called when the form is submitted for javascript validations
*/
function submit_form(objFrm)
{
	/*if(!isSubmitForm)
		isSubmitForm = true;
	else
		return false;*/
	
	if(checkValid(objFrm.name)==false) //general javascript validations for each field
	{
		return false; 
	}

	//if some extra validation required
	if(window.extraValid) //check whether the function for extra validation exist or not
	{
		if(extraValid()==false) //if the function returns false then return false
		{
			return false;	
		}
		else
		{
			//$("[name='smt_submit']").val("Submitting...");
			//$("[name='smt_submit']").attr("disabled","disabled");
			//objFrm.submit();
			//return false;
		}
	}
	else //if function doesnot exist return true
	{
		if(document.getElementById("project")!=undefined)
		{
			if(document.getElementById("project").value==0)
			{	
				document.frm_add_record.action="./../../MEM/employee/index.php";
			}
		}
		
		return true;
	}
}

function zoomIn(url,labelName,control_name,width,height)
{
	try
	{
		contType=document.getElementById(control_name).type;
	}
	catch(e)
	{
		alert(control_name+" does not exists");
		return false;	
	}
	if(contType == "text" || contType == "textarea")
		height = 335;
	else
		height = 200;
	popup(url+'&contName='+control_name+'&labelName='+labelName,width,height);

}
function assignValuesToControl()
{
	txtName = document.frm_zoom.hid_fieldname.value;
	window.opener.document.getElementById(txtName).value = document.frm_zoom.Taara_zoom_desc.value;
	window.close();
}
function assignValuesFromControl()
{
	txtName = document.frm_zoom.hid_fieldname.value;
	document.frm_zoom.Taara_zoom_desc.value = parent.opener.document.getElementById(txtName).value;
	window.focus();
	document.frm_zoom.Taara_zoom_desc.focus();
}

var intClientId; 	// intEmpId   used in Employee Links
var intSupportId; 	// intEmpId   used in Employee Links
var intInstId; 		// intEmpId   used in Employee Links
var strDivision; 	// intEmpId   used in Employee Links

function showLink(intCId,intSId,intIId,strDiv,e)
{
	intClientId		=	intCId;
	intSupportId	=	intSId;
	intInstId		=	intIId;
	strDivision		=	strDiv;
	
	
	
	var IE = document.all?true:false
	if (IE) 
    { // grab the x-y pos.s if browser is IE
		intX = event.clientX + document.documentElement.scrollLeft
		intY = event.clientY + document.documentElement.scrollTop
	} 
	else 
	{  // grab the x-y pos.s if browser is NS
		intX = e.pageX
		intY = e.pageY
	}  	
	document.getElementById(strDivision).style.left=intX+"px";	
	document.getElementById(strDivision).style.top=intY+8+"px";	
	document.getElementById(strDivision).style.visibility="visible";
	
}


//Hide or Show Report Menu
function hideShowReportLink(strVisible)
{	
	document.getElementById("div_gen_analysis_report").style.visibility	=	strVisible;
}

function showReportLink(strArguments,event,strSelectedReport)
{
	var divStyle

	if(navigator.appName=='Netscape')
		divStyle	='table-row';
	else
		divStyle	='inline';

	var IE = document.all?true:false
	intX=(event.pageX||event.clientX+OLfd().scrollLeft);
	intY=(event.pageY||event.clientY+OLfd().scrollTop);
	document.getElementById("div_gen_analysis_report").style.left	=	intX+"px";
	document.getElementById("div_gen_analysis_report").style.top	=	intY+"px";
	document.getElementById("div_gen_analysis_report").style.visibility	=	"visible";
	document.getElementById("hid_report_type").value				=	strArguments;
	document.getElementById("hid_selected_report").value			=	strSelectedReport;
	getElement("span_case_type").style.display	= divStyle;
	getElement("span_client_response").style.display = divStyle;
	getElement("span_observation").style.display = divStyle;
	getElement("span_product_id").style.display = divStyle;
	getElement("span_module_id").style.display = divStyle;
	getElement("span_case_status").style.display = divStyle;
	getElement("span_support_by").style.display = divStyle;
	getElement("span_support_type").style.display = divStyle;
	getElement("span_version_date").style.display = divStyle;
	getElement("span_client_id").style.display = divStyle;
	getElement("span_problem_type").style.display = divStyle;
	
	if(getElement("span_"+strSelectedReport) != null)
		getElement("span_"+strSelectedReport).style.display = "none";

	if(getElement("hid_hide_menu_items") != undefined)
	{
		strHidMenuItems	=	getElement("hid_hide_menu_items").value;
		arrHidMenuItems	=	strHidMenuItems.split(",");
		for(intMenuItem=0;intMenuItem<arrHidMenuItems.length;intMenuItem++)
		{
			if(arrHidMenuItems[intMenuItem] != "" && getElement("span_"+arrHidMenuItems[intMenuItem]) != null)
				getElement("span_"+arrHidMenuItems[intMenuItem]).style.display = "none";
		}
	}
	
}

function goGenReport(strReportType)
{
	strArgus	=	getElement("hid_report_type").value;
	strURL		=	strArgus+"&report_type="+strReportType+"&TB_iframe=true&height=500&width=750&modal=true";
	//eval("tb_show(null,strURL,null)");
	eval(self.parent.tb_med_remove(strURL));
	//window.open(strURL,"wind_gen_analysis");
}

function setPage(strPage)
{
	document.getElementById("div_clientLink").style.visibility="hidden";
	var strUrlNext="index.php?file="+strPage+"&client_id="+intClientId;
	window.location = strUrlNext;	
	intClientId="";
}
function setLeftPage(strPage)
{
	document.getElementById("div_clientLink").style.visibility="hidden";
	var strUrlNext="index.php?file="+strPage;
	window.location = strUrlNext;	
	intClientId="";
}
function setListPage(strPage)
{
	document.getElementById("div_updatelogLink").style.visibility="hidden";
	if(strPage == "med_support_detail_list")
		var strUrlNext="index.php?file="+strPage+"&supp_id="+intSupportId;
	else
		var strUrlNext="index.php?file="+strPage+"&client_id="+intClientId+"&supp_id="+intSupportId;
		
	window.location = strUrlNext;	
	intClientId="";
}

//Call Function on pressing enter key
function callFuncOnEnter(strKeyCode,functionName)
{
	if(strKeyCode == 13)	//Enter Key
	{
		eval(functionName);
	}
}


/**
  * This function is to submit search form
*/
function submit_search_form()
{
	if(document.frm_search_record.TaRtxt_search.value=='')
	{
		alert("Please enter value.");
		return false;
	}
	else
	{
		document.frm_search_record.file.value			=	"med_advance_search";		
		document.frm_search_record.submit();
		return false;
	}
}

/**
  * This function is  to send mail on error
*/
var strMailId = "";
function sendMail(strPkValue,strFileValue)
{
	if(strMailId != "")
	{
		document.frm_list_record.hid_send_mail.value	=	strMailId;
		strMailId										=	"";
	}
	else
	{
		document.frm_list_record.hid_send_mail.value	=	1;
	}
	document.getElementById("hid_primary_key").value	=	strPkValue;
	document.frm_list_record.file.value					=	strFileValue;
	document.frm_list_record.submit();
	return true;
	
}

function checkNsendMail(strPkValue,strFileValue,strFieldName)
{
	alertMsg	= "";
	if(checkEmail(document.getElementById(strFieldName),"Email",true) == false)
	{
		alertMsg += "\nPlease enter valid Email.";
		setStyle(document.getElementById(strFieldName));
	}
	else
	{
		resetStyle(document.getElementById(strFieldName));
	}
	
	if(alertMsg!="")
	{
		alertMsg="Following errors:\n\n" + alertMsg;	
		alert(alertMsg);	
		eval(strStyle);
		eval(strFocus);
		return false
	}
	else
		sendMail(strPkValue,strFileValue);

}

/**
function to clear client_id
*/
function clearClientId(strClientTxtName,strClientHidName)
{
	if(document.getElementById(strClientTxtName).value!="" && confirm("Are you sure to clear the selected Client?"))
	{
		document.getElementById(strClientTxtName).value="";
		document.getElementById(strClientHidName).value="";
	}
}

/**
function to clear client_id
*/
function clearEmployeeId(strEmployeeTxtName,strEmployeeHidName)
{
	if(document.getElementById(strEmployeeTxtName).value!="" && confirm("Are you sure to clear the selected Followup By?"))
	{
		document.getElementById(strEmployeeTxtName).value="";
		document.getElementById(strEmployeeHidName).value="";
	}
}

/**
function to clear client_id
*/
function clearTextBox(strClientTxtName,strClientHidName,strMessage)
{
	if(document.getElementById(strClientTxtName).value!="" && confirm(strMessage))
	{
		document.getElementById(strClientTxtName).value="";
		document.getElementById(strClientHidName).value="";
	}
}

/**
function to export to excel
*/
function exportExcelFile(objFrm)
{
	objFrm.submit();
	return true;
		
}

/* This function is used to check number of rows to display with general setting parameter */

function checkRowLimit(intHiddenControl,intMaxRowLimit)
{
	// Check for numeric value
	if(!(checkInteger(intHiddenControl,"","")))
	{
		alert("Please enter valid rows");
		setStyle(intHiddenControl);
		eval(strStyle);
		eval(strFocus);
		intHiddenControl.focus();
		return false;
		
	}
   
	if( parseInt(intHiddenControl.value) > parseInt(intMaxRowLimit))
	{
		alertMessage = "Number of rows should not be greater than "+intMaxRowLimit;  
		alert(alertMessage);
		setStyle(intHiddenControl);
		eval(strStyle);
		eval(strFocus);
		intHiddenControl.focus();
		return false;
	}
}


/* This function is used to zoom combo */
function zoomCombo(strComboName,elmImage,intMin,intMax)
{
	var combo		 = document.getElementById(strComboName);
	var imgZoomIn	 = "s_zoom_down.gif";
	var imgZoomOut	 = "s_zoom_up.gif";
	var imgImage	 = elmImage.src;
	
	if(combo.size >= intMax)
	{
		elmImage.src = imgImage.replace(imgZoomOut,imgZoomIn);
		combo.size	 = intMin;
	}
	else
	{
		elmImage.src = imgImage.replace(imgZoomIn,imgZoomOut);
		combo.size	 = intMax;
	}
		
	return false;
}

//This function will give selected values from multi combo (used in tool-tip)
function getSelectedComboValue(strControlId,strToolTipId)
{
	var strSelectedId 	= 	document.getElementById(strControlId);
	var strSelected		=	"";
	
	for(var intSelectedId=0;intSelectedId<strSelectedId.options.length;intSelectedId++)
	{	
		if(strSelectedId.options[intSelectedId].selected == true)
		{	
			strSelected = strSelected + strSelectedId.options[intSelectedId].text+"<br>";
		}
	}
	strSelected = strSelected.substring(0,strSelected.length-1);
	strSelected = strSelected.replace(/All,/gi,'')
//	return overlib(strSelected,CAPTION,'Selected Values', DELAY, 200, STICKY, MOUSEOFF, 1000, WIDTH, 400, CLOSETEXT, '<img border=0 src=./images/close-inline.gif>', CLOSETITLE, 'Click to Close', CLOSECLICK, FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass')
	return overlib(strSelected,CAPTION,'Selected Values', DELAY, 400, STICKY, MOUSEOFF, 1000, WIDTH, 250, CLOSETEXT, '<img border=0 src=./images/close-inline.gif>', CLOSETITLE, 'Click to Close', CLOSECLICK, FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass', CLOSEFONTCLASS, 'olCloseFontClass')
}


/* 	This function is used to pass selected clients in popup page
	This function is called when you click on select client image
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectClients(strPopupPageType,blnFromLead,intMaxSelect,blnFromClientReport)
{
	if(strPopupPageType == "F")
	{	
		var strSelClients	=	document.getElementById("hid_client_id").value;
		popup('index.php?file=med_client_search&txt_clientName=TaRtxt_client_name&hid_clientId=hid_client_id&hid_sel_clients='+strSelClients+'&hid_show_all=1&strPopupPageType='+strPopupPageType,900,600);
	}
	else if(strPopupPageType == "S")	
	{
		if(intMaxSelect != "")	
		{
			var strSelClients	=	document.getElementById("Sr_hid_clientId").value;
			popup('index.php?file=med_client_search&txt_clientName=Sr_txt_clientName&hid_clientId=Sr_hid_clientId&hid_sel_clients='+strSelClients+'&hid_show_all=1&strPopupPageType='+strPopupPageType+'&blnFromLead='+blnFromLead+'&intMaxSelect='+intMaxSelect+'&blnFromClientReport='+blnFromClientReport,900,600);
		}
		else
		{
			var strSelClients	=	document.getElementById("Sr_hid_clientId").value;
			popup('index.php?file=med_client_search&txt_clientName=Sr_txt_clientName&hid_clientId=Sr_hid_clientId&hid_sel_clients='+strSelClients+'&hid_show_all=1&strPopupPageType='+strPopupPageType+'&blnFromLead='+blnFromLead+'&blnFromClientReport='+blnFromClientReport,900,600);
		}
	}
}

/* 	This function is used to pass selected clients in popup page
	This function is called when you click on select client image
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectLead(strPopupPageType,intMaxSelect,blnHideShow)
{
	if(strPopupPageType == "F")
	{	
		var strSelLeads	=	document.getElementById("hid_lead_id").value;
		popup('index.php?file=med_lead_search&txt_leadName=Tatxt_lead_id&hid_leadId=hid_lead_id&hid_sel_lead='+strSelLeads+'&hid_show_all='+blnHideShow+'&strPopupPageType='+strPopupPageType,900,600);
	}
	else if(strPopupPageType == "S")	
	{
		if(intMaxSelect != "")	
		{
			var strSelClients	=	document.getElementById("Sr_hid_clientId").value;
			popup('index.php?file=med_client_search&txt_clientName=Sr_txt_clientName&hid_clientId=Sr_hid_clientId&hid_sel_clients='+strSelClients+'&hid_show_all='+blnHideShow+'&strPopupPageType='+strPopupPageType+'&blnFromLead='+blnFromLead+'&intMaxSelect='+intMaxSelect+'&blnFromClientReport='+blnFromClientReport,900,600);
		}
		else
		{
			var strSelClients	=	document.getElementById("Sr_hid_clientId").value;
			popup('index.php?file=med_client_search&txt_clientName=Sr_txt_clientName&hid_clientId=Sr_hid_clientId&hid_sel_clients='+strSelClients+'&hid_show_all='+blnHideShow+'&strPopupPageType='+strPopupPageType+'&blnFromLead='+blnFromLead+'&blnFromClientReport='+blnFromClientReport,900,600);
		}
	}
}


/*  This function is used when you click on select client / Select All Client button in popup page 
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectClientsFromPopup(strPopupPageType)
{

	objTargetElement	=	document.getElementsByName("list5096_cSlcPK[]");
	/*if(strPopupPageType == "F")
		strClientValue		=	window.opener.document.getElementById("hid_client_id").value;
	else if(strPopupPageType == "S")
		strClientValue		=	window.opener.document.getElementById("Sr_hid_clientId").value;*/
		
	strSelected			=	"";
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		if(objTargetElement[i].checked == true)
		{
			if(objTargetElement[i].value != "")
			{	
				strSelected	= strSelected  + objTargetElement[i].value + ",";
			}
		}
	}

	// Check that atleast one client is selected
	strSelected	= strSelected.substring(0,strSelected.length-1);
	if(strSelected == "")
	{
		alert("Please select atleast one client.");
		return false;	
	}
	
	//Set the path of the action file
	document.frm_list_record.client_id.value=strSelected;
	document.frm_list_record.file.value="med_client_search_action";
	document.frm_list_record.submit();
	return true;
}

/*  This function is used when you click on select Lead / Select All Lead button in popup page 
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectLeadFromPopup(strPopupPageType)
{

	objTargetElement	=	document.getElementsByName("list5224_cSlcPK[]");
	if(strPopupPageType == "F")
		strLeadValue		=	window.opener.document.getElementById("hid_lead_id").value;
/*	else if(strPopupPageType == "S")
		strClientValue		=	window.opener.document.getElementById("Sr_hid_clientId").value;*/
		
	strSelected			=	"";
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		if(objTargetElement[i].checked == true)
		{
			if(objTargetElement[i].value != "")
			{	
				strSelected	= strSelected  + objTargetElement[i].value + ",";
			}
		}
	}

	// Check that atleast one client is selected
	strSelected	= strSelected.substring(0,strSelected.length-1);
	if(strSelected == "")
	{
		alert("Please select atleast one lead.");
		return false;	
	}
	
	//Set the path of the action file
	document.frm_list_record.lead_id.value=strSelected;
	document.frm_list_record.file.value="med_lead_search_action";
	document.frm_list_record.submit();
	return true;
}


/* 	This function is used to pass selected employees in popup page
	This function is called when you click on select employee image
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectEmployees(strPopupPageType,strControl,strHidControl,blnSalesEmployee)
{
	if(strPopupPageType == "F")
	{	
		var strSelEmployees	=	document.getElementById("hid_employee_id").value;
		popup('index.php?file=med_employee_search&txt_employeeName=TaRtxt_employee_name&hid_employeeId=hid_employee_id&hid_sel_employees='+strSelEmployees+'&hid_show_all=1&blnSalesEmployee='+blnSalesEmployee+'&strPopupPageType='+strPopupPageType,900,600);
	}
	else if(strPopupPageType == "S")	
	{	
		var strSelEmployees	=	document.getElementById(strHidControl).value;
		popup('index.php?file=med_employee_search&txt_employeeName='+strControl+'&hid_employeeId='+strHidControl+'&hid_sel_employees='+strSelEmployees+'&hid_show_all=1&blnSalesEmployee='+blnSalesEmployee+'&strPopupPageType='+strPopupPageType,900,600);
	}
}


/*  This function is used when you click on select employees / Select All employees button in popup page 
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectEmployeesFromPopup(strPopupPageType,strHidControl)
{
	objTargetElement	=	document.getElementsByName("list5195_cSlcPK[]");
	if(strPopupPageType == "F")
		strEmployeeValue		=	window.opener.document.getElementById(strHidControl).value;
	else if(strPopupPageType == "S")
		strEmployeeValue		=	window.opener.document.getElementById(strHidControl).value;
		
	strSelected			=	"";
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		if(objTargetElement[i].checked == true)
		{
			if(objTargetElement[i].value != "")
			{	
				strSelected	= strSelected  + objTargetElement[i].value + ",";
			}
		}
	}

	// Check that atleast one client is selected
	strSelected	= strSelected.substring(0,strSelected.length-1);
	if(strSelected == "")
	{
		alert("Please select atleast one employee.");
		return false;	
	}
	
	//Set the path of the action file
	document.frm_list_record.employee_id.value=strSelected;
	document.frm_list_record.file.value="med_employee_search_action";
	document.frm_list_record.submit();
	return true;
}

/*  This function is used when you click on select misc  button in popup page 
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectMiscFromPopup(strPopupPageType,strHidControl)
{
	objTargetElement	=	document.getElementsByName("list5203_cSlcPK[]");
		
	strSelected			=	"";
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		if(objTargetElement[i].checked == true)
		{
			if(objTargetElement[i].value != "")
			{	
				strSelected	= strSelected  + objTargetElement[i].value + ",";
			}
		}
	}

	// Check that atleast one misc is selected
	strSelected	= strSelected.substring(0,strSelected.length-1);
	
	if(strSelected == "")
	{
		alert("Please select atleast one Misc");
		return false;	
	}
	
	//Set the path of the action file
	document.frm_list_record.misc_id.value=strSelected;
	document.frm_list_record.file.value="med_misc_popup_action";
	document.frm_list_record.submit();
	return true;
}

/*  This function is used when you click on select misc  button in popup page 
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectSpecialityFromPopup(strPopupPageType,strHidControl)
{
	objTargetElement	=	document.getElementsByName("list5204_cSlcPK[]");
		
	strSelected			=	"";
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		if(objTargetElement[i].checked == true)
		{
			if(objTargetElement[i].value != "")
			{	
				strSelected	= strSelected  + objTargetElement[i].value + ",";
			}
		}
	}

	// Check that atleast one misc is selected
	strSelected	= strSelected.substring(0,strSelected.length-1);
	
	if(strSelected == "")
	{
		alert("Please select atleast one Speciality");
		return false;	
	}
	
	//Set the path of the action file
	document.frm_list_record.misc_id.value=strSelected;
	document.frm_list_record.file.value="med_speciality_popup_action";
	document.frm_list_record.submit();
	return true;
}

/*  This function is used when you click on select misc  button in popup page 
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectCityFromPopup(strPopupPageType,strHidControl)
{
	objTargetElement	=	document.getElementsByName("list5205_cSlcPK[]");
		
	strSelected			=	"";
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		if(objTargetElement[i].checked == true)
		{
			if(objTargetElement[i].value != "")
			{	
				strSelected	= strSelected  + objTargetElement[i].value + ",";
			}
		}
	}

	// Check that atleast one misc is selected
	strSelected	= strSelected.substring(0,strSelected.length-1);
	
	if(strSelected == "")
	{
		alert("Please select atleast one City");
		return false;	
	}
	
	//Set the path of the action file
	document.frm_list_record.misc_id.value=strSelected;
	document.frm_list_record.file.value="med_city_popup_action";
	document.frm_list_record.submit();
	return true;
}

/*  This function is used when you click on select misc  button in popup page 
	strPopupPageType = 'F' if popup is opened from Add/Edit Page 
	strPopupPageType = 'S' if popup is opened from Search Page 
*/	
function selectStateFromPopup(strPopupPageType,strHidControl)
{
	objTargetElement	=	document.getElementsByName("list5206_cSlcPK[]");
		
	strSelected			=	"";
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		if(objTargetElement[i].checked == true)
		{
			if(objTargetElement[i].value != "")
			{	
				strSelected	= strSelected  + objTargetElement[i].value + ",";
			}
		}
	}

	// Check that atleast one misc is selected
	strSelected	= strSelected.substring(0,strSelected.length-1);
	
	if(strSelected == "")
	{
		alert("Please select atleast one State");
		return false;	
	}
	
	//Set the path of the action file
	document.frm_list_record.misc_id.value=strSelected;
	document.frm_list_record.file.value="med_state_popup_action";
	document.frm_list_record.submit();
	return true;
}
/*function selectMisc(strControl,strHidControl,intShowIn,strPopupPageType)
{
	if(strPopupPageType == "F")
	{	
		//var strSelClients	=	document.getElementById("hid_client_id").value;
		//popup('index.php?file=med_client_search&txt_clientName=TaRtxt_client_name&hid_clientId=hid_client_id&hid_sel_clients='+strSelClients+'&hid_show_all=1&strPopupPageType='+strPopupPageType,900,600);
		window.location("index.php?file=med_misc_popup&txt_miscName="+strControl+"&hid_miscId="+strHidControl+"&show_in="+intShowIn+"&hid_show_all=1&strPopupPageType="+strPopupPageType+"&TB_iframe=true&height=325&width=450&modal=true")
	}
	else if(strPopupPageType == "S")	
	{
		if(intMaxSelect != "")	
		{
			var strSelClients	=	document.getElementById("Sr_hid_clientId").value;
			popup('index.php?file=med_client_search&txt_clientName=Sr_txt_clientName&hid_clientId=Sr_hid_clientId&hid_sel_clients='+strSelClients+'&hid_show_all=1&strPopupPageType='+strPopupPageType+'&blnFromLead='+blnFromLead+'&intMaxSelect='+intMaxSelect,900,600);
		}
		else
		{
			var strSelClients	=	document.getElementById("Sr_hid_clientId").value;
			popup('index.php?file=med_client_search&txt_clientName=Sr_txt_clientName&hid_clientId=Sr_hid_clientId&hid_sel_clients='+strSelClients+'&hid_show_all=1&strPopupPageType='+strPopupPageType+'&blnFromLead='+blnFromLead,900,600);
		}
	}
}*/



/*  This function is used to show selected value of client when client popup page is opened */
function getSelectOnLoad()
{
	var strSelClients 	=	document.getElementById("hid_sel_clients").value;
	objTargetElement	=	document.getElementsByName("list5096_cSlcPK[]");
	strSelected			=	"";
	
	// Uncheck All Clients
	for(var i=0;i<objTargetElement.length;i++)
			objTargetElement[i].checked = false;
			
	// If All client is selected
	if(strSelClients == 0 && strSelClients != "")
	{
		for(var i=0;i<objTargetElement.length;i++)
			objTargetElement[i].checked = true;
	}
	else if(strSelClients != "")
	{
		arrSelClient		=	strSelClients.split(",");
		for(var i = 0; i < objTargetElement.length; i++) 
		{
			for(var j=0;j<arrSelClient.length;j++)
			{
				if(objTargetElement[i].value == arrSelClient[j])
				{
					objTargetElement[i].checked = true;
				}
				
			}
		}
	}
}


/*  This function is used to show selected value of client when client popup page is opened */
function getSelectLeadOnLoad()
{
	var strSelLead 	=	document.getElementById("hid_sel_lead").value;
	objTargetElement	=	document.getElementsByName("list5224_cSlcPK[]");
	strSelected			=	"";
	
	// Uncheck All Clients
	for(var i=0;i<objTargetElement.length;i++)
			objTargetElement[i].checked = false;
			
	// If All client is selected
	if(strSelLead == 0 && strSelLead != "")
	{
		for(var i=0;i<objTargetElement.length;i++)
			objTargetElement[i].checked = true;
	}
	else if(strSelLead != "")
	{
		arrSelLead		=	strSelLead.split(",");
		for(var i = 0; i < objTargetElement.length; i++) 
		{
			for(var j=0;j<arrSelLead.length;j++)
			{
				if(objTargetElement[i].value == arrSelLead[j])
				{
					objTargetElement[i].checked = true;
				}
				
			}
		}
	}
}


/*  This function is used to show selected value of employee when employee popup page is opened */
function getSelectEmployeeOnLoad()
{
	var strSelEmployees 	=	document.getElementById("hid_sel_employees").value;
	objTargetElement	=	document.getElementsByName("list5195_cSlcPK[]");
	strSelected			=	"";
	
	// Uncheck All Clients
	for(var i=0;i<objTargetElement.length;i++)
			objTargetElement[i].checked = false;
			
	// If All client is selected
	if(strSelEmployees == 0 && strSelEmployees != "")
	{
		for(var i=0;i<objTargetElement.length;i++)
			objTargetElement[i].checked = true;
	}
	else if(strSelEmployees != "")
	{
		arrSelEmployee		=	strSelEmployees.split(",");
		for(var i = 0; i < objTargetElement.length; i++) 
		{
			for(var j=0;j<arrSelEmployee.length;j++)
			{
				if(objTargetElement[i].value == arrSelEmployee[j])
				{
					objTargetElement[i].checked = true;
				}
				
			}
		}
	}
}



function clientCommentPopup(intEntityId)
{
	intWidth 	=	700;
	intHeight	=	400;
	
	popup('index.php?file=med_comment&entity_id='+intEntityId,intWidth,intHeight);	
}

// This function is used to open popup to add remark for case
function addCaseRemark(intSuppId,strPageType)
{
	if(strPageType == "V")
		popup("index.php?file=med_case_remark_addedit&strEditType=Remark&intSuppId="+intSuppId+"&blnRead=0&blnshowLink=0",800,600);
	else
		popup("index.php?file=med_case_remark_addedit&strEditType=Remark&hid_page_type=A&intSuppId="+intSuppId+"&blnRead=0&blnshowLink=",800,600);
}

// This function is used to open popup to add read remark for case
function addReadCaseRemark(intSuppId)
{
	popup("index.php?file=med_support_read_remark&hid_supp_id="+intSuppId,800,600);
	return false;
}

// This function is used to open popup for parmanent solution
function addPSolution(intSuppId)
{
	popup("index.php?file=med_support_psolution&hid_supp_id="+intSuppId,800,600);
	return false;
}

function AddNode(no)
{
	
	intMaxFiles	=	parseInt(document.frm_list_record.nodecount.value);
	if(parseInt(document.frm_list_record.maxnode.value)>=intMaxFiles)
	{
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id','filall_additional_file'+no);
		var mydiv = GetElement("div_files");
		newdiv.innerHTML = NewNode(no);
		mydiv.appendChild(newdiv);
	}
	else
	{
		alert("Maximum of "+(intMaxFiles-1)+" files can be added.");
	}

}
function NewNode(no)
{
//	var newNode = '<input type="file" class="comn-input" name="filall_additional_file['+no+']" id="filall_additional_file['+no+']"  readonly="readonly">&nbsp;<input type="button" name="x" value=" X " onclick="RemoveNode(\'filall_additional_file'+no+'\')">';
	var newNode = '<input type="file" class="comn-input" name="filall_additional_file[]" id="filall_additional_file[]"  >&nbsp;<font style="font-size: 9px;" color="#0000ff"><a onclick="RemoveNode(\'filall_additional_file'+no+'\')" style="cursor:pointer">Remove</a></font>';
	
	//Make an Increment to the hidden counter variable - as child node added
	document.frm_list_record.nodecount.value = parseInt(document.frm_list_record.nodecount.value)+1;
	document.frm_list_record.nodeindex.value = parseInt(document.frm_list_record.nodeindex.value)+1;
	return newNode;
}
function RemoveNode(node)
{
	//First of all lets get the main div which contains all created new child div
	var parentDiv = GetElement("div_files");
	//Now get the clield node which needs to be removed
	var childDiv = GetElement(node);
	//and at last time for final action -- Kill the child
	parentDiv.removeChild(childDiv);
	//Make an Decrement to the hidden counter variable -- as child node removed
	document.frm_list_record.nodecount.value = parseInt(document.frm_list_record.nodecount.value)-1;
	//never decrement "document.main.nodeindex.value" as it will create name conflict and is there for other purpose
}

//Browser Comptible GetElement Method
//Will work for all : Generalized ReUsable Function
function GetElement(element)
{
	var divx;
	if (document.getElementById) 
	{
		divx = document.getElementById(element);
	}
	else if (document.all) 
	{
		divx = document.all[element];
	}
	else if (document.layers) 
	{
		divx = document.layers[element];
	}
	return divx;
}

// set missing selected in edit mode at the time of page load only
function setMultipleSelected(objTargetElement,arrSelectValues)
{
	objTargetElement.disabled = "";
	
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		for(var j = 0; j < arrSelectValues.length; j++)
			objTargetElement.options[i].selected = false;
	}
	
	for(var i = 0; i < objTargetElement.length; i++) 
	{
		for(var j = 0; j < arrSelectValues.length; j++)
			if(objTargetElement.options[i].value == arrSelectValues[j])
				objTargetElement.options[i].selected = true;
	}
	
	if(arrSelectValues == 0)
		objTargetElement.disabled = "disabled";	
}

//This function is used  to clear hidden client id when we search using autoSuggest(called on onChange Event)
function onChangeClientName(client_name)
{
	if(client_name != undefined)
	{
		if(Trim(document.getElementById(client_name).value) == '')
			document.getElementById("hid_client_id").value = "";
	}
}

function onChangeClientSearch(strSrClientName,strSrHidClientId)
{
	strClientName = document.getElementById(strSrClientName).value;
	
	if(strClientName == "")
	{
		document.getElementById(strSrHidClientId).value = "";
	}
	else
	{
		document.getElementById(strSrHidClientId).value = getURLData("index.php?file=med_common_suggest&blnAjax=getClientId&client_name="+strClientName.replace("&","|"));
	}
}


function onChangeAjaxSearch(strSrName,strSrHidId,strFieldName,strAjax)
{
	strName = document.getElementById(strSrName).value;
	
	if(strName == "")
		document.getElementById(strSrHidId).value = "";
	else
	{
		document.getElementById(strSrHidId).value = getURLData("index.php?file=med_common_suggest&blnAjax="+strAjax+"&"+strFieldName+"="+strName.replace("&","|"));		
	}
}


// if(strClientName.search(/;/) > 0)

function onClickTR(inputobj,strLstTbl,indexRow)
{
	var strPro;
	for( var properties in inputobj ) {
    strPro	=	strPro + properties+" == "+inputobj[properties] +"\r\n";
	}
	//strContent = new String(inputobj.innerHTML);
	//rExp = /checkbox/;
	var strCheckBox = document.getElementById(strLstTbl+"_cSlcPK_"+indexRow);

	if(strCheckBox != null)
	{
		
		QL_CBClick(strLstTbl+"_cSlcPK_"+indexRow,strCheckBox,indexRow);
	}
}

if(navigator.appName=='Netscape')
	divStyle	=	'table-row';
else
	divStyle	=	'inline';
	
/* function is used for remove table row
created by : Namrata */
function removeRowByConditon(strTableId,strHiddenControl,strRowIndex,strCheckFieldNameBeforeDelete,callFunctionNameAfterDeleteRow,strDeleteButtonId,strBottomLineId,strTableType,strPageType,blnShowMessage)
{
	//get the table name
	var strTable		= 	document.getElementById(strTableId);
	strTableType		=	strTableType.toUpperCase();
	// get total no of row
	var intTotalRow		=	document.getElementById(strHiddenControl).value;
	
	// get the lenght of the table
	var len 			= 	strTable.rows.length;
	
	var intIndex		=	strRowIndex.substring(strRowIndex.length-1,strRowIndex.length);
	
	if(strCheckFieldNameBeforeDelete != "")
	{
		strElement	=	document.getElementById(strCheckFieldNameBeforeDelete);
		
		// if Office name text box is exists then and value is not null then
		if(strElement && strElement.value != "")
		{
			strDeleteRowMessage = "Are you sure want to delete this record permanently? ";
			//given the confirm message 
		
			if(confirm (strDeleteRowMessage) )
			{
				if( strTableType == "CONVERSION_TABLE")
				{
					var intActivityCntForSourceTable	=	$("#hid_activity_count_"+intIndex).val();
					//alert(intActivityCntForSourceTable);
					if(intActivityCntForSourceTable > 0 )
					{
						alert("There are "+intActivityCntForSourceTable+" Activitie(s) associated with Destination table.So It can not de deleted.");
						return false;
					}
					else
					{
						//delete from database 
						intEditRecordPk		=	$("#hid_row_id_"+intIndex).val();
						strUrl	=	"index.php?file=med_common_ajax&action=DELETE_DB_CONVERSION_TABLES&id="+intEditRecordPk;
						getURLData(strUrl);	
					}
				}	
				if( strTableType == "CONVERSION_SOURCE_FILE")
				{
					//delete from database
					intEditRecordPk		=	$("#hid_source_file_id_"+intIndex).val();						
					strUrl	=	"index.php?file=med_common_ajax&action=DELETE_CONVERSION_SOURCE_FILES&id="+intEditRecordPk;					
					getURLData(strUrl);	
				}
				if(strTableType == "CONVERSION_CONTACT")
				{
					//delete from database
					intConversionContactId	=	$("#hid_conversion_contact_id_"+intIndex).val();
					intContactId			=	$("#hid_contact_id_"+intIndex).val();
					
					strUrl	=	"index.php?file=med_common_ajax&action=DELETE_CONVERSION_CONTACT&conversion_contact_id="+intConversionContactId;
					strUrl	+=	"&contact_id="+intContactId;
					
					getURLData(strUrl);
				}	
				//remove one row
				deleteRow(strRowIndex,strTableId)
				intTotalRow--;
			}
		}
		else
		{
			deleteRow(strRowIndex,strTableId)
			intTotalRow--;
		}
	}	
	else	//else remove row without confirm messge
	{	
		deleteRow(strRowIndex,strTableId)
		intTotalRow--;
	}
	
	//at last set total no of row of the lead office
	document.getElementById(strHiddenControl).value	=	intTotalRow;

	if(callFunctionNameAfterDeleteRow != "")
	{
		//call function 
		eval(callFunctionNameAfterDeleteRow);		
	}
	
	eval(setShowHideRemoveButton(intTotalRow,strTableId,strDeleteButtonId,strBottomLineId));	
}
/*delete table row 
created by : Namrata */
function deleteRow(strRowId,strTable)
{
	var elem = document.getElementById(strRowId);	
	
	if(elem)
	 (elem.parentNode).removeChild(elem)	
}

//ad dynamic row at the end of last row of dynamic table
function addDynamicRowToTable(strTableId,strTransactionRow,strHiddenCountControl,strTableType,strDeleteButtonId,strBottomLineId)
{	
	var intTotalTableRow	;
	var strTable		= 	document.getElementById(strTableId);
	
	//get total no of row in a table
	intTotalTableRow	=	(strTable.rows.length) - 1 ;

	//passing this total no of row get the row office Object
	intLastTableRow		=	$("[id^='"+strTransactionRow+"']").get(intTotalTableRow);

	// get Inner HTML of the whole TR
	var strRowHTML		=	$("[id^='"+strTransactionRow+"']").get(intTotalTableRow).innerHTML;
	
	//get the total no
	intTotalTableRow	= 	(intLastTableRow.id).replace(/(\w+\_+)/,"");
	
	strRowHTML		=	strRowHTML.replace('<!--', "") ;
	strRowHTML		=	strRowHTML.replace('-->', "" ) ;

	//get number of rows of the table
	var intRow		=	strTable.getElementsByTagName("TR").length;

	// create a one TR
	var newRow		=	document.createElement("TR");
	
	var newTD		=	document.createElement("TD");

	intNewRowId		=	parseInt(+intTotalTableRow) + 1;
	
	strRowHTML		=	strRowHTML.replace(new RegExp('_'+intTotalTableRow+'','gi'),'_'+intNewRowId);
	
	//set attributes of the created TD
	newRow.setAttribute("id",strTransactionRow+intNewRowId);
	
	newTD.innerHTML	=	strRowHTML;
	
	newRow.appendChild(newTD);
	
	strTable.getElementsByTagName("tbody")[0].appendChild(newRow); 

	blankHTMLControlValue(intNewRowId,strTableType);
	
	if(strTableType == "CONVERSION_TABLE" )
	{
		strSourceElement	=	"slt_source_table_"+intNewRowId;	
		strDestElement		=	"slt_destination_table_"+intNewRowId;	
		//$("#hid_row_id_"+intNewRowId).val("");	
		$("#"+strSourceElement).attr("disabled",false);
		$("#"+strDestElement).attr("disabled",false);
		$("#Taara_note_"+intNewRowId).attr("disabled",false);		
		$("#hid_activity_count_"+intNewRowId).val("");
		$("#img_source_table_"+intNewRowId).css("visibility","hidden");		
		
		var strOnClickSrcTbl = strOnClickConvTbl.replace("ELEMENT_NAME",strSourceElement);
		var strOnClickDestTbl = strOnClickConvTbl.replace("ELEMENT_NAME",strDestElement);
		
		$("#div_src_table_plus_"+intNewRowId).attr("onclick",strOnClickSrcTbl);
		$("#div_dest_table_plus_"+intNewRowId).attr("onclick",strOnClickDestTbl);		
		$("#src_table_plus_"+intNewRowId).css("visibility","visible");
		$("#dest_table_plus_"+intNewRowId).css("visibility","visible");
		
		resetStyle(getElement(strSourceElement));
		resetStyle(getElement(strDestElement));
	}
	if(strTableType == "CONVERSION_SOURCE_FILE" )
	{
		$("#slt_type_"+intNewRowId).attr("disabled",false);
		$("#Taara_description_"+intNewRowId).attr("disabled",false);
		$("#Taara_path_"+intNewRowId).attr("disabled",false);			
	}
	if(strTableType == "CONVERSION_CONTACT" )
	{
		$("#hid_conversion_contact_id_"+intNewRowId).val("");	
		$("#hid_contact_id_"+intNewRowId).val("");	
		$("#hid_contact_id_"+intNewRowId).val("");	
		$("#Rtxt_first_name_"+intNewRowId).val("");	
		$("#txt_last_name_"+intNewRowId).val("");	
		$("#chk_email_after_conversion_"+intNewRowId).attr("checked",false)	;
		
		$("#txt_phone1_"+intNewRowId).val("");	
		$("#slt_designation_"+intNewRowId).val("");	
		$("#Emtxt_email_"+intNewRowId).val("");
	}

	intTotalHiddenRow	=	$("#"+strHiddenCountControl).val();
	intTotalHiddenRow++;
	$("#"+strHiddenCountControl).val(intTotalHiddenRow);
	
	setShowHideRemoveButton(intTotalHiddenRow,strTableId,strDeleteButtonId,strBottomLineId);
}
//function is used for set blank Value for new generate HTML  control
function blankHTMLControlValue(intRowId,strTableType)
{
	//declare and initialize veriable
	var strReplaceString	=	"";

	arrValues	=	new Array();
	
	if(strTableType == "CONVERSION_TABLE")
		arrValues	=	arrSourceDestValues;	
	if(strTableType == "CONVERSION_SOURCE_FILE")
		arrValues	=	arrConversionFilesVar;	
		
	//alert(arrValues);
	//use for loop for get one by one control
	for(intCnt = 0; intCnt <= arrValues.length; intCnt++)
	{
		//if control is selected then 
		if(arrValues[intCnt] !=	'selected="selected"')
		{
			//get the new control  name
			strReplaceString	=	arrValues[intCnt]+"_"+intRowId;
			
			//if control is exist in DOM
			if(document.getElementById(strReplaceString))
			{
				//and control is not undefiend
				if(arrValues[intCnt] == 'undefined')
				{
					// set control value -1 and NULL	
					document.getElementById(strReplaceString).value	= "-1";
					
					document.getElementById(strReplaceString).value	= "";
				}
				else	// if HTML control  is checkbox
				{
					
					strChkString = arrValues[intCnt].substr(0,3);
					
					if(strChkString == "chk" )
					{
						// set unchecked value for control
						document.getElementById(strReplaceString).checked	= false;
					}
					else
					{	// else set NULL value for control
						document.getElementById(strReplaceString).value	= "";
					}
				}
			}
		}
	}
}	
//function to show/hide show hie minus image and bottom line(row sepearator)
function setShowHideRemoveButton(intTotalRow,strTableId,strDeleteButtonId,strBottomLineId)
{
	$("[id^='"+strDeleteButtonId+"']").each(function(i)
	{								   
		intTableRow		= 	(this.id).replace(/(\w+\_+)/,"");		
		if(intTotalRow > 1)
		{
		  $("#"+this.id).attr("style","visibility:visible");
		  $("#"+strBottomLineId+intTableRow).attr("style","visibility:visible");
		}
		else
		{
		  $("#"+this.id).attr("style","visibility:hidden");
  		  $("#"+strBottomLineId+intTableRow).attr("style","visibility:hidden");
		}
	});	
	
	intLineRowId	=	getLastTableRow(strTableId,strBottomLineId);	
	$("#"+strBottomLineId+intLineRowId).attr("style","visibility:hidden");
} 
//function to get last row from table while delete/add dynamic table 
function getLastTableRow(strTableName,strCompareField)
{
	var strTable	= 	getElement(strTableName);

	//get total no of row in a table
	intTotalTableRow	=	(strTable.rows.length) - 1 ;

	//passing this total no of row get the row office Object
	intLastTableRow		=	$("[id^='"+strCompareField+"']").get(intTotalTableRow);

	if(intLastTableRow != undefined )
	{
		//get the total no
		intTotalTableRow		= 	(intLastTableRow.id).replace(/(\w+\_+)/,"");
		return intTotalTableRow;
	}	
}

//php function array_search
function array_search( needle, haystack, strict )
{
    // Searches the array for a given value and returns the corresponding key if
    // successful
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_array_search/
    // +       version: 804.1712
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
    // *     returns 1: 'surname'

    var strict = !!strict;

    for(var key in haystack){
        if( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) ){
            return key;
        }
    }

    return false;
}// }}}

function clientMenuRedirect(strURL)
{
	location.href	=	strURL + "&client_id="+MOS_CLIENT_MENU_LAST_CLICK_ID;
	return false;
}
function makeRadioDisabled(objCtl,blnFlag)
{
	radioObj	=	document.getElementsByName(objCtl.name);
	
	var radioLength = radioObj.length;
	
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].disabled	=	blnFlag;
	}
}

/*
	This function is used for Add/Edit and Listing is in same page and when we click
	on Add then the page should not refresh just drag....
*/

function showAddEditForm(obj,intScrollValue)
{
		
	if(getElement("hid_action").value=='A')
	{
		setTimeout('window.scrollTo('+intScrollValue+',getAbsoluteTop("addedit_form"))',1);
	}
	
	if(getElement("hid_action").value=='E')
	{
		getElement("hid_page_type").value='A';
		obj.form.submit();	
		return false;
	}
}