﻿function addnewdept(selectVal){
    if(selectVal == "newdept"){
	    document.getElementById("newdept").disabled = false;
	}
	else{
       resetnewdept();
    }
}

function resetnewdept(){
	document.getElementById("newdept").disabled = true;
}

function printPartOfPage(elementId)
{
    var printContent = document.getElementById(elementId);
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50,top=50,width=800,height=600');

    printWindow.document.write(printContent.innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();
}

//Custom trim functions
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//Validate an email address
function validateEmail(email, inputID) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email)) {
        alert('Please Provide A Valid Email Address!');
        document.getElementById(inputID).focus;
        return false;
    }
    return true;
}

function URLEncode(str)
{
    str = escape(str);
    str = str.replace(' ', '%20');
    str = str.replace('!', '%21');
    str = str.replace('"', '%22');
    str = str.replace('#', '%23');
    str = str.replace('$', '%24');
    str = str.replace('\'', '%27');
    str = str.replace('+', '%2B');
    str = str.replace(',', '%2C');
    //str = str.replace('/', '%2F');
    str = str.replace('<', '%3C');
    str = str.replace('>', '%3E');
    str = str.replace('@', '%40');
    str = str.replace('&', '%26');
    str = str.replace('=', '%3D');
    str = str.replace('?', '%3F');
    return str;
}
