var SUCCESS =1;

var EMPTY_STRING = "";

var LEFT = 0;

var RIGHT = 1;

var BOTH = 2;

var RADIX_INT = 10;

var bErrorOccured = false;

var sList;

var ggWinCal;



var strIE = (document.all) ? true : false;

var strNS = (document.layers) ? true : false;



var resize = ",resizable=yes";



if ( strNS )

{

    resize = ",resizable=no";

}



function closeReportWindow()

{

    var result;

    result = confirm('Are you sure you want to close this report?');



    if (result)

    {

        parent.close();

    }

}



function showLov(strURL)

{

    var win_nm;

    win_nm = Math.round(Math.random()*100000000);

    

    if (strURL.indexOf("eetScreenFlag") != -1)

    {

        sList = window.open(strURL, win_nm,

        config = 'height=320px,width=910px,top=80,left=50,scrollbars=yes,status=yes,location=no' + resize);

    }

    else if (strURL.indexOf("client") != -1)

    {

        sList = window.open(strURL, win_nm,

        config = 'height=610px,width=910px,top=80,left=50,scrollbars=yes,status=yes,location=no' + resize);



    }

    else if (strURL.indexOf("trader") != -1)

    {

        sList = window.open(strURL, win_nm,

        config = 'height=320px,width=950px,top=80,left=40,scrollbars=yes,status=yes,location=no' + resize);



    }

    else

    {

        sList = window.open(strURL, win_nm,

        config = 'height=320px,width=650px,top=150,left=150,scrollbars=yes,status=yes,location=no' + resize);

    }

}



function openChild(strURL, width, height)

{

    var win_nm;

    win_nm = Math.round(Math.random()*100000000);



    sList = window.open(strURL, win_nm,

    config='height=' + height + 'px,width=' + width + 

            'px,top=150,left=250,scrollbars=yes,status=yes,location=no' +  

            resize);

}



function openChildWithPosition(strURL, width, height, top, left)

{

    var win_nm;

    win_nm = Math.round(Math.random()*100000000);



    sList = window.open(strURL, win_nm,

    config='height=' + height + 'px,width=' + width + 'px,top=' + top +

            ',left=' + left + ',scrollbars=yes,status=yes,location=no,menubar=1' +  resize);

}



function openChildWithoutSList(strURL, width, height, top, left)

{

    var win_nm;

    win_nm = Math.round(Math.random()*100000000);



    window.open(strURL, win_nm,

    config='height=' + height + 'px,width=' + width + 'px,top=' + top +

            ',left=' + left + ',scrollbars=yes,status=yes,location=no,menubar=1' +  resize);

}



function fnClose()

{

    window.close();

}



function fnCalendar(gbObjCtrl)

{

    if(fnCheckWindow())

    {

        if(gbObjCtrl==null)

        {

            return false;

        }

        else

        {

            show_calendar(gbObjCtrl);

        }

    }

}



function fnSendToParent (lstReqd, screen)

{

   var numLoop      = 0;

   var textToParent     = "";

   var valueToParent    = "";

   var searchString = "";



    if (lstReqd.length < 100)

    {

       for ( numLoop=0; numLoop < lstReqd.length; numLoop++ )

       {

        textToParent   = textToParent + lstReqd[numLoop].text;

        valueToParent  = valueToParent + lstReqd[numLoop].value;



        if (numLoop < lstReqd.length - 1)

        {

            textToParent   = textToParent + ",";

            valueToParent   = valueToParent + ",";

        }

       }

    }

    else

    {

        alert(E068);

        return;

    }



   if (screen == '1')

       searchString = document.frmChild.client.value;

   if (screen == '2')

       searchString = document.frmChild.regionMarket.value;

   if (screen == '3')

       searchString = document.frmChild.execInstruction.value;

   if (screen == '4')

       searchString = document.frmChild.trader.value;

   if (screen == '5')

       searchString = document.frmChild.eetType.value;





   window.opener.fnSetLovValue(textToParent, valueToParent, searchString, screen);

   fnClose();

}



function fnAddAll (lst_from_name, lst_to_name)

{



  var objOption     = null;

  var numLoop       = 0;

  var numIndex      = 0;





   for ( numLoop=0; numLoop < lst_from_name.length; numLoop++ )

   {

        objOption = new Option();

        objOption.value = lst_from_name[numLoop].value;

        objOption.text = lst_from_name[numLoop].text;

        lst_to_name[lst_to_name.length] = objOption;

        lst_from_name[numLoop] = null;

        numLoop--;

   }



   fnSortLastItem(lst_to_name);



}



function fnAddItem (lst_from_name, lst_to_name)

{



  var arrSelected   = new Array();

  var objOption     = null;

  var numLoop       = 0;

  var numIndex      = 0;





   if (lst_from_name.selectedIndex == -1)

   {

     return;

   }



   for ( numLoop=0; numLoop < lst_from_name.length; numLoop++ )

   {



     if ( lst_from_name[numLoop].selected )

     {



        objOption = new Option();

        objOption.value = lst_from_name[numLoop].value;

        objOption.text = lst_from_name[numLoop].text;

        lst_to_name[lst_to_name.length] = objOption;

        lst_from_name[numLoop] = null;

        numLoop--;

     }



   }

    fnSortLastItem(lst_to_name);

    fnSortLastItem(lst_from_name) ;

}



function fnSortLastItem (array_item)

{



  var numCount, j = 0;

  var last_item = null;

  var tmp_buf_text, tmp_buf_value;





  if (array_item.length != 0)

    last_item = array_item[array_item.length - 1];





  for (numCount = 0; numCount < array_item.length; numCount++)

  {



    if (last_item.text >= array_item[numCount].text)

    {

      continue;

    }

    else

    { // swap

      tmp_buf_text  = array_item[numCount].text;

      tmp_buf_value = array_item[numCount].value;



      array_item[numCount].text  = last_item.text;

      array_item[numCount].value = last_item.value;



      last_item.text  = tmp_buf_text;

      last_item.value = tmp_buf_value;



    }



  }



}



