// Chicago Agent Functions

// Check Registration Form

function checkRegistration(theForm) {
  if (!checkText(theForm.sEmail,"Please enter your Email Address.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.sFirstName,"Please enter your First Name.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.sLastName,"Please enter your Last Name.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.sPassword,"Please enter a Password.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.sScreenName,"Please enter a Screen Name.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.iCatId,"Please select a Title.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.iStateId,"Please select a State.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.sCity,"Please enter a City.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.sCompany,"Please enter your Company's Name.", "yes"))  {
    return false;
  }
  if (!checkText(theForm.iOptIn,"Please choose whether you wish to Opt-In to Email notifications.", "yes"))  {
    return false;
  }
  return true;
}

// Check New Construction Submission forms (Chicago)

function checkNewConstruction(theForm) {
	if(!checkText(theForm.sAddress, "Please enter an address.", "yes")) {
		return false;
	}
	if(!checkText(theForm.sCity, "Please enter a city.", "yes")) {
		return false;
	}
	if(theForm.sCity.value == "Chicago" || theForm.sCity.value == "chicago" || theForm.sCity.value == "CHICAGO"){
		if(!checkText(theForm.sNeighborhood, "You have entered Chicago as the City. Please fill in the neighborhood field.", "yes")) {
			return false;
		}
	}
	if(!checkText(theForm.sPrice, "Please enter a price or a price range.", "yes")) {
		return false;
	}
	if(!checkText(theForm.tDescription, "Please enter a description for this property.", "yes")) {
		return false;
	} else if(!checkMin(theForm.tDescription, 300, "You must enter between 300 and 500 characters for the property description.")){
		return false;
	}
	if(!checkText(theForm.sMonth, "Please enter a delivery month for this property.", "yes")) {
		return false;
	}
	if(!checkText(theForm.sYear, "Please enter a delivery year for this property.", "yes")) {
		return false;
	}
	if(!checkText(theForm.sDeveloper, "Please fill in the developer field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sCommission, "Please fill in the co-op commission field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sAgent, "Please fill in the listing agent's name field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sCompany, "Please fill in the listing agent's company field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sPhone, "Please fill in the listing agent's contact number field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sEmail, "Please fill in the listing agent's email address field.", "yes")){
		return false;
	}
	return true;
}

// Check New Construction Submission forms (Miami)

function checkNewConstructionMiami(theForm) {
	if(!checkText(theForm.sAddress, "Please enter an address.", "yes")) {
		return false;
	}
	if(!checkText(theForm.sCity, "Please enter a city.", "yes")) {
		return false;
	}
	if(!checkText(theForm.sPrice, "Please enter a price or a price range.", "yes")) {
		return false;
	}
	if(!checkText(theForm.tDescription, "Please enter a description for this property.", "yes")) {
		return false;
	} else if(!checkMin(theForm.tDescription, 250, "You must enter between 250 and 400 characters for the property description.")){
		return false;
	}
	if(!checkText(theForm.sMonth, "Please enter a delivery month for this property.", "yes")) {
		return false;
	}
	if(!checkText(theForm.sYear, "Please enter a delivery year for this property.", "yes")) {
		return false;
	}
	if(!checkText(theForm.sDeveloper, "Please fill in the developer field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sCommission, "Please fill in the co-broke commission field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sAgent, "Please fill in the listing agent's name field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sCompany, "Please fill in the listing agent's company field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sPhone, "Please fill in the listing agent's contact number field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sEmail, "Please fill in the listing agent's email address field.", "yes")){
		return false;
	}
	return true;
}

// Open pop-up of supplied url

function openWindow(url){
	if(!url==""){
		// open var url in a new window
		window.open(url,"Window","width=700,height=700,menubar=no,toolbar=no,location=no,status=no,scrollbars=yes");
	}
}

// cache any images used in CSS rollovers

function loadImages(url){
	if(document.images && url != '') {
		// obtain server url to load images from host (thisHost)
		pic1= new Image();
	}
}

// stretch column heights based on offsetHeight to keep columns the same height

 function stretchColumn() {
 	if($('content')){
		$('content').style.height = 'auto';
		var contentSize = $('content').offsetHeight;
	}
	$('leftnav').style.height = 'auto';
	var leftNavSize = $('leftnav').offsetHeight;
	var rightNavSize = $('rightnav').offsetHeight;
	
	if(leftNavSize > contentSize){
		$('content').style.height = leftNavSize + "px";
	} else if(rightNavSize > (contentSize + 217) && rightNavSize > (leftNavSize + 217)){
		$('leftnav').style.height = (rightNavSize - 217) + "px";
		if($('content')){
			$('content').style.height = (rightNavSize - 217) + "px";
		}
		if($('contentLeft')){
			$('contentLeft').style.height = (rightNavSize - 217) + "px";
		}
	} else 	if(contentSize > leftNavSize){
		$('leftnav').style.height = contentSize + "px";
	} else if (contentSize > rightNavSize) {
		$('rightnav').style.height = (contentSize + 217) + "px";
	} else {
		if($('content')){
			$('content').style.height = leftNavSize + "px";
		}
	}
	if($('contentLeftInterior') && $('contentRightInterior')){
		$('contentLeftInterior').style.height = 'auto';
		$('contentRightInterior').style.height = 'auto';
		var contentLeftSize = $('contentLeftInterior').offsetHeight;
		var contentRightSize = $('contentRightInterior').offsetHeight;
		if(contentLeftSize < contentRightSize){
			$('contentLeftInterior').style.height = contentRightSize + "px";
		} else {
			$('contentRightInterior').style.height = contentLeftSize + "px";
		}
	}
}

