// --- [start /site/generic.js] ---
/* 
* Author : UI Development Team
* Description : sondakika.com Javascript - site wide functionality
* Contact : uidevelopment@sondakika.com
* Resource : http://www.prettyprinter.de - Used for formatting. 
*/

/* Description: Variables to detect environment */
var frontierProtocol = 'http';
var frontierHTTPHost = 'www.kibris.com.tr';
var frontierBaseUrl = '/site';
//var frontierURL = frontierProtocol+'://'+frontierHTTPHost+''+frontierBaseUrl;
var frontierURL = 'common/js/rezervasyon'
var frontierSkin = 'engb.sondakika.com';
var frontierLocale = 'en_GB';

/*
* Description : Adds to DOM the jsEnabled class name to indicate javascript availability 
*/
if (document.documentElement && document.getElementById) {
	document.documentElement.setAttribute('class','jsEnabled');
	document.documentElement.className = 'jsEnabled'; //For IE
}

/*
* Description: Include the library - important
*/
if( (typeof KBRS!='object') || (typeof KBRS == 'object' && !KBRS.loaded) ){		
	document.write('<script type="text/javascript" src="' + frontierURL + '/KBRS.js?skin=' + frontierSkin + '"></script>');
	document.write('<script type="text/javascript" src="' + frontierURL + '/KBRS_recently_search_template_title.js?skin=' + frontierSkin + '"></script>');
}


/*
* Description - Legacy onload function to use KBRS library addEvent
*/
function SafeAddOnload(f){	
	KBRS.addEvent({fn:f});
}

/*
* Description: Cookie read and create, and query string read param functions below
*/
function createCookie(name, value, days) {
	KBRS.cookie.create({name: name, value: value, expire: days});	
}

function readCookie(name){
	if (KBRS.cookie && KBRS.cookie[name]) {		
		return KBRS.cookie[name];		
	} else {
		return '0';
	}
}

function readQueryString(param) {
	if (KBRS.querystring[param]) {
		return KBRS.querystring[param];
	} else {
		return false;		
	}
}

/*
* Define a random number variable. Used as a param to js ads in master banners 
*/
var randNum = new Date().getTime();


/*
* Description: 
*/
function RTeCollector(strParam) {var intHeight = 460; var intWidth = 640; var intTop= ((screen.height/2)-(intHeight/2)); var intLeft= ((screen.width/2)-(intWidth/2)); var strFeatures='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height='+intHeight+',width='+intWidth+',top='+intTop+',left='+intLeft;var winEcollector = window.open('http://ecollector.responsetek.com/eCollector.asp?' + strParam, 'eCollector', strFeatures); }
function RenderPopup(windowsource,windowname,width,height,scrollbars,directories,location,menubar,status,toolbar,resizable) {  var windowfeatures = 'width=' + width +  ',height=' + height + ',directories=' + directories +  ',location=' + location + ',menubar=' + menubar +  ',scrollbars=' + scrollbars + ',status=' + status +  ',toolbar=' + toolbar + ',resizable=' + resizable;  window.open(windowsource, windowname, windowfeatures);  }
function frm_showhidelayer(lyrName, show) { if (document.getElementById) {var obj = KBRS.e(lyrName); obj.style.display = show ? "block" : "none"; } else if(document.all) {document.all[lyrName].style.display = show ? "block" : "none";} else if(document.layers) {document.layers[lyrName].display = show ? "block" : "none";}}
function isValidEmail(emailAddress) {var atIndex = emailAddress.indexOf('@');var dotIndex = emailAddress.indexOf('.',atIndex);if( (0 < atIndex) && (atIndex < dotIndex) && (dotIndex < emailAddress.length-1) ) {var firstChar = emailAddress.charAt(0); if( (firstChar >= 'a' && firstChar <= 'z') || (firstChar >='A' && firstChar <= 'Z') || (firstChar >= '0' && firstChar <='9') ) { for (var i=1, j = emailAddress.length; i < j; ++i) {  if(emailAddress.charCodeAt(i) <= 0x20){  if(emailAddress.charAt(i) == ' ') {   alert("There are no spaces allowed in your email address"); }  else { alert("The character \"" + emailAddress.charAt(i) + "\" is not allowed in your email address");   }  return false;  }   }  return true;     }   alert("The first character in your email address, \"" + firstChar + "\" is not allowed"); } alert("Please enter a full email address"); return false; }

