// JScript File

var C_S_DEBUGMODE = "RUNTIME";
var sVal = "D";

function eID(cltId)
{
  return document.getElementById(cltId);
}

function Trim(objTxtValue)
{
    if(objTxtValue != null && objTxtValue != 'undefined')
        return objTxtValue.toString().split(" ").join("");
    else
        return '';
}

// function to open a new window and close parent window
function OpenWindow(url, windowName)
{
    var browserName=navigator.appName;
    var width = /*1024;*/screen.availWidth-10;  //For full screen screen.width-3;
    var height = /*740;*/screen.availHeight-50; //Substract taskbar & header bar height 
    C_S_DEBUGMODE = "RUNTIME";
    if (browserName=="Microsoft Internet Explorer")
    { 
        if (C_S_DEBUGMODE=="DEBUG")
        {
            window.location.href = url;
            window.resizeTo(1024,690);        
        }
        else
        {
            //Specifically done for having scrollbars on Login Page when navigated from SessionExpire Page
            var intCount=url.indexOf("Session");
            if(intCount != -1)
            {
                var winHandle = window.open(url, windowName,"maximize=no, toolbar=no, menubar=no, left=0, top=0, status=yes , width="+width+"px, height="+height+"px,scrollbars=yes");   
            }
            else
            {
                var winHandle = window.open(url, windowName,"maximize=no, toolbar=no, menubar=no, left=0, top=0, status=yes , width="+width+"px, height="+height+"px,scrollbars=no"); 
            }
            winHandle.focus();
            if(window.parent)
            {
                window.parent.open('','_self');
                window.parent.opener = "top";
                window.parent.close();
            }
            else
            {
                window.open('','_self');
                window.opener = "top";
                window.close();
            }
        } 
    } 
    else
    { 
//        window.open(url,'_parent','');         
//        window.close(); 
        var intCount=url.indexOf("Session");
        if(intCount != -1)
        {
            var winHandle = window.open(url, windowName,"maximize=no, toolbar=no, menubar=no, left=0, top=0, status=yes , width="+width+"px, height="+height+"px,scrollbars=yes");   
        }
        else
        {
            var winHandle = window.open(url, windowName,"maximize=no, toolbar=no, menubar=no, left=0, top=0, status=yes , width="+width+"px, height="+height+"px,scrollbars=no"); 
        }
        winHandle.focus();
        window.close();//To close the opener
    }
}

function GetMarketSegmentId(strExName, strInstName)
{
    try
    {
        var strMktSegId = "-1";
        strExName  = Trim(strExName);
        strInstName = Trim(strInstName);
        switch(strExName)
        {
	        case BSETXT:
		        if (Trim(strInstName) == "")
			        strInstName = EQTXT;
		        if (Trim(strInstName) == EQTXT)
			        strMktSegId = BSE_C; 
			    if (Trim(strInstName) == FUTITXT)  
			        strMktSegId = BSE_D  ;
			    if (Trim(strInstName) == FUTSTXT)
			        strMktSegId = BSE_D  ;
			    if (Trim(strInstName) == OPTITXT)   
			        strMktSegId = BSE_D  ;
			    if (Trim(strInstName) == OPTSTXT)   
			        strMktSegId = BSE_D  ;
		        break;
		    case NSETXT:
		        if (Trim(strInstName) == "")
			        strInstName = EQTXT;
		        switch(strInstName)
		        {
			        case EQTXT:
				        strMktSegId = NSE_C;
				        break;
			        case FUTITXT:
			        case FUTSTXT:
			        case OPTITXT:
			        case OPTSTXT:
				        strMktSegId = NSE_D;
				        break;
		        }
		        break;
	        case MCXTXT:
		        switch(strInstName)
		        {
			        case FUTCOTXT:
				        strMktSegId = MCX_D;
			        break;
			        case FUTSPTXT:
				        strMktSegId = MCX_S;
			        break;
		        }
		        break;
	        case NCDXTXT:
		        switch(strInstName)
		        {
			        case FUTCOTXT:
				        strMktSegId = NCDX_D;
			        break;
			        case FUTSPTXT:
				        strMktSegId = NCDX_S;
			        break;
		        }
	        break;
	        case MSXTXT:
		        if(strInstName == FUTCURTXT || strInstName == FUTINTTXT || strInstName == OPTCTXT)
		            strMktSegId = new String(MSX_D);
		        else if(strInstName == EQTXT)
		            strMktSegId = new String(MSX_C);
		        else if(strInstName == FUTITXT || strInstName == FUTSTXT || strInstName == OPTSTXT || strInstName == OPTITXT)    
		            strMktSegId = new String(MSX_FAO);
		        else
		            strMktSegId = new String(MSX_S);    
	        break;
	        case NSXTXT:
		        if(strInstName == FUTCURTXT)
		            strMktSegId = new String(NSX_D);
		        else
		            strMktSegId = new String(NSX_S);    
	        break;
	        case NSELTXT:
		        if(strInstName == SPTCOMTXT)
		            strMktSegId = new String(NSEL_D);
		        else
		            strMktSegId = new String(NSEL_S);    
	        break;
	        case DSETXT:
	            if(strInstName == EQTXT)
		            strMktSegId = new String(DSE_C);
	        break;
	        case NMCETXT:
	            if(strInstName == FUTCOTXT)
		            strMktSegId = new String(NMCE_D);
	        break;
	        
        }   
        return strMktSegId;
    }
    catch(e)
    {
        LMsg('GetMarketSegmentId ' + e.message); 
    }
}

function DecDigits(dblValueToCheck, intNoOfDecimals)
{
	try
	{
		var strValue=dblValueToCheck.toString();
		intCount=strValue.indexOf(".");
		if(intCount != -1)
		{
			intCount=strValue.length-intCount-1;
			if(intCount > parseInt(intNoOfDecimals))
				return false;
		}
		return true;
	}
	catch(e)
	{
	}
}

function DateValidate(txtExpiryDate)
{
    try
    {
		var dtval,sDay,sMonth,sYear;
		dtval = Trim(txtExpiryDate)
		sDay = parseInt((txtExpiryDate),10)
		if(sDay.toString().length==1)
			sDay="0"+sDay;
		if (isNaN(sDay))
		{
			//alert('Please enter expiry date in valid format i.e. DDMMMYYYY');
			return false;
		}
		else
		{
			if (sDay <= 0)
			{
				//alert('Please enter expiry date in valid format i.e. DDMMMYYYY');
			    return false;					
			}
			if (dtval.substr(sDay.toString().length).length != 7) // 7 including month and year like Jan2004
			{
				//alert('Please enter expiry date in valid format i.e. DDMMMYYYY');
				return false;					
			}
			else
			{
			    sMonth = dtval.substr(sDay.toString().length,3)
				sMonth = sMonth.toUpperCase()
				sYear = dtval.substr(sDay.toString().length+3)
				sYear = parseInt(sYear)
				if (isNaN(sYear))
				{	
					return false;
				}				
				if(Trim(sYear.toString()).length != 4)
				{
					return false;					
				}
				if(Trim(sYear.toString()).length != 4)
				{
					return false;						
				}					
				if ( parseInt(sYear) <= parseInt(0))
				{
					return false;						
				}
				else
				{
					if (sMonth == "JAN" || sMonth == "MAR" || sMonth == "MAY" || sMonth == "JUL" || sMonth == "AUG" || sMonth == "OCT" || sMonth == "DEC" )
					{
						if (sDay > 31)
						{
							return false;
						}					
					}
					else if(sMonth == "APR" || sMonth == "JUN" || sMonth == "SEP" || sMonth == "NOV")
					{	
						if (sDay > 30)
						{
							return false;
						}
					}
					else if (sMonth == "FEB")
					{
						if (sYear % 4 == 0 && sDay > 29)
						{
							return false;
						}
						else if(sYear % 4 != 0 && sDay > 28)
						{
							return false;
						}
					}
					else
					{
					    return false;
					}
		        }
		    }
	    }
	    return true;
    }
	catch(e)
	{  }
}

