// JavaScript Document


// *******************************************
//  CVFS CURRENCY CONVERTOR
//  © Croatian Villas For Sale Ltd
//  This code may not be copied or reproduced
// *******************************************

// CURRENT CONVERSION RATES
// UPDATED: Tuesday 05-January-2010
// www.xe.com

var EUR2AUD = 1.5764;
var EUR2CAD = 1.4945;
var EUR2CHF = 1.4859;
var EUR2EUR = 1;
var EUR2GBP = 0.9005;
var EUR2NOK = 8.2233;
var EUR2NZD = 1.9619;
var EUR2RUB = 43.1395;
var EUR2USD = 1.4415;

// ******************************************


// getGBP2 is for old style property pages ONLY
function getGBP2(priceEUR) { 
	document.write(addCommas(Math.round(priceEUR * EUR2GBP))); 
}


function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function addCommas(nRate,nEur,nSign) {
	if (nRate == 1) 
		{ 
				x1 = " "; 
            currencyDisplay = " ";
	    return x1 + currencyDisplay;
	}

	var nStr = Math.round(nRate*nEur) + " ";
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}

        switch(nSign)
        {
        case 0:
           currencyDisplay = " ";
           break;
        case 1:
           currencyDisplay = " +";
           break;
        case 2:
           currencyDisplay = " ";
           x1 = " P.O.A."
           break;
        default:
           alert ("Case else: Invalid plus sign in db");
        }

	return x1 + currencyDisplay;
}

function ConvertPrice(x) {
	var rate = 0;	
	if(readCookie('currpref') == null && x == null) { x='4'; }
	document.currency.currency_type.selectedIndex = Number(x)-1;
	switch(x){
		case '1':rate = EUR2AUD;createCookie('currpref','1',1);break;
		case '2':rate = EUR2CAD;createCookie('currpref','2',1);break;
		case '3':rate = EUR2CHF;createCookie('currpref','3',1);break;
		case '4':rate = EUR2EUR;createCookie('currpref','4',1);break;
		case '5':rate = EUR2GBP;createCookie('currpref','5',1);break;
		case '6':rate = EUR2NOK;createCookie('currpref','6',1);break;
		case '7':rate = EUR2NZD;createCookie('currpref','7',1);break;
		case '8':rate = EUR2RUB;createCookie('currpref','8',1);break;
		case '9':rate = EUR2USD;createCookie('currpref','9',1);break;
		default:;
	}



	// get selected currency text label from drop down window
	var z = document.currency.currency_type.options[document.currency.currency_type.selectedIndex].text;

        // if EUR, clear currency sign
	if (z=='EUR') {z=' ';}

	
	// write the selected currency text label & converted price to the 
	// document as long as there's an id to write to
	// *************************************************************************
	// *** MAX 10 IDS PER LISTING PAGE CURRENTLY - ADD MORE BELOW IF REQUIRED ***
	// *************************************************************************

	if(document.getElementById('curr_type_01') !== null && 
		document.getElementById('conv_price_01') !== null) {
		document.getElementById('curr_type_01').innerHTML = z;
		document.getElementById('conv_price_01').innerHTML = 
                addCommas(rate,eurprice_01,currencyDisplay_01);
	}

	if(document.getElementById('curr_type_02') !== null && 
		document.getElementById('conv_price_02') !== null) {
		document.getElementById('curr_type_02').innerHTML = z;
		document.getElementById('conv_price_02').innerHTML = 
                addCommas(rate,eurprice_02,currencyDisplay_02);
	}
	
	if(document.getElementById('curr_type_03') !== null && 
		document.getElementById('conv_price_03') !== null) {
		document.getElementById('curr_type_03').innerHTML = z;
		document.getElementById('conv_price_03').innerHTML = 
                addCommas(rate,eurprice_03,currencyDisplay_03);
	}
	
	if(document.getElementById('curr_type_04') !== null && 
		document.getElementById('conv_price_04') !== null) {
		document.getElementById('curr_type_04').innerHTML = z;
		document.getElementById('conv_price_04').innerHTML = 
                addCommas(rate,eurprice_04,currencyDisplay_04);
	}

	if(document.getElementById('curr_type_05') !== null && 
		document.getElementById('conv_price_05') !== null) {
		document.getElementById('curr_type_05').innerHTML = z;
		document.getElementById('conv_price_05').innerHTML = 
                addCommas(rate,eurprice_05,currencyDisplay_05);
	}
	if(document.getElementById('curr_type_06') !== null && 
		document.getElementById('conv_price_06') !== null) {
		document.getElementById('curr_type_06').innerHTML = z;
		document.getElementById('conv_price_06').innerHTML = 
                addCommas(rate,eurprice_06,currencyDisplay_06);
	}
	if(document.getElementById('curr_type_07') !== null && 
		document.getElementById('conv_price_07') !== null) {
		document.getElementById('curr_type_07').innerHTML = z;
		document.getElementById('conv_price_07').innerHTML = 
                addCommas(rate,eurprice_07,currencyDisplay_07);
	}
	if(document.getElementById('curr_type_08') !== null && 
		document.getElementById('conv_price_08') !== null) {
		document.getElementById('curr_type_08').innerHTML = z;
		document.getElementById('conv_price_08').innerHTML = 
                addCommas(rate,eurprice_08,currencyDisplay_08);
	}
	if(document.getElementById('curr_type_09') !== null && 
		document.getElementById('conv_price_09') !== null) {
		document.getElementById('curr_type_09').innerHTML = z;
		document.getElementById('conv_price_09').innerHTML = 
                addCommas(rate,eurprice_09,currencyDisplay_09);
	}
	if(document.getElementById('curr_type_010') !== null && 
		document.getElementById('conv_price_010') !== null) {
		document.getElementById('curr_type_010').innerHTML = z;
		document.getElementById('conv_price_010').innerHTML = 
                addCommas(rate,eurprice_010,currencyDisplay_010);
	}
}


