//general
function CheckIfBlank(controlName, message)
{
    retVal = false;
    if (trim(document.getElementById(controlName).value) == '')    
    {    
        alert(message);
        document.getElementById(controlName).focus();
        retVal = true;
    }
     return  retVal;
}

function trim(stringToTrim)
{
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function insertSelectedValueInTextbox(chkSelectId, controlId)
{        
    chkSelectId = "," +  chkSelectId + ","   
    var textboxValue = document.getElementById(controlId).value;    
    if (trim(textboxValue) == '')
        document.getElementById(controlId).value = chkSelectId;
    else
    {
       if ((document.getElementById(controlId).value).indexOf(chkSelectId) == -1)
       {            
            document.getElementById(controlId).value += chkSelectId;
       }
       else
       {          
          document.getElementById(controlId).value = (document.getElementById(controlId).value).replace(chkSelectId, "");
       }
    }
}

function changeCheckboxState(state, controlId)
{
    document.getElementById(controlId).value = ''; 
    var x=document.getElementById("form1");
    for (var i=0;i<document.forms[0].length;i++)
    {   
        if (document.forms[0].elements[i].type == "checkbox")  
        {
            if (state == 'd')
            {
            //parentElement().id
            //alert(document.forms[0].elements[i].id.parentElement().id);
    		    document.forms[0].elements[i].checked = 0;
    		    document.getElementById(controlId).value = '';
                document.getElementById(controlId).className = '';
		
		        if (document.getElementById('row_1_'+document.forms[0].elements[i].id))		    
		        {
		            if (document.getElementById('orange_'+document.forms[0].elements[i].id))
		            {
		                document.getElementById('row_1_'+document.forms[0].elements[i].id).className = 'SelectedRowPaleOrange';
		            }
		            else
		            {
		    	        document.getElementById('row_1_'+document.forms[0].elements[i].id).className = 'GridRowItem';
		    	    }
		        }
		        else
		        {
				    if (document.getElementById('row_0_'+document.forms[0].elements[i].id))
				    {
				        if (document.getElementById('orange_'+document.forms[0].elements[i].id))
	                    {
	                        document.getElementById('row_0_'+document.forms[0].elements[i].id).className = 'SelectedRowPaleOrange';
	                    }
	                    else
	                    {
			                document.getElementById('row_0_'+document.forms[0].elements[i].id).className = 'GridRowAlternateItem';
			            }
				    }
		        }
            }
            else if (state == 's')
            {
                document.forms[0].elements[i].checked = 1;
                var chkSelectId = document.forms[0].elements[i].id;                    
                insertSelectedValueInTextbox(chkSelectId, controlId);
                
		        if (document.getElementById('row_1_'+document.forms[0].elements[i].id))		    
		        {
		            document.getElementById('row_1_'+document.forms[0].elements[i].id).className = 'SelectedRow';
		        }
		        else
		        {
			    if (document.getElementById('row_0_'+document.forms[0].elements[i].id))
			    {
		            	document.getElementById('row_0_'+document.forms[0].elements[i].id).className = 'SelectedRow';
			    }
		        }
            }
        }
    }
}

function insertCheckboxValueInTextbox(checkBoxId, textBoxId)
{   
    if (document.forms[0].elements[checkBoxId].checked)
    {        
        document.getElementById(textBoxId).value = "True";
    }
    if (!document.forms[0].elements[checkBoxId].checked)
    {        
        document.getElementById(textBoxId).value = "False";
    }   
}

function validateForm(controlId, alertMessage)
{   
    return CheckIfBlank(controlId, alertMessage) ? false : true;
}

function submitFormWithMultipleSelections(form1, actionValue, actionControlId, controlId, alertMessage)
{
    returnVal = false;
    
    if (actionValue.substring(0,3) == '---')
        return false;
     
    if (validateControl(controlId, alertMessage))
    { 
        masterDataFormPost1(actionValue, actionControlId);
        document.getElementById(form1).submit();
        returnVal = true;
    }
    return returnVal;
}

function submitFormWithMultipleSelections2(form1, actionValue, controlId, alertMessage)
{
    returnVal = false;
    
    if (actionValue.substring(0,3) == '---')
        return false;
    
    if (validateControl(controlId, alertMessage))  
    {        
        document.getElementById(form1).submit();
        returnVal = true;
    }
    return returnVal;
}

function validateControl(controlId, alertMessage)
{       
    retVal = true;
    if (trim(document.getElementById(controlId).value) == '')    
    {    
        alert(alertMessage);               
        retVal = false;
    }
    return  retVal;   
}

//country
function ValidateCountryForm(pageState)
{   
    retValidation = true;    
    if (CheckIfBlank("txtCountryName", "Please enter the country name.."))
    {       
        retValidation = false;        
    }
    else if (CheckIfBlank("txtAbbreviation", "Please enter country abbreviation.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtCurrency", "Please enter currency.."))        
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtCurrencySymbol", "Please enter currency symbol.."))        
    {
        retValidation = false;
    }
/*    else if (CheckIfBlank("txtGSTonBP", "Please enter GST on BP.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtGSTonAF", "Please enter GST on AF.."))
    {
        retValidation = false;
    }*/
    else if (CheckIfBlank("txtSDAbbr", "Please enter SD Abbr.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtTaxationAbbr", "Please enter Tax Abbr.."))
    {
        retValidation = false;
    }
    else if (trim(document.getElementById("txtGSTonBP").value) != '')
    {
        if (!isFloat(trim(document.getElementById("txtGSTonBP").value)))
        {
            alert("Please enter a numeric value for GST on BP..");
            document.getElementById("txtGSTonBP").focus();
            retValidation = false;
        }        
    }
    
    if (retValidation == true)
    {
        if (trim(document.getElementById("txtGSTonAF").value) != '')
        {
            if (!isFloat(trim(document.getElementById("txtGSTonAF").value)))
            {
                alert("Please enter a numeric value for GST on AF..");
                document.getElementById("txtGSTonAF").focus();
                retValidation = false;
            }
        }
    }
      
    if (pageState = "A")
    {
        if (retValidation)
        {
            if (CheckIfBlank("cboFlagFileName", "Please specify a flag file.."))
            {       
                retValidation = false;        
            }
        }
    }
    
    if (retValidation == true)
    {
        if (trim(document.getElementById('txtContactEmail').value) != '')
        {
            if (!isEmail(document.getElementById("txtContactEmail").value))
            {
                alert("Please enter a valid contact email address..");
                document.getElementById("txtContactEmail").focus();
                retValidation = false;
            }
        }
    }
    
    if (retValidation == true)
    {
        if (trim(document.getElementById('txtRenewalFromEmail').value) != '')
        {
            if (!isEmail(document.getElementById("txtRenewalFromEmail").value))
            {
                alert("Please enter a valid email address for renewal emails..");
                document.getElementById("txtRenewalFromEmail").focus();
                retValidation = false;
            }
            
            if (retValidation == true)
            {
                if (CheckIfBlank("txtRenewalFromEmailPassword", "Please enter email address password for renewal emails.."))
                {
                    retValidation = false;
                }
            }            
        }
    }
    
    if (retValidation == true)
    {
        if (trim(document.getElementById('txtPurchaseFromEmail').value) != '')
        {
            if (!isEmail(document.getElementById("txtPurchaseFromEmail").value))
            {
                alert("Please enter a valid email address for purchase emails..");
                document.getElementById("txtPurchaseFromEmail").focus();
                retValidation = false;
            }
            
            if (retValidation == true)
            {
                if (CheckIfBlank("txtPurchaseFromEmailPassword", "Please enter email address password for purchase emails.."))
                {
                    retValidation = false;
                }
            }
        }
    }
    
    return retValidation;
}

//therapy
function ValidateTherapyForm(pageState)
{   
    retValidation = true;    
    if (CheckIfBlank("txtTherapyDesc", "Please enter the therapy name.."))
    {       
        retValidation = false;        
    }   
    /*if (pageState = "A")
    {
        if (retValidation)
        {
            if (CheckIfBlank("cboPWFileName", "Please specify a policy wording file.."))
            {       
                retValidation = false;        
            }
        }
    }*/
    return retValidation;
}

function validateTherapyListForm()
{
    return CheckIfBlank("hidSelectedTherapyId", "Please select one or more therapies..") ? false : true;
}

function submitTherapyListFormWithMultipleSelections(actionValue, actionControlId)
{
    if (validateTherapyListForm())
    {
        masterDataFormPost1(actionValue, actionControlId)
        frmTherapyList.submit();
    }
    return;
}


/* --------------------// Check whether string s is empty.----------------------------------- */


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// isFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is an unsigned floating point (real) number. 
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
//
// Does not accept exponential notation.

var defaultEmptyOK = false
var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

function isFloat (s)
{       
    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);   
    return reFloat.test(s)
}