function ConfirmMessage(strText)
{
    try
    {
        return confirm(strText);
    }
    catch(e)
    {
        alert(e.message);
    }
}


function ConvertToRe(strPrice)
{
    try
    {
        var flPrice = parseFloat(strPrice);
        var result = flPrice/100;
        var strResult = result + ".00";
        return strResult;
    }
    catch(e)
    {
        alert(e.message);
    }
}

function DRC()
{
    return false;
}

function ChkSign(strValue)
{	
	try
	{
		if((strValue.indexOf("+")+1) || (strValue.indexOf("-")+1))
			return true;
		else
			return false;
	}
	catch(e)
	{
	}
}

function Nume(strValue)
{
	try
	{
		blnFlag = true;
		if(isNaN(strValue))
			return false;
		else
			return true;
	}
	catch(e)
	{
	}
}

function NumericOnly(event)
{
    try
	{
		var eveKeycode = GetKeyCode(event);
		if (eveKeycode == 13)
		{
			EnterKey(event);
			return false;
		}
		if(eveKeycode<32)
		    return true;
		if (eveKeycode > 57  || eveKeycode < 48 )
		{
		    SetKeyCode(event, 0);
		    return false;
		}
	}
	catch(e)
	{
	    //alert('NumericOnly ' + e.message); 
	}
}

function GetKeyCode(e)
{
    try
    {
        if(e.which != null) 
        { // Look for a Mozilla-compatible browser
            return e.which;
        }
        else 
        { // Must be an IE-compatible Browser
            return e.keyCode;
        }
    }
    catch(e)
	{   }
}

function NumDeciKeyPressDL(StrNoOfDeci, event)
{
    var eveKeycode=GetKeyCode(event);
    var objSource;
    if(document.all)
        objSource=event.srcElement;
    else
        objSource=event.target;
    if(eveKeycode < 32)
    {
        return true;
    }   
    if((eveKeycode < 48 || eveKeycode > 57) && eveKeycode != 46 )
		return false;
	else if(eveKeycode == 46)
	{
		if(objSource.value.indexOf(".") != -1)
			return false
	}
	else
	{
		ObjPriArr = objSource.value.split(".")
			
		if(typeof(ObjPriArr[1]) != "undefined")
		{
			if(ObjPriArr[1].length >= parseFloat(StrNoOfDeci))
				return false
		}	
	}
	return true;
}

/* Used in OrderEntry.js  */
function ConvertToRs(strPrice)
{
    try
    {
        if (strPrice == "") return "0.00";
	        var strOutput = 0;
        strOutput = (parseInt(strPrice) / 100).toFixed(2);
        return strOutput;
    }
    catch(e)
    {
        return "0.00";
    }
}
//Function to convert price in Paise
function ConvertToPaise(strPrice)
{
    try
    {
        if (strPrice == "") return "0";
	        var strOutput = 0;
        strOutput = parseFloat(parseFloat(strPrice) * 100);
        strOutput=Math.round(strOutput);
        return strOutput;
    }
    catch(e)
    {
        return "0";
    }
}
//Function to convert price in Paise multiplying with Decimal Locator for Exch MCXSX / NSX
function ConvertToPaiseDL(strPrice,sDecLcr)
{
    try
    {
        if (strPrice == "") return "0";
	        var strOutput = 0;
        strOutput = parseFloat(parseFloat(strPrice) * sDecLcr);
        strOutput=Math.round(strOutput);
        return strOutput;
    }
    catch(e)
    {
        return "0";
    }
}

// Finds the value of the tag in the raw message from OC 
function FindValue(arrInput, strCheckFor)
{
    if(arrInput !=null)
    {
        var iLength=arrInput.length;
        for(var i=0;i<iLength;i++)
        {
            if(arrInput[i].toString() !="")
            {
                var arrData=arrInput[i].split(ND);
                if(arrData.length>1 && arrData[0]==strCheckFor)
                    return arrData[1];
            }
        }
    }
    return "";
}

function parseMsg(sKey, sSrc)
{
    var sVal        = '';
    var myRegExp    = new RegExp('[^0-9]' + Trim(sKey) + '[ ]*=[ ]*([^|]*)','g');
    var aRegResult  = myRegExp.exec(sSrc);
    if(aRegResult[1] != 'undefined' && aRegResult[1] != '')
    {
        sVal=aRegResult[1];
    }
    return sVal;
}

function ConvertToRsDL(strPrice, strPrecision)
{
    try
    {
        if (Trim(strPrice) == "") return "0.00";
            var strOutput = 0;
            if(Trim(strPrecision) == "")
            {
                strPrecision = "100";
            }
            var iPrecision = parseInt(strPrecision);
            if(strPrecision == "10000")
                strOutput = (parseInt(strPrice) / iPrecision).toFixed(4);
            else
                strOutput = (parseInt(strPrice) / iPrecision).toFixed(2);
        return strOutput;
    }
    catch(e)
    {
        return "0.00";
    }
}

function FormatNumber(strNumber, noOfDecimals)
{
    var strRetval = "";
    try
    {
        var strNoToFormat = new String(strNumber);
        strNumber = parseFloat(strNoToFormat).toFixed(noOfDecimals);
        var strIntegerPart = strNumber;
        var iDecIdx = strNumber.indexOf(".");
        var strDecimalPart = strNumber.substr(iDecIdx + 1);
        if( iDecIdx > 0)
        {
            strIntegerPart = strNumber.substr(0, iDecIdx);  
            //strDecimalPart = strNumber.substr(iDecIdx + 1);
        }
        strRetval = formatCommas(strIntegerPart);
        if(noOfDecimals > 0)
            strRetval = strRetval + "." + strDecimalPart.substr(0, noOfDecimals);
    }
    catch(e)
    {
        strRetval = strNumber;
    }
    return strRetval;
}

function FormatPrice(strPrice, strMktSegmentId, strDecimalLocator)
{
    var strRetval = "";
    try
    {
        var iNoOfDecimals = 2;
        if(Trim(strMktSegmentId) == C_V_MSX_DERIVATIVES)
        {
            if(Trim(strDecimalLocator) == C_S_MSX_DECIMALLOC_VALUS)
                iNoOfDecimals = 4;
            else if(Trim(strDecimalLocator) == C_S_DECIMALLOC_VALUE)
                iNoOfDecimals = 2;
            else 
                iNoOfDecimals = 4;    
        }
        strRetval = FormatNumber(strPrice, iNoOfDecimals);
    }
    catch(e)
    {
        strRetval = strPrice;
    }
    return strRetval;
}

// This function is used to remove the commas in the Numbers
function DeFormatNumber(strValue)
{
    return strValue.toString().split(",").join("");
}

function formatCommas(numString) 
{
    try
    {
        var re = /(-?\d+)(\d{3})/;
        while (re.test(numString)) 
        {
            numString = numString.replace(re, "$1,$2");
        }
    }
    catch(e)
    {}
    return numString;
}

function thisMovie(movieName)
{
 	if (navigator.appName.indexOf("Microsoft") != -1)
	{
	    return window[movieName];
	}
	else
	{
	    return document[movieName];
	}
}

