﻿// JScript File
function DeleteConfirmation(GridId, GridRowCount)
{
    var flgChk = 0;
    var id;
    
    for(var i=0; i < GridRowCount; i++)
    {                  
        objId = GridId + '_ctl' + CheckLength(i+2) + '_chkSelect';             
        objChk = document.getElementById(objId);
               
        if (objChk.checked == true)
        {
            flgChk = 1;                    
        }
    }
    
    if (flgChk == 1)
    {
        if (confirm('Are u sure you want to delete this record?'))
        {
            return true;
        }
    }    
    else
    {
        alert('Please select a record !');      
    }            
    return false;
}

function CustomDeleteConfirmation(param)
{
    if (confirm('Are u sure you want to delete this ' + param + ' ?'))
    {
        return true;
    }
    
    return false;    
}   

function CloseNSubmit()
{    
    try
    {
        window.close();         
        //alert(window.opener.document.getElementById('ctl00_ContentPlaceHolder1_btn_Search'))
        window.opener.document.getElementById('ctl00_ContentPlaceHolder1_btn_Search').click();
    }
    catch(e){}    
}

function CloseNSubmitChild()
{   
    try
    {         
        window.close();
        window.opener.location.reload();
    }
    catch(e){}    
}

function CloseWindow()
{
    window.close();
    return false;
}

function OpenDialog(url,features)
{
    //window.showModalDialog(url,'',features);
    window.open(url,'',features);
    return false;
}    

function SelectRow()
{
	var obj = window.event.srcElement;
	if(obj.tagName=="INPUT")    //this is a checkbox
	{
	    checkRowOfObject(obj);
	}
	else if (obj.tagName=="TD") //this a table cell
	{
	    //get a pointer to the tablerow
	    var row = obj.parentNode;
	    var chk = row.cells[0].firstChild;
	    chk.checked = !chk.checked;
	    if (chk.checked)
	    {
	        row.className="SelectedRow";
	    }
	    else
	    {
	       row.className="";
	    }
	}
}

function checkRowOfObject(obj)
{
    if (obj.checked)
    {
        obj.parentNode.parentNode.className="SelectedRow";
    }
    else
    {
       obj.parentNode.parentNode.className="";
    }
}

function CheckLength(str)
{    
    if (parseInt(str) < 10)
    {        
        str = '0' + str;        
    }
    return str;
}

function OpenCalendar1(ctrlId)
{
    calendar_window = window.open('../../Includes/Calendar/Calendar1.aspx?formname=ctl00_ContentPlaceHolder1_' + ctrlId,'calendar_window','width=154px; height=188px;');
    calendar_window.focus();
}

function OpenCalendar(ctrlId)
{
    if(oDP)oDP.open(document.getElementById('ctl00_ContentPlaceHolder1_' + ctrlId)); return false;    
}

var oDP = null;
function init()
{
   oDate = new Date();   
   oDP   = new frameDatePicker.DatePicker("divDatePicker", oDate.getFullYear()-5, oDate.getFullYear()+5);

   // If you want Sunday as first day of the week use this construction call instead:
   // oDP = new frameDatePicker.DatePicker("divDatePicker", oDate.getFullYear()-2, oDate.getFullYear()+5, true);

   // Use another init year/month than todays. 0=Jan, 11=Dec
   //oDP.setInitDate(2003, 0);
}

function OpenChildFrame(strChildURL, Rec_ID)
{       
    document.getElementById('iFrameChild').src = strChildURL + Rec_ID;
}

function js_GetTopPosition(i__ControlID) 
{
    try
    {
        var oNode = document.getElementById(i__ControlID);
        var iTop = 0;

        while(oNode.tagName != "BODY") {
            iTop += oNode.offsetTop;
            oNode = oNode.offsetParent; 
        }
        return iTop;
    }
    catch(e)
    {
        alert("js_GetTopPosition:" + e.message);
    }
}
    
function SetTabPos(menuId)
{
    try
    {
        var js_TopPos = js_GetTopPosition(menuId)
        var js_MenuHeight = document.getElementById(menuId).style.pixelHeight;
        alert(document.getElementById(menuId).id)
        alert(js_TopPos+ '---'+js_MenuHeight)
        
        var js_objStyleEn = document.getElementById('Tbl_En');
        var js_objStyleFr = document.getElementById('Tbl_Fr');
        var js_objStyleAr = document.getElementById('Tbl_Ar');
        
        if (js_objStyleEn) js_objStyleEn.style.pixelTop = js_TopPos+js_MenuHeight-1;
        if (js_objStyleFr) js_objStyleFr.style.pixelTop = js_TopPos+js_MenuHeight-1;
        if (js_objStyleAr) js_objStyleAr.style.pixelTop = js_TopPos+js_MenuHeight-1;      
    }
    catch(e)
    {}
}

function CallCrossPostBack(objId)
{   
    document.getElementById(objId).click();    
}

function FillHiddenField(objId,objVal)
{   
    document.getElementById(objId).value = objVal;    
}

function ErrorAlertNotification(i__Message)
{
    alert(i__Message);
}

function SetParentMenuItemClass(objID)
{
    var objItem = document.getElementById(objID);
        
    objItem.parentElement.parentElement.parentElement.className = 'StaticMenuItemHover';
}

function RedirectToPaymentDuties()
{
    self.location.href = 'PaymentDuties.aspx';
}

function RedirectToHomePage()
{
    self.location.href = 'Index.aspx';
}