function CheckForm() {
	var errorMsg = '';
	var formArea = document.getElementById('frmMessageForm');

	//For Gecko Madis API (RTE)
	if (formArea.message.value.indexOf('<br>') > -1 && formArea.message.value.length==5) formArea.message.value = '';


	//Check for message
	if (formArea.message.value==''){
		errorMsg += '\n\tMessage Box \t\t- Enter a Message to Submit\n(You may need to disable script blocking software on your PC)';
	}

	//If there is aproblem with the form then display an error
	if (errorMsg != ''){
		msg = '_______________________________________________________________\n\n';
		msg += 'The form has not been submitted because there are problem(s) with the form.\n';
		msg += 'Please correct the problem(s) and re-submit the form.\n';
		msg += '_______________________________________________________________\n\n';
		msg += 'The following field(s) need to be corrected: -\n';

		errorMsg += alert(msg + errorMsg + '\n\n');
		return false;
	}

	return true;
}

//Function to choose how many topics are show
function ShowTopics(Show){

   	strShow = escape(Show.options[Show.selectedIndex].value);

   	if (Show != '') self.location.href = 'pre_approved_topics.asp?MT=' + strShow + '&PN=1';
	return true;
}

//Function to choose how many topics are show
function ShowTopics(Show){

   	strShow = escape(Show.options[Show.selectedIndex].value);

   	if (Show != '') self.location.href = 'pre_approved_topics.asp?MT=' + strShow + '&PN=1<% = strQsSID2 %>';
	return true;
}

function viewByCategory(){
	if($('category').value && $('state').value){
		location.href="/resources/jobs.asp?category=" + $('category').value + "&state=" + $('state').value;
	} else if($('category').value) {
		location.href="/resources/jobs.asp?category=" + $('category').value;
	} else {
		location.href="/resources/jobs.asp";
	}
	return true;
}

function viewByState(){
	if($('category').value && $('state').value){
		location.href="/resources/jobs.asp?category=" + $('category').value + "&state=" + $('state').value;
	} else if($('state').value) {
		location.href="/resources/jobs.asp?state=" + $('state').value;
	} else {
		location.href="/resources/jobs.asp";
	}
	return true;
}

function checkJobPosting(theForm){
	if(!checkText(theForm.sTitle, "Please fill in the Title field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sCompany, "Please fill in the Company field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sCity, "Please fill in the City field.", "yes")){
		return false;
	}
	if (!checkPullDown(theForm.iStateId, "Please select a State.", "yes")) {
		return false;
	}
	if (!checkPullDown(theForm.iCatId, "Please select a Category.", "yes")) {
		return false;
	}
	if(!checkText(theForm.tDetails, "Please fill in the Description field.", "yes")){
		return false;
	}
	if(!checkText(theForm.sContact, "Please fill in the How to Apply field.", "yes")){
		return false;
	}
	return true;	
}

// Validate Calendar of Events form
function checkEvent(theForm)
{
	if (!checkText(theForm.sTitle,"Please fill in the \"Title\" field!", "yes"))	{
		return false;
	}
	if (!checkDate(theForm.dStartDate, "yes")){
		return false;
	}
	if (!checkText(theForm.sLocation,"Please fill in the \"Location\" field!", "yes"))	{
		return false;
	}
	if (!checkText(theForm.sCity,"Please fill in the \"City\" field!", "yes"))	{
		return false;
	}
	if (!checkPullDown(theForm.iStateId,"Please select a State!", "yes"))	{
		return false;
	}
	if (!checkText(theForm.sDetail,"Please fill in the \"Description\" field!", "yes"))	{
		return false;
	}
	return true;
}

// Validate Editorial Submissions

function checkEditorial(theForm)
{
	if(!checkText(theForm.sTitle,"Please fill in the \"Title\" field!", "yes")) {
		return false;
	}
	if(!checkText(theForm.tBody,"Please fill in the \"Body\" field!", "yes")) {
		return false;
	}
	return true;
}

// Check End Dates against Start Dates

function checkEndDate(){
	if($('dEndDate').value && $('dStartDate').value){
		if($('dEndDate').value < $('dStartDate').value){
			$('dEndDate').value = $('dStartDate').value;
		}
	} else if($('dEndDate').value && !$('dStartDate').value){
		$('dStartDate').value = $('dEndDate').value;
	}
	return true;
}