﻿// JScript File

function isNumberKey(evt)
  {
     var charCode = (evt.which) ? evt.which : event.keyCode
     
     if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        //a letter
        if (charCode > 95 && charCode < 106)
            return true;    //num keys
            
        return false;
    }
    
     return true;
  }
  
  
//disable a pic button
function _disablePicButton(btn) {
    if ($ == null)
        window.alert("Please include the JQuery to work with this functions");
        
    var button;
    var buttonBtn;
    
    var buttonID = btn.id;
    
    button = "#" + buttonID + "_div";
    buttonBtn= "#" + buttonID;
        
    $(button)[0].onmouseover = function() { };
    $(button)[0].onmouseout = function() { };
    $(button)[0].onclick = function() { };
    $(button)[0].onmousedown = function() { };
    
    $(buttonBtn)[0].onmouseover = function() { };
    $(buttonBtn)[0].onmouseout = function() { };
    $(buttonBtn)[0].onclick = function() { };
    $(buttonBtn)[0].href = "#";
    $(buttonBtn)[0].onmousedown = function() { };
    
    $(buttonBtn)[0].style.backgroundPosition='-75px 28px';
    $(button)[0].style.backgroundPosition='-75px 28px';
    
    $(buttonBtn)[0].disabled = true;
    
    return false;
}

//enable a pic button
function _enablePicButton(btn, functionName) {
    if ($ == null)
        window.alert("Please include the JQuery to work with this functions");

    var button;
    var buttonBtn;
    var divName;
    var functionName;
    
    var buttonID = btn.id;
    
    button = "#" + buttonID + "_div";
    buttonBtn= "#" + buttonID;
    divName = buttonID + "_div";
    		
	$(button)[0].onmouseover = function() { 
	    document.getElementById(divName).style.backgroundPosition='-75px 0px';
	};
	
	$(button)[0].onmouseout = function() { 
	    document.getElementById(divName).style.backgroundPosition='0px 0px';
	};
	
	if (functionName != "") {
        $(button)[0].onclick = function() { 
            eval(functionName);
        };
	}
	
	$(button)[0].onmousedown = function() { 
	    document.getElementById(divName).style.backgroundPosition='0px -28px';
	};
	
	$(buttonBtn)[0].onmouseover = function() { 
	    document.getElementById(divName).style.backgroundPosition='-75px 0px';
	};
	
	$(buttonBtn)[0].onmouseout = function() { 
	    document.getElementById(divName).style.backgroundPosition='0px 0px';
	};
	
	$(buttonBtn)[0].onmousedown = function() { 
	    document.getElementById(divName).style.backgroundPosition='0px -28px';
	};

    $(button)[0].style.backgroundPosition='0px 0px';
    $(buttonBtn)[0].style.backgroundPosition='0px 0px';
    
    $(buttonBtn)[0].disabled = false;
    
    return false;
}    


//returns "" if everything was OK, or the message in case it's not OK
function validateTextForXMLStorage(textToValidate) {
    var regx = /([\x20-\x7E])*/;
    var invChars = /&|<|>/;
    
    var result = "";
    
    //remove the enters for easier comparation
    textToValidate = textToValidate.replace(/\r\n/gi, "");

    if (textToValidate.match(regx)) {
        if (textToValidate.match(regx).length==0) {
            result = "Please don't enter special characters";
            return { valid : false, message : result };
        }
    }
    
    if (textToValidate.match(regx)[0] != textToValidate) {
        result = "Please don't enter special characters";
        return { valid : false, message : result };
    } else if (textToValidate.match(invChars) ){
        result = "Please remove the following character(s): " + textToValidate.match(invChars)[0];
        return { valid : false, message : result };
    }
    
    return { valid : true, message : "" };

}

function disableButton(button, message) {
    button.value = message;
    button.disabled = true;
    
    return true;
}