/******************************************************************/
/**                                                              **/
/** TechnoMedia International, Inc.                              **/
/** Copyright 2005                                               **/
/** All Rights Reserved                                          **/
/**                                                              **/
/******************************************************************/

/*** QueryString **************************************************/
/******************************************************************/

function QueryString(key){
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++){
		if ((QueryString.keys[i]).toUpperCase()==key.toUpperCase()){
			value = unescape(QueryString.values[i]);
			break;
		}
	}
	if((value==null)&&(QueryString.arguments.length>1)){
		value=QueryString.arguments[1];
	}
	return value;
}

QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse(){
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	for (var i=0;i<pairs.length;i++){
		var pos = pairs[i].indexOf('=');
		if (pos >= 0){
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;
		}
	}
}

QueryString_Parse();

/*** reference a frame ********************************************/
/******************************************************************/

function findTopFrame(){
	var f=this;
	while(f!=null){
		try{
			if(f.topFrame==true){
				return f;
			}e
		}catch(e){
			f=null;
		}
		try{
			if(f.name==""){
				f=null;
			}
		}catch(e){
			f=null;
		}
		try{
			f=f.parent;
		}catch(e){
			f=null;
		}
		if(this==f){
			f=null;
		}
	}
}

function findFrame(fName,f){
	var foundFrame = null;
	if(f==null){
		//f=top;
		f=findTopFrame();
	}
	if(f==null){
		return;
	}
	try{
		if(f.name==fName){
			foundFrame = f;
		}else{
			for(var i=0;i<f.frames.length;i++){
				foundFrame = findFrame(fName,f.frames[i]);
				if(foundFrame!=null){
					break;
				}
			}
		}
	}catch(e){}
	return foundFrame;
}

function setFrameURI(fname,uri,replace){
	replace=((replace==null)?true:replace);
	try{
		if(replace){
			findFrame(fname).location.replace(uri);
		}else{
			findFrame(fname).location=uri;
		}
	}catch(e){}
}

/***URI utiltites *************************************************/
/******************************************************************/

function myRedir(targetURL){
	var redirURL=targetURL;
	redirURL += document.location.search;
	var prePend=""
	if(myRedir.arguments.length>1){
		if(document.location.search!=""){
			prePend = "&";
		}else{
			prePend = "?";
		}
	}
	for (var i=1;i<myRedir.arguments.length;i++){
		redirURL+=prePend+myRedir.arguments[i]
		prePend="&";
	}
	return redirURL;
}

/** array utilitites **********************************************/
/******************************************************************/

function addArrElem(a,p,v){
	p=(p==-1)?a.length:p;
	return (a.slice(0,p)).concat(v,a.slice(p));
}

function delArrElem(a,p){
	p=(p==-1)?a.length-1:p;
	return (a.slice(0,p).concat(a.slice(p+1)));
}

/***Misc utiltites ************************************************/
/******************************************************************/

function preloadImages(path,arrI,imgType){
	for(var i=0;i<arrI.length;i++){
		var image1 = new Image();
		image1.src = path+arrI[i]+"."+imgType;
	}
}

function preloadGlyphs(arrI){
	preloadImages("images/app/glyphs/",arrI,"gif");
}

function trim(str){
	var s = str.replace(/^(\s)*/, '');
	s = s.replace(/(\s)*$/, '');
	return s;
}

function booleanValue(b){
	return ((""+b).toUpperCase()).indexOf("T")>=0;
}

function getElementTop(e){
	if((!e) && (this)){
		e=this;
	}
	var p=e.offsetTop;
	var ePar=e.offsetParent;
	while(ePar!=null){
		p+=ePar.offsetTop;
		ePar=ePar.offsetParent;
	}
	return p;
}

/**** VB MsgBox wrappers * requires the VB code on page ***********/
/******************************************************************/

IE4 = document.all;

function newAlert(title,mess,icon,mods){
	(IE4)?makeMsgBox(title,mess,icon,0,0,mods):alert(mess);
}

function newConfirm(title,mess,icon,defbut,mods){
	if(IE4){
		icon=(icon==0)?0:2;
		defbut=(defbut==0)?0:1;
		retVal=makeMsgBox(title,mess,icon,4,defbut,mods);
		retVal=(retVal==6);
	}
	else{
		retVal=confirm(mess);
	}
	return retVal;
}