function fnCheckStringForComma(temp)

{

    var returnString = ""; 

    if (temp.indexOf(",") == -1)

    {

        return temp;

    }

    else

    {

        return returnString;

    }

}



function fnBack()

{

    /*document.frmCreditLineApp.method = "post";

    document.frmCreditLineApp.hdnActionID.value = "AD_CREDIT_INIT";

    document.frmCreditLineApp.action = "<%= response.encodeURL ( ABPConfig.strGetString ( Consts.APP_ROOT )+ "/ControlServlet" ) %>";

    document.frmCreditLineApp.submit();*/

}



function fnCheckWindow()

{

    if (( sList && !sList.closed ) || (ggWinCal && !ggWinCal.closed)  )

    {

        alert(E017);

        return false;

    }

    else

    {

        return true;

    }



}



var numURLChanger=1000000;

var url1;



function fnCheck(strURL)

{

    numURLChanger++;

    parent.frames.fra_main.focus();

    var bConfirm=true;



    if((parent.frames.fra_main.window.sList || parent.frames.fra_main.window.ggWinCal)

            && !parent.frames.fra_main.window.fnCheckWindow())

    {

        bConfirm = false;

    }



     if(parent.frames.fra_main.window.frmParent.hdnScrChanged.value == "true") 

     {

        bConfirm = confirm(parent.frames.fra_main.window.E003);

     }



    if (bConfirm)

    {

        url1 = strURL ;//+ "&hdnChanger=" + numURLChanger;



        setTimeout("fnRedir()", 500)

    }



}



function fnRedir()

{

    parent.frames.fra_main.location.href=url1;

    return;

}



function fncmIsEmail (sMailID)

{

    var bRetValue = true;

    var sFieldValue = "";

    var iFieldWidth = 0;

    var sTempAt = "";



    sFieldValue = fncmTrim(sMailID, BOTH);



    if (true == fncmIsEmpty (sFieldValue))  // If empty return

    {

        bRetValue = false;

    }//end of if null

    else

    {

    // split Email by "@"

    sTempAt = sMailID.split ("@");



    if (true == bRetValue)

    {

        //if there is zero of more then one "@" return false

        if(sTempAt.length != 2)

        {

             bRetValue = false;

        }



    }//end of if ( bRetval)

    }//end of else when if ==null

    return bRetValue;



} // end of fncmfnIsEmail



function fnConvertIntoUpperCase(objText)

{

    if(objText != null && objText.className != "cssdisabledTextbox")

    {

        objText.value=objText.value.toUpperCase();

    }

}



function fnConvertIntoUpperCaseDate(objText)

{

  objText.value=objText.value.toUpperCase();

  if(fncmValidateDate(objText.value) && fncmTrim(objText.value,2).length > 0)

    objText.value = fnCheckDateString(objText.value);

}



function fnChange()

{



    document.frmParent.hdnScrChanged.value=true;

}



function fncmCheckLst(objLst)

{



    var bErrCode = false;

    if(0 == objLst.length)

    {

        bErrCode = true;

    }

    else

    {

        if(objLst.type != "hidden")

        {

            var sValue = objLst[objLst.selectedIndex].value;

            bErrCode = fncmIsEmpty (sValue);

        }

    }

    // Mandatory Check

    if (true == objLst.ATMANDATORY)

    {

        if (true == bErrCode)

        {

            objLst.ATErrCode = E016;

            return objLst;

        }

    }

}



function fncmCheckTxt(objTxt)

{

    var sValue = objTxt.value;

    var bErrCode = fncmIsEmpty (sValue);

    // Mandatory Check

    if (true == objTxt.ATMANDATORY)

    {

        if (true == bErrCode)

        {

            objTxt.ATErrCode = E016;

            objTxt.value = "";

            return objTxt;

        }

    }

    if (false == fncmIsEmpty (sValue))

    {

        // Conversion to caps

        if(true == objTxt.ATCAPS)

        {

            fnConvertIntoUpperCase(objTxt);

        }

        // Numeric check

        if (true == objTxt.ATNUMERIC)

        {

            bErrCode = fncmIsNumeric(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E014;

                objTxt.value = fncmTrim (sValue, BOTH);

                return objTxt;

            }

        }

        if (true == objTxt.ATNEGATIVENUMERIC)

        {

            if (sValue.charAt(0) == "-")

            {

                sValue = sValue.replace("-", "0");

            }           

            bErrCode = fncmIsNumeric(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E014;

                objTxt.value = fncmTrim (sValue, BOTH);

                return objTxt;

            }

        }

        // Integer Check

        if (true == objTxt.ATALPHANUMERIC)

        {

            bErrCode = fncmIsAlphaNumeric(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E019;

                //objTxt.value = fncmTrim (sValue, BOTH);

                return objTxt;

            }

        }



        if (true == objTxt.ATSALPHANUMERIC)

        {

            bErrCode = fncmIsSpaceAlphaNumeric(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E019;

                //objTxt.value = fncmTrim (sValue, BOTH);

                return objTxt;

            }

        }



        if (true == objTxt.ATINTEGER)

        {

            bErrCode = fncmIsInteger(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E013;

                return objTxt;

            }

        }



        if (true == objTxt.ATALLINTEGER)

        {

            bErrCode = fnIsValidInteger(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E041;

                return objTxt;

            }

        }



        /* Added by Partha to test Positive Integers */

        if (true == objTxt.ATPOSITIVEINTEGER)

        {

            bErrCode = fncmIsPositiveInteger(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E023;

                return objTxt;

            }

        }

        /* End add by Partha */



        /* Added by Jaijeev to check E-Mail Address.

            It check for one and only one "@" */

        if (true == objTxt.ATEMAIL)

        {

            bErrCode = fncmIsEmail(sValue);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E043;

                return objTxt;

            }

        }

        /* End add by Jaijeev */





        //Min Length check

        if (null != objTxt.ATMINLENGTH)

        {

            iMinLength = objTxt.ATMINLENGTH;

            bErrCode = fncmCheckMinLength (sValue, iMinLength);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E020;

                return objTxt;

            }

        }



        if (null != objTxt.ATMAXLENGTH)

        {

            iMaxLength = objTxt.ATMAXLENGTH;

            bErrCode = fncmCheckMaxLength (sValue, iMaxLength);

            if (false == bErrCode)

            {

                objTxt.ATErrCode = E031;

                return objTxt;

            }

        }



    }

    else if((true == objTxt.ATNUMERIC) ||

            (true == objTxt.ATNEGATIVENUMERIC) ||

            (true == objTxt.ATINTEGER) ||

            (true == objTxt.ATALLINTEGER))

    {

            objTxt.value = fncmTrim (sValue, BOTH);

    }



    var objTemp = new Object();

    objTemp.ATErrCode = SUCCESS;

    return objTemp;

}