// Function used on travel/flights/deals section pages to populate the flights search form
function prePopulate(dep,dest,airline) {
	if (document.getElementById) {
		var fieldsId = ['departurePoint','destination','airline'];
		var formField;		
		for(var i=0, j=fieldsId.length; i < j; i++) {
			if(formField = KBRS.e(fieldsId[i])) {				
				if(formField.type == 'select-one') {					
					for (var x=0, y=formField.length; x < y; x++) {
						if(formField.options[x].text == dep || formField.options[x].text == airline) { 
							formField.selectedIndex = 1;
						}							
						if (!(airline)) {
							formField.selectedIndex = 0; 
						}
					}				
				} 				
				if (formField.type == 'text') { 
					formField.value = dest;	
				}
			}
		}
	}
}


/* 
* Descriotion: Set a LAB cookie for (Lightweight A-B Testing) 
*/
var lab_numGroups=6;
function lab_getCookieVal(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1){endstr=document.cookie.length;}return unescape(document.cookie.substring(offset, endstr));}
function lab_getCookie(name){var arg=name + "=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i < clen){var j = i + alen;if (document.cookie.substring(i, j) == arg) return lab_getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;if (i == 0) break;}return null;}
var labIndex = document.location.href.indexOf('LAB=');
if(labIndex>-1)	{
	var lab_group = document.location.href.slice(labIndex+4,labIndex+5);
    if(s_account=='lastmintravelocitycouk') {
		document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=travelocity.co.uk";
	} else {
		document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=sondakika.com";
	}
} else {	
	var lab_group = lab_getCookie('LLAB');
	if (lab_group==null) {
		lab_group=''+Math.floor(Math.random()*lab_numGroups);
      if(frontierSkin=='engb.travelocity.co.uk') { //Use skin to detect domain
         document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=travelocity.co.uk";}
      else {
      	document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=sondakika.com"; }
      }
}

/*
* Description: View product images thumbnail as larger image - on UI details pages
*/
function thumbnailSwitch(targetId,imageSrc,caption){
	KBRS.e(targetId).src = imageSrc;	
	if (KBRS.e(targetId + 'Caption')) {
		KBRS.e(targetId + 'Caption').innerHTML = caption;
	}
}

/*
* Toggle popups
*/
function togglePopup(obj){	
	var bubbleContainer = KBRS.e(obj.href.split('#')[1]);		
	var masterContainer = KBRS.e('master_center');
	var pageContent = KBRS.e('page_content');
	var iframeId = 'underIframe' + obj.href.split('#')[1]
	var popupsOnScreen = KBRS.getElementsBy({tagName:'div', className:'bubbleText', filter:function(item){
			return (item.style.visibility=='visible')
		}
	});	
	var zInd = (popupsOnScreen.length) ? popupsOnScreen[popupsOnScreen.length-1].style.zIndex+1 : Math.floor(Math.random() * 1000);
	KBRS.addEvent({e:bubbleContainer.getElementsByTagName('a')[0], eT:'click', fn:function(e){		
		KBRS.styles(bubbleContainer, {visibility:'hidden'});
		masterContainer.style.zIndex = '2';
		if (KBRS.e(iframeId)) pageContent.removeChild(KBRS.e(iframeId));		
		if (!e) e = window.event;
		if (e.preventDefault) {
			e.preventDefault();
		} else {
			e.returnValue = false;															 
		}
	}});
	var isIE6 = /msie ([0-6]{1,}[\.0-9]{0,})/.test(navigator.userAgent.toLowerCase());
	if ( !KBRS.e(iframeId) && isIE6 && navigator.userAgent.indexOf('opera')==-1) {		
		new KBRS.element.block({p: 'page_content', tagName: 'iframe', id: iframeId, frameBorder: '0', scrolling: 'no', src: 'javascript:false;'})
		var iframeReference = KBRS.e(iframeId);		
		KBRS.styles(iframeReference, {
			position: 'absolute',
			left: KBRS.getLeft(obj) - KBRS.getLeft(pageContent) - 30, 
			top: KBRS.getTop(obj) - KBRS.getTop(pageContent) - bubbleContainer.offsetHeight, 
			width: bubbleContainer.offsetWidth,
			height: bubbleContainer.offsetHeight,
			zIndex: zInd - 1,
			filter: 'alpha(opacity=0)'
		});			
	}
	masterContainer.style.zIndex = '25';
	KBRS.styles(bubbleContainer, {visibility:'visible', left: KBRS.getLeft(obj) - KBRS.getLeft(pageContent) - 30, top:KBRS.getTop(obj) - KBRS.getTop(pageContent) - bubbleContainer.offsetHeight, zIndex: zInd});
}

/* 
* Description - Price formatter functions
*/
function currencyFormat(amount, currencyCode, locale, decimalPoints) {
 	var decimalPoints = decimalPoints || 0;
	var amount = (typeof amount == 'string') ? amount : parseFloat(amount).toFixed(decimalPoints); 

	var currencyCodes = {
		'EUR' : "&euro;",
		'GBP' : "&pound;",
		'INR' : "Rs",
		'HKD' : "HKD",
		'AUD' : "AUD",
		'SGD' : "SGD"};
 
	switch(locale) {
	case 'en_GB':
		return currencyCodes[currencyCode] + amount;
		break
	case 'es_ES':		
		return amount + ' ' + currencyCodes[currencyCode];
		break    
	case 'fr_FR':
		return amount + ' ' + currencyCodes[currencyCode];
		break
	case 'en_IN':
	case 'it_IT':
	case 'en_HK':
	case 'en_AU':
	case 'en_SG':
		return currencyCodes[currencyCode] + ' ' + amount;
		break
	default:
		return amount + '?';
	}
}

/*
* Description : Airport code finder
*/
var originOrDestination = 'D'; //Updates the airport name field in Search with the name found by the service
//Takes the value entered and send this to the page calling the service
function findDestination(url,field) {
    var airportCodes = KBRS.e(field);
	var value = (airportCodes)? airportCodes.value : '';
	var urlString = url;		
	if (urlString.indexOf('?') == -1) {
		var location = '?location=';
	}		
	else {
		var location = '&'+'location=';	
	}		
	var url = urlString + location + value + '&'+'fieldName=' + field;
	window.open(url,'findAiports','width=300,height=300,resizable=0,status=yes,scrollbars=yes');
	originOrDestination = 'D'
}

/* 
 * Description: Replace the value of the field with the value found by the service
 */
function setDestination(text, field) {
	KBRS.e(field).value = text;
}

/*
* Description : calendar positioning hack
*/
var hijackShowCalendarTimer=-1;var calendarIframe=false;function hijackShowCalendar(){if(typeof showCalendar=="function"){clearTimeout(hijackShowCalendarTimer);showCalendar=function(e){var o=(typeof event!="undefined")?event.srcElement:e.target;var _3=KBRS.e("cIframe");if(!calendarIframe){_3.style.visibility="hidden";calendar.show(0,0);calendarIframe={left:KBRS.getLeft(_3),top:KBRS.getTop(_3)};_3.style.visibility="visible";}calendar.show((KBRS.getLeft(o)-calendarIframe.left)+o.width+5,KBRS.getTop(o)-calendarIframe.top);};}else{hijackShowCalendarTimer=setTimeout("hijackShowCalendar()",500);}}hijackShowCalendar();function stopHijackShowCalendarLoop(){if(typeof showCalendar != "function" && hijackShowCalendarTimer != -1){clearTimeout(hijackShowCalendarTimer);}}if(typeof calendar=="object"){var hijackOldOnload = window.onload; if(typeof hijackOldOnload == "function"){window.onload=function(){stopHijackShowCalendarLoop(); hijackOldOnload(); } ; } else {window.onload=stopHijackShowCalendarLoop;}}


/*
* Description : accent strip library
*/
function stripVowelAccent(str, str_type) {var s=str;	var stripped=str; var rExps=[ /[\xC0-\xC5]/g, /[\xE0-\xE5]/g,	/[\xC8-\xCB]/g, /[\xE8-\xEB]/g,	/[\xCC-\xCF]/g, /[\xEC-\xEF]/g,	/[\xD2-\xD6]/g, /[\xF2-\xF6]/g,	/[\xD9-\xDC]/g, /[\xF9-\xFc]/g,/[\xD1]/g, /[\xF1]/g, /[\xC7]/g, /[\xE7]/g ]; var repChar=['A','a','E','e','I','i','O','o','U','u','N','n','C','c']; for(var i=0; i<rExps.length; i++) {	stripped=stripped.replace(rExps[i],'_'); s=s.replace(rExps[i],repChar[i]); } return s; }

/* 
* Description: link the radio buttons for the search box categories in IE
*/ 

if (window.attachEvent){
window.attachEvent("onload", function () {
								var inputs = document.getElementsByTagName('input')
								for(var i = 0;i < (inputs.length -1); i++){
									var input = inputs[i]
									if(input.type=='radio' && input.checked==false && input.name=='' && input.parentNode.tagName=='A'){
										input.onclick = function(){ 
														window.location = this.parentNode.href;
														this.checked = true
													  }
									}
								}
							}				   
					)
}
// --- [end prdpctbd6008:5001 - /site/generic.js - Jun 23, 2008 8:44 am GMT - ORAC,pct4,pct9 - dQ8GCgqoTFUAADvH1wEAAAAg - cache 1800 ] ---
