﻿// JScript File
function __prth_doPostBack(ctlid, Act) {
    if (Act.indexOf("DeleteFile$", 0) == 0) {
        if (confirm("Are you sure to Delete this file?")) if (confirm("The file will be deleted permanatly and will not be recoverable so are you sure?")) __doPostBack(ctlid, Act);
    }
    else {
        __doPostBack(ctlid, Act);
    }
}

function SetValueToControl(ControlID, ControlValue) {
    //alert(ControlValue);
    document.getElementById(ControlID).value = ControlValue;
}

function replaceAll(str, oldval, newval) {
    while (str.indexOf(oldval) != -1) {
        str = str.replace(oldval, newval)
    }
    return str;
}
function open_dialogbox_Top(path, width, height, resize, scroll, status, samewindow) {
    var w = 480, h = 340;

    if (!width)
        width = "700";
    if (!height)
        height = "500";
    if (!resize)
        resize = "no";
    if (!scroll)
        scroll = "no";
    if (!samewindow)
        samewindow = "objwnd";
    if (!status)
        status = "no";


    if (document.all || document.layers) {
        w = screen.availWidth;
        h = screen.availHeight;
    }
    var topPos = (h - height) / 2, leftPos = (w - width) / 2;
    objwnd = window.open(path, samewindow, "munubar=no,titlebar=no,status=" + status + ",resizable=" + resize + ",scrollbars=" + scroll + ",width=" + (width) + ",height=" + (height) + ",left=0,top=0,screenX=" + leftPos + ",screenY=" + topPos);
    objwnd.focus();
}
function open_dialogbox(path, width, height, resize, scroll, status, samewindow) {
    var w = 480, h = 340;

    if (!width)
        width = "700";
    if (!height)
        height = "500";
    if (!resize)
        resize = "no";
    if (!scroll)
        scroll = "no";
    if (!samewindow)
        samewindow = "objwnd";
    if (!status)
        status = "no";


    if (document.all || document.layers) {
        w = screen.availWidth;
        h = screen.availHeight;
    }
    var topPos = (h - height) / 2, leftPos = (w - width) / 2;
    objwnd = window.open(path, samewindow, "munubar=no,titlebar=no,status=" + status + ",resizable=" + resize + ",scrollbars=" + scroll + ",width=" + (width) + ",height=" + (height) + ",left=" + leftPos + ",top=" + topPos + ",screenX=" + leftPos + ",screenY=" + topPos);
    objwnd.focus();
}



function DisplayCustomTag(param, objname) {
    if (param != "") {
        paramarr = param.split(",");
        var paramstr = "";
        for (i = 0; i < paramarr.length; i++) {
            paramstr += ",[\"" + paramarr[i] + "\",\"[[" + paramarr[i].toUpperCase() + "\]]\"]";
            //[paramarr[i],"["+paramarr[i].toUpperCase()+"]"]
        }
        objname.arrCustomTag = eval("[" + paramstr.substr(1) + "]");
    }
}

function showModalPopupViaClient(BehaviorID) {
    var modalPopupBehavior = $find(BehaviorID);
    modalPopupBehavior.show();
}

function hideModalPopupViaClient(BehaviorID) {
    var modalPopupBehavior = $find(BehaviorID);
    modalPopupBehavior.hide();
    return false;
}

function ResetPaging(PagingCtl) {
    __doPostBack(PagingCtl);
}
function NotBlank(obj, cap) {
    if (obj) {
        if (obj.value == "") {
            alert(cap + " is mandatory");
            obj.focus();
            return false;
        }
    }
    
    return true;
}
function Check_CheckboxSelection(objfld, cap) {
    if (objfld) {
        var bool = false;
        if (objfld) {
            if (objfld.length) {
                for (i = 0; i < objfld.length; i++) {
                   
                    if (objfld[i].checked) {
                        bool = true;
                        break;
                    }
                }
            }
            else {
                if (objfld.checked) {
                    bool = true;
                }
            }

        }
        if (!bool) {
            alert('Please select atleast one ' + cap);
        } 
    }
    return bool
}
function IsNumeric(obj, cap) {
    if (obj) {
        var tempstr;
        tempstr = obj.value;
        if (obj.value != "") {
            var nreg = /[^0-9]/g;
            nresult = tempstr.match(nreg);
            if (nresult != null) {
                alert("Please Enter Valid " + cap);
                obj.focus();
                return false;
            }
        }
    }
    return true;
}

function IsDecimal(obj, cap) {
    if (obj) {
        if (obj.value != "") {
            if (isNaN(obj.value) || obj.value == "") {
                alert("Please Enter Valid " + cap);
                obj.focus();
                return false;
            }
        } 
    }
    return true;
}
function check_emailval(obj, cap) {
    if (obj) { 
        var em = obj.value;
        if (obj.value == "") {
            alert(cap + " is mandatory");
            obj.focus();
            return false;
        }
        atspos = em.indexOf('@') + 1;
        dtspos = em.lastIndexOf('.');
        len = em.length - 3;
        if (atspos < 2 || dtspos < 3 || dtspos <= atspos || len < dtspos) {
            alert("Enter Valid " + cap);
            obj.focus();
            return false;
        }
    }
    return true;
}
function check_checkboxval(obj, cap) {
    if (obj) {
        if (!obj.checked) {
            alert("Please check " + cap + " checkbox");
            obj.focus();
            return false;
        } 
    }
    return true;
}

function CloseFilterPopup(iframename) {
    var iframe = document.getElementById(iframename);
    iframe.src = "about:blank";
}


function ShowByID(id) {
    document.getElementById(id + "_div").style.display = "block";
    document.getElementById(id + "_img").src = "/images/expanded.gif";
}

function HideByID(id) {
    document.getElementById(id + "_div").style.display = "none";
    document.getElementById(id + "_img").src = "/images/collapsed.gif";
}

function HideShowByID(id) {
    if (document.getElementById(id + "_div").style.display == "" || document.getElementById(id + "_div").style.display == "none") ShowByID(id);
    else HideByID(id);
}


function Nl2BR(Content) {
    Content = Content.replace(/\n/ig, "<br>");
}
function DeleteConfirmation() {
    if (confirm("Are you sure to delete this record?"))
        return true;
    else
        return false;
}

function FireOnSubmit(event) {
    if (event.which) // mozilla
        var keycode = event.which;
    else // ie
        var keycode = event.keyCode;
    //alert(keycode);
    if (keycode == 13) {
        return true;
    }
    return false;
}

function SearchClick(event,frm)
{
    if (FireOnSubmit(event))
    {                     
        frm.submit();
        return false;
    }
}

function SearchClickCallFunction(event, fnc) {
    if (FireOnSubmit(event)) {
        eval(fnc());
        return false;
    }
}

var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}

function SelectAllAction(obj) {
    if (theForm.elements["selected_ids"].length) {
        for (i = 0; i < theForm.elements["selected_ids"].length; i++) {
            theForm.elements["selected_ids"][i].checked = obj.checked;
        }
    }
    else {
        theForm.elements["selected_ids"].checked = obj.checked;
    }
}

function RemoveMainCheckbox() {
    document.getElementsByName("selectAll")(0).checked = false;
}