function newPrompt(title,mess,def){
	retVal=(IE4)?makeInputBox(title,mess,def):prompt(mess,def);
	return retVal;
}

function IEBox(title,mess,icon,buts,defbut,mods){
	retVal=(IE4)?makeMsgBox(title,mess,icon,buts,defbut,mods):null;
	return retVal;
}

/**** forms breakItUp for long data *******************************/
/******************************************************************/
function breakItUp(frm,fld){
	//Set the limit for field size.
	var FormLimit = 102399;
	FormLimit=65000;
	//Get the value of the large input object.
	var TempVar = new String;
	TempVar = fld.value;
	//If the length of the object is greater than the limit, break it into multiple objects.
	if(TempVar.length > FormLimit){
		fld.value = TempVar.substr(0, FormLimit);
		TempVar = TempVar.substr(FormLimit);
		while(TempVar.length > 0){
			var objTEXTAREA = document.createElement("TEXTAREA");
			objTEXTAREA.name = fld.name;
			objTEXTAREA.value = TempVar.substr(0, FormLimit);
			objTEXTAREA.style.display="none";
			frm.appendChild(objTEXTAREA);
			TempVar = TempVar.substr(FormLimit);
		}
	}
}

/**** isSMTP ******************************************************/
/******************************************************************/

function isSMTP(a){
	a=trim(a.toLowerCase());
	vChars="abcdefghijklmnopqrstuvwxyz1234567890@._-'`";
	for(var i=0;i<a.length;i++){
		if(vChars.indexOf(a.charAt(i))==-1){
			return false;
		}
	}
	if(a!=""){
		arrA1=a.split("@");
		if(arrA1.length==2){
			if(((trim(arrA1[0]).length>0)&&(trim(arrA1[0]).length==arrA1[0].length))&&((trim(arrA1[1]).length>0)&&(trim(arrA1[1]).length==arrA1[1].length))){
				arrA2=trim(arrA1[1]).split(".");
				if(arrA2.length>1){
					for(i=0;i<arrA2.length;i++){
						if((trim(arrA2[i]).length==0)||(trim(arrA2[i]).length!=arrA2[i].length)){
							return false;
						}
					}
					return true;
				}
			}
		}
	}
	return false;
}

//function isSMTPx(a){
//	var re = new RegExp("^(([A-Za-z0-9'`]+_+)|([A-Za-z0-9'`]+\-+)|([A-Za-z0-9'`]+\.+)|([A-Za-z0-9'`]+\++))*[A-Za-z0-9'`]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$");
//	var m = re.exec(a);
//	return (m!=null);
//}

	function validChars(s){
		var illChars="%*'\"?!@#$^&()+-,<>/\\:;=|[]}{";
		for(var i=0;i<illChars.length;i++){
			if(s.indexOf(illChars.charAt(i))>-1){
				return false;
			}
		}
		return true;
	}
/**** MyVector ****************************************************/
/******************************************************************/

function MyVector() {
	this.init();
}

MyVector.prototype.init = function(){
	if(MyVector.superclass!=null){
		MyVector.superclass.init.call(this);
	}
	this.collIndex=new Array();
	this.collVObj=new Object;
	this.uid=0;
}

MyVector.prototype.add = function(v){
	this.addAt(this.collIndex.length,v);
}

MyVector.prototype.addAt = function(p,v){
	this.collIndex=addArrElem(this.collIndex,p,"oid"+this.uid++);
	this.set(p,v);
}

MyVector.prototype.set = function(p,v){
	if(p<this.collIndex.length){
		this.collVObj[this.collIndex[p]]=v;
	}
}

MyVector.prototype.get = function(p){
	if(p<this.collIndex.length){
		return this.collVObj[this.collIndex[p]];
	}
}

MyVector.prototype.deleteAt = function(p){
	if(p<this.collIndex.length){
		var delVal=this.get(p);
		this.collVObj[this.collIndex[p]]=null;
		this.collIndex=delArrElem(this.collIndex,p);
		return delVal;
	}
}

