function fnValidateFile(strfilext) {
    var validExtensions = new Array("jpg", "png", "jpeg", "gif", "pjpeg", "tif", "bmp");

    for (var i = 0; i < validExtensions.length; i++) {
        //check to see if it's the proper extension
        if (validExtensions[i] == strfilext) {
            return true;
        }
    }

}

function fngetFileExt(strfiltype) {
    var dot_pos = strfiltype.lastIndexOf(".");
    if (dot_pos == -1)
        return "";
    return strfiltype.substr(dot_pos + 1).toLowerCase();
}





function isNumeric(elem, helperMsg) {
    var numericExpression = /^[-]?\d*\.?\d*$/;
    if (elem.value.toString().match(numericExpression)) {
        return true;
    } else {
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function isNumericWhole(elem, helperMsg) {
    var numericExpression = /^\d+$/;
    if (elem.value.toString().match(numericExpression)) {
        return true;
    } else {
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function isNumericWithDecimals(elem, helperMsg) {
    var numericExpression = /(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)/;
    if (elem.value.toString().match(numericExpression)) {
        return true;
    } else {
        alert(helperMsg);
        elem.focus();
        return false;
    }
}
function isNumericWithDecimalsNegetive(elem, helperMsg) {
    var numericExpression = /^([+-]?(((\d+(\.)?)|(\d*\.\d+))([eE][+-]?\d+)?))$/;
    /*
    /^([+/-]?((([0-9]+(\.)?)|([0-9]*\.[0-9]+))([+\-]?[0-9]+)?))$/;
    */
    if (elem.value.toString().match(numericExpression)) {
        return true;
    } else {
        alert(helperMsg);
        elem.focus();
        return false;
    }
} 

function fnCheckLength(objValidate, val) {
    var strDescription = TrimString(objValidate.value);
    if (strDescription.length > val) {
        alert("- Maximum Length is " + val + " characters, Data will be truncated to " + val + " characters.");
        objValidate.value = strDescription.substring(0,val);
        return false;
    }
}

function fnValidateText(txtBoxId, Name) {
    var iChars = "`!@#$%^&*()+=-[]\\\';{}|\":<>?";
    for (var i = 0; i < txtBoxId.value.length; i++) {
        if (iChars.indexOf(txtBoxId.value.charAt(i)) != -1) {
            alert("- " + Name +" contains invalid character.");
            return false;
        }
    }
}

function fnValidateName(txtBoxId, Name) {
    var iChars = "`!@#$%^&*()+=-[]\\\';{}|\",:<>?";
    for (var i = 0; i < txtBoxId.value.length; i++) {
        if (iChars.indexOf(txtBoxId.value.charAt(i)) != -1) {
            alert("- " + Name + " contains invalid character.");
            return false;
        }
    }
}



function fnValidateDesc(txtBoxId, Name) {
    var iChars = "`#^\\;{}|<>";
    for (var i = 0; i < txtBoxId.value.length; i++) {
        if (iChars.indexOf(txtBoxId.value.charAt(i)) != -1) {
            alert("- " + Name + " contains invalid character.");
            return false;
        }
    }
}
function checkPhone(elem, helperMsg) {
    var numericExpression = /^\+?[\d\s]+\(?[\d\s]{1,}$/;
    if (elem.value.toString().match(numericExpression)) {
        return true;
    } else {
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function fnMuliSelect(listBoxId) {
    var strApend = "";
    var strValues = "";
    var i_Length = listBoxId.options.length;

    for (var i = 0; i < i_Length; i++) {
        if (listBoxId.options[i].selected == true) {
            strValues = strValues + strApend + listBoxId.options[i].value;
            strApend = ",";
        }
    }
    return strValues;

}

function fnListItems(listBoxId) {
    var strApend = "";
    var strValues = "";
    var i_Length = listBoxId.options.length;

    for (var i = 0; i < i_Length; i++) {
        strValues = strValues + strApend + listBoxId.options[i].value;
        strApend = ",";
    }
    return strValues;

}

function TrimString(strInString) {
    strInString = strInString.replace(/^\s+/g, ""); // trim leading
    return strInString.replace(/\s+$/g, ""); // trim trailing
}


function fnSelectList(strListBox, strMessage) {
    var myArray = "";
    try {
        for (var i = 0; i < strListBox.options.length; i++) {
            if (strListBox.options[i].selected == true) {
                myArray += strListBox.options[i].text + ";";
            }
        }

        var resArray = myArray.split(";");
        if (resArray.length <= 1) {
            alert("- Please select atleast one" + strMessage +".");
            return false;
        }
        else {
            return true;
        }
    }
    catch (e) {
        alert(e.message);
    }

}

function fnValidateID(intCase,strCheck,strID,Name) {
    var strReturn;
    $.ajax({
        url: '../Administration/Authenticate.aspx?caseId=' + intCase + '&Check=' + strCheck +"&Id="+strID,
        async: false,
        cache:false,
        success: function (data) {
            $('.result').html(data);
            if (data == "1") {
                strReturn = "1";
            }
            else {
                strReturn = "0";
            }
        }
    });

    if (strReturn == 1) {
        alert("- " + Name + " already exists. Specify different " + Name +".");
        return false;
    }
    else {
        return true;
    }

}


function fnTemplate(intCase, strID) {
    var strReturn;
    $.ajax({
        url: '../Administration/Authenticate.aspx?caseId=' + intCase + "&Id=" + strID,
        async: false,
        cache: false,
        success: function (data) {
            $('.result').html(data);
            if (data != "") {
                strReturn = data;
            }
            else {
                strReturn = "";
            }
        }
    });

    if (strReturn != "") {
        return strReturn;
    }
    else {
        //alert("- Template Not available.");
        return strReturn;
    }

}




function fnPasswordCompaire(intCase,strCheck,strID,Name) {
    var strReturn;
    $.ajax({
        url: '../Administration/Authenticate.aspx?caseId=' + intCase + '&Check=' + strCheck +"&Id="+strID,
        async: false,
        cache:false,
        success: function (data) {
            $('.result').html(data);
            if (data == "1") {
                strReturn = "1";
            }
            else {
                strReturn = "0";
            }
        }
    });

    if (strReturn == 1) {
        alert("- Old "  + Name +  " entered is wrong, Please enter correct Password.");
        return false;
    }
    else {
        return true;
    }

}

function passwordStrength(password) {
    var desc = new Array();
    desc[0] = "Very Weak";
    desc[1] = "Weak";
    desc[2] = "Better";
    desc[3] = "Medium";
    desc[4] = "Strong";
    desc[5] = "Strongest";

    var score = 0;

    //if password bigger than 6 give 1 point
    if (password.length > 6) score++;

    //if password has both lower and uppercase characters give 1 point	
    if ((password.match(/[a-z]/)) && (password.match(/[A-Z]/))) score++;

    //if password has at least one number give 1 point
    if (password.match(/\d+/)) score++;

    //if password has at least one special caracther give 1 point
    if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) score++;

    //if password bigger than 12 give another 1 point
    if (password.length > 12) score++;

    document.getElementById("passwordDescription").innerHTML = desc[score];
    document.getElementById("passwordStrength").className = "strength" + score;

    if (password.length == 0) {
        document.getElementById("passwordDescription").innerHTML = "- Password not entered.";
    }
    return score;
}

///<Summary>
///This method is Dual list move function
///<Summary>
///-->
function MoveItem(ctrlSource, ctrlTarget, All) {
    var Source = document.getElementById(ctrlSource);
    var Target = document.getElementById(ctrlTarget);
    if(All==true){
        if ((Source != null) && (Target != null)) {
            for(var i=0;i<Source.options.length;i++) {
                var newOption = new Option(); // Create a new instance of ListItem
                newOption.text = Source.options[i].text;
                newOption.value = Source.options[i].value;

                Target.options[Target.length] = newOption; //Append the item in Target
                Source.remove(i); //Remove the item from Source
                i--;
            }
        }  
    }else{
        var intSelected=0;
        var intSelectedIndex=0;
        if ((Source != null) && (Target != null)) {
            while (Source.options.selectedIndex >= 0) {
                intSelected= 1;
                intSelectedIndex=Source.options.selectedIndex;
                var newOption = new Option(); // Create a new instance of ListItem
                newOption.text = Source.options[Source.options.selectedIndex].text;
                newOption.value = Source.options[Source.options.selectedIndex].value;
                Target.options[Target.length] = newOption; //Append the item in Target
                Source.remove(Source.options.selectedIndex); //Remove the item from Source
             }
                try{
                if(intSelectedIndex>=Source.options.length){
                    Source.options.selectedIndex = intSelectedIndex-1;
                }else{
                    Source.options.selectedIndex = intSelectedIndex;
                }
                }catch(e){
                }

            if (intSelected == 0) {
                if(Source.options.length>0)
                    alert("- Select atleast one item to move.");
            }
        }
    }
}

function fnCheckEmail(str) {

    var strExp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
    if (str.match(strExp)) {
        return true;
    } else {
        return false;
    }
}

function fnBindDDL(objDDL, strXML, strTextTagName, strValueTagName, isSelect) {
    
    objDDL.options.length = 0;
    var intOptCntr = -1;
    if (isSelect == true) {
        objDDL.options[0] = new Option();
        objDDL.options[0].text = "[-- Select --]";
        objDDL.options[0].value = "0";
        intOptCntr=0;
    }
   var strParameterName = strXML.getElementsByTagName(strTextTagName);
    var strParameterId = strXML.getElementsByTagName(strValueTagName);
    for (var i = 0; i < strParameterName.length; i++) {
        if (window.ActiveXObject) { // For IE
            objDDL.options[intOptCntr + 1] = new Option();
            objDDL.options[intOptCntr + 1].text = strParameterName.item(i).text
            objDDL.options[intOptCntr + 1].value = strParameterId.item(i).text;
            intOptCntr++;
        }
        else if (document.implementation.createDocument) {/// For Firefox
            objDDL.options[intOptCntr + 1] = new Option();
            objDDL.options[intOptCntr + 1].text = strParameterName[i].firstChild.nodeValue;
            objDDL.options[intOptCntr + 1].value = strParameterId[i].firstChild.nodeValue;
            intOptCntr++;
        }
        else {
            alert("Your browser doesnot support the application");
            return false;
        }
    }
}


function fnCheckSpecialChar(){
        var strPos;
        var intD;
        intD=event.keyCode;
        if(event.keyCode<32){
            strPos=false;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==32){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
         if(event.keyCode<40){
            strPos=false;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode<42){
            strPos=false;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode>47 && event.keyCode<58 ){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode>64 && event.keyCode<91 ){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==95){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode>96 && event.keyCode<123){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        else{
             event.returnValue=false;
        }
    }

    function fnCheckSpecialCharAllow(){
        var strPos;
        var intD;
        intD = event.keyCode;
        if (event.keyCode < 13) {
            strPos = false;
            event.returnValue = strPos;
            return;
        }
        if (event.keyCode == 13) {
            strPos = true;
            event.returnValue = strPos;
            return;
        }
        if(event.keyCode<32){
            strPos=false;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==32){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==33){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==34){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==38){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==39){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
         if(event.keyCode<40){
            strPos=false;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode<42){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        
        if(event.keyCode>42 && event.keyCode<60 ){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==61){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==63){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==64){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode>64 && event.keyCode<91 ){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode==95){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        if(event.keyCode>96 && event.keyCode<123){
            strPos=true;
            event.returnValue=strPos;
            return;
        }
        else{
             event.returnValue=false;
        }
    }

 
