/* General Functions */


// Adds event to window.onload without overwriting currently assigned onload functions.
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}

function resizeWin(width,height) {
	window.moveTo(((screen.availWidth / 2) - (width / 2) - 10),(screen.availHeight / 2) - (height / 2));
	window.resizeTo(width,height);
}

function resizeByWin(widthAdjust,heightAdjust) {
	window.resizeBy(widthAdjust,heightAdjust);
}

function launchWin(page,name,height,width,trim,resize,scroll) {
	var leftvalue = ((screen.availWidth / 2) - (width / 2) - 10);
	var topvalue = ((screen.availHeight / 2) - (height / 2));
	
	if (trim) {
		OpenWin = this.open(page, name, "top=" + topvalue + ", left=" + leftvalue + ",status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=" + scroll + ",resizable=" + resize + ",height=" + height + ",width=" + width);
	} else {
		OpenWin = this.open(page, name, "top=" + topvalue + ", left=" + leftvalue + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=" + scroll + ",resizable=" + resize + ",height=" + height + ",width=" + width);
	}
	if (OpenWin) {
		OpenWin.focus();
	}
}

function launchFullWin(page,name,trim,resize,scroll) {
	var height = screen.availHeight - 60;
	var width = screen.availWidth - 5;
	var leftvalue = 0;
	var topvalue = 0;
	
	if (trim) {
		OpenWin = this.open(page, name, "top=" + topvalue + ", left=" + leftvalue + ",status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=" + scroll + ",resizable=" + resize + ",height=" + height + ",width=" + width);
	} else {
		OpenWin = this.open(page, name, "top=" + topvalue + ", left=" + leftvalue + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=" + scroll + ",resizable=" + resize + ",height=" + height + ",width=" + width);
	}
	OpenWin.focus();
}

function expandCollapse() {
	for (var i=0; i<expandCollapse.arguments.length; i++) {
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

function preloadimages() {
	var myimages=new Array()
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}	
}

function pm_friend(IKI) {
	location.href="ymsgr:sendIM?"+escape(IKI);
};

function launchCalendar(field) {
	var width = 215;
	var height = 255;
	var leftvalue = ((screen.availWidth / 2) - (width / 2) - 10);
	var topvalue = ((screen.availHeight / 2) - (height / 2));
	OpenWin = this.open("../modules/module_calendar.cfm?field=" + field, "FieldCalendar", "top=" + topvalue + ", left=" + leftvalue + ",toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,height=" + height + ",width=" + width +"");
	OpenWin.focus();
}

/* Dynamic field resizing */
function sizeUp(targetField) {
	var maxHeight = 1000;
	var temp = document.getElementById(targetField);
	if (parseFloat(temp.style.height) < maxHeight) {temp.style.height = (parseFloat(temp.style.height) + 50) + 'px';}
}

function sizeDown(targetField) {
	var minHeight = 100;
	var temp = document.getElementById(targetField);
	if (parseFloat(temp.style.height) > minHeight) {temp.style.height = (parseFloat(temp.style.height) - 50) + 'px';}
}



/* Ajax */
var xmlhttp;
   
function createXMLHttp() {
    try {
        xmlhttp = new XMLHttpRequest();
    } catch (e) {
        var MSXML_XMLHTTP_PROGIDS = new Array(
            'MSXML2.XMLHTTP.5.0',
            'MSXML2.XMLHTTP.4.0',
            'MSXML2.XMLHTTP.3.0',
            'MSXML2.XMLHTTP',
            'Microsoft.XMLHTTP'
        );
        var success = false;
        for (var i=0;i < MSXML_XMLHTTP_PROGIDS.length && !success; i++) {
            try {
                xmlhttp = new ActiveXObject(MSXML_XMLHTTP_PROGIDS[i]);
                success = true;
            } catch (e) {}
        }
        if ( !success ) {
            alert('AJAX: Your browser does not support some of our advanced features.\n\nPlease consider upgrading to the latest browser of your choice.');
        }
    }
}

function callInProgress(xmlhttp) {
   switch ( xmlhttp.readyState ) {
       case 1, 2, 3:
           return true;
       break;

       // Case 4 and 0
       default:
           return false;
       break;
   }
}

createXMLHttp();

 





/* Smooth Scroll */
function SmoothScroll(){
	Xtop = document.body.scrollTop / 6;
	if(Xtop < 2){
		Xtop = 0;
		document.body.scrollTop = Xtop;
	}else{
		document.body.scrollTop = document.body.scrollTop - Xtop;
		setTimeout('SmoothScroll()', 10); 
	}
}

function ScrollInitGo(){
	targetPos = arguments[0];
	diff = targetPos - document.body.scrollTop;
	
	Xtop = diff / 4;
	if(Xtop >= 1 && scrollTimedOut == 0){
		document.body.scrollTop = document.body.scrollTop + Xtop;
		setTimeout('ScrollInitGo('+arguments[0]+')', 45); 
	}
}

function ScrollInit() {
	scrollTimedOut = 0;
	if (arguments.length) {
		setTimeout('ScrollInitGo('+arguments[0]+')',300);
	} else {
		setTimeout('ScrollInitGo(96)',300);
	}
	setTimeout('scrollTimedOut=1',2000);
}









/* Error Trapping */
function stoperror(){
	return true
}
window.onerror=stoperror

