/*
| javascript library
| Robert Huttinger
| roberthuttinger@traveldocument.com
| 11-01-2007
*/
//////////////////////////////////////////////////////////////////////////////////////
    //=========================================================================
    //                             editbusiness.php                           =
    //=========================================================================
// set all the vars to nothing
var title = "";
var subtitle = "";
var address1 = "";
var address2 = "";
var city = "";
var state = "";
var zip = "";
var phone1 = "";
var phone2 = "";
var fax = "";
var email1 = "";
var email2 = "";
var owner = "";
var owneremail = "";
var contact = "";
var contactemail = "";
// displayText is used for the alrt box in updateBusInfo function
var displayText = "";

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// when the function is called populate the alert box with a rough preview
function updateBusInfo() {
	
	// clear the var for each use
	displayText = "";
	
	title = document.getElementById('title').value;
	  if (title != "") { displayText += title + "\r"   }
	  
	subtitle = document.getElementById('subtitle').value;
	  if (subtitle != "") { displayText += subtitle + "\r"   }
	  
	address1 = document.getElementById('address1').value;
	if (address1 != "") { displayText += address1   }
	
	address2 = document.getElementById('address2').value;
	if (address2 != "") { displayText += " " + address2   }
	
	city = document.getElementById('city').value;
	if (city != "") { displayText += "\r" + city   }
	
	state = document.getElementById('state').value;
	if (state != "") { displayText += " " + state   }
	
	zip = document.getElementById('zip').value;
	if (zip != "") { displayText += " " + zip   }
	
	phone1 = document.getElementById('phone1').value;
	if (phone1 != "") { displayText += "\rp" + phone1   }
	
	phone2 = document.getElementById('phone2').value;
	if (phone2 != "") { displayText += " p" + phone2   }
	
	fax = document.getElementById('fax').value;
	if (fax != "") { displayText += " f" + fax   }
	
	email1 = document.getElementById('email1').value;
	if (email1 != "") { displayText += "\r" + email1   }
	
	email2 = document.getElementById('email2').value;
	if (email2 != "") { displayText += " " + email2   }
	
	owner = document.getElementById('owner').value;
	if (owner != "") { displayText += "\r" + owner   }
	
	owneremail = document.getElementById('owneremail').value;
	if (owneremail != "") { displayText += " " + owneremail   }
	
	contact = document.getElementById('contact').value;
	if (contact != "") { displayText += "\r" + contact   }
	
	contactemail = document.getElementById('contactemail').value;
	if (contactemail != "") { displayText += " " + contactemail   }
	
    // update the textbox for a preview
    document.getElementById('previewBox').value = displayText;

}
    //=========================================================================
    //                           end editbusiness.php                         =
    //=========================================================================
	
//////////////////////////////////////////////////////////////////////////////////////

    //=========================================================================
    //                                edit.php                                =
    //=========================================================================

function expandtextarea(which, areaAffected, whichEd) {  // start expandtextarea
var areaAffected = areaAffected;
	if(which==0) { // add rows
		document.getElementById(areaAffected).rows+1;
		document.getElementById(areaAffected).style.height=document.getElementById(areaAffected).offsetHeight+250+"px";
	} else if(which==3) { // onfocus make the box bigger
		document.getElementById(areaAffected).cols=50;
		document.getElementById(areaAffected).style.width=576+"px"; // 70 cols
		document.getElementById(areaAffected).rows=3;
		document.getElementById(areaAffected).style.height=659+"px"; // 1 row

	} else if(which==2) { // onblur return to small size
		document.getElementById(areaAffected).cols=50;
		document.getElementById(areaAffected).style.width=576+"px"; // 70 cols
		document.getElementById(areaAffected).rows=3;
		document.getElementById(areaAffected).style.height=33+"px"; // 1 row
		
	} else { // add columns
		document.getElementById(areaAffected).cols+1;
		document.getElementById(areaAffected).style.width=document.getElementById(areaAffected).offsetWidth+50+"px";
	}
// clear the var
areaaffected = "";
} // end expandtextarea

// function to open or close div - state based

function divTagToggle(whichEd) {
	if (document.getElementById(whichEd).style.display == "none") { var num = 1; }
	if (num == 1) {
	    // open tag
	    document.getElementById(whichEd).style.display = "block";
	} else {
	    // close tag
	    document.getElementById(whichEd).style.display = "none";
	}
} // close function divTagToggle

function editorToggle(num, whichEd) {
	if (num == 1) {
	    // turn on buttons
	    document.getElementById(whichEd).style.display = "block";
	} else {
	    // turn off buttons
	    document.getElementById(whichEd).style.display = "none";
	}
} // close editorToggle

// function to open or close the editor

function editorToggle(num, whichEd) {
	if (num == 1) {
	    // turn on buttons
	    document.getElementById(whichEd).style.display = "block";
	} else {
	    // turn off buttons
	    document.getElementById(whichEd).style.display = "none";
	}
}

