﻿//Shortcut functions

//function $get(thisElement){try{return document.getElementById( thisElement);}catch(e){return null;}}
function $get(thisElement){
	if(document.getElementById(thisElement)){
		try{return document.getElementById( thisElement);}catch(e){return null;}
	}
	else{
		var prefixes = [];
		prefixes = getElementsByClass('prefixes');
		
		//Now parse through prefixes
		for(var i=0; i<prefixes.length; i++){
			if(document.getElementById(prefixes[i].value + thisElement)!=null){
				try{return document.getElementById( prefixes[i].value + thisElement);}catch(e){return null;}			 
			}
		}
	}
}

function $string(thisElement){try{return $get(thisElement).value.toString();}catch(e){return null;}}
function $val(thisElement){try{return $get(thisElement).value;}catch(e){return null;}}
function $enable(thisElement){try{$get(thisElement).disabled=false;}catch(e){}}
function $disable(thisElement){try{$get(thisElement).disabled=true;}catch(e){}}
function $hide(thisElement){try{$get(thisElement).style.display="none";}catch(e){}}
function $show(thisElement){try{$get(thisElement).style.display="";}catch(e){}}
function $check(thisElement){try{$get(thisElement).checked=true;}catch(e){}}
function $uncheck(thisElement){try{$get(thisElement).checked=false;}catch(e){}}
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}


//Prototypes
String.prototype.trim=function(){return this.replace(/^\s*/,"").replace(/\s*$/,"");};
String.prototype.digitsonly=function(){
	var newString="";var temp;
	var digits="1234567890";
	var strLen=this.length;
	for(var x=0;x<strLen;x++){
		temp=''+this.substring(x,x+1);
		if(digits.indexOf(temp)!="-1"){newString+=temp;}
	}
	return newString;
};
Date.prototype.mdy=function(){return $right("0"+this.getMonth(),2)+"/"+$right("0"+this.getDate(),2)+"/"+this.getFullYear();};
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//Regular functions
function $right(oldString,numChars){
	var lenStr=oldString.length;
	if(lenStr<=numChars){return oldString;}
	var posStart=lenStr-numChars;
	var newString=oldString.substr(posStart,numChars);
	return newString;
}
function $getLeft(elem){
	var x=elem.offsetLeft;
	var tmpelem=elem.offsetParent;
	while(tmpelem){
		x+=tmpelem.offsetLeft;
		tmpelem=tmpelem.offsetParent;
	}
	return x;
}
function $getTop(elem){
	var y=elem.offsetTop;
	var tmpelem=elem.offsetParent;
	while(tmpelem){
		y+=tmpelem.offsetTop;
		tmpelem=tmpelem.offsetParent;
	}
	return y;
}
function NewWindow(url,wname,wwidth,wheight){
	if(!url||url===""){return null;}
	if(!wname){wname="";}
	if(!wwidth){wwidth=800;}
	if(!wheight){wheight=600;}
	return window.open(url,wname,"alwaysRaised=yes; dependent=yes; status=yes,scrollbars=yes,resizable=yes,width="+wwidth+",height="+wheight+",top=0,left=0");
}
//"Extended" functions
var CurrentField="";
var CurrentFieldValue="";
function NextField(obj,next_field){
	if(obj.value.length==obj.maxLength&&next_field&&CurrentField==obj.name){
		CurrentField="";
		
		$get(next_field).focus();
		
		
		
	}
}

//DotNet ID Suffix 
function DotNetSfx(id){
//parse through document and grab all the id's - store them into an array

//trim them to get the possible suffixes ( maybe using _ to differentiate)

//compare each suffix to the id in question

//if(match) then append the suffix to the name

//return a string that has the appended suffix

}

//DotNet ID Suffix (Idea 2)
function DotNetSfx(id){
//parse through document and grab all the id's - store them into an array

//trim them to get the possible suffixes ( maybe using _ to differentiate)

//compare each suffix to the id in question

//if(match) then append the suffix to the name

//return a string that has the appended suffix

}