function fncmCheckDate(objDate)

{

    var sValue = objDate.value;

    var bErrCode;

    // Mandatory Check

    if (true == objDate.ATMANDATORY)

    {

        if (sValue == "" )

        {

            objDate.ATErrCode = E016;

            objDate.value = "";

            return objDate;

        }

    }

    if (sValue != "" )

    {

        bErrCode = fncmValidateDate(sValue);

        if (false == bErrCode)

        {

            objDate.ATErrCode = E001;

            return objDate;

        }

        bErrCode = fncmValidateDate1900(sValue); //DateValidation<1900 -begin

        if (false == bErrCode)

        {

            objDate.ATErrCode = E022;

            return objDate;

        } //DateValidation<1900 - end



    }



    objDate.value = fncmTrim (sValue, BOTH);



    var objTemp = new Object();

    objTemp.ATErrCode = SUCCESS;

    return objTemp;

}



function fncmCheckError(objControls)

{

  var PREFIX_WIDTH = 3;

  var START = 0;



  var PR_TEXT = "";

  var PR_TEXT_AREA = "";

  var PR_PWD = "";



  var PR_LST = "lb_";

  var PR_COMBO = "cm_";

  var PR_CHECK = "cb_"

  var PR_RADIO = "rb_"



  var sName;

  var sPrefix;

  var objResult;



  sName=objControls.name;

  bErrorOccured=false;



  sPrefix = sName.substring(START,PREFIX_WIDTH);



  if (PR_COMBO== sPrefix)

  {

    objResult=fncmCheckLst(objControls);

  }

  else if(objControls.ATDATE)

  {

    //fnConvertIntoUpperCaseDate(objControls)

    objResult=fncmCheckDate(objControls);

  }

  else

  {

    objResult=fncmCheckTxt(objControls);

  }



  if(objResult != null && objResult.ATErrCode!=SUCCESS)

  {

    bErrorOccured=true;

    alert(objResult.ATErrCode);

    //window.status= objResult.ATErrCode;

    objResult.focus();

  }

}



function fncmIsEmpty (sFieldValue)

{



    var bRetValue = false;



    replacement = / /gi;            // regular expression



    // remove all spaces

    sFieldValue = sFieldValue + EMPTY_STRING;

    sFieldValue = sFieldValue.replace(replacement, EMPTY_STRING);



    if ((EMPTY_STRING == sFieldValue) || (null == sFieldValue))

    {

        bRetValue = true;

    }

    return bRetValue;

} // end of fncmIsEmpty





function fncmIsNumeric (numFieldValue)

{

    var MAX_SPLIT = 2;

    var iCount = 0;

    var iCode = 0;

    var bRetValue = true;

    var sTemp = "";

    var iTemp = 0;

    var iFieldWidth = 0;



    var objRe = new RegExp ("[^0-9|\.]");        // Regular expression



    // trim on both sides

    numFieldValue = fncmTrim(numFieldValue, BOTH);



    if (true == fncmIsEmpty (numFieldValue))

    {

        bRetValue = false;

    }

    else

    {

        if (numFieldValue.substring(numFieldValue.length-1) == ".")

        {

            bRetValue = false;

        }

        sTemp = numFieldValue.split(".");

        iTemp = sTemp.length;

        if (MAX_SPLIT < iTemp)

        {

            bRetValue = false;

        }

        else

        {

            if ((sTemp.length >= MAX_SPLIT) && ((sTemp[1].length) < 1))

            {

                bRetValue = false;

            }

            if (objRe.test (numFieldValue))        // If not a number

            {

                bRetValue = false;

            }

        } // end of number of dots check if

    } // end of empty check if

    

    var iFieldWidth = numFieldValue.length;

    var iCode = 0;

    for (iCount = 0; iCount < iFieldWidth; iCount++)

    {

    iCode = numFieldValue.charCodeAt (iCount);

        if (iCode > 122)

        {

             bRetValue = false;     

        }

    }



    return bRetValue;

} // end of fncmIsNumeric



function fncmIsAlphaNumeric (sFieldValue)

{

    var iCount = 0;

    var iCode = 0;

    var bRetValue = true;

    sFieldValue = fncmTrim (sFieldValue, BOTH);



    if (EMPTY_STRING == sFieldValue)

    {

        bRetValue = false;

    }

    else

    {

        var iFieldWidth = sFieldValue.length;

        for (iCount = 0; iCount < iFieldWidth; iCount++)

        {

            iCode = sFieldValue.charCodeAt (iCount);

            if (48 > iCode || (57 < iCode && 65 > iCode) ||

                (90 < iCode && 97 > iCode) || iCode > 122 )

            {

                bRetValue = false;

                break;

            }

        }

    }

    return bRetValue;



} // end of fncmIsAlphaNumeric



function fncmIsSpaceAlphaNumeric (sFieldValue)