function GetExchangeName(sMktSegId)
{
    var sExName;
    if(sMktSegId == NSE_C || sMktSegId == NSE_D)
	    sExName = NSETXT;
	else if(sMktSegId == BSE_C || sMktSegId == BSE_D)
	    sExName = BSETXT;
	else if(sMktSegId == MCX_D || sMktSegId == MCX_S)
    	sExName = MCXTXT;
	else if(sMktSegId == NCDX_D || sMktSegId == NCDX_S)
	    sExName = NCDXTXT;
	else if(sMktSegId == NSEL_D || sMktSegId == NSEL_S)
	    sExName = NSELTXT;
	else if(sMktSegId == MSX_D || sMktSegId == MSX_S || sMktSegId == MSX_C || sMktSegId == MSX_FAO)
	    sExName = MSXTXT;
	else if(sMktSegId == NSX_D || sMktSegId == NSX_S)
	    sExName = NSXTXT;
	else if(sMktSegId == DSE_C)
	    sExName = DSETXT;
	else if(sMktSegId == NMCE_D)
	    sExName = NMCETXT;
	    
	return sExName;    
}


// called on onkeypress event to be removed alpha numeric validations
function Text_NumAlphaKeyPress(eve)
{	
    try
    {
        var eveKeyCode = GetKeyCode(eve);
        if(eveKeyCode < 32)
        {
            return true;
        }   
        if(!(eveKeyCode >= 48 && eveKeyCode <= 57) && !(eveKeyCode >= 97 && eveKeyCode <= 122)&& !(eveKeyCode >= 65 && eveKeyCode <= 90) && !(eveKeyCode == 38) && !(eveKeyCode == 42) && !(eveKeyCode == 45) )
        {			
            return false;
        }
        return true;
    }
    catch(e)
    {
      alert(e.message);
    }
}

// called on onkeypress event only numeric
function Text_NumKeyPress(eve)
{
    var eveKeycode = GetKeyCode(eve);
    if(eveKeycode < 32)
    {
        return true;
    }   
    if(eveKeycode < 48 || eveKeycode > 57)
        return false;
    
    return true;
}

// used to validate Price fields onkeypress event
function NumDeciKeyPress(StrNoOfDeci, eve)
{    
    var eveKeyCode = GetKeyCode(eve);
    if(eveKeyCode < 32)
    {
        return true;
    }   
    if((eveKeyCode < 48 || eveKeyCode > 57) && eveKeyCode != 46)
        return false;

    var objElement;
    if(eve.which != null) 
        objElement = eve.target;
    else 
        objElement = eve.srcElement;
    
    if(objElement.value.indexOf(".") != -1)
    {
        if(eveKeyCode == 46)
        {
            return false;
        }
        var strArr = objElement.value.split('.');
        if(strArr.length > 1)
        {
            if(strArr[1].length >= parseInt(StrNoOfDeci, 10))
            {
                return false;
            }
        }
    }

    return true;
}

function ValidatKeyPress(iValdType, eve)
{
    try
    {
        if(iValdType == C_V_ALPHANUM)
        {
            if(Text_NumAlphaKeyPress(eve))                                                
            {
                if(GetKeyCode(eve) == 13)
                {
                    //eID('btnSave').click();
                    return false;
                }
                return true;
            }
        }
        return false;
    }
    catch(e)
    {
        alert(e.message);
    }
}
// function to check the no of decimal places on keypress
function CheckDecimal(exchDropdown, eve)
{
    try
    {
    //alert("Enter ChkDecimal");
    var bDecimal;
        if(Trim(document.getElementById(exchDropdown)[document.getElementById(exchDropdown).selectedIndex].innerHTML) != Trim(MSXTXT))
           bDecimal = NumDeciKeyPressDL(2, eve);
        else
            bDecimal = NumDeciKeyPressDL(4, eve);
        return bDecimal;    
    }
    catch(e)
    {
        LMsg('ChkDecimal' + e.message);
    }
}


  /*  
    Generic function for Swapping Listitem(s) ...
    Parameters details --
    objSourceList   - Control refering to the Listbox from which the item(s) to be moved ...
    objTargetList   - Control refering to the Listbox in which the item(s) to be moved ...
    bMoveAll        - Flag denoting whether all the items to be moved or some selected item(s) to be moved ...
                      If passed as << true >> all the items will be moved irrespective of how many item(s) selected ...
                      If passed as << false >> only selected item(s) will be moved ...
    bCheckCondition - Flag denoting whether any condition to be checked while moving item(s) ... 
*/

function SwapListitems(objSourceList, objTargetList, bMoveAll, bCheckCondition, ConditionFunction, FuncParam)
{
    try 
    {
        // Declaring and initializing variables ...
        var bSwapItem, strConcatDeleteColumns, iIncrementor;
	    bSwapItem               = true;
	    strConcatDeleteColumns  = '';
	    iIncrementor            = 0;
        
        // If 'bMoveAll' parameter is passed as false i.e. only selected items to be moved ...
        if(!bMoveAll)
        {
            // Check whether any listitem is selected at all or not ...
            // If no item is selected ...
            if(objSourceList.selectedIndex == -1)
	        {
	            // Set the Swapping flag as false ...
		        bSwapItem = false;
		        // Show proper notification to User ...
		        showModalPopup('Column Template', 'Please Select Item(s) to Move', null);
	        }
	    }
	    
	    // If Swapping flag is true i.e. either all columns to be moved OR one or more columns 
	    // are selected listbox for being moved ... 
	    if(bSwapItem)
	    {
	        // Rendering the Listbox ...
	        for(var iLSTSelected = 0; iLSTSelected < objSourceList.length; iLSTSelected++)
	        {
	            // Set the 'bSwapItem' flag for the current item as true by default ...
                bSwapItem = true;
	            
	            // If all items are not to be moved i.e. only selected item(s) to be moved from the listbox ...
	            if(!bMoveAll)
	                // And if the current item in the Listbox is not selected ...
	                if(!(objSourceList[iLSTSelected].selected))
                        // Then set the 'bSwapItem' flag for this item as false ...
                        bSwapItem = false;
                
                // If bSwapItem is true i.e. either all items are to be moved from the listbox 
                // Or the current item is marked as selected then proceed ...
                if(bSwapItem)
                {
                    // If 'bCheckCondition' flag is passed as << true >> then check custom condition before moving the item ...
                    // In this particular context while moving the items from Assigned Columns to Unassigned Columns the 
                    // Default Columns should not be moved and this function checks that ... If selected item in the Assigned
                    // Columns list is found to be a default column then bSwapItem flag is set to << false >> i.e. no futher processing
                    // required for the selected item i.e. it should not be moved ... else if not default column then bSwapItem
                    // flag is set to << true >> i.e. proceed to move the item ...
                    // Since while moving item(s) from Unassigned Columns to Assigned Columns no check is required so in the function 
                    // MoveUnassignedtoAssigned() 'bCheckCondition' flag is passed as false ...
                    // At the other hand while moving item(s) from Assigned Columns to Unassigned Columns check is required for default 
                    // columns so in the function MoveAssignedtoUnassigned() 'bCheckCondition' flag is passed as true and in the function
                    // CheckDefaultColumns() it is checked whether the column is default column or not ...
                    if(bCheckCondition)
	                    //(CheckCondition(ConditionFunction, FuncParam, objSourceList[iLSTSelected].value)) ? (bSwapItem = false) : (bSwapItem = true);
	                    bSwapItem = CheckCondition(ConditionFunction, FuncParam, objSourceList[iLSTSelected].value);
	                    
                    // If bSwapItem is true i.e. either an listitem being moved from Unassigned column listbox 
                    // Or an non-default-column listitem being moved from Assigned column listbox ...
                    if(bSwapItem)
                    {
                        // Create an element ...
	                    oOption                 = document.createElement("OPTION");
	                    // Add the element in the Target Listbox ..
	                    objTargetList.options.add(oOption);
	                    // Set the required parameters i.e. id, value & innerHTML for that element to those
	                    // of the current selected element in the Source Listitem ...
		                oOption.id              = objSourceList[iLSTSelected].id;
		                oOption.value           = objSourceList[iLSTSelected].value;
		                oOption.innerHTML       = objSourceList[iLSTSelected].text;    
		                // Add the itemindex of the current listitem item in the concateneted string for storing 
		                // the list of index of items to be removed from the Source Listbox ...
		                strConcatDeleteColumns  += iLSTSelected + FD;
		            }
                }
	        }
	        
	        // If 'strConcatDeleteColumns' is not an empty string i.e. one or more items were removed ...
	        if(strConcatDeleteColumns != '')
	        {
	            // Create an Array of index of items moved ...
	            var arrConcatDeleteColumns = strConcatDeleteColumns.split(FD);
	            // Render the Array ...
	            for(var iArrContent = 0; iArrContent < arrConcatDeleteColumns.length - 1; iArrContent++)
	            {
	                // Remove the listitem from the Source Listbox ...
	                objSourceList.remove(Number(Number(arrConcatDeleteColumns[iArrContent]) - Number(iIncrementor)));
	                iIncrementor++;
	            }
	        }
	    }
    }
    catch (e)
    {
	    showModalPopup('Column Template', 'Error Occured in SwapListitems :\n\n' + e.message, null);
    }
}