MyVector.prototype.indexOf = function(v){
	for(var i=0;i<this.collIndex.length;i++){
		if(this.collVObj[this.collIndex[i]]==v){
			return i;
		}
	}
}

MyVector.prototype.getLast = function(){
	if(this.collIndex.length>0){
		return this.collVObj[this.collIndex[this.collIndex.length-1]];
	}
}

MyVector.prototype.size = function(){
	return this.collIndex.length;
}

MyVector.prototype.getArray = function(){
	var arrRet=new Array();
	for(var i=0;i<this.collIndex.length;i++){
		arrRet[i]=(this.collVObj[this.collIndex[i]]).toString();
	}
	return arrRet;
}

/**** MyStack ***************************************************/
/******************************************************************/

MyStack.prototype=new MyVector();
MyStack.prototype.constructor=MyStack;
MyStack.superclass=MyVector.prototype;

function MyStack(){
	this.init();
}

MyStack.prototype.init = function(){
	if(MyStack.superclass!=null){
		MyStack.superclass.init.call(this);
	}
}

MyStack.prototype.push = function(v){
	MyStack.superclass.add.call(this,v);
	return this.collVObj[this.collIndex[this.collIndex.length-1]];
}

MyStack.prototype.pop = function(){
	if(this.collIndex.length>0){
		var retVal=this.collVObj[this.collIndex[this.collIndex.length-1]];
		MyStack.superclass.deleteAt.call(this,this.collIndex.length-1);
		return retVal;
	}
}

MyStack.prototype.peek = function(){
	if(this.collIndex.length>0){
		var retVal=this.collVObj[this.collIndex[this.collIndex.length-1]];
		return retVal;
	}
}

/**** MyHashMap ***************************************************/
/******************************************************************/

function MyHashMap(){
	this.init();
}

MyHashMap.prototype.init = function(){
	if(MyHashMap.superclass!=null){
		MyHashMap.superclass.init.call(this);
	}
	this.collIndex=new Array();
	this.collKObj=new Object;
	this.collVObj=new Object;
	this.uid=0;
}

MyHashMap.prototype.put = function(k,v){
	for(var i=0;i<this.collIndex.length;i++){
		if(this.collKObj[this.collIndex[i]]==k){
			break;
		}
	}
	if(i>=this.collIndex.length){
		this.collIndex[this.collIndex.length]="oid"+this.uid++;
	}
	this.collKObj[this.collIndex[i]]=k;
	this.collVObj[this.collIndex[i]]=v;
	return v;
}

MyHashMap.prototype.set = function(k,v){
	for(var i=0;i<this.collIndex.length;i++){
		if(this.collKObj[this.collIndex[i]]==k){
			this.collVObj[this.collIndex[i]]=v;
			return;
		}
	}
}

MyHashMap.prototype.get = function(k){
	for(var i=0;i<this.collIndex.length;i++){
		if(this.collKObj[this.collIndex[i]]==k){
			break;
		}
	}
	if(i<this.collIndex.length){
		return this.collVObj[this.collIndex[i]];
	}
}

MyHashMap.prototype.getKeyAt = function(p){
	if(p<this.collIndex.length){
		return this.collKObj[this.collIndex[p]];
	}
}

MyHashMap.prototype.getValueAt = function(p){
	if(p<this.collIndex.length){
		return this.collVObj[this.collIndex[p]];
	}
}

MyHashMap.prototype.indexOfKey = function(k){
	for(var i=0;i<this.collIndex.length;i++){
		if(this.collKObj[this.collIndex[i]]==k){
			return i;
		}
	}
}

MyHashMap.prototype.indexOfValue = function(v){
	for(var i=0;i<this.collIndex.length;i++){
		if(this.collVObj[this.collIndex[i]]==v){
			return i;
		}
	}
}

MyHashMap.prototype.deleteElem = function(k){
	for(var i=0;i<this.collIndex.length;i++){
		if(this.collKObj[this.collIndex[i]]==k){
			break;
		}
	}
	if(i<this.collIndex.length){
		this.collKObj[this.collIndex[i]]=null;
		this.collVObj[this.collIndex[i]]=null;
		this.collIndex=delArrElem(this.collIndex,i);
	}
}

MyHashMap.prototype.size = function(){
	return this.collIndex.length;
}