{

    var iCount = 0;

    var iCode = 0;

    var bRetValue = true;

    sFieldValue = fncmTrim (sFieldValue, BOTH);



    if (EMPTY_STRING == sFieldValue)

    {

        bRetValue = false;

    }

    else

    {

        var iFieldWidth = sFieldValue.length;

        for (iCount = 0; iCount < iFieldWidth; iCount++)

        {

            iCode = sFieldValue.charCodeAt (iCount);

            if (iCode == 32)

            {

                continue;

            }

            if (48 > iCode || (57 < iCode && 65 > iCode) ||

                (90 < iCode && 97 > iCode) || iCode > 122)

            {

                bRetValue = false;

                break;

            }

        }

    }

    return bRetValue;



} // end of fncmIsSpaceAlphaNumeric



function fncmIsInteger (iFieldValue)

{

    var bRetValue = true;



    var objRe = new RegExp ("[^0-9|\]");        // Regular expression



    // trim from both sides

    iFieldValue = fncmTrim (iFieldValue, BOTH);



    if (true == fncmIsEmpty (iFieldValue))

    {

        bRetValue = false;

    }

    else

    {

        if (objRe.test (iFieldValue))            // If not an integer

        {

            bRetValue = false;

        }

    }



    return bRetValue;

} // end of fncmIsInteger



/* Added by Partha to test Positive Integers */

function fncmIsPositiveInteger (iFieldValue)

{

    var bRetValue = true;

    var iCount = 0;

    var iCode = 0;      

    var objRe = new RegExp ("[^0-9|\]");        // Regular expression





    // trim from both sides

    iFieldValue = fncmTrim (iFieldValue, BOTH);



    if (true == fncmIsEmpty (iFieldValue))

    {

        bRetValue = false;

    }

    else

    {

        if (objRe.test (iFieldValue))            // If not an integer

        {

            bRetValue = false;

        }

        else if (iFieldValue == 0)        // If it is Zero

        {

            bRetValue = false;

        }

    }

    

    

    var iFieldWidth = iFieldValue.length;

    for (iCount = 0; iCount < iFieldWidth; iCount++)

    {

    iCode = iFieldValue.charCodeAt (iCount);

        if (iCode > 122)

        {

             bRetValue = false;     

        }

    }

    



    return bRetValue;



} // end of fncmIsPositiveInteger

/* End add by Partha */





function fncmCheckMinLength (sFieldValue, iMinLength)

{

    var bRetValue = true;

    var iLen = 0;

    var iLength = 0;



    sFieldValue = fncmTrim (sFieldValue, BOTH);

    iLen = sFieldValue.length;

    iLength = parseInt (iMinLength, RADIX_INT);



    if (true == fncmIsEmpty (sFieldValue))

    {

        bRetValue = false;

    }

    else

    {

        if(iLen < iLength)

        {

            bRetValue = false;

        }

        else

        {

            bRetValue = true;

        }

    }

    return bRetValue;



} // end of fncmCheckMinLength





function fncmTrim (sInput, iSide)

{



    var sTemp = "";

    var cChar = "";

    var iCount = "";

    var SINGLE_BLANK = " ";

    var iInputWidth = 0;



    if (null == sInput)

    {

        sTemp = EMPTY_STRING;

    }

    else

    {

        iInputWidth = sInput.length;



        switch (iSide)

        {

        case 0:

            //left trim

            for (iCount = 0; iCount < iInputWidth; iCount++)

            {

                cChar = sInput.charAt (iCount);

                if (SINGLE_BLANK != cChar)

                {

                    sTemp = sInput.substring (iCount, iInputWidth);

                    break;

                }

            }

            break;

        case 1:

            //right trim

            for (iCount = iInputWidth - 1; iCount >= 0 ; iCount--)

            {

                cChar = sInput.charAt (iCount);

                if (cChar != SINGLE_BLANK)

                {

                    sTemp = sInput.substring (0, iCount+1);

                    break;

                }

            }

            break;

        case 2:

            //both trim

            for (iCount = 0; iCount < iInputWidth; iCount++)

            {

                cChar = sInput.charAt (iCount);

                if (SINGLE_BLANK != cChar)

                {

                    sTemp = sInput.substring (iCount, iInputWidth);

                    break;

                }

            }

            iInputWidth = sTemp.length;

            for (iCount = iInputWidth - 1; iCount >= 0 ; iCount--)

            {

                cChar = sTemp.charAt (iCount);

                if (cChar != SINGLE_BLANK)

                {

                    sTemp = sTemp.substring (0, iCount+1);

                    break;

                }

            }

            break;

        }

    }



    return sTemp;

} // end of fncmTrim





function fncmCheckSplChar (sFieldValue, cSplChar)

{

    var NOT_FOUND_SPL = -1;

    var bRetValue = true;



    if (NOT_FOUND_SPL == sFieldValue.indexOf (cSplChar))

    {

        bRetValue = false;

    }



    return bRetValue;

} // end of fncmCheckSplChars







function fncmValidateControls(objForm)

{

    var objEle=null;

    var objResult=null;

    // for loop to validate control on form one by one

    for (var iEleCount=0;iEleCount<objForm.elements.length;iEleCount++)

    {

        objEle=objForm.elements[iEleCount];

        objEle.ATErrCode = SUCCESS;

        fncmCheckError(objEle)

        if (bErrorOccured)

        {

            return false;

        }

    }

    return true;

}





function fnCheckDateString(strDate)

{

    var arrDate = "";

    arrDate = strDate.split("-");

    if(arrDate[0].length == 1)

        strDate = "0"+strDate;

    return strDate;

}





function fncmCheckSingleByteKatakana (sValue)

{

    var SINGLE_BYE_KANA_START = 65376;

    var SINGLE_BYE_KANA_END = 65439

    var bRetValue = true;

    var iCount = 0;

    var iCode = 0;

    var iLength = 0;



    sValue = sValue + "";

    iLength = sValue.length;

    for (iCount=0; iCount<iLength; iCount++)

    {

        iCode = sValue.charCodeAt(iCount); // get ascii code of character
		alert(iCode);
        if (SINGLE_BYE_KANA_START <= iCode && SINGLE_BYE_KANA_END >= iCode)

        {
			
            bRetValue = false;

            break;

        }

    }

    return bRetValue;

} //End of fncmCheckSingleByteKatakana



