﻿document.onclick=function(e)
{if(typeof e!='undefined'&&typeof e.which!='undefined'&&e.which!=1){return true;}
var node=e?e.target:window.event.srcElement;while(node.nodeName.toLowerCase()!='a')
{if(!node.parentNode){return true;}
else if(node.nodeName.toLowerCase()=='body'){return true;}
else{node=node.parentNode;}}
if(node.getAttribute('rel'))
{var rel=node.rel.split('|');if(rel[0]=='external')
{node.target='_blank';return true;}}
return true;};if(top.frames.length!=0)
{top.location=document.location}
function newsPop(imageid,newsid){theimage=new Image();theimage.src='http://www.south-ayrshire.gov.uk/sac/images/news/'+imageid+'.jpg';ChildWindow=window.open('http://www.south-ayrshire.gov.uk/sac/news/viewimage.aspx?id='+newsid,'Image','width='+theimage.width+',height='+theimage.height+',top=0,left=0,toolbar=no,scrollbars=no,status=no,resizable=no');ChildWindow.focus();}
function limitText(limitField,limitNum){if(limitField.value.length>limitNum){limitField.value=limitField.value.substring(0,limitNum);}}
var _req;var _div;var _keyCode;var _highlightedSuggestionIndex=-1;var _suggestionCount=5;var _highlightedDiv=null;var _txtFld=null;var _originalVal;document.onmousedown=function(){HideDiv("autocomplete");}
String.prototype.trim=function(){var
r=/^\s+|\s+$/,a=this.split(/\n/g),i=a.length;while(i-->0)
a[i]=a[i].replace(r,'');return a.join('\n');}
function Init(){if(window.XMLHttpRequest){_req=new XMLHttpRequest();}
else if(window.ActiveXObject){try{_req=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{_req=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){}}}}
SendQuery=function(key,e)
{Init();if(window.event)e=window.event;if(e.keyCode)_keyCode=e.keyCode;else if(e.which)_keyCode=e.which;_txtFld=e.srcElement?e.srcElement:e.target;createDiv(_txtFld);var url="http://www.south-ayrshire.gov.uk/search.aspx?k="+key;if(_keyCode==38||_keyCode==40)
{upDownCursorHandler();}
else if(_keyCode==13)
{_originalVal=key;HideDiv("autocomplete");setRange(_txtFld,_txtFld.value.length,_txtFld.value.length);}
else if(_req!=null)
{_originalVal=key;_highlightedSuggestionIndex=-1;_req.onreadystatechange=processStateChange;_req.open("GET",url,true);_req.send(null);}}
function escapeURI(uri)
{if(encodeURIComponent)
return encodeURIComponent(uri);if(escape)
return escape(uri);}
processStateChange=function(){if(_req.readyState==4){if(_req.status==200){if(_req.responseText=="")
HideDiv("autocomplete");else{eval(_req.responseText);}}
else{document.getElementById("autocomplete").innerHTML="errors occured:<br />"+_req.statusText;}}}
ShowDiv=function(divid){if(document.layers)document.layers[divid].visibility="show";else document.getElementById(divid).style.visibility="visible";}
HideDiv=function(divid){try{if(document.layers)document.layers[divid].visibility="hide";else document.getElementById(divid).style.visibility="hidden";}
catch(e){}}
window.onload=function(){if(document.getElementById("autocomplete"))
HideDiv("autocomplete");}
function createDiv(txtFld)
{_div=document.createElement("DIV");_div.id="autocomplete";_div.style.borderRight="#ddd 1px solid";_div.style.borderLeft="#ddd 1px solid";_div.style.borderTop="#ddd 1px solid";_div.style.borderBottom="#ddd 1px solid";_div.style.zIndex="1";_div.style.backgroundColor="#ffffff";_div.style.position="absolute";_div.style.visibility="hidden";_div.style.paddingLeft="3px";setDivSizePosition(txtFld);document.body.appendChild(_div);return false;}
function setDivSizePosition(txtFld)
{if(_div)
{_div.style.left=calculateOffsetLeft(txtFld)+"px";_div.style.top=calculateOffsetTop(txtFld)+txtFld.offsetHeight-1+"px";_div.style.width=calculateWidth(txtFld)+"px"}}
function calculateWidth(txtFld)
{if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1)
{return txtFld.offsetWidth-2}
else
{return txtFld.offsetWidth-5}}
calculateOffsetLeft=function(r){return calc(r,"offsetLeft")}
calculateOffsetTop=function(r){return calc(r,"offsetTop")}
calc=function(r,attr)
{var kb=0;while(r)
{kb+=r[attr];r=r.offsetParent}
return kb}
callback=function(a){_div=document.getElementById("autocomplete");while(_div.childNodes.length>0){_div.removeChild(_div.childNodes[0]);}
_suggestionCount=a.length;if(_suggestionCount==0)HideDiv("autocomplete");else{for(var i=0;i<a.length;++i){var div=document.createElement("DIV");var sp=document.createElement("SPAN");sp.style.display="block";var sp1=document.createElement("SPAN");sp1.style.fontSize="14px";sp1.style.paddingBottom="3px";sp1.style.paddingTop="3px";sp1.style.styleFloat="left";sp1.style.cursor="hand";sp1.style.fontFamily="verdana,arial,sans-serif";sp1.innerHTML=a[i];sp1.style.width="100%";sp1.style.wordWrap="break-word";sp1.className="Suggest";div.id="_div"+i.toString();div.onmouseover=omover;div.onmouseout=omout;div.onmousedown=omdown;sp.appendChild(sp1);div.appendChild(sp);_div.appendChild(div);}
ShowDiv("autocomplete");}}
omover=function(){this.style.color="#0033ff";this.style.backgroundColor="#eeeeee";}
omout=function(){this.style.color="#000000";this.style.backgroundColor="#ffffff";}
getSpanValue=function(i,className){var sp=i.getElementsByTagName("span");if(sp){for(var f=0;f<sp.length;++f){if(sp[f].className==className){var value=sp[f].innerHTML;if(value==" "){return"";}else{var s=stripCR(value);return s}}}}else{return""}}
function stripCR(va){for(var i=0,s="",zb="\n\r";i<va.length;i++){if(zb.indexOf(va.charAt(i))==-1){s+=va.charAt(i);}else{s+=" ";}}
return s}
var omdown=function(){v=getSpanValue(this,"Suggest");v=decode(v);_txtFld.value=v.trim();HideDiv("autocomplete");}
function upDownCursorHandler(){if(_keyCode==40){highlit(_highlightedSuggestionIndex+1);}else if(_keyCode==38){highlit(_highlightedSuggestionIndex-1);}}
function highlit(indx){if(indx<0)return;if(_suggestionCount<=indx)return;_highlightedSuggestionIndex=indx;completeList=document.getElementById("autocomplete");if(completeList)
{if(_highlightedDiv)
{_highlightedDiv.style.color="#000000";_highlightedDiv.style.backgroundColor="#ffffff";}
_highlightedDiv=completeList.childNodes[_highlightedSuggestionIndex];var v=getSpanValue(_highlightedDiv,"Suggest");v=decode(v);_txtFld.value=v.trim();setRange(_txtFld,_originalVal.length,_txtFld.value.length);_highlightedDiv.style.color="#0033ff";_highlightedDiv.style.backgroundColor="#eeeeee";}}
function decode(s)
{return s.replace("&amp;","&");}
var setRange=function(inputField,start,end){if(inputField.setSelectionRange){inputField.focus();inputField.setSelectionRange(start,end);}
else if(inputField.createTextRange){var tr=inputField.createTextRange();tr.collapse(true);tr.moveEnd('character',end);tr.moveStart('character',start);tr.select();}}