//territory
function validateTerritoryForm()
{    
    retValidation = true;
    if (CheckIfBlank("txtTerritoryName", "Please enter the territory name.."))
    {       
        retValidation = false;        
    }
    else if (CheckIfBlank("txtPISDRate", "Please enter PI SD Rate.."))        
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtLiabSDRate", "Please enter Liability SD Rate.."))        
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtEffectiveSDRate", "Please enter Effective SD Rate.."))        
    {
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtPISDRate").value)))
    {
        alert("Please enter a numeric value for PI SD Rate..");
        document.getElementById("txtPISDRate").focus();
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtLiabSDRate").value)))
    {
        alert("Please enter a numeric value for Liability SD Rate..");
        document.getElementById("txtLiabSDRate").focus();
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtEffectiveSDRate").value)))
    {
        alert("Please enter a numeric value for Effective SD Rate..");
        document.getElementById("txtEffectiveSDRate").focus();
        retValidation = false;
    }
    return retValidation;
}


function validateRateInsert(rateType)
{  
    retValidation = true;
    if (CheckIfBlank("cboCover", "Please specify the Cover.."))
    {       
        retValidation = false;        
    }
    else if (CheckIfBlank("txtBasePremium", "Please enter Base Premium.."))        
    {
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtBasePremium").value)))
    {
        alert("Please enter a numeric value for Base Premium..");
        document.getElementById("txtBasePremium").focus();
        retValidation = false;
    }
    else if (CheckIfBlank("txtAdminFee", "Please enter Admin Fee.."))        
    {
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtAdminFee").value)))
    {
        alert("Please enter a numeric value for Admin Fee..");
        document.getElementById("txtAdminFee").focus();
        retValidation = false;
    }
    else if (CheckIfBlank("cboBroker", "Please specify the Broker.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtTrueComm", "Please specify the True Commission.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtRateName", "Please enter Rate Name.."))        
    {
        retValidation = false;
    }   
    else if (!isFloat(trim(document.getElementById("txtTrueComm").value)))
    {
        alert("Please enter a numeric value for True Commission..");
        document.getElementById("txtTrueComm").focus();
        retValidation = false;
    }
    
       
    if (rateType == "c")
    {
         if (retValidation)
        {
            if (trim(document.getElementById("cboTherapy").value) == '' && trim(document.getElementById("cboOrganisation").value) == '')    
            {         
                alert("Please specify at least a therapy or an organisation..");
                document.getElementById("cboTherapy").focus();
                retValidation = false;        
            }
        }
    }
       
    return retValidation;
}


function validateBrokerForm(pageState)
{
    retValidation = true;    
    if (CheckIfBlank("txtBrokerName", "Please enter the broker name.."))
    {       
        retValidation = false;        
    }
    else if (CheckIfBlank("txtCityState", "Please enter the city and state name.."))
    {       
        retValidation = false;        
    }
    else if (CheckIfBlank("cboCountry", "Please select the country.."))
    {       
        retValidation = false;        
    }
    else if (CheckIfBlank("txtTrueComm", "Please enter true commission value.."))        
    {
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtTrueComm").value)))
    {
        alert("Please enter a numeric value for true commission..");
        document.getElementById("txtTrueComm").focus();
        retValidation = false;
    }
      
    if (pageState = "A")
    {
        if (retValidation)
        {
            if (CheckIfBlank("cboBrokerLogo", "Please specify a Logo file.."))
            {       
                retValidation = false;        
            }
        }
    }
    return retValidation;
}

    
function putValueInTextBox(brokerId)
{   
   pos = brokerId.indexOf(",");
   if (pos > 0)
   {
    len = brokerId.length;
    trueComm = brokerId.substring(pos+1);
    document.getElementById("txtTrueComm").value = trueComm;
   }
   else
   {
    document.getElementById("txtTrueComm").value = '';
   }
}


function validateProductRateInsert(rateType)
{  
    retValidation = true;
    if (CheckIfBlank("cboProduct", "Please specify the Product.."))
    {       
        retValidation = false;        
    }
      else if (CheckIfBlank("txtBasePremium", "Please enter Base Premium.."))        
    {
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtBasePremium").value)))
    {
        alert("Please enter a numeric value for Base Premium..");
        document.getElementById("txtBasePremium").focus();
        retValidation = false;
    }
    else if (CheckIfBlank("txtAdminFee", "Please enter Admin Fee.."))        
    {
        retValidation = false;
    }
    else if (!isFloat(trim(document.getElementById("txtAdminFee").value)))
    {
        alert("Please enter a numeric value for Admin Fee..");
        document.getElementById("txtAdminFee").focus();
        retValidation = false;
    }
    else if (CheckIfBlank("cboBroker", "Please specify the Broker.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtTrueComm", "Please specify the True Commission.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtProductRateName", "Please enter Product Custom Name.."))        
    {
        retValidation = false;
    }
     if (rateType == "c")
    {
        if (retValidation)
        {
            if (trim(document.getElementById("cboOrganisation").value) == '')    
            {         
                alert("Please specify an organisation..");
                document.getElementById("cboOrganisation").focus();
                retValidation = false;        
            }
        }
    }
           
    return retValidation;
}

function changeCheckboxState1(state, controlId, controlId2)
{
    document.getElementById(controlId).value = ''; 
    document.getElementById(controlId2).value = ''; 
    
    var x=document.getElementById("form1");
    
    for (var i=0;i<document.forms[0].length;i++)
    {   
        if (document.forms[0].elements[i].type == "checkbox")  
        {
            if (state == 'd')
            {      
    		    document.forms[0].elements[i].checked = 0;            
		        
		        if (document.forms[0].elements[i].id.indexOf("cr_") < 0)
		        {
		            if (document.getElementById('row_1_' + document.forms[0].elements[i].id))		    
		            {
		    	        document.getElementById('row_1_' + document.forms[0].elements[i].id).className = 'GridRowItem';
		            }
		            else
		            {
				        if (document.getElementById('row_0_' + document.forms[0].elements[i].id))
				        {
			        	    document.getElementById('row_0_' + document.forms[0].elements[i].id).className = 'GridRowAlternateItem';
				        }
		            }
		        }
            }
            else if (state == 's')
            {
                document.forms[0].elements[i].checked = 1;
                var chkSelectId = document.forms[0].elements[i].id;
                if (chkSelectId.indexOf("cr_") < 0)
                {
                    insertSelectedValueInTextbox(chkSelectId, controlId);
                    insertSelectedValueInTextbox(chkSelectId, controlId2);                                 
                    
                    if (document.forms[0].elements[i].id.indexOf("cr_") < 0)
		            {
		                if (document.getElementById('row_1_' + chkSelectId))		    
		                {
		                    document.getElementById('row_1_' + chkSelectId).className = 'SelectedRow';
		                }
		                else
		                {
			                if (document.getElementById('row_0_' + chkSelectId))
			                {
		            	        document.getElementById('row_0_' + chkSelectId).className = 'SelectedRow';
			                }
		                }
		            }
		        }
            }
        }
    }
}


function insertSelectedValueInTextboxes(chkSelectId, controlId, controlId2)
{   
    insertSelectedValueInTextbox(chkSelectId, controlId);    
    
    /*checkBoxId = 'cr_' + chkSelectId;
    checkBoxIdValue =  "," +  chkSelectId + ",";
    
    if (document.getElementById(chkSelectId).checked)
    {        
        document.forms[0].elements[checkBoxId].checked = 1;        
        pos = (document.getElementById(controlId2).value).indexOf(checkBoxIdValue);
        if (!(pos > -1))        
        {
            insertSelectedValueInTextbox(chkSelectId, controlId2);
        }
    }
    else
    {
        document.forms[0].elements[checkBoxId].checked = 0;
        document.getElementById(controlId2).value = (document.getElementById(controlId2).value).replace(checkBoxIdValue, "");  
    }    */
}

/* --------------------- pending policies ----------------------------- */
function AddPolicyIdToTextbox()
{
	if (document.forms) 
	{
		document.getElementById('txtSelectedPolicies').value = '';
		for (var i=0; i<document.forms['frmPendingPolicies'].length; i++) 
		{
			if (document.forms['frmPendingPolicies'][i].type == 'checkbox' && document.forms['frmPendingPolicies'][i].checked==true)
			{
				document.getElementById('txtSelectedPolicies').value += document.getElementById(document.forms['frmPendingPolicies'][i].id).id.substring(4) + ",";				
			}
		}
		
		selectedPolicies = document.getElementById('txtSelectedPolicies').value;
		if (selectedPolicies != '')
			document.getElementById('txtSelectedPolicies').value = selectedPolicies.substring(0, selectedPolicies.length - 1);
	}
}

function UpdateActionSubmitForm(actionValue)
{	
	if (document.getElementById('txtSelectedPolicies').value == '')
	{
		alert('Please select one or more policies and click an action button.');
		return;
	}
	document.getElementById('txtAction').value=actionValue;	
	frmPendingPolicies.submit();	
}

/* ---------------------  renewal ----------------------------- */

function validateIndemnityLimitForm()
{    
    retValidation = true;
    if (CheckIfBlank("txtIndemnityLimit", "Please enter the Indemnity Limit.."))
    {       
        retValidation = false;        
    }
    else if (!isFloat(trim(document.getElementById("txtIndemnityLimit").value)))
    {
        alert("Please enter a numeric value for Indemnity Limit..");
        document.getElementById("txtIndemnityLimit").focus();
        retValidation = false;
    }

    return retValidation;
}

function validateCoverForm()
{    
    retValidation = true;
    if (CheckIfBlank("txtCoverDesc", "Please enter the cover description.."))
    {       
        retValidation = false;        
    }
    else if (trim(document.getElementById("txtExcess").value) != "")
    {        
        if (!isFloat(trim(document.getElementById("txtExcess").value)))
        {
            alert("Please enter a numeric value for Excess..");
            document.getElementById("txtExcess").focus();
            retValidation = false;
        }
    }
    return retValidation;
}

function validateProductForm()
{    
    retValidation = true;
    if (CheckIfBlank("txtProductName", "Please enter the product name.."))
    {       
        retValidation = false;
    }
    else if (trim(document.getElementById("txtExcess").value) != "")
    {        
        if (!isFloat(trim(document.getElementById("txtExcess").value)))
        {
            alert("Please enter a numeric value for Excess..");
            document.getElementById("txtExcess").focus();
            retValidation = false;
        }
    }
    return retValidation;
}


function validateCSVEmailForm()
{    
    retValidation = true;
    if (CheckIfBlank("txtStartDate", "Please enter the start date.."))
    {       
        retValidation = false;
    }
    else if (CheckIfBlank("txtEndDate", "Please enter the end date.."))
    {       
        retValidation = false;
    }
    return retValidation;
}



function validateRenewalForm()
{    
    retValidation = true;
    if (CheckIfBlank("txtStartDate", "Please enter the start date.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtEndDate", "Please enter the end date.."))
    {
        retValidation = false;
    }
    else if (isDate(document.getElementById("txtStartDate").value, 'd-NNN-yyyy') == false)
    {
        alert("Invalid date format..");
        document.getElementById("txtStartDate").focus();
        retValidation = false;
    }
    else if (isDate(document.getElementById("txtEndDate").value, 'd-NNN-yyyy') == false)
    {
        alert("Invalid date format..");
        document.getElementById("txtEndDate").focus();
        retValidation = false;
    }
    return retValidation;
}

function validateRenewEmailTextDetails(templateType)
{    
    retValidation = true;
    if (templateType == "c")
    {
        if (CheckIfBlank("cboCover", "Please specify the Cover.."))
        {       
            retValidation = false;        
        }        
    }
    
    if (retValidation == true)
    {
        if (templateType == "p")
        {
            if (CheckIfBlank("cboProduct", "Please specify the Product.."))
            {       
                retValidation = false;        
            }        
        }
    }
    
    if (retValidation == true)
    {
        if (getEditorValue('oFCKeditor')=='')
        {
            alert("Please define an email template..");
            retValidation = false;
        }
    }
    
    if (retValidation == true)
    {
        if (CheckIfBlank("txtEmailId", "Please enter the test email address.."))
        {
            retValidation = false;
        }
        else if (!isEmail (document.getElementById("txtEmailId").value))
        {
            alert("Please enter a valid email address..");
            document.getElementById("txtEmailId").focus();
            retValidation = false;
        }    
    }
    
    return retValidation;    
}

// BOI, followed by one or more characters, followed by @,
// followed by one or more characters, followed by ., 
// followed by one or more characters, followed by EOI.
var reEmail = /^.+\@.+\..+$/

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)

{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    
    else {
       return reEmail.test(s)
    }
}


//////////////Renewal Email Text

function changeStyle(clickedTemplate) {    
    var selectedTemplateId = document.getElementById('hidTemplateCategory').value;
    
    if (selectedTemplateId != "")
    {
        document.getElementById(selectedTemplateId).className = "unselectedMenu";        
        document.getElementById(selectedTemplateId).innerHTML = document.getElementById(selectedTemplateId).innerHTML.replace("[", "").replace("]", "");
    }
    
    document.getElementById(clickedTemplate).innerHTML = "[" + document.getElementById(clickedTemplate).innerHTML + "]"
    document.getElementById(clickedTemplate).className = "selectedMenu";    
    
    document.getElementById('hidTemplateCategory').value = clickedTemplate;
}


function validateRenewEmailTextDefine(templateType, templateCategory)
{    
    retValidation = true;
    if (templateType == "c")
    {
        if (CheckIfBlank("cboCover", "Please specify the Cover.."))
        {       
            retValidation = false;        
        }        
    }
    else if (templateType == "p")
    {
        if (CheckIfBlank("cboProduct", "Please specify the Product.."))
        {       
            retValidation = false;        
        }        
    }    


    if (retValidation == true)
    {
        if (document.getElementById("hidTemplateCategory").value == "")
        {
            alert("Please select the category..");
            retValidation = false;
        }       
    }
    return retValidation;
    
}

function getEditorValue( instanceName )
{
    // Get the editor instance that we want to interact with.
    var oEditor = FCKeditorAPI.GetInstance( instanceName ) ;

    // Get the editor contents as XHTML.
    return oEditor.GetXHTML( true ) ; // "true" means you want it formatted.
}

function onDefaultTemplateClick(templateType)
{
    var doPostBack = false;
    
    if (document.getElementById(templateType + ' Email Template').innerHTML.substring(0,1) != '[')
        doPostBack = true;
        
    changeStyle(templateType + ' Email Template');
    
    if (doPostBack == true) {
        masterDataFormPost1('', 'hidButtonType');
        frmRenewalsEmailText.submit();
    }    
}

function ValidateRenewPolicy()
{
    retVal = true;
    if (document.getElementById('hidSelectedPolicies').value == "")
    {
        alert("Please select one or more policies for renewal..");
        retVal = false;
    }
    return retVal;
}

function CheckIfEmailIsValid()
{
    retValidation = true;
    if (!isEmail (trim(document.getElementById("txtEmailId").value)))
    {
        alert("Please enter a valid email address..");
        document.getElementById("txtEmailId").focus();
        retValidation = false;
    }
    return retValidation;
}

function validateProductCategoryForm()
{
    retValidation = true;
    if (CheckIfBlank("txtProductCategory", "Please enter the product category.."))
    {
        retValidation = false;
    }
    else if (CheckIfBlank("txtShortCode", "Please enter the short code.."))
    {
        retValidation = false;
    }
    return retValidation;
}

function validateFAQForm()
{
    retValidation = true;    
    if (CheckIfBlank("txtQuestion", "Please enter the FAQ question.."))
    {       
        retValidation = false;        
    }
    else if (CheckIfBlank("txtAnswer", "Please enter the FAQ answer.."))
    {       
        retValidation = false;        
    }
    else if (trim(document.getElementById('hidSelectedCountryId').value) == '')
    {
        alert('Please link this FAQ to at least one country..');
        retValidation = false;        
    }
    
    return retValidation;
}