pic1= new Image(); 
pic1.src="/images/loaders/preloaderWhiteish.gif";
//----------------------------------------------------------------
// XMLHttpRequest Object (cross browser)
//----------------------------------------------------------------

var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

//----------------------------------------------------------------
// Make RPC Call
//----------------------------------------------------------------

var scriptIdCounter = 0;

function rpcCall(scriptId, url, params) {
	
	scriptIdCounter++;
	var scriptId = scriptId + '_' +  scriptIdCounter;
	var head = document.getElementsByTagName('head').item(0);
	var scriptTag = document.getElementById(scriptId);
	var nocache = 'nocache_' + Math.floor(Math.random()*(9999999999)) + '=' + scriptIdCounter;

	if(scriptTag) head.removeChild(scriptTag);
	script = document.createElement('script');
	script.src = url + '?scriptId=' + scriptId + '&' + params + '&' + nocache;
	script.type = 'text/javascript';
	script.id = scriptId;
	if (head.appendChild(script)) {
		return true;
	} else {
		return false;
	}

}
/*

---------------------------------------------------------------------
Cross Browser Modal v1.0 by i-dream solutions
---------------------------------------------------------------------

Usage: 
	openModal(id, title, width, height, src);

	id = Custom id of the window appended to modalWin_
	title = title of modal
	width = int width
	height = int height
	src = page to load


Resources:
 -> Iframe Shim for layering over Windowed Objects: http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx

*/
function initMask() {

	var docBody = document.getElementsByTagName('BODY')[0];
	var dispWidth = window.innerWidth || docBody.clientWidth;
	var dispHeight = window.inneHeight || docBody.clientHeight;

	//Create Screen Mask Div if it doesn't exist.
	if (!document.getElementById('screenMaskDiv')) {

		var disWidth = window.innerWidth || document.body.clientWidth;
		var disHeight = window.inneHeight || document.body.clientHeight;

		createMask = document.createElement('div');
		createMask.id = 'screenMaskDiv';
		createMask.style.width = dispWidth + 'px';
		createMask.style.height = dispHeight + 'px';

		docBody.appendChild(createMask);

		//windowedPatch -> Create an iframe mask to cover Windowed Objects
		createWindowedPatch = document.createElement('iframe');
		createWindowedPatch.id = 'windowedPatch';
		createWindowedPatch.src = '';
		createWindowedPatch.frameborder = '0';
		createWindowedPatch.scrolling = 'no';
		docBody.appendChild(createWindowedPatch);

	}

}

function closeModal(id) {
	var docBody = document.getElementsByTagName('BODY')[0];

	//Remove Modal
	var modalWin = document.getElementById(id);
	if (modalWin) {
		docBody.removeChild(modalWin);
	}

	//Hide Mask
	toggleFade('screenMaskDiv', 35, 0, 60);
	document.getElementById('windowedPatch').style.display = 'none';

}