function fncmCheckKatakana (sValue)

{

    var KANA_START = 12448;

    var KANA_END = 12543;

    var SPACE = 32;

    var DOUBLE_BYTE_SPACE = 12288;

    var HYPEN = 65293;

    var DIGITS_START = 65296;

    var DIGITS_END = 65305;

    var DOUBLE_BYTE_DOT = 65294;

    var DOUBLE_BYTE_STAR = 65290;

    var DOUBLE_BYTE_OPEN_BRACE = 65288;

    var DOUBLE_BYTE_CLOSE_BRACE = 65289;



    var bRetValue = true;

    var iCount = 0;

    var iCode = 0;

    var iLength = 0;



    sValue = sValue + "";

    iLength = sValue.length;

    for (iCount=0; iCount<iLength; iCount++)

    {

        iCode = sValue.charCodeAt(iCount); // get ascii code of character



        if (KANA_START > iCode || KANA_END < iCode)

        {

            if (!((iCode >= DIGITS_START && iCode <= DIGITS_END) ||

                (iCode == SPACE) || (iCode == HYPEN) || (iCode == DOUBLE_BYTE_SPACE) ||

                (iCode == DOUBLE_BYTE_DOT) || (iCode == DOUBLE_BYTE_STAR) ||

                (iCode == DOUBLE_BYTE_OPEN_BRACE) || (iCode == DOUBLE_BYTE_CLOSE_BRACE)))

            {

                bRetValue = false;

                break;

            }

        }

    }

    return bRetValue;

} //End of fncmCheckKatakana



function fncmCheckEnglishCharacter (sValue)

{

    var ENGLISH_START = 0;

    var ENGLISH_END = 127;

    var bRetValue = true;

    var iCount = 0;

    var iCode = 0;

    var iLength = 0;



    sValue = sValue + "";

    iLength = sValue.length;

    for (iCount=0; iCount<iLength; iCount++)

    {

        iCode = sValue.charCodeAt(iCount); // get ascii code of character
		//alert(iCode);
        if (iCode <  ENGLISH_START  || iCode > ENGLISH_END)
        {
            //alert("Returniong false");
			bRetValue = false;
            break;

        }

    }

    return bRetValue;

} //End of fncmCheckSingleByteKatakana


function fncmIsDoubleByte (sFieldValue)

{

    var sRetValue = false;
	var skatakanaValue = false;


    var SIZE = 4;

    var CODE_SPACE = 32;

    var CODE_LINE_FEED = 16;

    var CODE_CARRAGE_RETURN = 19;

    var iCount = 0;

    var iCode = 0;

    var sUcode = "";

    var iSize = 0;

	

    sFieldValue = fncmTrim (sFieldValue, BOTH);



    if (EMPTY_STRING == sFieldValue)

    {

        sRetValue = true;

    }

    else

    {

        iFieldWidth = sFieldValue.length;

		// this was checking for japanese characters , and if it finds Englisg
		// returning false (which means no double byte code)
		/*
        for (iCount = 0; iCount < iFieldWidth; iCount++)

        {
			
			alert('Before Char code'+sFieldValue);
            iCode = sFieldValue.charCodeAt (iCount);
			alert('in chk double byte'+iCode);
			
            if ((iCode != CODE_SPACE) && (iCode != CODE_CARRAGE_RETURN) &&(iCode != CODE_LINE_FEED))

            {
                sUcode = escape (iCode);

                iSize = sUcode.length;
				alert(iSize+sUcode);
                if(SIZE > iSize)

                {

					alert('Ret value false');
					sRetValue = false;

                }

            }
			

        }
		*/
		skatakanaValue = fncmCheckEnglishCharacter(sFieldValue);
		//alert(skatakanaValue);
		if(skatakanaValue == false){
			sRetValue = true;
		}

    }
    return sRetValue;

} // end of fncmIsDoubleByte



function IsValidTime(timeStr)

{

    var timePat = /^([1-9]|[0-1][0-9]|2[0-3]):[0-5]\d$/;



    var matchArray = timeStr.match(timePat);

    if (matchArray == null)

    {

        alert("#TBF");



        return false;

    }

    return true;



}





function fncmCheckMaxLength (sFieldValue, iMaxLength)

{

    var DB_SIZE = 4;



    var sRetValue = "";

    var iTmp = 0;

    var iCount= 0;

    var iContentLength = 0;

    var iLen = 0;



    iLen = sFieldValue.length;

    for (iCount = 0; iCount < iLen ; iCount++)

    {

        iTmp = escape(sFieldValue.charAt(iCount)).length;

        // If  iTmp greater than 4 increment length by 2

        if (DB_SIZE <= iTmp)

        {

            iContentLength = iContentLength + 2;

        }

        else    // else increment by 1

        {

            iContentLength++;

        }

    }

    if (iContentLength > iMaxLength)

    {

        sRetValue = false;

    }

    else

        sRetValue = true;

    return sRetValue;

} // end of fncmCheckMaxLength





function fncmCheckFileName (sFieldValue)

{

    var iCount = 0;

    var iCode = 0;

    var bRetValue = true;

    sFieldValue = fncmTrim (sFieldValue, BOTH);

    var iFieldWidth = sFieldValue.length;

    for (iCount = 0; iCount < iFieldWidth; iCount++)

    {

        iCode = sFieldValue.charCodeAt (iCount);

        if (34 == iCode || 35 == iCode || 37 == iCode ||

            39 == iCode || 42 == iCode || 44== iCode ||

            46 ==iCode || 47 ==iCode || 58==iCode ||

            59 ==iCode || 60 ==iCode || 62==iCode ||

            63 == iCode || 92 ==iCode || 124 ==iCode ||

            43 ==iCode || 32 ==iCode )



        {

            bRetValue = false;

            break;

        }

    }



    return bRetValue;



} // end of fncmCheckFileName



function replaceString(sFieldValue,strFrom,strWith)