// *************************************************************************************************
function LoadGallery(pictureName,imageFile,titleCaption,captionText)
  
  {if (document.all)
  { document.getElementById(pictureName).style.filter="blendTrans(duration=1)";
    document.getElementById(pictureName).filters.blendTrans.Apply();
  }
    document.getElementById(pictureName).src = imageFile;
     if (document.all)
  {  document.getElementById(pictureName).filters.blendTrans.Play();
  }
     document.getElementById(titleCaption).innerHTML=captionText;
  }
  
 
 
function bookmarkus(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}


/*****************************************************
* Bookmark site script- © Dynamic Drive DHTML code
* library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/
* for full source code
*****************************************************/

/* Modified to support Opera */
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);
}


function mailpage(){
	mail_str = "mailto:?subject=Check out the " + document.title;
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ". You can view it at, " + location.href;
	location.href = mail_str;
}


// ***************************************************************************
// Photo Gallery from http://www.alistapart.com/articles/imagegallery
// ***************************************************************************
function showPic (whichpic) { 
	
	// test browser for getelementbyid capability
	if (document.getElementById) { 

		// swap picture link
		document.getElementById('piccurrent').src = whichpic.href; 

		// test for a title attribute and use that if present
		if (whichpic.title) { 
			document.getElementById('picdesc').childNodes[0].nodeValue = whichpic.title; 
		}
		
		// if no title text then return link text
		// else { 
		//	document.getElementById('picdesc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue; 
		// }
		
		// if no title text return a blank line
		else {
			document.getElementById('picdesc').childNodes[0].nodeValue = '';
		}
		return false; 
	}
	else { 
		return true; 
	} 
}

// ***************************************************************************
// Return date in text format
// ***************************************************************************
function TodaysDate() {
	// This array holds the "friendly" day names
	var day_names = new Array(7)
	day_names[0] = "Sunday"
	day_names[1] = "Monday"
	day_names[2] = "Tuesday"
	day_names[3] = "Wednesday"
	day_names[4] = "Thursday"
	day_names[5] = "Friday"
	day_names[6] = "Saturday"

	// This array holds the "friendly" month names
	var month_names = new Array(12)
	month_names[0]  = "January"
	month_names[1]  = "February"
	month_names[2]  = "March"
	month_names[3]  = "April"
	month_names[4]  = "May"
	month_names[5]  = "June"
	month_names[6]  = "July"
	month_names[7]  = "August"
	month_names[8]  = "September"
	month_names[9]  = "October"
	month_names[10] = "November"
	month_names[11] = "December"

	// Get the current date
	date_now = new Date()

	// Figure out the friendly day name
	day_value = date_now.getDay()
	date_text = day_names[day_value]

	// Add the day of the month
	date_text += " " + date_now.getDate()

	// Figure out the friendly month name
	month_value = date_now.getMonth()
	date_text += " " + month_names[month_value]

	// Add the year
	date_text += " " + date_now.getFullYear()

	return(date_text)
}


// ***************************************************************************
//Chrome Drop Down Menu v2.01- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: November 14th 06- added iframe shim technique
// ***************************************************************************

var cssdropdown={
disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
disablemenuclick: true, //when user clicks on a menu item with a drop down menu, disable menu item's link?
enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no
enableiframeshim: 1, //enable "iframe shim" technique to get drop down menus to correctly appear on top of controls such as form objects in IE5.5/IE6? 1 for yes, 0 for no

//No need to edit beyond here////////////////////////
dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,

getposOffset:function(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
},

swipeeffect:function(){
if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
this.bottomclip+=10+(this.bottomclip/10) //unclip drop down menu visibility gradually
this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"
}
else
return
this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10)
},

