/* Copyright (c) 2004,2005 Talkingstone Solutions.    **
** This source may not be reproduced in any           **
** form without the express written consent of        **
** Talkingstone Solutions.                            **/
var loadEvents = new Array();
function registerLoadEvent(loadEvent){	loadEvents[loadEvents.length] = loadEvent;}
function launchPageEvents(){
	for(var i=0;i<loadEvents.length;i++){		eval(loadEvents[i]);	}}
function init(){	var relXpos = document.getElementById("logoMiddle").style.width;	var relYpos = document.getElementById("logoMiddle").style.top;	document.getElementById("quickSearch").style.left 	= (parseInt(relXpos.substring(0,relXpos.length-2))+25) +"px";	document.getElementById("quickSearch").style.top 	= "55px"; 
// relYpos;	document.getElementById("quickSearch").style.visibility= "visible";
}
function clearStatus(){	window.status = "";	return false;}
function execute(event,action,secure){ _form = this.document.forms[0]; _form.target="_self"; if(event.length>0){ _form.event.value = event; if(action.length>0) {  _form.subEvent.value = action; } if(_form.secure && _form.secure.value=="true")  _form.method="post";  if(!secure){ _form.action='/whippoorwill/fsbo/'; _form.submit(); } else if(secure=='1'){ _form.action="https://www.fsbozone.com/whippoorwill/fsbo/"; _form.submit(); } else if(secure=="0"){ window.location.href="http://www.fsbozone.com/"; _form.submit(); } } else { alert("Please check your entry and try again."); }}
function expandContract(item){	if(this.document.getElementById(item).style.display=="none"){		this.document.getElementById(item).style.display = "";	} else {		this.document.getElementById(item).style.display = "none";	}}
function expand(item){	this.document.getElementById(item).style.display = "inline";}
function contract(item){this.document.getElementById(item).style.display = "none";}
function addListItem(list,text,value){	var selectList = this.document.forms[0][list];	var newOption = new Option();	    newOption.text 	= text;	    newOption.value 	= value;  	    selectList.options[selectList.options.length]=newOption;}
function clearList(list){	var selectList = this.document.forms[0][list];	    selectList.options.length=0;}
function stringTokenizer(str,token){	return new Array( str.split(token) );}
function show(id){	this.document.getElementById(id).style.display='inline';}
function hide(id){	this.document.getElementById(id).style.display='none';}
function setFieldValue(id,value){       this.document.forms[0][id].value = value;}
function replace(anyText, a, b){	var outgoing = anyText;	var stringScrubber = null;	    stringScrubber = new RegExp();	    stringScrubber.compile(a, "gi");	    stringScrubber.multiline=true;	    outgoing = outgoing.replace(stringScrubber,b);	return outgoing;}
function setEnctype(type){	if(type=="multipart") 	this.document.forms[0].enctype="multipart/form-data";	else			this.document.forms[0].enctype="application/x-www-form-urlencoded";}
function getValue(field){	return this.document.forms[0][field].value;}
function setValue(field,value){	this.document.forms[0][field].value=value;}
function filter(field){	var fieldType = field.type;	switch(fieldType){            case 'numeric':		validateNumber(field);	}}
function validateNumber(field){	if(field.value.isNaN()) {		field.focus();		return false;	}else{		return true;	}}
var remote;
function openWindow(page,w,h){	var remotePage  = (page)? page : "";	var width  	= (w) ? w : 215;	var height	= (h) ? h :  150;	if(!remote || remote.closed){		remote = window.open(remotePage,"stub","status=0,height="+height+",width="+width+",toolbar=0");		if(!remote.opener)		{			remote.opener = window;		}		if(remote.focus)		{			remote.focus();		}	}	else if(remote.focus){		remote.focus();	}}
function getPX(value){    return value.substring(0,value.length-2);}
function documentWordFilter(textDocument){
	// will match any word bounded by various seperators or common word boundries
	var documentWords = new Array();
	var searchexp = new RegExp();
	searchexp.compile(/[A-Za-z][^\d|\s|,|.|:|\)|\(|#|s][\w]*/g);
	searchexp.multiline=true;
	documentWords = text.match(searchexp);
	documentWords = removeDuplicates(possibleKeywords);
	documentWords.sort();
	return documentWords;
}
function joinArrays(array_a,a_beginIndex,a_endIndex,array_b,b_beginIndex,b_endIndex){
	var result = new Array();
	var begin 	= array_a.slice(a_beginIndex,a_endIndex);
	var end		= array_b.slice(b_beginIndex,b_endIndex);
	result = begin.concat(end);
	return result;
}
function removeDuplicates(_array)
{
	var alpha 			= _array.toString();
	var beta 			= new Array();
	var currentString	= "";
	var mark			= 0;

	while(alpha.length>0 && alpha.indexOf(",")>-1 )
	{
		if(alpha.substring(0,1)=="," || alpha.substring(0,1)==" ")
		{
			alpha = alpha.substring(1,alpha.length);
		}
		currentString = alpha.substring(0,alpha.indexOf(","));

		if(currentString.length>0 && currentString!=" " && currentString!=",")
		{
			beta[beta.length] = currentString;
		}
		var pattern = (mark==0)
					? "("+currentString+",|,"+currentString+",)"
					: "("+currentString+",)";
		alpha = replaceUtility(alpha,pattern,',');
		++mark;
	}
	return beta;
}
function isDateRangeValid(limit){ // limit active date to 7 days frome approval

	var today 		= new Date();
	var retireYear 	= document.forms[0].retireYear.value;
	var retireMonth = document.forms[0].retireMonth.value;
	var retireDay 	= document.forms[0].retireDay.value;
	var retireDate 	= new Date(retireYear,(retireMonth-1),retireDay);
	var diff = Math.ceil((retireDate - today)/1000/60/60/24);

	if(diff<=limit){
		return true;

	} else {
		alert("Please enter a new date no later than "+limit+" days from present.");
		return false;
	}
}

// code for list management
function addItemToList(srcList, targetList){

	var forms = this.document.forms[0];

	if(srcList.selectedIndex>-1){

		var newElement = document.createElement("OPTION");
			newElement.text 	= srcList[srcList.selectedIndex].text;
			newElement.value 	= srcList[srcList.selectedIndex].value;

		if(targetList!="selectedKeywords" || (targetList=="selectedKeywords" && forms.selectedKeywords.options.length<101) )
		{
			forms[targetList].options.add(newElement);
			srcList.remove(srcList.selectedIndex);
			sortList(targetList);
		}
		else
		{
			alert("You have reached the maximum number of keywords.\nIf you would like to add your selection, please remove one from the selected list.");
		}
	}
	else
	{
		alert("Nothing is selected.");
	}
}

function sortList(srcList) // will sort any selectBox
{
	var forms = this.document.forms[0];
	var holder = new Array();

	for(var i=0;i<forms[srcList].options.length;++i)
	{
		holder[i] = forms[srcList].options[i].text;
	}

	forms[srcList].length=0;
	holder.sort();

	for(var j=0;j<holder.length;++j)
	{
		var newElement = document.createElement("OPTION");
			newElement.text 	= holder[j];
			newElement.value 	= holder[j];
		forms[srcList].options.add(newElement);
	}
}

var scrolling = false;
function scrollVertically(container,dir){

	if(scrolling){

		var top = parseInt(siftPX(this.document.getElementById(container).style.top));

		if(dir=="dn")
			this.document.getElementById(container).style.top = parseInt(siftPX(this.document.getElementById(container).style.top))-SCROLL_FACTOR;
		else if(top<0)
			this.document.getElementById(container).style.top = parseInt(siftPX(this.document.getElementById(container).style.top))+SCROLL_FACTOR;
	}
}
function selectAll(fieldType,fieldName){
    var field = this.document.forms[0][fieldName];
    if(fieldType=="select"){
        for(var i=0;i<field.options.length;++i){
            field[i].selected=true;
        }
    } else {
        alert("This function is not available for "+fieldType+"!");
    }
}
function swapImage(id,newImage){
    document.images[id].src = newImage;
}
function loadImages(){
    var doc,args,i,j;
    doc=document;
    args = loadImages.arguments;
    if(!doc.library)
        doc.library = new Array();
    i=0,j=doc.library.length;
    for(var i=0;i<args.length;++i){
        doc[j] = new Image;
        doc[j++].src = args[i];
    }
}
function initQuickSearch(){
    this.document.getElementById("quickSearch").style.position="absolute";
        this.document.getElementById("quickSearch").style.left="-1px";
        setTimeout("toggleSearch()",1);
        this.document.getElementById("quickSearch").style.top="130px";
        this.document.getElementById("quickSearch").style.display="inline";
}
var tabstate = "open",animeIncrement = 5;
function toggleSearch(){

    with(this.document){
        var pos = getPX(getElementById("quickSearch").style.left);                
        if( tabstate == "open" && getPX( getElementById("quickSearch").style.left ) > -130 ) {
                getElementById("quickSearch").style.left = 
                            (
                                getPX(getElementById("quickSearch").style.left) - animeIncrement
                            )+"px";
                setTimeout("toggleSearch()",1);

        } else  if( tabstate == "closed" && getPX( getElementById("quickSearch").style.left ) < -1 ) {

                getElementById("quickSearch").style.left = 
                            (
                                parseInt( getPX( getElementById("quickSearch").style.left ) ) + animeIncrement
                            )+"px";
                setTimeout("toggleSearch()",1);
        } else {
            tabstate = (tabstate=="open")?"closed":"open";
        }
    }
}
function activateEngine(level){ 
    this.document.forms[0].level.value=level; 
    this.document.forms[0].action="/whippoorwill/fsbo/"; 
    this.document.forms[0].event.value = "dataEngine"; 
    this.document.forms[0].subEvent.value = level; 
    this.document.forms[0].target="engine"; 
    this.document.forms[0].submit();}
function _getEngineData(level){ 
    if(level=="getSearchMetrosByState"){ 
        loadSelectData('searchState','searchMetros',parent.frames["engine"]._data_0,1,0); 
    } else if(level=="getSearchTerritoriesByMetro"){ 
        loadSelectData('searchMetros','searchTerritories',parent.frames["engine"]._data_0,1,0); 
    } else { 
        try{  
            getEngineData(level); 
        } catch(er){} 
    }
}
function loadSelectData(srcList,targetList,dataSet,keyIndex,textIndex){
    var key = (keyIndex) ? keyIndex : 0;
    var text = (textIndex) ? textIndex : 1;
    var code = this.document.forms[0][srcList][this.document.forms[0][srcList].selectedIndex].value;
    this.document.forms[0][targetList].length=0;
    for( var cnt=0; cnt < dataSet.length; ++cnt ){
//        if(code==dataSet[cnt][keyIndex]){
            var newElement = document.createElement("OPTION");
            newElement.text 	= dataSet[cnt][text];
            newElement.value 	= dataSet[cnt][key];
            this.document.forms[0][targetList].options.add(newElement);
//        }
    }
}
function getObjReference(id){
    return document.getElementById(id);
}
function getImgReference(id){
    return document.images[id];
}
function toggleDisplay(id,val){ 
    if(this.document.getElementById(id) && null!=val) 
        this.document.getElementById(id).style.display=val; 
    else if(this.document.getElementById(id) && this.document.getElementById(id).style.display=="none") 
        this.document.getElementById(id).style.display=""; 
    else if(this.document.getElementById(id)) 
        this.document.getElementById(id).style.display="none";
}
function print_mail_to_link(address,domain,link)
{
document.write("<A HREF=\"mailto");
document.write(":" + address + "@");
document.write(domain + "\">" + link + "<\/a>");
}
