/**********
 * browser tests
 **************************/
var agt=navigator.userAgent.toLowerCase();
var is_ie=(agt.indexOf("msie")!=-1);
var is_ie5_5=(is_ie && agt.indexOf("5.5")!=-1);
var is_nav = (!is_ie && agt.indexOf('mozilla')!=-1);


/************************************************
* Nifty Corners Code
************************************************/
function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
      this[this.length]=arguments[0]; return(this.length);}}
return(true);
}

function Rounded(selector,wich,bk,color,opt){
var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false;

if(color=="transparent"){
    cn=cn+"x";
    ecolor=bk;
    bk="transparent";
    }
else if(opt && opt.indexOf("border")>=0){
    var optar=opt.split(" ");
    for(i=0;i<optar.length;i++)
        if(optar[i].indexOf("#")>=0) ecolor=optar[i];
    if(ecolor=="") ecolor="#666";
    cn+="e";
    edges=true;
    }
else if(opt && opt.indexOf("smooth")>=0){
    cn+="a";
    ecolor=Mix(bk,color);
    }
if(opt && opt.indexOf("small")>=0) cn+="s";
prefixt=cn;
prefixb=cn;
if(wich.indexOf("all")>=0){t=true;b=true}
else if(wich.indexOf("top")>=0) t="true";
else if(wich.indexOf("tl")>=0){
    t="true";
    if(wich.indexOf("tr")<0) prefixt+="l";
    }
else if(wich.indexOf("tr")>=0){
    t="true";
    prefixt+="r";
    }
if(wich.indexOf("bottom")>=0) b=true;
else if(wich.indexOf("bl")>=0){
    b="true";
    if(wich.indexOf("br")<0) prefixb+="l";
    }
else if(wich.indexOf("br")>=0){
    b="true";
    prefixb+="r";
    }
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    if(edges) AddBorder(v[i],ecolor);
    if(t) AddTop(v[i],bk,color,ecolor,prefixt);
    if(b) AddBottom(v[i],bk,color,ecolor,prefixb);
    }
}

function AddBorder(el,bc){
var i;
if(!el.passed){
    if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){
        var t=el.firstChild.nodeValue;
        el.removeChild(el.lastChild);
        var d=CreateEl("span");
        d.style.display="block";
        d.appendChild(document.createTextNode(t));
        el.appendChild(d);
        }
    for(i=0;i<el.childNodes.length;i++){
        if(el.childNodes[i].nodeType==1){
            el.childNodes[i].style.borderLeft="1px solid "+bc;
            el.childNodes[i].style.borderRight="1px solid "+bc;
            }
        }
    }
el.passed=true;
}
    
function AddTop(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingTop=0;
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateEl(x){
if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x));
else return(document.createElement(x));
}

function getElementsBySelector(selector){
var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];

if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    f=document.getElementById(fs[1]);
    if(f) return(f.getElementsByTagName(s[1]));
    return(objlist);
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    f=document.getElementById(selid);
    if(f) objlist.push(f);
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className.indexOf(selclass)>=0){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    }
return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16));
} 

function roundCorners()
{

	Rounded("div.boxTop1","top","transparent","#ffffff","border #cbcccc");
	Rounded("div.boxBottom1","bottom","transparent","#ffffff","border #cbcccc");
	Rounded("div.boxTop2","top","transparent","#ffffff","border #cececd");
	Rounded("div.boxBottom2","bottom","transparent","#e7e7e7","border #cececd");
	Rounded("div.boxTopLogin","top","transparent","#ffffff","border #cececd");
	Rounded("div.boxBottomLogin","bottom","transparent","#e9e9e9","border #cececd");
	Rounded("div.boxOnTab","top","transparent","#ffffff","border #999999");
	Rounded("div.boxTab","top","transparent","#E5E5E5","border #999999");
	
	//for page b and c
	Rounded("div.boxBottomApply","bottom","transparent","#e7e7e7","border #cbcccc");	
	
	//for messaging
	Rounded("div.boxErrorTop","top","transparent","#fff9de","border #ff0000");	
	Rounded("div.boxErrorBtm","bottom","transparent","#fff9de","border #ff0000");	
	Rounded("div.boxWarningTop","top","transparent","#fff9de","border #faa946");	
	Rounded("div.boxWarningBtm","bottom","transparent","#fff9de","border #faa946");
	Rounded("div.boxConfirmTop","top","transparent","#fff9de","border #1f9d4a");	
	Rounded("div.boxConfirmBtm","bottom","transparent","#fff9de","border #1f9d4a");	
	Rounded("div.boxEducationTop","top","transparent","#ebf8fd","border #4c79be");	
	Rounded("div.boxEducationBtm","bottom","transparent","#ebf8fd","border #4c79be");
	Rounded("div.boxPositiveTop","top","transparent","#f0f7eb","border #c2e1bc");	
	Rounded("div.boxPositiveBtm","bottom","transparent","#f0f7eb","border #c2e1bc");
}

function roundCornersOK() {if(!document.getElementById || !document.createElement)    return(false);isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);if(Array.prototype.push==null){Array.prototype.push=function(){      this[this.length]=arguments[0]; return(this.length);}}return(true);}

var agt=navigator.userAgent.toLowerCase();
var is_ie=(agt.indexOf("msie")!=-1);
/**********
 * Changes the css style and events for buttons
 **************************/