function addLinkHere(id) {
	var e = document.getElementById(id);
	var linktitle = prompt("What is the title of the link?", "");
	var linkurl = prompt("What is the URL of the link? \n ex: http://www.google.com", "");
	var ltarget = prompt("1: Different Window/Tab \n2: Same Window/Tab \n Enter 1 or 2", "");
	var lcode = "";
	if (ltarget == 1) {
		lcode = ' target="_blank"';
	} else {
		lcode = "";
	}
	e.value+='<a href="' + linkurl + lcode + ' title="' + linktitle+'">' + linktitle+'</a>';
}

function addImageHere(id) {
	var e = document.getElementById(id);
	var imgtitle = prompt("What is the title of the image?", "");
	var imgurl = prompt("What is the URL of the link? \n ex: http://www.google.com/image.jpg", "");
	var imgborder = prompt("Border? \n enter 0, 1, 2, or 3", "");
	var imgheight = prompt("Height in pixels \nLeave blank or enter 20-200", "");
	var imgwidth = prompt("Width in pixels \nLeave blank or enter 20-200", "");
	e.value+='<img src="' + imgurl + '" border="' + imgborder + '"  height="' + imgheight +  '" width="' + imgwidth + '" alt="' + imgtitle+'" />';
}



//  function to insert text at the insertion point
/**
@param textObj could be a text area or a text field
Only required for IE
*/
function setCaret (textObj) {
if (textObj.createTextRange) {
textObj.caretPos = document.selection.createRange().duplicate();
}
}

/**
@param textObj could be a text area or a text field
@param text field value that needs to be inserted in
*/
function insertAtCaret (textObj, textFeildValue) {
if(document.all){
if (textObj.createTextRange && textObj.caretPos) {
var caretPos = textObj.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?textFeildValue + ' ' : textFeildValue;
}else{
textObj.value = textFeildValue;
}
}else{
if(textObj.setSelectionRange){
var rangeStart = textObj.selectionStart;
var rangeEnd = textObj.selectionEnd;
var tempStr1 = textObj.value.substring(0,rangeStart);
var tempStr2 = textObj.value.substring(rangeEnd);
textObj.value = tempStr1 + textFeildValue + tempStr2;
}else{
alert("This version of Mozilla based browser does not support setSelectionRange");
}
}
}



    //=========================================================================
    //                              end edit.php                              =
    //=========================================================================
	
	
	// change on select event
	
function changeTextBox(xelement, xvalue) {
	document.getElementById(xelement).value = xvalue;
}

    // jump menu
function MM_jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//  open called div then close all other divs in set.

function selectedDiv(which, numDivs) {
	document.getElementById(which).style.display = "block";
}

function turnOff(whichOff) {
	document.getElementById(whichOff).style.display = "none";
}

// function for turning on / off an element onclick
function displayDivz(which) {
	if (document.getElementById(which).style.display == "none") {
	  document.getElementById(which).style.display = "block";
	} else {
	  document.getElementById(which).style.display = "none";
	}
}

// functions for opening a single div when clicked, then closing all others by class="NAME"

// dont forget body onload="closeNav();" or close them to begin with

function closeNav(classNamez) {
    var x = document.getElementsByTagName('div');
	    for (var i=0;i<x.length;i++) {
		    if (x[i].className == classNamez)
			    x[i].style.display = 'none';
	    }
}

function openSingleDiv(which, classNamez, zImg) {
	openSingleDivImg(zImg);
    closeNav(classNamez);
    document.getElementById(which).style.display = "block";
}

// functions for changing the src of an img when clicked, then reverting all others by class="NAME"

// dont forget body onload="closeNav();" or close them to begin with

function closeNavImg(classNamez) {
    var x = document.getElementsByTagName('span');
	    for (var i=0;i<x.length;i++) {
		    if (x[i].className == "passportstepsz")
			    x[i].style.backgroundImage = 'url(devimages/tde_steps_d3.gif)';
	    }
}

function openSingleDivImg(zImg, classNamez) {
    closeNavImg(classNamez);
    document.getElementById(zImg).style.backgroundImage = 'url(devimages/tde_steps_d3on.gif)';
}

// swap images function takes id of target then name of image to change to
function swapImage(targetImage, newImage) {
	document.getElementById(targetImage).src = "devimages/" + newImage + ".gif";
}

// open window

function openwindow(omgform) {
	var zOMGform = "forms/" + omgform;
window.open('getform.php?form=' , 'newwindow', 'width=200,height=200,scrollbars=no');
}

function addFormLink(omgform, whichdivform) {
	var tempomgform = document.getElementById(omgform).value;
  document.getElementById(whichdivform).innerHTML += "<a href='forms/" + tempomgform + "'>" + tempomgform + "</a><br />";	
}

function deleteFormLink(omgform, whichdivform) {
	var tempomgform = document.getElementById(omgform).value;
  document.getElementById(whichdivform).innerHTML += "<a href='delete.php?dform=" + tempomgform + " onclick=\"return confirm('Really delete?');\"'>Really Delete " + tempomgform + "</a><br /><br />";	
  // <a href="delete.php" onclick="return confirm('Really delete?');"> Delete record </a>
}