// Generic Function to assign JavaScript Function dynamically ...
function CheckCondition(FunctionName, Param1, Param2)
{
    var funcRef = window[FunctionName];
    if ('function' == typeof funcRef)
    {
        return funcRef(Param1, Param2);
    }
}

/*  
    Function for checking an listitem being Default Column ...
    In parameter 'strColumnValue' the value of the column which needs be checked for Default Column is passed ...
*/
function CheckDefaultColumns(strConcatDefaultColumns, strColumnValue)
{
    try
    {
        // Declare a flag variable and initialize its value to << false >>
        var bSwapRecord = true;
        // If the item passed is among the Default items then do not swap ...
        if(String(strConcatDefaultColumns).indexOf(FD + String(strColumnValue) + FD) != -1)
	        bSwapRecord = false;
        // Return the flag variable ...
        return bSwapRecord;
    }
    catch (e)
    {
	    showModalPopup('Column Template', 'Error Occured in CheckDefaultColumns :\n\n' + e.message, null);
    }
}

//Generalized function for moving Listitems up/down one step ...
//<< 1 >> to be passed for moving down and << -1 >> to be passed to moving up the listitem ...
function MoveListitems(objTargetList, direction)
{
    try 
    {
	   	if (objTargetList.length == 0)
		    return;
		var idx = objTargetList.selectedIndex;
		
		if(idx != -1)
		{
		    var iSelected = 0;
		    for(var iListItem = 0; iListItem < objTargetList.options.length; iListItem++)
		    {
		        if(objTargetList.options[iListItem].selected)
		            iSelected++;
                if(iSelected > 1)
                {
                    showModalPopup('Column Template', 'Please select only one Item at once', null);
                    break;
                }
		    }
		    if(iSelected > 1)
		        return false;
		        
            var bReturn = false;
		    if (direction == 1)
		    {
                var intLen;
	            intLen = objTargetList.options.length - 1;
	            if(idx == intLen)
			    {
				    showModalPopup('Column Template', 'Selected item is already at the bottom position', null);
				    bReturn = true;
			    }     
		    }
			
		    else if (direction == -1)
		    {
	            if(idx == 0)
			    {	
				    showModalPopup('Column Template', 'Selected item is already at the top position', null);
				    bReturn = true;
			    }   
		    }			
			
		    if(bReturn)
			    return false;

		    var SourceId, SourceText, SourceValue, TargetId, TargetText, TargetValue;
			
		    SourceId                                = objTargetList[idx].id;
		    SourceText                              = objTargetList[idx].text;
		    SourceValue                             = objTargetList[idx].value;
		    TargetId                                = objTargetList[idx + direction].id;
		    TargetText                              = objTargetList[idx + direction].text;
		    TargetValue                             = objTargetList[idx + direction].value;
			 
		    objTargetList[idx + direction].id       = objTargetList[idx].id;
		    objTargetList[idx + direction].text     = objTargetList[idx].text;
		    objTargetList[idx + direction].value    = objTargetList[idx].value;				
		    objTargetList[idx].id                   = TargetId;
		    objTargetList[idx].text                 = TargetText;
		    objTargetList[idx].value                = TargetValue;
		    objTargetList[idx + direction].selected = true;
			
		    if(direction == 1)
		        objTargetList.selectedIndex         = idx + 1;
		    else
		        objTargetList.selectedIndex         = idx - 1; 
        }
        else
        {
            showModalPopup('Column Template', 'Please select Item to Move', null);
        }
	}
	catch (e)
    {	
	    showModalPopup('Column Template', 'Error Occured in MoveListitems :\n\n' + e.message, null);
    }
}

function GetScripDesc(sMktSegId, sToken, sSymbol, sSeries, sExpiryDate, sStrikePrice, sOptionType, sInst)
{
    try
    {
	    var sScripDesc = "";
	    
	    if(sMktSegId == C_V_NSE_CASH || sMktSegId == C_V_BSE_CASH || sMktSegId == C_V_DSE_CASH || sMktSegId == C_V_MSX_CASH)
		    sScripDesc = sSymbol + " " + sSeries;
	    else if(sMktSegId == C_V_NSE_DERIVATIVES || sMktSegId == C_V_BSE_DERIVATIVES || sMktSegId == C_V_MSX_FAO)
		    sScripDesc = sSymbol + " " + sSeries + " " + sExpiryDate + " " + sStrikePrice + " " + sOptionType;
	    else if(sMktSegId == C_V_MCX_DERIVATIVES || sMktSegId == C_V_NCDEX_DERIVATIVES || sMktSegId == C_V_NMCE_DERVIVATIVES)
		    sScripDesc = sSymbol + " " + sSeries + " " + sExpiryDate;
	    else if(sMktSegId == C_V_MCX_SPOT)
		    sScripDesc = sSymbol + " " + sSeries;
	    else if(sMktSegId == C_V_NCDEX_SPOT)
		    sScripDesc = sSymbol + " " + sSeries;
	    else if(sMktSegId == C_V_NSEL_DERIVATIVES || sMktSegId == C_V_NSEL_SPOT)	//case for NSEL
		    sScripDesc = sSymbol + " " + sSeries;
	    else if(sMktSegId == C_V_MSX_DERIVATIVES)		//case for MSX FUTCUR
	    {
	        if(sInst == OPTCTXT)
	            sScripDesc = sInst + " " + sSymbol + " " + sSeries + " " + sExpiryDate + " " + sStrikePrice + " " + sOptionType;
	        else
		        sScripDesc = sInst + " " + sSymbol + " " + sSeries + " " + sExpiryDate;
		}
	    else if(sMktSegId == C_V_MSX_SPOT)				//case for MSX CUR
		    sScripDesc = sSymbol + " " + sSeries;
	    else if(sMktSegId == C_V_NSX_DERIVATIVES)		//case for NSX FUTCUR
		    sScripDesc = sSymbol + " " + sSeries + " " + sExpiryDate;
	    else if(sMktSegId == C_V_NSX_SPOT)				//case for NSX CUR
		    sScripDesc = sSymbol + " " + sSeries;
	    
	    return sScripDesc;
    }
    catch(e)
    {
        alert('GetScripDesc: ' + e.message);
        return '';
    }
}





