function shortlistToggleMoreFriends(type){
	if (document.getElementById('shortlistMoreFriends')){
		if (type == 'on'){
			div_switch('shortlistMoreFriends',true,true);
			div_switch('shortlistAddMoreFriends',false,true);			
		}else{
			div_switch('shortlistMoreFriends',false,true);
			div_switch('shortlistAddMoreFriends',true,true);			
		}
	}
}


function MoreFriends() {
	oCopyFrom = document.getElementById('shortlistCopyFrom');	
	oCopyTo = document.getElementById('shortlistCopyTo');	
	oCounter = document.getElementById('shortlistFriendCount');	
	if(oCopyFrom && oCopyTo && oCounter) {
		oEmails = document.getElementsByName('shortlistSendEmail');
		var oEmailArray = new Array();
		for(x=0;x<oEmails.length;x++) {
			if(oEmails[x].value){
				oEmailArray[x] = oEmails[x].value;
			}
		}
		sFromHTML = oCopyFrom.innerHTML;
		oCopyTo.innerHTML += sFromHTML;
		iNumber = parseFloat(oCounter.innerHTML.split(' ')[0]);
		iNewNumber = iNumber+1;
		sNumberText = 'friend';
		if(iNewNumber!=1){sNumberText += 's';}
		oCounter.innerHTML = iNewNumber+' '+sNumberText;
		for(x=0;x<oEmailArray.length;x++) {
			if(oEmailArray[x]) {
				oEmails[x].value = oEmailArray[x]; 
			}
		}
		//alert(oEmails.length);
		oEmails[oEmails.length-1].value = '';
	}	
}

function SendShortlist() {
	var e = '';
	var sPostVal='';
	var sShortlistSaveAs = '';
	var sShortlistName = '';
	oEmails = document.getElementsByName('shortlistSendEmail');
	sName = trim(document.getElementById('shortlistSendYourName').value);
	sMessage = document.getElementById('shortlistSendMessage').value;
	if(document.getElementById('shortlistSendShortlistName')){
		sShortlistName = document.getElementById('shortlistSendShortlistName').value;
	}
	if(document.getElementById('shortlistSendShortlistSaveAs')){
		sShortlistSaveAs = document.getElementById('shortlistSendShortlistSaveAs').value;
	}
	if(oEmails.length>0){
		if(!sName || sName =='- Enter your name -'){e+='- Please enter your name\n';}
		if(!sShortlistName && (!sShortlistSaveAs || sShortlistSaveAs=='- Give your list a name -')){e+='- Please enter a name for your shortlist\n';}
		for(x=0;x<oEmails.length;x++) {
			sEmail = oEmails[x].value;
			if(sEmail != '' || x==0){
				if(!/.+@[^.]+(\.[^.]+)+/.test(sEmail) || isValidField(sEmail,2) == false){
					e+='- Please enter a valid email address for your friend '+parseFloat(x+1)+'\n';
				}
			}
		}
	}
	if(e) {
		alert(e);
		return false;
	}else{
		document.frmSendShortlist.submit();
	}
}

function SaveShortlist() {
	var e = '';
	sEmail = document.getElementById('shortlistSaveEmail').value;
	sName = document.getElementById('shortlistSaveName').value;
	if(!sEmail || sEmail=='- Enter your email -'){e+='- Please enter your email address\n';}
	if(!sName|| sName=='- Give your list a name -'){e+='- Please enter a name for your shortlist\n';}
	if(e) {
		alert(e);
		return false;
	}else{
		document.frmSaveShortlist.submit();
	}
}



function showLoader(id) {
	if(!id) {
		oResultDiv = document.getElementById('ResultContent1');
	}else{
		oResultDiv = document.getElementById(id);
	}
	if(oResultDiv && !bLoaderShowing) {
		bLoaderShowing = true;
		if(!sHTMLLoadTemplate){
			sHTMLLoadTemplate = readFileInAsync('/includes/shortlist/loader.html');
		}
		oResultDiv.innerHTML = sHTMLLoadTemplate;
	}	
}

function readFileInAsync(url, bPost, sPostValues) {
	if (window.XMLHttpRequest) {              
		SyncDOMInAsync=new XMLHttpRequest();              
	} else {                                  
		SyncDOMInAsync=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (SyncDOMInAsync) {
		if(bDebug){
			var timestamp = new Date();
			if(url.indexOf('?')>-1) {
				url	= url+'&timestamp='+timestamp;
			}else{
				url	= url+'?timestamp='+timestamp;
			}
		}
		if(bPost){
			sMethod='POST';
		}else{
			sMethod='GET';
		}
		SyncDOMInAsync.open(sMethod, url, false);
		if(bPost) {
			SyncDOMInAsync.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			SyncDOMInAsync.setRequestHeader("Content-length", sPostValues.length);
			SyncDOMInAsync.setRequestHeader("Connection", "close");
		}
		SyncDOMInAsync.send(sPostValues);
		return SyncDOMInAsync.responseText;                                         
	} else {
		return false;
	}                                             
}

function addToShortlist(sProvider, sIdentifier){
	//sIdentifier example: &itineraryid=619363125
	if(document.getElementById('SessionID')){
		sSessionID = document.getElementById('SessionID').value;
	}
	if(document.getElementById('search_type')){
		sSearchType = document.getElementById('search_type').value;		
	}
	sQueryString = escape(window.location.search);	
	if(sSessionID && sSearchType && sQueryString){
		sQueryString = sQueryString.replace(/%3F/gi,'[') //?
		sQueryString = sQueryString.replace(/%3D/gi,']') //=
		sQueryString = sQueryString.replace(/%26/gi,'|') //&
		sIdentifier = sIdentifier.replace(/&/gi,'%26')
		sIdentifier = sIdentifier.replace(/=/gi,'%3D')
		//alert('/shortlist/addtoshortlist.asp?search_type=' + sSearchType + '&sessionid=' + sSessionID + '&qs=' + sQueryString + sIdentifier)
		//LightBox('', '',0,0, 'LightBox', '/shortlist/addtoshortlist.asp?search_type=' + sSearchType + '&sessionid=' + sSessionID + '&qs=' + sQueryString + sIdentifier, 430, 400);
		//alert('/shortlist/addtoshortlist.asp%3Fsearch_type%3D' + sSearchType + '%26sessionid%3D' + sSessionID + '%26qs%3D' + sQueryString + sIdentifier)
		LightBox('', '',0,0, 'LightBox', '/shortlist/addtoshortlist.asp%3Fsearch_type%3D' + sSearchType + '%26sessionid%3D' + sSessionID + '%26qs%3D' + sQueryString + sIdentifier, 380, 141);
	}
}

function ClearShortlist() {
	if(confirm('Are you sure you want to delete all the items in your shortlist?')) {
		var id = '0'
		document.location.href='/shortlist/removefromshortlist.asp?item='+id;
	}else{
		//return false;
	}
}

function RemoveShortlistItem(id) {
	if(confirm('Are you sure you want to delete this item from your shortlist?')) {
		document.location.href='/shortlist/removefromshortlist.asp?item='+id;
	}else{
		return false;
	}
}