{

    var iPos = 0;

    var iFieldLength = 0;

    var iFromLength = 0;

    var replacedString = sFieldValue;



    iFieldLength = sFieldValue.length;

    iFromLength  = strFrom.length;



    iPos = sFieldValue.indexOf(strFrom);



    replacedString = sFieldValue.substring(0,iPos) +

                     strWith +

                     sFieldValue.substring(iPos+iFromLength,iFieldLength);



    return replacedString;

}



function fnReplaceStringAll(sFieldValue,strFrom,strWith)

{

    var iPos = 0;

    var iFieldLength = 0;

    var iFromLength = 0;

    var replacedString = sFieldValue;



    iFieldLength = sFieldValue.length;

    iFromLength  = strFrom.length;



    iPos = sFieldValue.indexOf(strFrom);

    replacedString = sFieldValue;

    while (iPos != -1)

    {

        replacedString = replacedString.substring(0,iPos) +

                     strWith +

                     replacedString.substring(iPos+iFromLength,iFieldLength);

        iPos = replacedString.indexOf(strFrom);

    }

    return replacedString;

}





function fnCheckChange()

{

    var confirm_message = true;

    if(document.frmParent.hdnScrChanged.value == "true")

    {

        confirm_message = confirm(E003);

    }

    return confirm_message;

}





function fnInit(width)

{

}

function fnExit()

{

    if ( sList && !sList.closed )

    {

        sList.close();

    }

    if ( ggWinCal && !ggWinCal.closed )

    {

        ggWinCal.close();

    }

}





function modErrMsg(sFieldValue,strValue)

{

    var iPos = 0;

    var iFromLength = 3;

    var iFieldLength = sFieldValue.length;

    var modString = sFieldValue;

    iPos = sFieldValue.indexOf("###");

    modString = sFieldValue.substring(0,iPos) + strValue + sFieldValue.substring(iPos+iFromLength,iFieldLength);

    return modString;

}





function fnRplcSpclChrctrs(str)

{

    str = str.replace(/\"/g, "\\\"");

    str = str.replace(/\\/g, "\\\\");



    return str;

}



function fnIsValidInteger(sFieldValue)

{

    var bRetValue = false;

    var sFirstChar ;

    var sRestStr ;



    if (true == fncmIsEmpty (sFieldValue))

    {

        bRetValue = false;

    }

    else

    {

        firstChar = sFieldValue.substring(0,1);

        if (firstChar == "-" || firstChar == "+")

        {

            sRestStr = sFieldValue.substring(1,sFieldValue.length);

            bRetValue = fncmIsPositiveInteger(sRestStr);

        }

        else

        {

            bRetValue = fncmIsPositiveInteger(sFieldValue);

        }

    }

    return bRetValue;

}



function esc(val)

{

    var val1 = "";

    var val_cnt;



    if(document.all)

    {

        for(val_cnt=0;val_cnt<val.length;val_cnt++)

        {

            switch(val.charCodeAt(val_cnt))

            {

                case 36 : val1 += "%24";break;// $

                case 38 : val1 += "%26";break;

                case 43 : val1 += "%2B";break;// +

                case 44 : val1 += "%2C";break;

                case 47 : val1 += "%2F";break;

                case 58 : val1 += "%3A";break;

                case 59 : val1 += "%3B";break;

                case 61 : val1 += "%3D";break;

                case 63 : val1 += "%3F";break;

                case 64 : val1 += "%40";break;

                case 32 : val1 += "%20";break;

                case 34 : val1 += "%22";break;

                case 60 : val1 += "%3C";break;

                case 62 : val1 += "%3E";break;

                case 35 : val1 += "%23";break;

                case 37 : val1 += "%25";break;

                case 123 : val1 += "%7B";break;

                case 125 : val1 += "%7D";break;

                case 124 : val1 += "%7C";break;

                case 92 : val1 += "%5C";break;

                case 94 : val1 += "%5E";break;

                case 126 : val1 += "%7E";break;

                case 91 : val1 += "%5B";break;

                case 93 : val1 += "%5D";break;

                case 96 : val1 += "%60";break;

                default : val1 += val.charAt(val_cnt);

            }

        }

    }

    else

    {

        val1 = escape(val);

        val1 = val1.replace(/\+/g, "%2B");

    }

    return val1;

}



function fncmFormatCheck(objEle,iFirst,iSecond)

{

    var boolResult = true;

    var strValue = objEle.value;

    var arrValue = "";

    var frmt = "";

    var x = 0;

    var frmt1 = "1234567890";



    if(strValue.indexOf(".") == -1)

    {

        if(strValue.length > iFirst)

        {

            boolResult= false;

        }

    }

    else

    {

        arrValue = strValue.split(".");



        var inumFrst = arrValue[0];

        if (inumFrst == "")

        {

            inumFrst = 0;

        }

        var inumScnd = arrValue[1];



        if(inumFrst.length > iFirst)

        {

            boolResult= false;

        }



        if(inumScnd.length > iSecond)

        {

            var x = inumScnd.substring(iSecond,iSecond+1);

            var y = inumScnd.substring(0,iSecond);



            if(x >= 5)

            {

                inumScnd = eval(y) + 1;

            }

            else

            {

                inumScnd = y;

            }



            strValue1 = eval(inumFrst) + inumScnd/Math.pow(10,iSecond);

            eval(objEle).value = strValue1;

        }

    }

    if(!boolResult)

    {

        var cnt;

        if( iFirst > 9 && iFirst < 21)

        {

            frmt = frmt + frmt1;

            for(cnt=1; cnt<= iFirst-10; cnt++)

            {

                frmt = frmt + cnt;

            }

        }

        else

        {

            for(cnt=1; cnt<= iFirst; cnt++)

            {

                frmt = frmt + cnt;

            }

        }



        frmt = frmt + ".";

        for(cnt=1; cnt<= iSecond; cnt++)

        {

            frmt = frmt + cnt;

        }

        alert(modErrMsg(E042 ,frmt));

        objEle.focus();

    }

    return boolResult;

}



function fncmTrunc(strValue,iSecond)