function openModal(id, title, width, height, src, scrolling) {

	var docBody = document.getElementsByTagName('BODY')[0];
	initMask();

	//Screen Mask
	var screenMask = document.getElementById('screenMaskDiv');
	var windowedPatch = document.getElementById('windowedPatch');

	//Create Modal Div if it doesn't exist.
	if (!document.getElementById('modalWin_' + id)) {

		var disWidth = window.innerWidth || document.body.clientWidth;
		var disHeight = window.inneHeight || document.body.clientHeight;

		//Center Box
		var indentLeft = (disWidth - width) / 2;
		var indentTop = (disHeight - height) / 2;

		//Setup Modal Base
		modalBase = document.createElement('div');
		modalBase.id = 'modalWin_' + id;
		modalBase.style.position = 'absolute';
		modalBase.style.zIndex = 501;
		modalBase.style.width = width;
		modalBase.style.height = height;
		modalBase.style.textAlign = 'center';
		modalBase.style.left = indentLeft + 'px';
		modalBase.style.top = indentTop + 'px';
		docBody.appendChild(modalBase);

	}
	modalWin = document.getElementById('modalWin_' + id);

	//Populate modalWin
	modalWin.innerHTML = '<div id="modalWindow_' + id + '" style="background-Color:#000000;">';
	modalWin.innerHTML += '<div id="modalTopBar_' + id + '" class="modalTopBar"><div id="modalTitleOuter_' + id + '" class="modalTitleOuter"><div id="modalTitle_' + id + '" class="modalTitle"></div></div><div id="modalOptions_' + id + '" class="modalOptions"><div id="modalOptionsInner_' + id + '" class="modalOptionsInner" onclick="closeModal(\'modalWin_' + id + '\');"></div></div></div>';
	modalWin.innerHTML += '<iframe src="' + src + '" id="modalSrc_' + id + '" class="modalSrc" frameborder="0" scrolling="' + scrolling + '" align="center" style="background-Color:#000000;"></iframe>';
	modalWin.innerHTML += '</div>';

	//Settings for modalSrc frame
	var modalSrc = document.getElementById('modalSrc_' + id);
	modalSrc.style.height = (height - document.getElementById('modalTopBar_' + id).offsetHeight - 1) + 'px';
	modalSrc.style.width = (width - 2) + 'px';
	modalSrc.style.backgroundColor = '#000000';

	//Width settings for modalTitle in conjunction with IE's Glow Filter
	document.getElementById('modalTitle_' + id).style.width = document.getElementById('modalWindow_' + id).offsetWidth - document.getElementById('modalOptions_' + id).offsetWidth - 20;

	//Place Windowed Shim underneath modalWin
	windowedPatch.style.width = modalWin.style.width;
	windowedPatch.style.height = modalWin.style.height;
	windowedPatch.style.left = modalWin.style.left;
	windowedPatch.style.top = modalWin.style.top;
	//windowedPatch.style.display = 'block';

	//Display Mask
	toggleFade('modalWin_' + id, 31, 100, 0);
	toggleFade('screenMaskDiv', 32, 60, 0);

}

function toggleFade(id, fadeTime, targetOpacity, currentOpacity) {

	var obj = document.getElementById(id);
	var increment = 10;

	//Hidden Object, Fade In
	if (currentOpacity < targetOpacity) {
		currentOpacity += increment;
		changeOpac(currentOpacity, id);
		
		if (currentOpacity != targetOpacity) {
			setTimeout('toggleFade(\'' + id + '\', ' + fadeTime + ', ' + targetOpacity + ', ' + currentOpacity + ');', fadeTime);
		} else {
			//obj.style.filter = 'alpha(opacity=' + targetOpacity + ');';
			obj.style.filter = 'alpha(opacity=' + targetOpacity + ')';
		}
		obj.style.display = 'block';
	} else {
		//Fade Out
		currentOpacity -= increment;
		changeOpac(currentOpacity, id);
		if (!currentOpacity) {
			obj.style.display = 'none';
		} else {
			setTimeout('toggleFade(\'' + id + '\', ' + fadeTime + ', ' + targetOpacity + ', ' + currentOpacity + ');', fadeTime);
		}
	}

}

/*function toggleBiFade(id, id_second, fadeTime, targetOpacity, currentOpacity) {

	var obj = document.getElementById(id);
	var increment = 10;

	//Hidden Object, Fade In
	if (currentOpacity < targetOpacity) {
		currentOpacity += increment;
		obj.style.display = 'block';
		changeOpac(currentOpacity, id);
		if (currentOpacity != targetOpacity) {
			setTimeout('toggleBiFade(\'' + id + '\', \'' + id_second + '\', ' + fadeTime + ', ' + targetOpacity + ', ' + currentOpacity + ');', fadeTime);
		} else {
			if (id_second.length > 0){
				document.getElementById('modalWin_' + id_second).style.display = '';
				toggleBiFade('modalWin_' + id_second, '', 40, 100, 0);
			}
		}
	} else {
		//Fade Out
		currentOpacity -= increment;
		changeOpac(currentOpacity, id);
		if (!currentOpacity) {
			obj.style.display = 'none';
		} else {
			setTimeout('toggleBiFade(\'' + id + '\', \'' + id_second + '\',  ' + fadeTime + ', ' + targetOpacity + ', ' + currentOpacity + ');', fadeTime);
		}
	}

}*/

function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function thisModalId(str) {
	matches = str.match(/modalSrc_{1}(.*)/i);
	return matches[1];
}

