function getScroll(){
	if (window.pageYOffset) {
		scrollTop = window.pageYOffset;
		scrollLeft = window.pageXOffset;
	}
	else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
		scrollTop = document.documentElement.scrollTop;
		scrollLeft = document.documentElement.scrollLeft;
	}
	else if (document.body){
		scrollTop = document.body.scrollTop;
		scrollLeft = document.body.scrollLeft;
	}
	
	
	if (window.innerHeight){
		windowHeight = window.innerHeight
		windowWidth = window.innerWidth
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		windowHeight = document.documentElement.clientHeight
		windowWidth = document.documentElement.clientWidth
	}
	else if (document.body) {
		windowHeight = document.body.clientHeight;
		windowWidth = document.body.clientWidth;
	}
	return {Top:scrollTop,Left:scrollLeft}
}



Number.prototype.format= function(d){
	var a,m,m2;
	var rgx = /(\d+)(\d{3})/;
	var d = d || 0;

	if (d){
		a = this.toString().split('.');
		a[1] = a[1] || '0'
		m = Math.pow(10,d)
		m2 = Math.pow(10,-(a[1].length-d))
		a[1] = (Math.round(a[1]*m2)/m).toString().substr(2)
		while (a[1].length < d) 
			a[1] += '0';
	}
 	else 
		a = [Math.round(this).toString()];

	while (rgx.test(a[0])) 
		a[0] = a[0].replace(rgx, '$1' + ',' + '$2');
	return a.join('.')
} 
function padZero(n,totalDigits){
	n=n+'';
	while (n.length<totalDigits)
		n='0'+n
	return n;
}
function formatDate(d){
	if (!d || !d.getDate) 
		return '';
	return padZero((d.getMonth()+1),2)+'/'+padZero(d.getDate(),2)+'/'+d.getFullYear().toString().substr(2,2)
}
function iraStatus(adstatus,expiredate){
	switch (adstatus){
		case 'e':
			return 'Expired';
		case 'w':
			return 'Withdrawn';
		case 's':
			return 'Sold';
		case 'b':
			return 'Backup Offers';
		case 'p':
			return 'Pending';
		case 'c':
			return 'CMA';
		case 't':
			return 'Cancelled';
		case 'a':
			if (expiredate > new Date())
				return 'Active';
			else
				return 'Expired';
	}
	return '';
}
function getElmById(searchStr,elm){
	var returnElm;
	while (elm && !returnElm){
		if (elm.id == searchStr)
			returnElm = elm;
		else if (elm.childNodes.length)
			returnElm = getElmById(searchStr,elm.firstChild);
		elm = elm.nextSibling;
	}
	return returnElm;
}



function CSSRule(cName,styleObj,optObj){
	if (!optObj)
		var optObj = {};
	if(document.styleSheets.length == 0)
		return;
	for (var i=0;i<document.styleSheets.length;i++){
		var cx = document.styleSheets[i].cssRules || document.styleSheets[i].rules
		for (var x=0;x<cx.length;x++){
			if (cx[x].selectorText == cName){
				if (!optObj.insertOnly)
					Object.extend(cx[x].style,styleObj)
				else
					for (var y in styleObj){
						if (!cx[x].style[y])
							cx[x].style[y] = styleObj[y]
					}
				return;
			}
		}
	}
	var s='';
	delim = '';
	for (var i in styleObj){
		if (i == 'cssFloat' || i == 'styleFloat')
			s+= 'float:'+styleObj[i]+';';
		else
			s += i.underscore().dasherize()+':'+styleObj[i]+';';
	}
	var myStyle = document.styleSheets[0];
	//alert(cName)
	if (myStyle.addRule){//ie
		x = myStyle.addRule(cName,s)
	}
	else {
		myStyle.insertRule(cName+'{'+s+'}',  myStyle.cssRules.length-1)
	}

}

function debug(obj){
	var msg=[];
	for (i in obj){
		try {msg[msg.length] = i+':'+obj[i];}
		catch(e) {msg[msg.length] = i+':'}
	}
	if (!window.debugBox){
		debugBox = document.createElement('div')
		debugBox.style.position = 'absolute';
		debugBox.style.top="10px";
		debugBox.style.left="10px";
		debugBox.style.border="1px solid black";
		debugBox.style.height="100px";
		debugBox.style.padding="10px";
		debugBox.style.backgroundColor="lightblue";
		document.body.appendChild(debugBox);
		debugBox.onclick=function(){debugBox.style.visibility="hidden"};
	}
	
	debugBox.innerHTML = msg.join('<br>')
	debugBox.style.visibility='visible';
}
function getElmsByName(searchString,scope){
	var x = scope.all
	var a=[];
	for (var i=0;i<x.length;i++)
		if (x[i].name == searchString)
			a[a.length]=x[i]
	return a
}
function createCookie(name,value,days,mydomain) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
		var expires = "";

	if (!mydomain)
		var mydomain = '';
	else
		mydomain = 'domain='+mydomain;
		
	document.cookie = name+"="+value+expires+"; path=/; "+mydomain;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
//function isDate(a) {
//    return typeof a == 'date';
//}

function wait(millis) {
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); } 
		while(curDate-date < millis);
} 

function isFunction(a) {
    return typeof a == 'function';
}
function trim(str_var){
	// added trim function
	return str_var.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}
function mainmenu(){
	history.go('http://'+location.host+'/wwwroot/remaint/index.cfm');
	history.go('http://'+location.host+'/remaint/index.cfm');
	history.go('http://'+location.host+'/remaint/');
	setTimeout('window.location = "/wwwroot/remaint/index.cfm"',500);
}
function checklength(obj){
	setTimeout("updateCounter(textarea.value.length)",3);
	//var uselessKeys = /^9|16|17|35|36|37|8|46|91|38|66|39|40$/
	var uselessKeys = /^9|16|35|36|37|8|46|91|38|66|39|40$/
	if (uselessKeys.test(event.keyCode)) {
		return;
	}
	if (!event.keyCode == "17") {
		if (obj.value.length >= obj.maxlength) {
			return false;
		}
	}
}
function updateCounter(used){
	if (!textarea.maxlength)
		textarea.maxlength=textarea.maxLength;

	if (textarea.value.length > textarea.maxlength){
		textarea.value = textarea.value.substring(0,textarea.maxlength)
		used = textarea.maxlength
	}
	_from.innerHTML = 'used '+used+' ';
	_to.innerHTML = ' of '+textarea.maxlength;
}
function init_from_to(obj){
	textarea = obj;
	_from = document.getElementById(textarea.name+'_from');
	_to = document.getElementById(textarea.name+'_to');
	updateCounter(obj.value.length);
}

function testEmails(str){
	str = str.replace(/;/g,',')
	str = str.replace(/ /g,',')
	var r = /,,/;
	while (r.test(str))
		str=str.replace(r,',')
	var a = str.split(',')
	var v = true;
	for (var i=0;i<a.length;i++)
		if (!testEmail(a[i])){
			v = false;
			break;
		}
	return (v) ? str : v
}
function testEmail(str){
	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	return emailRe.test(str)
}
CSSRule('.fLink',{cursor:'pointer',color:'blue',textDecoration:'underline'});