// sets the keycode value for an event 
// this function handles all the browser specific properties for KeyCode
function SetKeyCode(e, value)
{
    if(document.all)
    {
        e.keyCode = value;
    }
    else
    {
    }
}

function ToggleCheckBox(chkBox)
{
    var ctlId = eID(chkBox);
    
    try 
    {
        if(ctlId.type != 'radio' || !ctlId.checked)
        {
            ctlId.checked = !ctlId.checked;
        }
    }
    catch (e)
    {}
}

// opens the symbol lookup page
function OpenSymbolLookup(objPageHandle, strPageName)
{
    var sQueryString;
    strArr = new Array();
    strArr[0] = objPageHandle;
    strArr[1] = strPageName;
    
    if(strPageName == "OrderEntry")
        sQueryString = LOOKUP_URL + "?Module=OE";
    else
        sQueryString = LOOKUP_URL;
        
    if(window.showModalDialog)
        window.showModalDialog(sQueryString, strArr, C_S_LOOKUP_MOD_PROP);
    else
    {
        try {
            var objHandle = null;
            if(window.opener)
                objHandle = window.opener;
            else if(window.parent)
                objHandle = window.parent;
            var objLookup = objHandle.SearchPopup('LookUp');
            if(objLookup != null)
                objLookup.close();
            var objWin = window.open(sQueryString, 'LookUp', C_S_LOOKUP_WND_PROP);
            objWin.focus();
            objHandle.addPopUp(objWin);
        } catch(e){
            showModalPopup(strPageName, 'Unable to open lookup', null);
        }
    }
    return false;
}

//For Stock Chart
function UpdateChart(strResp)
{
    try
    {
        var sResp = new String(strResp);
        var iLTP = 0;
        var strLUT = "";
        var strVolume = "";
        var sOpen = "";
        var sHigh ="";
        var sLow = "";
	    arrF=sResp.split("|");
        if(sResp != "")
        {
            for(i=0;i<arrF.length;i++)
            {
                arrE = arrF[i].split("=");
                switch (parseInt(arrE[0]))
		        {
		            case 1:
		                  iExSegId = parseInt(arrE[1]);
		            case 7:
		                 iToken = parseInt(arrE[1]);
		            case 8:
		                iLTP = parseInt(arrE[1]);
			            break;
    		        case 74:
	    	            strLUT = arrE[1];
		                break;
		            case 9:
		                strVolume = arrE[1];
		                break;
		            case 75:
		                sOpen = arrE[1];
		            case 77:
		                sHigh = arrE[1];
		            case 78:
		                sLow =  arrE[1];
		        }
		    }
        return iExSegId + "|" + iToken + "|" + iLTP + "|" + strLUT + "|" + strVolume + "|" + sOpen + "|" + sHigh+ "|" + sLow;
		}
    }
    catch(e)
    {
        
    }
}

// shows a modal dialog which will act as the alert popup to show message to the user
function showCustimizedDialog(strMessage)
{
    $.modal(strMessage, {opacity: 50,
		overlayId: 'modalOverlay',
		overlayCss: {},
		containerId: 'modalPopup bdr stTxt pA2',
		containerCss: {},
		dataCss: {},
		zIndex: 1000,
		close: true,
		closeHTML: '<img src="images/btn_Close.gif" class="flRt" />',
		closeClass: 'simplemodal-close',
		position: null,
		persist: false,
		onOpen: null,
		onShow: null,
		onClose: null});
}

// shows a modal dialog which will act as the alert popup to show message to the user
function showCustomizedDialog(strMessage)
{
    $.modal(strMessage, {opacity: 0.7,
		overlayId: 'modalOverlay',
		overlayCss: {},
		containerId: 'modalPopup bdr stTxt pA2',
		containerCss: 'confirmModal',
		dataCss: {},
		zIndex: 1000,
		close: true,
		closeHTML: '<img src="../images/close.gif" class="flRt" />',
		closeClass: 'simplemodal-close',
		position: null,
		persist: false,
		onOpen: null,
		onShow: null,
		onClose: null});

}


/***************** Start of JQuery Modal Dialouge Box by Souvik M *****************/


function showModalPopup(sTitle, sMessage, objControl, highlight)
{
    if(sTitle == '')
        sTitle = 'Microsoft Internet Explorer';

    var strMessageBox  = "<div id='confirmModal'>";
    strMessageBox     += "<div class='header'><span>" + sTitle + "</span></div>";
    strMessageBox     += "<p class='message'>" + sMessage + "</p><div class='buttons'>";
    strMessageBox     += "<div class='no'>OK</div></div>";

    $(strMessageBox).modal
    ({
	    overlayId : 'modalOverlay',
	    onShow    :    
	    function (dialog) 
        {
	        dialog.data.find('.no').click(function () 
	        {
	            if(objControl != null)
	            {   
	                objControl.focus();
	                if(highlight)
	                    objControl.select();
	            }
		        $.modal.close();
	        });
        }
    });
}

function showAlliedModalPopupConfirm(sTitle, sMessage, objControl, highlight,mode)
{
    if(sTitle == '')
        sTitle = 'Microsoft Internet Explorer';

    var strMessageBox  = "<div id='confirmModal'>";
    strMessageBox     += "<div class='header'><span>" + sTitle + "</span></div>";
    strMessageBox     += "<p class='message'>" + sMessage + "</p><div class='buttons'>";
    strMessageBox     += "<div class='no' style='margin-left:0px;' >OK</div><div class='cancel' style='float:right;'>Cancel</div></div>";

    $(strMessageBox).modal
    ({
	    overlayId : 'modalOverlay',
	    onShow    :    
	    function (dialog) 
        {
	        dialog.data.find('.no').click(function () 
	        {
	            setExitConfirmFalg(false);//flag to be reset so that on before unload confirmation is not shown
	            if(objControl != null)
	            {   
	                LogOffWAUserFromLink(mode);
	            }
		        $.modal.close();
	        });
	        dialog.data.find('.cancel').click(function () 
	        {	            
		        $.modal.close();
	        });
        }
    });
}

//function to show popup in case of 2 frames in one page
function showModalPopupForMulFrames(sTitle, sMessage, objControl, highlight)
{
    if(sTitle == '')
        sTitle = 'Microsoft Internet Explorer';

    var strMessageBox  = "<div id='confModal'>";
    strMessageBox     += "<div class='header'><span>" + sTitle + "</span></div>";
    strMessageBox     += "<p class='message'>" + sMessage + "</p><div class='buttons'>";
    strMessageBox     += "<div class='no'>OK</div></div>";

    $(strMessageBox).modal
    ({
	    overlayId : 'modalOverlay',
	    onShow    :    
	    function (dialog) 
        {
	        dialog.data.find('.no').click(function () 
	        {
	            if(objControl != null)
	            {   
	                objControl.focus();
	                if(highlight)
	                    objControl.select();
	            }
		        $.modal.close();
	        });
        }
    });
}