function searchMe(){

	var search_string = document.getElementById('search');
	
	var url = '/rpc/search.php';
	var params = 'action=search&terms=' + search_string.value;

	rpcCall('searchMe', url, params);
}

function getFields(){
	
	var url = '/rpc/search.php';
	var params = 'action=getForm&id=1';

	rpcCall('getForm', url, params);
}

function loadViewer(){
	
	var url = '/rpc/viewer.php';
	var params = '';

	rpcCall('loadViewer', url, params);

}

// Use this to properly write out the HTML for any Flash.
function FlashWriter(url, width, height, parameters)
{
	// Options here are "window", "opaque", and "transparent"
	var DEFAULT_WINDOW_SETTING = "window";

	// Defaults for optional stuff below
	var quality = "best";
	var id = "flash" + GetRandomNumber(1000000, 9999999);
	var wmode = DEFAULT_WINDOW_SETTING;
	var script_access = "sameDomain";
	var allow_fullscreen = "false";
	var params = parameters;
	var has_flash = LookForFlashPlugin();

	this.SetQuality = function(new_quality)
	{
		quality = new_quality;
	}

	this.SetID = function(new_id)
	{
		id = new_id;
	}

	this.SetTransparent = function(is_transparent)
	{
		wmode = is_transparent ? "transparent" : DEFAULT_WINDOW_SETTING;
	}

	this.SetFullScreen = function(fullscreen)
	{
		allow_fullscreen = fullscreen ? "true" : "false";
	}

	this.SetScriptAccess = function(new_script_access)
	{
		script_access = new_script_access;
	}

	this.SetParams = function(new_params)
	{
		params = new_params;
	}

	this.ToString = function()
	{
		var str = "";

		if(has_flash)
		{
			str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + width + '" height="' + height + '" id="' + id + '">';

			str += '<param name="allowScriptAccess" value="' + script_access + '" />';
			str += '<param name="allowFullScreen" value="' + allow_fullscreen + '" />';
			str += '<param name="movie" value="' + url + '" /><param name="quality" value="best" />';
			str += '<param name="wmode" value="' + wmode + '" />';

			if(params != null)
			{
				// IE needs this
				str += '<param name="FlashVars" value="' + params + '" />';
			}

			str += '<embed src="' + url + '" quality="best" ';

			if(params != null)
			{
							// Non-IE browsers need this
				str += 'FlashVars="' + params + '" ';
			}

			str += 'wmode="' + wmode + '" width="' + width + '" height="' + height + '" name="' + id + '" allowScriptAccess="' + script_access + '" allowFullScreen="' + allow_fullscreen + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
			str += '</object>';
		}
		else
		{
			str += '<p style="text-align: center; margin-top: 2em; margin-bottom: 2em; padding-top: 3em; padding-bottom: 3em; background: #d9d9d9;">According to our system, you do not appear appear to have Flash installed. <a target="_blank" href="http://adobe.com">Click here</a> to download now!</a></p>';
		}

		return(str);
	}

	this.Print = function()
	{
		document.write(this.ToString());
	}

	function LookForFlashPlugin()
	{
		var flash_versions = 12;

		// Code swiped from http://www.dangrossman.info/2007/01/03/detecting-flash-and-java-with-javascript/
		if (navigator.plugins && navigator.plugins.length) {
			// Netscape style plugin detection
		    for (x = 0; x <navigator.plugins.length; x++) {
		        if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
		            return(true);
		        }
		    }
		}
		else if (window.ActiveXObject) {
			// ActiveX style plugin detection
		    for (x = 2; x <= flash_versions; x++) {
		        try {
		            oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
		            if (oFlash) {
		                return(true);
		            }
		        }
		        catch(e) { }
		    }
		}

		return(false);
	}
}

function GetRandomNumber(low, high)
{
	return(Math.floor((Math.random() * (high - low + 1)) + low));
}

function quitViewer(){
	parent.tb_remove();

}

function submitProperty(){
	document.getElementById('property').submit();
}

function submitFolio(){
	document.getElementById('folio').submit();
}

function submitSearch(){
	document.getElementById('search_form').submit();
}

function submitDropSearch(){
	document.getElementById('quick_search').submit();
}