{

    var arrValue = "";

    var x = 0;

    strValue = strValue.toString();

    if(strValue != "" && strValue.indexOf(".") != -1)

    {

        arrValue = strValue.split(".");



        var inumFrst = arrValue[0];

        var inumScnd = arrValue[1];



        if(inumFrst == "")

        {

            inumFrst = "0";

        }



        if(inumScnd.length > iSecond)

        {

            var x = inumScnd.substring(iSecond,iSecond+1);

            var y = inumScnd.substring(0,iSecond);



            if(x >= 5)

            {

                inumScnd = eval(y) + 1;

            }

            else

            {

                inumScnd = eval(y);

            }



            strValue = eval(inumFrst) + inumScnd/Math.pow(10,iSecond);

        }

    }

    return strValue;

}



function fncmMaxLenChk(objTxt)

{

    var sValue = objTxt.value;

    iMaxLength = objTxt.ATMAXLENGTH;

    bErrCode = fncmCheckMaxLength (sValue, iMaxLength);

    if (false == bErrCode)

    {

        alert(E031);

        objTxt.focus();

        return false;

    }

    else

    {

        return true;

    }

}



function fnChangeFlag(row)

{

    fnChange();

    if(eval("document.frmParent.hdnAudiStatus"+row).value

        == "I")

    {

        eval("document.frmParent.hdnAudiStatus"+row).value =

            "U";

    }

    if(eval("document.frmParent.hdnAudiStatus"+row).value

        == "N")

    {

        eval("document.frmParent.hdnAudiStatus"+row).value =

            "A";

    }

    if(eval("document.frmParent.hdnAudiStatus"+row).value

        == "DI")

    {

        eval("document.frmParent.hdnAudiStatus"+row).value =

            "DU";

    }



}



function fnChangeAudi(hdnVariableName, row)

{

    fnChange();

    if(eval("document.frmParent." + hdnVariableName +row).value

        == "I")

    {

        eval("document.frmParent." + hdnVariableName +row).value =

            "U";

    }

    if(eval("document.frmParent." + hdnVariableName +row).value

        == "N")

    {

        eval("document.frmParent." + hdnVariableName +row).value =

            "A";

    }

    if(eval("document.frmParent." + hdnVariableName +row).value

        == "DI")

    {

        eval("document.frmParent.hdnAudiStatus"+row).value =

            "DU";

    }



}



function fnDeleteFlag(row)

{

    fnChange();

    if (eval("document.frmParent.deleteCheckBox"+row).checked)

    {

        if(eval("document.frmParent.hdnAudiStatus"+row).value

            == "I")

        {

            eval("document.frmParent.hdnAudiStatus"+row).value =

                "DI";

        }

        if(eval("document.frmParent.hdnAudiStatus"+row).value

            == "U")

        {

            eval("document.frmParent.hdnAudiStatus"+row).value =

                "DU";

        }

    }

    else

    {

        if(eval("document.frmParent.hdnAudiStatus"+row).value

            == "DI")

        {

            eval("document.frmParent.hdnAudiStatus"+row).value =

                "I";

        }

        if(eval("document.frmParent.hdnAudiStatus"+row).value

            == "DU")

        {

            eval("document.frmParent.hdnAudiStatus"+row).value =

                "U";

        }

    }

}





function fnDisableControls(obj_control)

{

    if (obj_control.type == 'text')

    {

        return true;

    }

    else

    {

        return false;

    }

}



function fnIsDisable(obj_control)

{

    ret_val = true;



    if(document.all)

    {

        var key = window.event.keyCode;



        if(obj_control.type =="text")

        {

            if(key!=37 && key!=38 && key!=39 && key!=40 && key!=16 && key!=9 && key!=36 && key!=35)

            {

                event.returnValue = false;

            ret_val = false;

            }

            else

            {

            event.returnValue = true;

                ret_val = true;

            }

         }

         else

         {

             event.returnValue = true;

             ret_val = true;

         }

    }

    else

    {

        ret_val = true;

    }

    return ret_val;

}









//This function checks whether the objet has Mojibake characters or not.

//checkStr is the string containing all the Mojibake chars



function fnCheckMojibaka(strTarget)
{

	var i, transTarget;
	var flag = true;
	var err_String = " ";
	var temp_Char = " ";
	var checkStr = new String ("\u3349\u3314\u3322\u334d\u3318\u3327\u3303\u3336\u3351\u3357\u330d\u3326\u3323\u332b\u334a\u333b\u339c\u339d\u339e\u338e\u338f\u33c4\u33a1\u337b\u301d\u301f\u2116\u33cd\u2121\u32a4\u32a5\u32a6\u32a7\u32a8\u3231\u3232\u3239\u337e\u337d\u337c\u222e\u2211\u221f\u22bf");		

	transTarget = strTarget.replace(/   /g," ");

	if (flag != false)

	{

		for (i=0;i<transTarget.length;i++)

		{

			temp_char = " ";

			temp_char = transTarget.charAt(i);

			if (checkStr.indexOf(temp_char,0)  != -1)

			{

				return false;

			}

		}

	}

	return true;

}

 

function fnCheckMojibakaWithoutRoman(strTarget)

{

	var i, transTarget;

	var flag = true;

	var err_String = " ";

	var temp_Char = " ";

	var checkStr = new String ("\u3349\u3314\u3322\u334d\u3318\u3327\u3303\u3336\u3351\u3357\u330d\u3326\u3323\u332b\u334a\u333b\u339c\u339d\u339e\u338e\u338f\u33c4\u33a1\u337b\u301d\u301f\u2116\u33cd\u2121\u32a4\u32a5\u32a6\u32a7\u32a8\u3231\u3232\u3239\u337e\u337d\u337c\u222e\u2211\u221f\u22bf");

	transTarget = strTarget.replace(/   /g," ");

	if (flag != false)

	{

		for (i=0;i<transTarget.length;i++)

		{

			temp_char = " ";

			temp_char = transTarget.charAt(i);

			if (checkStr.indexOf(temp_char,0)  != -1)

			{

				return false;

			}

		}

	}

	return true;

}