function showModalPopupConfirm(sTitle, sMessage, objControl, highlight)
{
    if(sTitle == '')
        sTitle = 'Microsoft Internet Explorer';

    var strMessageBox  = "<div id='confirmModal'>";
    strMessageBox     += "<div class='header'><span>" + sTitle + "</span></div>";
    strMessageBox     += "<p class='message'>" + sMessage + "</p><div class='buttons'>";
    strMessageBox     += "<div class='no' style='margin-left:0px;' >OK</div><div class='cancel' style='float:right;'>Cancel</div></div>";

    $(strMessageBox).modal
    ({
	    overlayId : 'modalpopupbg',
	    onShow    :    
	    function (dialog) 
        {
	        dialog.data.find('.no').click(function () 
	        {
	            setExitConfirmFalg(false);//flag to be reset so that on before unload confirmation is not shown
	            if(objControl != null)
	            {   
	                LogOffUserFromLink();
	            }
		        $.modal.close();
	        });
	        dialog.data.find('.cancel').click(function () 
	        {	            
		        $.modal.close();
	        });
        }
    });
}

/***************** End of JQuery Modal Dialouge Box by Souvik M *****************/


function GetTickerScripDescription(strExchName, strInst, strSymbol, strExpDate, strStkPrc, strOptType)
{
    var strDesc=Trim(strExchName);
    if(strInst==EQTXT) {
        strDesc=strDesc + 'EQ';
    } else if(strInst==FUTITXT || strInst == FUTSTXT || strInst == OPTSTXT || strInst == OPTITXT) {
        strDesc = strDesc + 'FO '+ strInst;
    } else {
        strDesc = strDesc + ' ' + Trim(strInst);
    }
    strDesc = strDesc + ' ' + Trim(strSymbol);
    if(Trim(strExpDate)!='') {
        strDesc = strDesc + ' ' + Trim(strExpDate);
    }
    if(strInst == OPTSTXT || strInst == OPTITXT || strInst == OPTCTXT) {
        strDesc = strDesc + ' ' + Trim(strStkPrc) + ' ' + Trim(strOptType);
    }
    return strDesc;
}

// function used for printing reports
function Print(cltId)
{
    prtContent = eID(cltId);
    var wPrint = window.open('', '', 'letf=0, top=0, width=1, height=1, toolbar=0, scrollbars=0, status=0');
    wPrint.document.write(prtContent.outerHTML);
    wPrint.document.close();
    wPrint.focus();
    wPrint.print();
    wPrint.close();
    return false;
}


function isValidDate(sDateValue, sPageTitle, isFromDate, isToDate)
{
	try
	{   	
		var dateStrArr;		
		var iDay, iMonth, iYear;
		
		if (!isValidFormat(sDateValue, sPageTitle))
		{
		    if (isFromDate)
			{
			    if (Trim(sVal) == "D")
			        showModalPopup(sPageTitle, 'Please enter a valid date for From Date', sDateValue);
		        else if (Trim(sVal) == "M")
		            showModalPopup(sPageTitle, 'Please enter a valid month for From Date', sDateValue);
		        else
		            showModalPopup(sPageTitle, 'Please enter From Date in valid format i.e. dd/MM/yyyy', sDateValue);
			}
			else if(isToDate)
			{
			    if (Trim(sVal) == "D")
			        showModalPopup(sPageTitle, 'Please enter a valid date for To Date', sDateValue);
		        else if (Trim(sVal) == "M")
		            showModalPopup(sPageTitle, 'Please enter a valid month for To Date', sDateValue);
		        else
		            showModalPopup(sPageTitle, 'Please enter To Date in correct format i.e. dd/MM/yyyy', sDateValue);
			}
			
			sDateValue.value = "";
			sDateValue.focus();
			return false;
		}

		dateStrArr = sDateValue.value.split('/');
		iDay	= dateStrArr[0];
		iMonth	= dateStrArr[1];
		iYear	= dateStrArr[2];
		
		if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) && (iDay > 30))
		{
		    showModalPopup(sPageTitle, 'Please enter a valid date. The specified month cannot have more than 30 days', sDateValue);
			sDateValue.value = "";
			return false;
		} 
		else if ((iMonth == 2) && ((iYear)% (4) != 0) && (iDay > 28))	
		{
		    showModalPopup(sPageTitle, 'Please enter a valid date. February cannot have more than 28 days, except for a leap year', sDateValue);
			sDateValue.value = "";
			return false;
		}
		else if ((iMonth == 2) && (iDay > 29))
		{
		    showModalPopup(sPageTitle, 'Please enter a valid date. February cannot have more than 29 days', sDateValue);
			sDateValue.value = "";
			return false;
		}
		return true;
	} 
	catch(e)
	{
		
	}
}
	
function isValidFormat(sDateValue, sPageTitle) 
{
	try
	{
	    var dateStrArr;
		dateStrArr = sDateValue.value.split('/');
		if (dateStrArr.length < 3)
		{   
		    sVal = "N"
			return false;
		}
		for (i = 0; i < dateStrArr.length; i++)
		{
			if (isNaN(dateStrArr[i]) || Trim(dateStrArr[i]) == "")
			{
			    sVal = "N";
			    return false;
			}
			else if (dateStrArr[i].length < 2)
			{
			    sVal = "N";
			    return false;
			}
			else if (((parseInt(dateStrArr[i], 10) < 1) || (parseInt(dateStrArr[i], 10) > 31)) && (i == 0))
			{
			    if (dateStrArr[i].length == 4)
			        sVal = "N";
			    else
			        sVal = "D";
			    return false;
	        }
			else if (((parseInt(dateStrArr[i], 10) < 1) || (parseInt(dateStrArr[i], 10) > 12)) && (i == 1))
			{
			    sVal = "M";
			    return false;
	        }
			//else if (((dateStrArr[i].length != 4) || (parseInt(dateStrArr[i], 10) < 2000) || (parseInt(dateStrArr[i], 10) > 9999)) && (i == 2) )
			else if (((dateStrArr[i].length != 4) || (parseInt(dateStrArr[i], 10) > 9999)) && (i == 2) )
			{
			    sVal = "N";
				return false;
	        }
		}
		return true;
	}
	catch(e)
	{
		
	}
}
	
// datetime parsing and formatting routines. modify them if you wish other datetime format
function str2dt_D (str_datetime)
 {
    var sre_date = /^(\d+)\/(\d+)\/(\d+)$/;
    if (!sre_date.exec(str_datetime))
        return false;
    return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1));
}

function CompareDate(pDate1,pOperator,pDate2)
{
    pDate1 = str2dt_D(pDate1);
    pDate2 = str2dt_D(pDate2);
    
    if(typeof(pDate1) == "boolean" || typeof(pDate2) == "boolean")
        return false;
	
    switch(pOperator)
    {
        case ">":
	        return pDate1 > pDate2;
	        break;
        case "<":
	        return pDate1 < pDate2;
	        break;
        case "=":
        	return pDate1 == pDate2;
	        break;
        case "<=":
	        return pDate1 <= pDate2;
	        break;        
    }
}

function days_between(t1, t2)
{
    try
    {
        // The number of milliseconds in one day
        var ONE_DAY = 1000 * 60 * 60 * 24;
        var x=t1.split("/");
        var y=t2.split("/");
        //date format(Fullyear,month,date) 
        var date1=new Date(x[2],(x[1]-1),x[0]);
        var date2=new Date(y[2],(y[1]-1),y[0])
        
        //Calculate difference between the two dates, and convert to days
        return(Math.ceil((date1.getTime()-date2.getTime() + 1 )/(ONE_DAY))); 
    }
    catch(e)
    {
    }
}

function HandleAjaxError(XMLHttpRequest, textStatus, errorThrown)
{   
    showModalPopup('AjaxError', 'Error Occured while fetching data. Either you may be offline or server may be down. If the problem persists please contact admin.');// through Ajax:\n\n' + textStatus + ' ' + errorThrown + ' ' + XMLHttpRequest, null);
    return false;
}

