/****************************************************************************************************************
 * File modification History
 *
 * Revision - 	Katherine Youngblood - 6/21/2006
 *				Commented out a line of code that was causing the page to not display correctly in Firefox
 ***************************************************************************************************************/
// newWindow is the variable which holds the preview window
var newWindow
// this function is called when the user requests a preview
// by pressing the Preview button.
function fncPreviewPage(theLink){
	var thisForm = document.Form4
	// lstFunctions contains the list of Job Functions selected
	var lstFunctions = ""
	var j=0
	for (var i = 0; i < thisForm.functions.length; i++){
		if (thisForm.functions.options[i].selected){
			if (j > 0){
				lstFunctions +=", "
			}
			j +=1
			lstFunctions += thisForm.functions.options[i].text
		}
		}
	// there are similar routines for Category and Region
	var lstCategory = ""
	var j=0
	for (var i = 0; i < thisForm.category.length; i++){
		if (thisForm.category.options[i].selected){
			if (j > 0){
				lstCategory +=", "
			}
			j +=1
			lstCategory += thisForm.category.options[i].text
		}
		}
	var lstRegion = ""
	var j=0
	for (var i = 0; i < thisForm.region.length; i++){
		if (thisForm.region.options[i].selected){
			if (j > 0){
				lstRegion +=", "
			}
			j +=1
			lstRegion += thisForm.region.options[i].text
		}
		}
	// fncPresentCheck checks to be sure that the text box has been filled in.
	// If it hasn't, it returns a zero length string. If it has, it returns
	// the label in bold and the value in normal text as a string.
	var strSalary = fncPresentCheck (thisForm.job_salary.value, "Salary ")
	var strAddress2 = fncPresentCheck (thisForm.recruiter_address2.value, "")
	var strPhone = fncPresentCheck (thisForm.recruiter_phone.value, "Phone ")
	var strFax = fncPresentCheck (thisForm.recruiter_fax.value, "Fax ")
	//var strEmail = fncPresentCheck (thisForm.recruiter_email.value, "Email ")
	//var strWeb = fncPresentCheck (thisForm.recruiter_link.value, "Web ")
	var strEmail = thisForm.recruiter_email.value
	var strWeb = thisForm.recruiter_link.value
	// fncParse creates HTML which translates the Carriage Returns in the
	// Job Description field into BR's
	var txtDescriptionParsed = fncParse(thisForm.job_description.value)
			
	// newContent contains the HTML for the Preview Page
	var newContent="<p>This is a preview of what the posting will look like once submitted. If you are satisfied with the look of your posting, please close this window and press the <em><strong>Submit Listing</strong></em> button on the main page.</p>"
	newContent +="<p><table style='width: 50%'>"
	newContent +="<tr>"
	newContent +="<td><label>Region(s)</label></td>"
	newContent +="<td>" + lstRegion + "</td>"
	newContent +="</tr>"
	newContent +="<tr>"
	newContent +="<td><label>Function(s)</label></td>"
	newContent +="<td>" + lstFunctions + "</td>"
	newContent +="</tr>"
	newContent +="<tr>"
	newContent +="<td><label>Industry(s)</label></td>"
	newContent +="<td>" + lstCategory + "</td>"
	newContent +="</tr>"
	newContent +="<tr>"
	newContent +="</table>"
	newContent +="</p>"
	newContent +="<h3>" + thisForm.job_title.value + "</h3>" 
	newContent +="<p>" + thisForm.job_org_name.value + "<br />"
	newContent +=thisForm.job_location.value + "<br />"
	newContent +=strSalary + "</p>"
	
	// Revision - 	Katherine Youngblood - 6/21/2006
 	//				Commented out the below line of code that was causing the page to not display correctly in Firefox
	//newContent +="<%=Replace(request(\"job_description\"),chr(13),\"<br>\")%>"
	
	newContent +="<p>" + txtDescriptionParsed + "</p>"

	newContent +="<h3>Contact Information</h3>"
	newContent +="<p>"
	newContent +=thisForm.recruiter_contact_name.value + "<br />"
	newContent +=thisForm.recruiter_contact_title.value + "<br />"
	newContent +=thisForm.recruiter_org_name.value + "<br />"
	newContent +=thisForm.recruiter_address1.value + "<br />"
	newContent +=strAddress2
	newContent +=thisForm.recruiter_city.value + ", " + thisForm.recruiter_state.value + "  " + thisForm.recruiter_zip.value + "<br />"
	newContent +=strPhone
	newContent +=strFax
	newContent +="<a href='mailto:" + strEmail + "'>"
	newContent +=strEmail
	newContent +="</a><br />"
	newContent +="<a href='http://" + strWeb + "' target='_blank'>"
	newContent +=strWeb
	newContent +="</a></p>"
	newContent +="<p class='pageNote'><strong><em>Refer to this ad in your response.</em></strong></p>"
	
	var prevForm = document.frmContent
	// this routine checks to see if a preview window is already open. If it is,
	// it closes.
	//if (newWindow && !newWindow.closed){
	///	newWindow.close()
		//newWindow = null
	//}
	
	// these lines open the preview window
	//newWindow=window.open("","","SCROLLBARS,WIDTH=400,HEIGHT=450")
	//newWindow.document.write(newContent)
	//newWindow.document.close
	prevForm.txtContent.value=newContent;
	prevForm.submit();
	//window.frmContent.txtContent.value=newContent;
	//alert(window.frmContent.txtContent.value);
	//window.frmContent.submit();	
	//window.location.href="Post_Preview.asp?txtContent=" + newContent
}
// this is the function that converts the text box Job Description into HTML with BRs
function fncParse(newString){
	var txtDescription = "<br />"
	var loct = 0
	var i=0
	while (newString.length > 0){
		// these are the three platform specific Carriage Return markers
		loct = newString.indexOf("\n")
		loct1 = newString.indexOf("\r")
		loct2 = newString.indexOf("\r\n")
		if (loct == i){
			txtDescription = txtDescription + newString.substring(0,i) + "<br />"
			newString = newString.substring(i+1, newString.length)
			i=-1
		}
		if (loct1 == i){
			txtDescription = txtDescription + newString.substring(0,i) + "<br />"
			if (loct2 == i){
				i=i+1
			}
			newString = newString.substring(i+1, newString.length)
			i=-1
		}
		if (loct == -1 && loct1 == -1){
			txtDescription = txtDescription + newString +"<br />"
			newString=""
		}
	i++
	}
	return (txtDescription)
}
// this function checks if txtTest is present. If it is, it returns it with a bold label.
function fncPresentCheck(txtTest, txtLabel){
	if (txtTest){
		var txtReturn = "<label>" + txtLabel + "</label>" + txtTest + "<br />"
		return txtReturn
	} else {
		return ""
	}
}
// this function fires when the check box is clicked that the recruiter info is the
// same as the billing info.
function funcRecruiterToBilling(theBox) {
	if (theBox.checked) {
		var thisForm = document.Form4
		thisForm.billing_org_name.value=thisForm.recruiter_org_name.value
		thisForm.billing_address1.value=thisForm.recruiter_address1.value
		thisForm.billing_address2.value=thisForm.recruiter_address2.value
		thisForm.billing_city.value=thisForm.recruiter_city.value
		thisForm.billing_state.value=thisForm.recruiter_state.value
		thisForm.billing_zip.value=thisForm.recruiter_zip.value
		thisForm.billing_country.value=thisForm.recruiter_country.value
		thisForm.billing_contact_name.value=thisForm.recruiter_contact_name.value
		thisForm.billing_email.value=thisForm.recruiter_email.value
		thisForm.BILLING_FAX.value=thisForm.recruiter_fax.value
		thisForm.billing_phone.value=thisForm.recruiter_phone.value
	}
	}
// -->
