function swapPhoto(){
    origPhoto = document.getElementById('origPhoto').src;
    paraFirst = document.getElementsByTagName('p')[0];
    newPhoto = document.createElement('img');
    newPhoto.src = origPhoto
    newPhoto.setAttribute("id", "newPhoto");
    paraFirst.appendChild(newPhoto);
}

function insertPhoto(){
    var objOfficePic = document.getElementById('OfficePic');
    if (objOfficePic != null){
        origPhoto = document.getElementById('origPhoto').src;
        objOfficePic.src = origPhoto;
    }
}

function insertSlideShow(agencyNo) {
    var objSlideShow = document.getElementById("SlideShow");
    if (objSlideShow != null){
        newURL = "http://www.unitedcountry.com/AgencyFeaturedProperties.aspx?AgencyNo=" + agencyNo;
        objSlideShow.innerHTML = "<iframe src=" + newURL + " marginwidth=1 marginheight=1 scrolling=no align=center frameborder=0 />";
    }
}

function hideBody() {
	document.getElementById('pageContent').style.visibility="hidden";
	document.getElementById('pageContent').style.display="none";
	document.getElementById('swapContent').style.visibility="visible";
	document.getElementById('swapContent').style.display="block";
	return frame;
}

function extractURL() {
	var query = window.location.search.substring(1);
	position = query.indexOf('url=') 
	position = position + 4 //move to end of 'url='
	newURL = query.substr(position);
	return frame;
}

function frame() {
	var query = window.location.search.substring(1);

	if (query.indexOf('frame=quick') > -1) {
  	    var query = window.location.search.substring(1);
	    var agencyNo;
		hideBody();
	    position = query.indexOf('agency=') 
	    position = position + 7 //move to end of 'url='
	    agencyNo = query.substr(position);
		newURL = "http://www.unitedcountry.com/aa/ALLOfficeListings.asp?office=" + agencyNo;
		document.getElementById('frame').src = newURL;
	}
	
	if (query.indexOf('frame=area') > -1) {
  	    var query = window.location.search.substring(1);
	    var agencyNo;
		hideBody();
	    position = query.indexOf('agency=') 
	    position = position + 7 //move to end of 'url='
	    agencyNo = query.substr(position);
		newURL = "http://www.unitedcountry.com/aa/officeareainformation.asp?office=" + agencyNo;
		document.getElementById('frame').src = newURL;
	}

	if (query.indexOf('frame=about') > -1) {
  	    var query = window.location.search.substring(1);
	    var agencyNo;
		hideBody();
	    position = query.indexOf('agency=') 
	    position = position + 7 //move to end of 'url='
	    agencyNo = query.substr(position);
		newURL = "http://www.unitedcountry.com/aa/officeaboutus.asp?office=" + agencyNo;
		document.getElementById('frame').src = newURL;
	}
	
	if (query.indexOf('frame=contact') > -1) {
  	    var query = window.location.search.substring(1);
	    var agencyNo;
		hideBody();
	    position = query.indexOf('agency=') 
	    position = position + 7 //move to end of 'url='
	    agencyNo = query.substr(position);
		newURL = "http://www.unitedcountry.com/forms/form_cdo.asp?office=" + agencyNo + "&Resp=3";
		document.getElementById('frame').src = newURL;
	}	
	
	if (query.indexOf('frame=detail') > -1) {
  	    var query = window.location.search.substring(1);
	    var agencyNo;
		hideBody();
	    position = query.indexOf('agency=') 
	    position = position + 7 //move to end of 'url='
	    agencyNo = query.substr(position);
		newURL = "http://www.unitedcountry.com/aa/OfficeDetailedSearch.asp?office=" + agencyNo;
		document.getElementById('frame').src = newURL;
	}
	
	if (query.indexOf('frame=buyers') > -1) {
		hideBody();
		extractURL();
		newURL = "http://www.unitedcountry.com/AA/BuyersAndSellers.htm?office=" + agencyNo;		
		document.getElementById('frame').src = newURL;
	}
	
	if (query.indexOf('frame=privacy') > -1) {
		hideBody();
		newURL = "http://www.unitedcountry.com/privacystatement.htm";
		document.getElementById('frame').src = newURL;
	}

	if (query.indexOf('frame=terms') > -1) {
		hideBody();
		newURL = "http://www.unitedcountry.com/termsofuse.htm";
		document.getElementById('frame').src = newURL;
    }
    return;
}

$(document).ready(function() {

    var link = $('#origPhoto').attr('src');
    $('#OfficePic').attr('src', link);

});