showhide:function(obj, e){
if (this.ie || this.firefox)
this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
if (this.enableswipe==1){
if (typeof this.swipetimer!="undefined")
clearTimeout(this.swipetimer)
obj.clip="rect(0 auto 0 0)" //hide menu via clipping
this.bottomclip=0
this.swipeeffect()
}
obj.visibility="visible"
}
else if (e.type=="click")
obj.visibility="hidden"
},

iecompattest:function(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
},

clearbrowseredge:function(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
},

dropit:function(obj, e, dropmenuID){
if (this.dropmenuobj!=null) //hide previous menu
this.dropmenuobj.style.visibility="hidden" //hide menu
this.clearhidemenu()
if (this.ie||this.firefox){
obj.onmouseout=function(){cssdropdown.delayhidemenu()}
obj.onclick=function(){return !cssdropdown.disablemenuclick} //disable main menu item link onclick?
this.dropmenuobj=document.getElementById(dropmenuID)
this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()}
this.dropmenuobj.onmouseout=function(e){cssdropdown.dynamichide(e)}
this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()}
this.showhide(this.dropmenuobj.style, e)
this.dropmenuobj.x=this.getposOffset(obj, "left")
this.dropmenuobj.y=this.getposOffset(obj, "top")
this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
this.positionshim() //call iframe shim function
}
},

positionshim:function(){ //display iframe shim function
if (this.enableiframeshim && typeof this.shimobject!="undefined"){
if (this.dropmenuobj.style.visibility=="visible"){
this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
this.shimobject.style.left=this.dropmenuobj.style.left
this.shimobject.style.top=this.dropmenuobj.style.top
}
this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
}
},

hideshim:function(){
if (this.enableiframeshim && typeof this.shimobject!="undefined")
this.shimobject.style.display='none'
},

contains_firefox:function(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
},

dynamichide:function(e){
var evtobj=window.event? window.event : e
if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
this.delayhidemenu()
else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
this.delayhidemenu()
},

delayhidemenu:function(){
this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'; cssdropdown.hideshim()",this.disappeardelay) //hide menu
},

clearhidemenu:function(){
if (this.delayhide!="undefined")
clearTimeout(this.delayhide)
},

startnavresources:function(){
for (var ids=0; ids<arguments.length; ids++){
var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
for (var i=0; i<menuitems.length; i++){
if (menuitems[i].getAttribute("rel")){
var relvalue=menuitems[i].getAttribute("rel")
menuitems[i].onmouseover=function(e){
var event=typeof e!="undefined"? e : window.event
cssdropdown.dropit(this,event,this.getAttribute("rel"))
}
}
}
}
if (window.createPopup && !window.XmlHttpRequest){ //if IE5.5 to IE6, create iframe for iframe shim technique
document.write('<IFRAME id="iframeshim"  src="" style="display: none; left: 0; top: 0; z-index: 90; position: absolute; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" frameBorder="0" scrolling="no"></IFRAME>')
this.shimobject=document.getElementById("iframeshim") //reference iframe object
}
}

}


// ****************************************************************************
	function thisYear () {
		var d = new Date();
		var d = d.getFullYear();
		// use below for last 2 digits
		// var d = d.getFullYear().toString().slice(2);
		return (d);
	}

// ****************************************************************************
function thisYear2 ()
	{
		var d = new Date();
		var d = d.getFullYear().toString().slice(2);
		return (d)
	}
	
	

// ===== PROPERTY SEARCH - VALIDATE SEARCH FORM ========

function validateSearch()
{
    var frm = document.pSearchForm;

// Check at least one region is selected
   if(!frm.prgn1.checked && !frm.prgn2.checked && !frm.prgn3.checked)
    {
  	alert("Please select the region");
  	frm.prgn1.focus();
  	return false;
    }

// Check at least one property type is selected
   if(!frm.ptyp1.checked && !frm.ptyp2.checked && !frm.ptyp3.checked)
    {
  	alert("Please select the property type");
  	frm.ptyp1.focus();
  	return false;
    }
}

// ****************************************************************************************
// *  BACK TO LISTING where we came from - used in croatia-property-cnnn.html  		  *
// *  If we came from external site or from bookmark then go to the first page of listing *
// ****************************************************************************************

function changeLink()
{
	if(getCookie('listingurl') == null) { 
	   return; }

	if (window.history.length < 2) { 
	   return; }

	var c = getCookie('listingurl');

	if (c.indexOf('croatia-property-listing') == -1) {
	   return; }

	document.getElementById('myAnchor').innerHTML="Back to Listing";
	document.getElementById('myAnchor').href="javascript:history.go(-1)";
}


function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