//******************************************************************************

// Function Name	:	getSelectedRadio

// Created Date		:	12-Aug-2003

// Description		:	This function is used to find the selected radio button	

// Input Parameters	:	Radiobutton Group Name

// return Parameters	:	-1 - if no radiobutton is selected else returns 

//				the selected radio button index

//******************************************************************************

function getSelectedRadio(buttonGroup) {

   // returns the array number of the selected radio button or -1 if no button is selected

   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)

      for (var i=0; i<buttonGroup.length; i++) {

	 if (buttonGroup[i].checked) {

	    return i

	 }

      }

   } else {

      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero

   }

   // if we get to this point, no radio button is selected

   return -1;

} // Ends the "getSelectedRadio" function





//******************************************************************************

// Function Name	:	getSelectedRadioValue

// Created Date		:	12-Aug-2003

// Description		:	This function is used to find the selected radio button	value

// Input Parameters	:	Radiobutton Group Name

// return Parameters	:	returns the value of the selected radio button or 

//				"" if no button is selected

//******************************************************************************	

function getSelectedRadioValue(buttonGroup) {

   // returns the value of the selected radio button or "" if no button is selected

   var i = getSelectedRadio(buttonGroup);

   if (i == -1) {

      return "";

   } else {

      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)

	 return buttonGroup[i].value;

      } else { // The button group is just the one button, and it is checked

	 return buttonGroup.value;

      }

   }

} // Ends the "getSelectedRadioValue" function





//******************************************************************************

// Function Name	:	setDefaultRadio

// Created Date		:	16-Sep-2003

// Description		:	This function is used to select a default radiobutton.

// Input Parameters	:	buttonGroup - Radiobutton Group Name (Required) 

//				radioValue - value of a radio button which needs to be selected (Optional)

// return Parameters	:	None

//******************************************************************************

function setDefaultRadio(buttonGroup, radioValue)

{	   	

   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)	   	

      if(radioValue == null) {

	buttonGroup[0].checked = true;	      	

      } else {	      	

	    for (var i=0; i<buttonGroup.length; i++) {

		if (buttonGroup[i].value == radioValue) {

		   buttonGroup[i].checked = true;

		}

	    }

      }

   } else {	   

      buttonGroup.checked = true;

   }	

}





//******************************************************************************

// Function Name	:	fnIsPwdValid

// Created Date		:	12-Aug-2003

// Description		:	This function is used to find that the password contains both 

//						 character and numbers.

// Input Parameters	:	Text fields value

// return Parameters	:	booean true or false.

//******************************************************************************	

function fnIsPwdValid(sFieldValue)

{

    var iCount = 0;

    var iCode = 0;

    var bRetValue = true;

	var numFlag = false;

	var charFlag = false;

    sFieldValue = fncmTrim (sFieldValue, BOTH);



    if (EMPTY_STRING == sFieldValue)

    {

        bRetValue = false;

    }

    else

    {

        var iFieldWidth = sFieldValue.length;

        for (iCount = 0; iCount < iFieldWidth; iCount++)

        {

            iCode = sFieldValue.charCodeAt (iCount);



			if (48 > iCode || (57 < iCode && 65 > iCode) ||

                (90 < iCode && 97 > iCode) || iCode > 122 )

            {

				bRetValue = false;

                break;

            }

			else 

			{

				if (iCode > 47 && iCode < 58)

				{

					numFlag = true;

				}

				else

				{

					charFlag = true;

				}

			}

		}

		

		if (numFlag && charFlag)

		{

	       	bRetValue = true;

		}

		else

		{

			bRetValue = false;

		}

	}

    return bRetValue;



} // end of fnIsPwdValid

function fncmChkText(sFieldValue)
{
	var iCount = 0;
	var iCode = 0;
	var bRetValue = true;

	sFieldValue = fncmTrim (sFieldValue, 2);

	if ("" == sFieldValue)
	{
		bRetValue = false;
	}
	else
	{
		var iFieldWidth = sFieldValue.length;
		for (iCount = 0; iCount < iFieldWidth; iCount++)
		{
			iCode = sFieldValue.charCodeAt (iCount);
			if ( 65 > iCode || (90 < iCode && 97 > iCode) || iCode > 122 )
			{
				bRetValue = false;
				break;
			}
		}
	}
	return bRetValue;

} // end of fncmChkText


function fncmChkAlphaNumeric(sFieldValue)
{
	var iCount = 0;
	var iCode = 0;
	var bRetValue = true;

	sFieldValue = fncmTrim (sFieldValue, 2);

	if ("" == sFieldValue)
	{
		bRetValue = false;
	}
	else
	{
		var iFieldWidth = sFieldValue.length;
		for (iCount = 0; iCount < iFieldWidth; iCount++)
		{
			iCode = sFieldValue.charCodeAt (iCount);
			if ( 48 > iCode || (57 < iCode && 65 > iCode) || (90 < iCode && 97 > iCode) || iCode > 122 )
			{
				bRetValue = false;
				break;
			}
		}
	}
	return bRetValue;

} // end of fncmChkAlphaNumeric

function fncmHTTPSURL()

{
   var url = window.location;
   url = "" + url;
   var sURL;
   var startIndex = url.indexOf("/", url.indexOf("/", url.indexOf("/", url.indexOf("/")+1)+1)+1);
   sURL = url.substring(0,startIndex);
   sURL = sURL+"/";
   sURL = sURL.substring(sURL.indexOf("//")-1,sURL.length);
   sURL = "https" + sURL;
   return sURL;

}

 

function fncmHTTPURL()

{
   var url = window.location;
   url = "" + url;
   var sURL;
   var startIndex = url.indexOf("/", url.indexOf("/", url.indexOf("/", url.indexOf("/")+1)+1)+1);
   sURL = url.substring(0,startIndex);
   sURL = sURL+"/";
   sURL = sURL.substring(sURL.indexOf("//")-1,sURL.length);
   sURL = "http" + sURL;
   return sURL;

}