function GetNormalMktSegmentID(strMktSegID)
{
    
    var sNormalSegID="";
    if(strMktSegID == C_V_MAPPED_NSE_CASH)
        sNormalSegID = NSE_C;
    else if(strMktSegID == C_V_MAPPED_NSE_DERIVATIVES)
        sNormalSegID = NSE_D;
    else if(strMktSegID == C_V_MAPPED_BSE_CASH)
        sNormalSegID = BSE_C;
    else if(strMktSegID == C_V_MAPPED_BSE_DERIVATIVES)
        sNormalSegID = BSE_D;
    else if(strMktSegID == C_V_MAPPED_MCX_DERIVATIVES)
        sNormalSegID = MCX_D;    
    else if(strMktSegID == C_V_MAPPED_MCX_SPOT)
        sNormalSegID = MCX_S;    
    else if(strMktSegID == C_V_MAPPED_NCDEX_DERIVATIVES)
        sNormalSegID = NCDX_D;    
    else if(strMktSegID == C_V_MAPPED_NCDEX_SPOT)
        sNormalSegID = NCDX_S;    
    else if(strMktSegID == C_V_MAPPED_NSEL_DERIVATIVES)
        sNormalSegID = NSEL_D;    
    else if(strMktSegID == C_V_MAPPED_NSEL_SPOT)
        sNormalSegID = NSEL_S;    
    else if(strMktSegID == C_V_MAPPED_MSX_DERIVATIVES)
        sNormalSegID = MSX_D;    
    else if(strMktSegID == C_V_MAPPED_MSX_SPOT)
        sNormalSegID = MSX_S;    
    else if(strMktSegID == C_V_MAPPED_NSX_DERIVATIVES)
        sNormalSegID = NSX_D;    
    else if(strMktSegID == C_V_MAPPED_NSX_SPOT)
        sNormalSegID = NSX_S;            
        
    else if(strMktSegID == C_V_MAPPED_MSX_CASH)
        sNormalSegID = MSX_C;       
    else if(strMktSegID == C_V_MAPPED_MSX_FAO)
        sNormalSegID = MSX_FAO;       
    else if(strMktSegID == C_V_MAPPED_DSE_CASH)
        sNormalSegID = DSE_C;       
    else if(strMktSegID == C_V_MAPPED_NMCE_DERIVATIVES)
        sNormalSegID = NMCE_D;           
    return sNormalSegID;
                
}
 
