/*
function selectRadio(e){
	document.forms[0][e].checked =  true;//(document.forms[0][e].checked ? false : true);	
}
*/

function clearDesc(n){
	var value = document.form1[n].value;
	if(value == 'Project description MUST be 100 characters or longer') 
		document.form1[n].value = '';
	document.form1[n].focus();
	document.form1[n].select();	
}


function phoneFill() {
	var phone1 = document.form1.phone1.value;
	
	if(phone2.length < 14) {
		document.form1.phone2.value = phone1;
	}
}



function openWin(URL, wName, wWidth, wHeight, wTop, wLeft, wResize) {
	features = 'scrollbars=1,status=1,resizable=' + ((wResize) ? 1 : 0) + ((wWidth) ? ',width=' + wWidth : '') + ((wHeight) ? ',height=' + wHeight : '') + ((wTop) ? ',top=' + wTop : '') + ((wLeft) ? ',left=' + wLeft : '');;
	popWin = window.open(URL, wName, features);
	if(popWin.focus) { popWin.focus(); }
//	return true;
}

function ShowHide(e) {
	ImageObject = document.getElementById(e + "Image");
	TextObject = document.getElementById(e + "Text");
	if (TextObject.style.display == "none")	{
//		ImageObject.src = "images/arrow_smdkred.gif";
		TextObject.style.display = "";
	} 	else 	{
//		ImageObject.src = "images/arrow_smred.gif";
		TextObject.style.display = "none";
	}
}





//DOM SCRIPTS FOR SHOW/HIDE

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	var msg = 'getting checked value\n' + radioObj;
//	alert (msg);
	if(!radioObj){
		alert('not a radio object');
		return "";
	}
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function extraQuestions(formname) {
	var len = document.forms[formname].elements.length;
	for(i = 0; i < len; i++){
		if(document.forms[formname].elements[i].type == 'radio'){
			val = getSelectedRadioValue(document.forms[formname].elements[i]);
			if(val == 1){
				Show(document.forms[formname].elements[i].name+"_row");
			}
		}
	}
}

function showDesc(){
//	alert('begin showing desc:');
	var bankruptcy = document.forms[0].elements['bankruptcy'];
	bankruptcy = bankruptcy.length;
//	alert(bankruptcy);
//	var bankruptcy = getCheckedValue(document.forms[0].bankruptcy);
//	alert(bankruptcy);


	/*var ids = new Array();
	ids[0] = 'bankruptcy';
	ids[1] = 'judgements';
	ids[2] = 'liens';	
	ids[3] = 'foreclosures';*/
	
//	for(x = 0; x < ids.length; x++) 
//		alert(ids[x].value);
//		var foo = getSelectedRadioValue(ids[x]);
//		alert(x + ' ' + foo);
//		alert(ids[x]);
		// problem seems to be with this function
//		var foo = getSelectedRadioValue(ids[x]);
//		alert(foo);
//		document.write(ids[x] + "<br>");

//	if(foo)
//		alert('bankrupt');
//	else 
//		alert('not bankrupt');
}

function showHideChannel(){
	var	source = getDropDownValue('source');
	if(source == "111"){
		hideOne('channel');		
		showOne('channelRBSL');		
		shiftFocus('channelRBSL');
	} else {
		hideOne('channelRBSL');
		showOne('channel');
		shiftFocus('channel');		
	}
}


/******************************************************/
/*  GENERAL DOM FUNCTIONS FOR HIDING/SHOWING ELEMETS  */
/******************************************************/
var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById) {
	isID = 1; 
	isDHTML = 1;
} else {
		if (document.all) {
			isAll = 1; isDHTML = 1;
		} else {
			browserVersion = parseInt(navigator.appVersion);
			if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
				isLayers = 1; isDHTML = 1;
		}
	}
}

function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return (document.getElementById(objectID).style) ; }
		else {
			if (isAll) { return (document.all[objectID].style); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
	else {
		if (isID) { return (document.getElementById(objectID)) ; }
		else {
			if (isAll) { return (document.all[objectID]); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
}


function hideOne (e) {
	var dom = findDOM(e,1);
	dom.display = "none";
}

function showOne(e)	{
	var dom = findDOM(e,1);
	dom.display = "";
}


function getDropDownValue (name){
	var index = document.forms[0][name].options.selectedIndex;
	var selected_value = document.forms[0][name].options[index].value;
	return selected_value;
}


function getSelectedRadio(buttonGroup) {
	// returns the array number of the selected radio button or -1 if no button is selected
	var foo = buttonGroup.length;
	if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		for (var i=0; i<buttonGroup.length; i++) {
			if (buttonGroup[i].checked) {
				return i;
			}
		}
	} else {
		if (buttonGroup.checked) {
			return 0;  // if the one button is checked, return zero
		}
	}// if we get to this point, no radio button is selected
	return -1;
} // Ends the "getSelectedRadio" function




function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function
/*******************************************/
/* END DOM FUNCTIONS                       */
/*******************************************/

//****************************
// BEGIN HINT BOX FUNCTIONS **
//****************************

var horizontal_offset="9px" //horizontal offset of hint box from anchor link
var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge"){
		var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
	} else {
		var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
	}
	return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
	if ((ie||ns6) && document.getElementById("hintbox")){
		dropmenuobj=document.getElementById("hintbox")
		dropmenuobj.innerHTML=menucontents
		dropmenuobj.style.left=dropmenuobj.style.top=-500
		if (tipwidth!=""){
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=tipwidth
		}
	dropmenuobj.x=getposOffset(obj, "left")
	dropmenuobj.y=getposOffset(obj, "top")
	dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
	dropmenuobj.style.visibility="visible"
	dropmenuobj.style.zIndex="999"
	obj.onmouseout=hidetip
	}
}

function hidetip(e){
	dropmenuobj.style.visibility="hidden"
	dropmenuobj.style.left="-500px"
}

function createhintbox(){
	var divblock=document.createElement("div")
	divblock.setAttribute("id", "hintbox")
	document.body.appendChild(divblock)
}



if (window.addEventListener)
	window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
	window.attachEvent("onload", createhintbox)
else if (document.getElementById)
	window.onload=createhintbox

//**************************
// END HINT BOX FUNCTIONS **
//**************************
