//functions for frontend

//function to bookmark site;
function bookmarksite(title,url){
if (window.sidebar){ // firefox
	window.sidebar.addPanel(title, url, "");
	}
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}



//this version of gri passes actual object
function gri(obj){
//obj = eval("theform."+obj.name);
for(i=0;i<obj.length;i++){
if(obj[i].checked){
return(i);
}
}
}

function buildquerystring(){
qarray= new Array();
if(theform.propertytype){
qarray[qarray.length] = "propertytype="+((theform.propertytype) ? escape(theform.propertytype.value):""); 
}
if(theform.category){
qarray[qarray.length] = "category="+((theform.category) ? escape(theform.category.value):""); 
}
qarray[qarray.length] = "province="+((theform.province) ? escape(theform.province.value):""); 
qarray[qarray.length] = "area="+((theform.area) ? escape(theform.area.value):"");
//qarray[qarray.length] = "suburb="+escape(menuselectedlist(theform.suburblist));//"suburb="+escape(theform.suburblist.value);
qarray[qarray.length] =  "suburb="+((theform.suburblist) ? escape(menuselectedlist(theform.suburblist)):"");//"suburb="+escape(theform.suburblist.value);
qarray[qarray.length] = "transaction="+((theform.transaction) ? escape(theform.transaction[gri(theform.transaction)].value):"");
//if(theform.pricemin>0){
qarray[qarray.length] = "pricemin="+((theform.pricemin) ? escape(theform.pricemin.value):"");
//}
//if(theform.pricemax>0){
qarray[qarray.length] = "pricemax="+((theform.pricemax) ? escape(theform.pricemax.value):"");
//}

//qarray[qarray.length] = "mode="+escape(theform.mode.value);

//new for remote prop2000 site
if(theform.agencyid){
qarray[qarray.length] = "agencyid="+((theform.agencyid) ? escape(theform.agencyid.value):"");
}
if(theform.rbu){
qarray[qarray.length] = "rbu="+((theform.rbu) ? escape(theform.rbu.value):"");
}


qarray[qarray.length] = "rom="+((theform.rom) ? escape(theform.rom[gri(theform.rom)].value):"");

qstring="?"+qarray.join("&");
//if(mode=="godmode"){
//alert(qstring);
//}
//alert(qstring);
//alert(tempjs_suburb_index);
return qstring;
}


function fillcategoryoptions(thetype,obj){
if(categoryarray[thetype]){
catarray = categoryarray[thetype].split(",");
obj.options.length=0;
if(catarray.length){

obj.options[0] = new Option("Any "+thetype,0);
for(i=0;i<catarray.length;i++){
obj.options[obj.options.length] = new Option(catarray[i],catarray[i]);
}
obj.style.display='';

}
}
else
{
obj.options.length=0;
//obj.style.display='none';
}
}

function swappriceoptions(transaction){
theminarray=priceminarray[transaction];
themaxarray=pricemaxarray[transaction];

obj = theform.pricemin;
tempobjindex = obj.selectedIndex;
obj.options.length=0;
if(theminarray.length){
for(i=0;i<theminarray.length;i++){
pricearray = theminarray[i].split(":");
obj.options[obj.options.length] = new Option(pricearray[1],pricearray[0]);
}
obj.selectedIndex = tempobjindex;
}

obj = theform.pricemax;
tempobjindex = obj.selectedIndex;
obj.options.length=0;
if(themaxarray.length){
for(i=0;i<themaxarray.length;i++){
pricearray = themaxarray[i].split(":");
obj.options[obj.options.length] = new Option(pricearray[1],pricearray[0]);
}
obj.selectedIndex = tempobjindex;
}



}

//hide panel
function hidepanel(objid){
document.getElementById(objid).style.display="none";
}

//display panel
function showpanel(objid){
document.getElementById(objid).style.display="inline";
}



//reset scroll
function resetscroll(){
if(self.pageYOffset){
self.pageYOffset=0;
}else if(document.documentElement && document.documentElement.scrollTop){
document.documentElement.scrollTop=0;
}else if(document.body){
document.body.scrollTop=0;
}
}




function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);



//function to display flash image

			function putflashfile(flashfile,width,height,bgcolor,version){
			document.writeln('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'" WIDTH='+width+' HEIGHT='+height+'>');
            document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
			document.writeln('<PARAM NAME=movie VALUE="'+flashfile+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE='+bgcolor+'> <EMBED src="'+flashfile+'" quality=high bgcolor='+bgcolor+'  WIDTH='+width+' HEIGHT='+height+'  allowScriptAccess="sameDomain" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');
           document.writeln('</OBJECT>');
			}

function swapbigimage(triggerimage){
tempimage=document.getElementById("frontend_imagepanel_image_1").src;
document.getElementById("frontend_imagepanel_image_1").src=triggerimage.src.replace(/_s.jpg/,"_m.jpg");
triggerimage.src=tempimage.replace(/_m.jpg/,"_s.jpg");
}





//COPIED FROM VS2011 FOR IMAGE OVERLAY


//start import from coatingworx

function windowsize(){
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return (w+","+h);
}

function centeroverlay(elementid){
overlaypanelwidth = document.getElementById(elementid).offsetWidth;
overlaypanelheight = document.getElementById(elementid).offsetHeight;
windowdims = windowsize().split(",");
windowwidth = windowdims[0];
windowheight = windowdims[1];
document.getElementById(elementid).style.left=(windowwidth/2)-(overlaypanelwidth/2)+"px";
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-(overlaypanelheight/2)+"px";

//this includes fix to nudge image up
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-((overlaypanelheight/2)+80)+"px";




/*
//this includes fix to nudge portraitimages up
//this will only work if centeroverlay is called again once image has loaded as we do not know image dims until it has loaded
if(overlaypanelheight > overlaypanelwidth){
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-((overlaypanelheight/2)+40)+"px";
}
else
{
document.getElementById(elementid).style.top=scrolly()+(windowheight/2)-(overlaypanelheight/2)+"px";
}
*/

}




function cleargreyout(){
document.getElementById('greyout').style.visibility='hidden';
}


function show_panel(panelid){
document.getElementById(panelid).style.display='';
centeroverlay(panelid);
}

function hide_panel(panelid){
document.getElementById(panelid).style.display='none';
}

function hide_imagepanel(){
hide_panel("image_panel");
cleargreyout();
document.getElementById("image_panel_image").src="images/loadingimage.jpg";
}

function show_imagepanel(){
show_panel("image_panel");
}

//end of import from newcoatingworx

// END OF VS2011 COPY



//added in 2011 based on setajaxcookie from vs2011

//function to call url via ajax for processing
//url comprises the url (proccessor) + querystring containing variables and values
    function ajaxurlcall(url) {
//alert(url);
		var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
		
		
        http_request.onreadystatechange = function() { ajaxurlcallresponse(http_request); };
			
        http_request.open('GET', url, false);
        http_request.send(null);
       
    }

    function ajaxurlcallresponse(http_request) {
            if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			
			responsetext=http_request.responseText;
     				alert(responsetext);
							
            } 
			else 
			{
                alert('There was a problem with the request.');
            //obj.innerHTML='There was a problem with sending your message.'
			}
        }
		
    }


//end of add