function OpenDisclaimer()
{
    callPopUp(CONST_FILES_PATH + DISCLAIMER_FILE_NAME, 'Disclaimer', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}

function OpenAboutUs()
{
    callPopUp(CONST_FILES_PATH + ABOUT_US_FILE_NAME, 'AboutUs', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}

function OpenTNC()
{
    callPopUp(CONST_FILES_PATH + TNC_FILE_NAME, 'TermsAndConditions', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}
function OpenMemberDetails()
{
    callPopUp(BROKERINFO_URL, 'MembershipDetails', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=500, height=320, left=190, resizable=yes, top=360', 'undefined');
}  
function OpenHelp()
{
    callPopUp(HELP_FILE_NAME, 'Help', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}

//NetNet Allied Products
function OpenDisclaimerAllied()
{
    callPopUp(CONST_FILES_PATH_AllIED + DISCLAIMER_FILE_NAME, 'Disclaimer', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}
function OpenAboutUsAllied()
{
    callPopUp(CONST_FILES_PATH_AllIED + ABOUT_US_FILE_NAME, 'AboutUs', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}
function OpenTNCAllied()
{
    callPopUp(CONST_FILES_PATH_AllIED + TNC_FILE_NAME, 'TermsAndConditions', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}    
function OpenMemberDetailsAllied()
{
    callPopUp(BROKERINFO_URL_AllIED, 'MembershipDetails', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=500, height=320, left=190, resizable=yes, top=360', 'undefined');
}  
function OpenHelpAllied()
{
    callPopUp(HELP_FILE_NAME_AllIED, 'Help', 'toolbar=no, menubar=no, location=no, scrollbars=yes, directories=no, width=800, height=535, left=190, resizable=yes, top=160', 'undefined');
}
//to validate Quote symbol
function ValdQuoteText (strQuote)
 {
   var myRegxp = /^[-.&0-9a-zA-Z ]+$/;
   if (myRegxp.test(strQuote))
        return true;
        else 
        return false;
}

//to url encode query string values
function UrlEncoding(inputString)
{ 
  var encodedInputString=escape(inputString);
  //Following two parameters are not encoded by the in built escape function
  encodedInputString=encodedInputString.replace("+", "%2B"); 
  encodedInputString=encodedInputString.replace("/", "%2F");  
  return  encodedInputString;
}

function OpenChartInfo(strAdvChart)
{
    if(strAdvChart=="Y")
        OpenAdvChartInfo();
    else
        OpenBasicChartInfo();
}

 function OpenAdvChartInfo()
{
    try
    {   
       window.open(ADV_CHART_URL, '', 'maximize=no, toolbar=no, menubar=no, left=0, top=0, status=yes , width=800px, height=600px, scrollbars=yes');
    }
    catch(e)
    {}
} 
function OpenBasicChartInfo()
{
    try
    {   
        window.open(BASIC_CHART_URL, '', "maximize=no, toolbar=no, menubar=no, left=0, top=0, status=yes , width=500px, height=300px, scrollbars=yes");
    }
    catch(e)
    {}
} 

function objectID(ctrl)
{
    return document.getElementById(ctrl);
}

function funcShowCalendar(objCalender, ctrlTarget)
{
    objTarget = objectID(ctrlTarget);
    if(objTarget.getAttribute("XaxisVal") != "")
        fixedX = objTarget.getAttribute("XaxisVal");
    if(objTarget.getAttribute("YaxisVal") != "")
        fixedY = objTarget.getAttribute("YaxisVal");
    popUpCalendar(objCalender, objTarget, objTarget.getAttribute("DateFormat"));
    return false;
}


function ValidAmount(dValueToCheck,iNoOfDigit)
{
	try
	{
		var sValue = dValueToCheck.toString();
		intCount=sValue.indexOf(".");
		
		if (intCount != -1)
	    {	
		    var sBeforeDec;
		    sBeforeDec =sValue.substring(0,sValue.indexOf('.'));
		    if (sBeforeDec.length > iNoOfDigit)
		    {
		        return false;
		    }
       } 
       else
	   {
		  if (sValue.length > iNoOfDigit)
	        {
		       return false;
	        }
		}
    	return true;
	}
	catch(e)
	{ }
}

//Check if User is Admin User
function IsAdminUser(strIsAdminUser)
{
	var  bAdminUser = true;
    if(strIsAdminUser.toUpperCase() == "FALSE")
        bAdminUser =false;
    return bAdminUser;   
}

//Check if User is Login through ODIN
function IsLoginThroughOdin(strLoginThroughOdin)
{
	var  bLoginThroughOdin = true;
    if(strLoginThroughOdin.toUpperCase() == "FALSE")
        bLoginThroughOdin =false;
    return bLoginThroughOdin;   
}

function openNewWindow(strValue)
{
    try
    {
        window.open(strValue, '', "maximize=no, toolbar=no, menubar=no, left=0, top=0, status=yes , width=1000px, height=600px, scrollbars=yes");    
        return false;
    }
    catch(e)
    { 
    }    
}

function isNumericData(num)
{
    if ((num >=0 || num < 0) && (num.length > 0))
        return true;
    else    
        return false;
} 
function Text_NumKeyPressIPO(eve)
{
    var eveKeycode = GetKeyCode(eve);
    if(eveKeycode < 32)
    {
        return true;
    }   
    if(eveKeycode < 48 || eveKeycode > 57)
        return false;
    
    return true;
}

function Text_NumAlphaKeyPressIPO(eve)
{	
    try
    {
        var eveKeyCode = GetKeyCode(eve);
        if(eveKeyCode < 32)
        {
            return true;
        }   
        if(!(eveKeyCode >= 48 && eveKeyCode <= 57) && !(eveKeyCode >= 97 && eveKeyCode <= 122)&& !(eveKeyCode >= 65 && eveKeyCode <= 90) && !(eveKeyCode == 38) && !(eveKeyCode == 42) && !(eveKeyCode == 45) )
        {			
            return false;
        }
        return true;
    }
    catch(e)
    {
      alert(e.message);
    }
}

function GetMappedMktSegmentID(strMktSegID)
{
    
    var sMappedSegID="";
    if(strMktSegID == NSE_C)
        sMappedSegID = C_V_MAPPED_NSE_CASH;
    else if(strMktSegID == NSE_D)
        sMappedSegID = C_V_MAPPED_NSE_DERIVATIVES;
    else if(strMktSegID == BSE_C)
        sMappedSegID = C_V_MAPPED_BSE_CASH;
    else if(strMktSegID == BSE_D)
        sMappedSegID = C_V_MAPPED_BSE_DERIVATIVES;
    else if(strMktSegID == MCX_D)
        sMappedSegID = C_V_MAPPED_MCX_DERIVATIVES;    
    else if(strMktSegID == MCX_S)
        sMappedSegID = C_V_MAPPED_MCX_SPOT;    
    else if(strMktSegID == NCDX_D)
        sMappedSegID = C_V_MAPPED_NCDEX_DERIVATIVES;    
    else if(strMktSegID == NCDX_S)
        sMappedSegID = C_V_MAPPED_NCDEX_SPOT;    
    else if(strMktSegID == NSEL_D)
        sMappedSegID = C_V_MAPPED_NSEL_DERIVATIVES;    
    else if(strMktSegID == NSEL_S)
        sMappedSegID = C_V_MAPPED_NSEL_SPOT;    
    else if(strMktSegID == MSX_D)
        sMappedSegID = C_V_MAPPED_MSX_DERIVATIVES;    
    else if(strMktSegID == MSX_S)
        sMappedSegID = C_V_MAPPED_MSX_SPOT;    
    else if(strMktSegID == NSX_D)
        sMappedSegID = C_V_MAPPED_NSX_DERIVATIVES;    
    else if(strMktSegID == NSX_S)
        sMappedSegID = C_V_MAPPED_NSX_SPOT;            
        
    else if(strMktSegID == MSX_C)
        sMappedSegID = C_V_MAPPED_MSX_CASH;       
    else if(strMktSegID == MSX_FAO)
        sMappedSegID = C_V_MAPPED_MSX_FAO;       
    else if(strMktSegID == DSE_C)
        sMappedSegID = C_V_MAPPED_DSE_CASH;       
    else if(strMktSegID == NMCE_D)
        sMappedSegID = C_V_MAPPED_NMCE_DERIVATIVES;           
    return sMappedSegID;
                
}

function GetAlertParamString(intParameter)
{
    var strParamVal = "0";

    try
    {
        if (intParameter == C_V_SETALERTS_LTP)
            strParamVal = C_S_SETALERTS_LTP;
        else if (intParameter == C_V_SETALERTS_BID)
            strParamVal = C_S_SETALERTS_BID;
        else if (intParameter == C_V_SETALERTS_OFFER)
            strParamVal = C_S_SETALERTS_OFFER;
        else if (intParameter == C_V_SETALERTS_LTQ)
            strParamVal = C_S_SETALERTS_LTQ;
        else if (intParameter == C_V_SETALERTS_BIDQTY)
            strParamVal = C_S_SETALERTS_BIDQTY;
        else if (intParameter == C_V_SETALERTS_OFFERQTY)
            strParamVal = C_S_SETALERTS_OFFERQTY;
        else if (intParameter == C_V_SETALERTS_VOLUME)
            strParamVal = C_S_SETALERTS_VOLUME;
        else if (intParameter == C_V_SETALERTS_VALUE)
            strParamVal = C_S_SETALERTS_VALUE;
        else if (intParameter == C_V_SETALERTS_PERCENTCHANGE)
            strParamVal = C_S_SETALERTS_PERCENTCHANGE;
        else if (intParameter == C_V_SETALERTS_ATP)
            strParamVal = C_S_SETALERTS_ATP;
        else if (intParameter == C_V_SETALERTS_OIPERCCHANGE)
            strParamVal = C_S_SETALERTS_OICHANGE;
        else if (intParameter == C_V_SETALERTS_PREVCLOSE)
            strParamVal = C_S_SETALERTS_PREVCLOSE;
        else if (intParameter == C_V_SETALERTS_PREVHIGH)
            strParamVal = C_S_SETALERTS_PREVHIGH;
        else if (intParameter == C_V_SETALERTS_PREVLOW)
            strParamVal = C_S_SETALERTS_PREVLOW;
        else if (intParameter == C_V_SETALERTS_PREVOPEN)
            strParamVal = C_S_SETALERTS_PREVOPEN;
        else if (intParameter == C_V_SETALERTS_OPENPRICE)
            strParamVal = C_S_SETALERTS_OPENPRICE;
        else if (intParameter == C_V_SETALERTS_HIGH)
            strParamVal = C_S_SETALERTS_HIGH;
        else if (intParameter == C_V_SETALERTS_LOW)
            strParamVal = C_S_SETALERTS_LOW;
        else if (intParameter == C_V_SETALERTS_52WEEKHIGH)
            strParamVal = C_S_SETALERTS_52WEEKHIGH;
        else if (intParameter == C_V_SETALERTS_52WEEKLOW)
            strParamVal = C_S_SETALERTS_52WEEKLOW;
        else if (intParameter == C_V_SETALERTS_USEVALUE)
            strParamVal = C_S_SETALERTS_USEVALUE;
        else if (intParameter == C_V_SETALERTS_PREVVOLUME)
            strParamVal = C_S_SETALERTS_PREVVOLUME;
        else if (intParameter == C_V_SETALERTS_PREVVALUE)
            strParamVal = C_S_SETALERTS_PREVVALUE;
        else if (intParameter == C_V_SETALERTS_PREVOI)
            strParamVal = C_S_SETALERTS_PREVOI;
        else if (intParameter == C_V_SETALERTS_OPENINTEREST)
            strParamVal = C_S_SETALERTS_OPENINTEREST;

    }
    catch (e)
    {
        alert(e.message);;
    }

    return strParamVal;
}

function GetOperatorString(intOperatorVal)
{
    var strOperator = '';

    try
    {
        if (intOperatorVal == C_V_GREATER_THAN_EQUAL_TO_STR_ID)
            strOperator = C_S_GREATER_THAN_EQUAL_TO_STR;
        else if (intOperatorVal == C_V_LESS_THAN_EQUAL_TO_STR_ID)
            strOperator = C_S_LESS_THAN_EQUAL_TO_STR;
        else if (intOperatorVal == C_V_GREATER_THAN_STR_ID)
            strOperator = C_S_GREATER_THAN_STR;
        else if (intOperatorVal == C_V_LESS_THAN_STR_ID)
            strOperator = C_S_LESS_THAN_STR;
        else if (intOperatorVal == C_V_EQUAL_TO_STR_ID)
            strOperator = C_S_EQUAL_TO_STR;
    }
    catch (e)
    {
        alert(e.message);
    }
    return strOperator;
}