//button class name constants
var OUTER = "Outer";
var MIDDLE = "Middle";
var INNER = "Inner";
var PRIORITY = "Priority";
function btnOn(id){
	var linkRef = document.getElementById(id);
	if (linkRef){
		var pClass = (linkRef.getAttribute("priority")=="true") ? PRIORITY : ""; //if priority, change class
		changeBtnClass(id,pClass+"On");
		linkRef.onfocus = function(){ changeBtnClass(id,pClass+"Over") } ;
		linkRef.onblur = function(){ changeBtnClass(id,pClass+"On") } ;
		linkRef.onmouseover = function(){ changeBtnClass(id,pClass+"Over") 
		} ;
		linkRef.onmousedown = function(){//need to also clear onfocus and blur on mousedown for mozilla/firefox conflicts
			if (!is_ie){
				document.getElementById(id).onfocus=null;
				document.getElementById(id).onblur=null;
			}
			changeBtnClass(id,pClass+"Down");
		} ;
		linkRef.onmouseup = function(){ 
			changeBtnClass(id,pClass+"On") 
		};
		linkRef.onmouseout = function(){ //need to also reset onfocus and blur on mousedown for mozilla/firefox conflicts
			changeBtnClass(id,pClass+"On");
			if (!is_ie){
				document.getElementById(id).onfocus = function(){changeBtnClass(id,pClass+"Over")};
				document.getElementById(id).onblur= function(){changeBtnClass(id,pClass+"On")};	
			}
		} ;
		linkRef.onclick = linkRef.inlineonclick; 
	}
 }
 
 function btnOff(id) {
	var linkRef = document.getElementById(id);
	if (linkRef){
		var pClass = (linkRef.getAttribute("priority")=="true") ? PRIORITY : ""; //if priority, change class
		changeBtnClass(id,pClass+"Off");
		linkRef.onfocus = null;
		linkRef.onblur = null;
		linkRef.onclick = function(){return false;};
		linkRef.onmouseover = null;
		linkRef.onmousedown = null ;
		linkRef.onmouseup = null;
		linkRef.onmouseout = null;	
	}
 }
 
function changeBtnClass(id,state){
	var btn = document.getElementById(id + OUTER);
	if (btn){
		 btn.className = "btn" + state + OUTER;
		 var middleBtn = document.getElementById(id+MIDDLE);
		 if (middleBtn) middleBtn.className = "btn" + state + MIDDLE;
		 var innerBtn = document.getElementById(id+INNER);
		 if (innerBtn) innerBtn.className = "btn" + state + INNER;
	}
}

function btnInit(id,priority,on,setwidth,mozmargin,iconPre,iconPost,smallsize){
	var linkRef = document.getElementById(id); //get a tag link
	var iconImg = "";//for icons
	if (iconPre || iconPost) {
		iconImg = document.createElement("img");
		iconImg.src = (iconPre) ? iconPre: iconPost;
		iconImg.border = "0";
		iconImg.hspace = "4";
		iconImg.style.paddingTop = "2px"
		//iconImg.width = 10;
		//iconImg.height = 10;
	}
	
	if (linkRef){
		var txt = linkRef.firstChild.nodeValue; //get text in link
		var oswidth = linkRef.offsetWidth; //buttons may need to be same width for design, if so, pass width size
		var padding = (smallsize) ?  16 : 21; //add extra width padding
		var width = (setwidth) ? setwidth : oswidth + padding; //get width of link, and add padding
		linkRef.firstChild.nodeValue = " "; //erase text link
		linkRef.className = "btnLink"; 
		linkRef.style.width = width; //reset link width
		if (mozmargin) {
			if (!is_ie) linkRef.style.marginRight = mozmargin + "px"; //mozilla firefox need extra margin due to floating left a
		} else {
			if (!is_ie) linkRef.style.marginRight = "6px"; //mozilla firefox need extra margin due to floating left a
		}
		if (iconPre || iconPost) {
			width += 11; //size of icon image + buffer
		}
		
		//writing out this structure <a href="#"><div><div></div><div></div></div></a>
		//triple divs for additional borders
		var outerDiv = document.createElement("div"); 
		outerDiv.id = id + OUTER;
		outerDiv.style.width = width + "px";
		
		var middleDiv = document.createElement("div"); 
		middleDiv.id = id + MIDDLE;
		middleDiv.style.width = (width - 2) + "px";
		
		var innerDiv = document.createElement("div");
		innerDiv.id = id + INNER;
		innerDiv.style.width = (width - 4) + "px";
		if (smallsize) { innerDiv.style.padding = "0px"; innerDiv.style.fontSize = "11px";}
	
		
		outerDiv.appendChild(middleDiv);
		middleDiv.appendChild(innerDiv);
		if (iconPre) {
			innerDiv.appendChild(iconImg);
		}
		innerDiv.appendChild(document.createTextNode(txt));
		if (iconPost) {
			innerDiv.appendChild(iconImg);
		}		
		linkRef.appendChild(outerDiv);
						
		if (priority) { //priority setting
			var newAttr = document.createAttribute("priority");
			newAttr.nodeValue="true";
			linkRef.setAttributeNode(newAttr);
		}
		
		//hold on to inline onclick on the original link
		if (linkRef.inlineset!=true) {
			linkRef.inlineonclick = linkRef.onclick; 
			linkRef.inlineset = true;
		}
		on ? btnOn(id) : btnOff(id); //set button states
	}
}

function multipleMessages(div){
	var errors = document.getElementById(div);
	var errorMsgs = errors.getElementsByTagName("p");
	
	if (errorMsgs.length > 1){
		for(var e=0; e<errorMsgs.length; e++){
			var error = errorMsgs.item(e);		
			if(e!=errorMsgs.length-1){
				error.className = "dottedLine";
			}
			else{
				error.style.marginTop = "3px";
			}		
		}
	}
}