var timerID = new Array(null,null,null,null);
var timerpos = new Array(0,0,0,0);
var maxopts = new Array(10,9,9,9);
var smiling=0, requesting = 0, respptr=null, favsptr=null, blockptr=null, IMptr=null, noIMs=0, warning=0;
var IMtimerID = null, imptr = null, toID = 0, frID = 0;
document.oncontextmenu = rClick;

function setLang(lang, page){
var sh = document.getElementById('singles-holiday');
if(lang != 'english'){
sh.action='http://www.myholidaypartner.com/'+lang+'/'+page;
}else{
sh.action='http://www.myholidaypartner.com/'+page;
}
sh.submit();
return false;
}
function doIt(){
var sh = document.getElementById('singles-holiday');
sh.submit();
return false;
}
function setSearch(lang, page){
var sh = document.getElementById('singles-holiday');
if(lang != 'english'){
sh.action='http://www.myholidaypartner.com/'+lang+'/'+page;
}else{
sh.action='http://www.myholidaypartner.com/'+page;
}
sh.page.value = '0';
sh.submit();
return false;
}
function resetViews(lang, page){
var sh = document.getElementById('singles-holiday');
if(lang != 'english'){
sh.action='http://www.myholidaypartner.com/'+lang+'/'+page;
}else{
sh.action='http://www.myholidaypartner.com/'+page;
}
sh.resetViews.value = '1';
sh.submit();
return false;
}
function logIn(lang, ud){
var sv = document.getElementById('singles-vacation');
var d = new Date();
if(sv.remember){
	if(sv.remember.checked == true){
		d.setTime(d.getTime() + 60*60*24*365*1000);
		document.cookie = 'MHP_usrname='+escape(sv.username.value)+';expires='+d.toGMTString()+';path=/';
		document.cookie = 'MHP_psswrd='+escape(sv.password.value)+';expires='+d.toGMTString()+';path=/';
	}
}
if(lang != 'english'){
sv.action='http://www.myholidaypartner.com/'+lang+'/'+lang+'.php';
}else{
sv.action='http://www.myholidaypartner.com/';
}
sv.undelete.value = ud;
sv.submit();
return false;
}
function goSearch(lang, p, add, remove, pg, t){
var sh = document.getElementById('singles-holiday');
var page = 'search.php';
if(pg == 's'){
sh.page.value = p;
sh.searchType.value = t;
}else if(pg == 'd'){
page = 'details.php';
}else{
sh.favpage.value = p;
if(pg == 'ds'){ page = 'singles_holiday_or_singles_vacation_disaster_stories.php'; }else if(pg == 'ib'){ page = 'inbox.php'; }else if(pg == 'mimi'){ page = 'missed-IMs-in.php'; }else if(pg == 'mimo'){ page = 'missed-IMs-out.php'; }else if(pg == 'mf'){ page = 'myfavourites.php'; }else if(pg == 'si'){ page = 'sent-items.php'; }else if(pg == 'news'){ page = 'holiday_news_and_vacation_news.php'; }else if(pg == 'probs'){ page = 'holiday_problems_and_vacation_problems.php'; }else if(pg == 'ques'){ page = 'holiday_questions_and_vacation_questions.php'; }else{ page = 'whosfavourite.php'; }
}
if(add){
sh.add.value = add;
}else if(remove){
sh.remove.value = remove;
}
if(lang != 'english'){
sh.action='http://www.myholidaypartner.com/'+lang+'/'+page;
}else{
sh.action='http://www.myholidaypartner.com/'+page;
}
sh.submit();
return false;
}
function getDets(lang, page, p, memb){
if(page == 'send-a-smile.php'){
	if(smiling) return false;
	smiling = 1;
	var str = 'sendasmile' + memb;
	var sm = document.getElementById(str);
	if(sm){
		sm.innerHTML = '<img src="./img/smile-sm.gif" width="17" height="15" border="0" hspace="8" align="middle"><span style="font-size:11px">SMILING...</span>';
	}
}else if(page == 'IM-request.php'){
	if(requesting) return false;
	requesting = 1;
	var str = 'IMrequest' + memb;
	var sm = document.getElementById(str);
	if(sm){
		sm.innerHTML = '<img src="./img/clock.gif" width="16" height="16" border="0" hspace="9" align="middle"><span style="font-size:11px">REQUESTING...</span>';
	}
}
var sh = document.getElementById('singles-holiday');
if(sh){
	if(sh.visitor && p == -99) sh.visitor.value = '1';
	sh.page.value = p == -99 ? 0 : p;
	sh.member.value = memb;
	if(lang != 'english'){
	sh.action='http://www.myholidaypartner.com/'+lang+'/'+page;
	}else{
	sh.action='http://www.myholidaypartner.com/'+page;
	}
	sh.submit();
}
return false;
}
function viewEmail(recd, tstamp, memb){
var sh = document.getElementById('singles-holiday');
sh.member.value = memb;
sh.tstamp.value = tstamp;
sh.inbox.value = recd;
sh.action='http://www.myholidaypartner.com/view-email.php';
sh.submit();
return false;
}
function missIMresp(yn, tstamp, memb){
var sh = document.getElementById('singles-holiday');
sh.member.value = memb;
sh.tstamp.value = tstamp;
if(yn == 1){
	sh.action='http://www.myholidaypartner.com/IM-request.php';
}else if(yn == 2){
	sh.action='http://www.myholidaypartner.com/missed-IMs-hi.php';
}else if(yn == 3){
	sh.action='http://www.myholidaypartner.com/missed-IMs-view-response.php';
}else{
	sh.action='http://www.myholidaypartner.com/missed-IMs-no.php';
}
sh.submit();
return false;
}
function smileRespond(yn, page, p, memb){
var sh = document.getElementById('singles-holiday');
sh.page.value = p;
sh.member.value = memb;
if(yn == 99)
	sh.resp.value = yn;
else 
	sh.resp.value = yn ? 5 : 9;
sh.action='http://www.myholidaypartner.com/'+page;
sh.submit();
return false;
}
function IMRespond(yn, ts, memb){
var sh = document.getElementById('singles-holiday');
sh.member.value = memb;
sh.resp.value = yn;
sh.ts.value = ts;
sh.action='http://www.myholidaypartner.com/IM-request-response.php';
sh.submit();
return false;
}
function goBlock(lang, block, unblock, page){
var sh = document.getElementById('singles-holiday');
if(block){ sh.block.value = block; }
if(unblock){ sh.unblock.value = unblock; }
if(lang != 'english'){
sh.action='http://www.myholidaypartner.com/'+lang+'/'+page;
}else{
sh.action='http://www.myholidaypartner.com/'+page;
}
sh.submit();
return false;
}
function sendem(id, to, sub){
var yn = confirm('This will open your default email application');
	if(yn){
		var fm = document.getElementById(id);
		fm.href = 'mailto:';
		fm.href += to;
		fm.href += '@';
		fm.href += 'myholidaypartner.com?subject=';
		fm.href += sub;
	}
}
function popup(yn, id, l, mnum){
	if(timerID[mnum] != null){
		clearTimeout(timerID[mnum]);
		timerID[mnum] = null;
	}
	if(yn){
		if(id){
			var e = document.getElementById(id);
			if(e){
				var t = 150, ladj = 0;
				var string = navigator.userAgent.toLowerCase();
				if(string.indexOf('opera') != -1){
					t = 142;
				}else if(string.indexOf('firefox') != -1){
					t = 143;
					ladj = 3;
				}
				e.style.top = t + 'px';
				e.style.left = l + ladj + 'px';
				if(++timerpos[mnum] <= maxopts[mnum]){
					var tmp = 'm' +mnum+ 'opt' +timerpos[mnum];
					var opt = document.getElementById(tmp);
					if(opt){
						opt.style.zIndex = (100 + mnum);
						opt.style.display = 'block';
					}
					if(timerpos[mnum] < maxopts[mnum]){
						var str = 'popgrow(1,' +mnum+ ')';
						timerID[mnum] = setTimeout(str, 10);
					}
				}
			}
		}
	}else{
		if(timerpos[mnum] > 0){
			var tmp = 'm' +mnum+ 'opt' +timerpos[mnum];
			var opt = document.getElementById(tmp);
			if(opt){
				opt.style.display = 'none';
			}
			if(--timerpos[mnum] > 0){
				var str = 'popgrow(0,' +mnum+ ')';
				timerID[mnum] = setTimeout(str, 10);
			}
		}
	}
}
function popgrow(yn, mnum){
	if(yn){
		if(++timerpos[mnum] <= maxopts[mnum]){
			var tmp = 'm' +mnum+ 'opt' +timerpos[mnum];
			var opt = document.getElementById(tmp);
			if(opt){
				opt.style.zIndex = (100 + mnum);
				opt.style.display = 'block';
			}
			if(timerpos[mnum] < maxopts[mnum]){
				var str = 'popgrow(1,' +mnum+ ')';
				timerID[mnum] = setTimeout(str, 10);
			}else{
				timerID[mnum] = null;
			}
		}
	}else{
		if(timerpos[mnum] > 0){
			var tmp = 'm' +mnum+ 'opt' +timerpos[mnum];
			var opt = document.getElementById(tmp);
			if(opt){
				opt.style.display = 'none';
			}
			if(--timerpos[mnum] > 0){
				var str = 'popgrow(0,' +mnum+ ')';
				timerID[mnum] = setTimeout(str, 10);
			}else{
				timerID[mnum] = null;
			}
		}
	}
}
function hlight(o, yn){
	if(yn){
		o.style.backgroundColor='rgb(147,178,221)';
	}else{
		o.style.backgroundColor='navy';
	}
}
function shlight(o, yn){
	if(yn){
		o.style.backgroundColor='navy';
		o.style.color='white';
	}else{
		o.style.backgroundColor='rgb(147,178,221)';
		o.style.color='navy';
	}
}
function goldfor(see, id){
	var im = document.getElementById(id);
	if(im){
		if(see){
			im.style.display='block';
		}else{
			im.style.display='none';
		}
	}
	return false;
}
function IMsYN(yn, memb){
	if(IMptr == null){
		noIMs = noIMs ? noIMs : yn;

		if(window.XMLHttpRequest)
			IMptr = new XMLHttpRequest();
		else if(window.ActiveXObject)
			IMptr = new ActiveXObject("Microsoft.XMLHTTP");
		if(IMptr != null){
			IMptr.onreadystatechange=IMResponse;
			IMptr.open("POST", 'http://www.myholidaypartner.com/noIMs.php', true);
			IMptr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			IMptr.send('noIMs=' +noIMs+ '&memberID=' +memb);
		}else if(warning == 0){
			warning = 1;
			alert("Your browser is old or obscure and does not support the advanced features required.\n\nIf you are still using IE5 or IE6 you may need to enable 'Safe ActiveX Controls'");
		}
	}
}
function IMResponse(){
	if(IMptr.readyState!=4) return;
	if(IMptr.status!=200) return;
	set=IMptr.responseXML.documentElement.getElementsByTagName("noIMs");
	noIMs = set[0].firstChild.nodeValue;
	
	if(noIMs == 1){
		if(IMtimerID != null)
			clearTimeout(IMtimerID);
		var str = '&nbsp;Uncheck to enable incoming Instant Messages';
	}else{
		var str = '&nbsp;Switch off incoming Instant Messages';
		sendReq();
	}
	var line = document.getElementById('noIMmess');
	line.innerHTML = str;
	IMptr = null;
}
function psswrd(lang, e){
	var key;
	if(window.event){
		key = e.keyCode;
	}else if(e.which){
		key = e.which;
	}else{
		return true;
	}
	if(key == 13){
		logIn(lang, '');
		return false;
	}else{
		return true;
	}
}
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 rememberMe(){
	var rm = 0;
	var sv = document.getElementById('singles-vacation');
	if(sv){
		var un = readCookie('MHP_usrname');
		if(un && sv.username){
			sv.username.value = un;
			rm = 1;
		}
		var pw = readCookie('MHP_psswrd');
		if(pw && sv.password){
			sv.password.value = pw;
			rm = 1;
		}
		if(rm && sv.remember){
			sv.remember.checked = true;
		}
	}
}
function forgetMe(){
	var sv = document.getElementById('singles-vacation');
	if(sv){
		if(sv.remember && sv.remember.checked == false){
			var d = new Date();
			d.setTime(d.getTime() - 1000);
			document.cookie = 'MHP_usrname="0";expires='+d.toGMTString()+';path=/';
			document.cookie = 'MHP_psswrd="0";expires='+d.toGMTString()+';path=/';
		}
	}
	return true;
}
function silly(){
	alert("Don't be silly!!\n\nThis is you!");
	return false;
}
function onlyvisiting(){
	alert("It is free to search for a holiday partner, but you need to have your own profile first.\n\nGo to 'Create My Profile' from the 'MY PROFILE' menu at the top of the page.");
	return false;
}
function smileResp(yn, smto, smfrom){
	if(respptr == null){
		if(window.XMLHttpRequest)
			respptr = new XMLHttpRequest();
		else if(window.ActiveXObject)
			respptr = new ActiveXObject("Microsoft.XMLHTTP");
		if(respptr != null){
			respptr.onreadystatechange=smileResponse;
			respptr.open("POST", 'http://www.myholidaypartner.com/smile-response.php', true);
			respptr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			respptr.send('yn=' +yn+ '&smto=' +smto+ '&smfrom=' +smfrom);
		}else if(warning == 0){
			warning = 1;
			alert("Your browser is old or obscure and does not support the advanced features required.\n\nIf you are still using IE5 or IE6 you may need to enable 'Safe ActiveX Controls'");
		}
	}
}
function smileResponse(){
	if(respptr.readyState!=4) return;
	if(respptr.status!=200)	return;
	var set=respptr.responseXML.documentElement.getElementsByTagName("memtype");
	var memtype = set[0].firstChild.nodeValue;
	set=respptr.responseXML.documentElement.getElementsByTagName("yn");
	var yn = set[0].firstChild.nodeValue;
	set=respptr.responseXML.documentElement.getElementsByTagName("smname");
	var smname = set[0].firstChild.nodeValue;

	var butt = document.getElementById('smilebut');
	butt.innerHTML = '&nbsp;';
	if(yn == 0){
		var smiler = document.getElementById('smiler');
		smiler.innerHTML = '<img src="./img/miserable-75x63.gif" width="75" height="63">';
		var str = "<div class=\"orangetextlg\">You have said 'Sorry, but No Thanks' to " +smname+ '</div><br>';
	}else{
		var str = '<div class="orangetextlg">You have smiled back at ' +smname+ '</div><br>';
		if(memtype == 0){
			str += 'Now they know you are interested too! This is the time to become a <span style="color:silver">SILVER</span> or <span style="color:olive">GOLD MEMBER</span> so they will be able to contact you via email.<br><br>If you become a <span style="color:olive">GOLD MEMBER</span> you will even be able to talk in real time using Instant Messages!';
		}else if(memtype == 1){
			str += 'Now they know you are interested too! Now is the time to make contact via email!<br><br>Or, if you become a <span style="color:olive">GOLD MEMBER</span> you will even be able to talk in real time using Instant Messages!';
		}else if(memtype == 99){
			str = '<div class="orangetextlg">Sorry, there was an error when responding to their smile</div>';
		}else{
			str += 'Now they know you are interested too! Connect with each other via email or Instant Messages!';
		}
	}
	butt = document.getElementById('smilebox');
	butt.innerHTML = str;
}
function pickday(d){
	var tmp = 'imhr' + d;
	var v = document.getElementById(tmp);
	v.disabled = false;
	tmp = 'immin' + d;
	v = document.getElementById(tmp);
	v.disabled = false;
	for(var x=1;x<=31;x++){
		if(x != d){
			tmp = 'imhr' + x;
			if((v = document.getElementById(tmp))){
				v.disabled = true;
				tmp = 'immin' + x;
				v = document.getElementById(tmp);
				v.disabled = true;
			}
		}
	}
}
function addFavs(yn, memb, addmemb){
	if(favsptr == null){
		var temp = 'favs'+addmemb;
		var line = document.getElementById(temp);
		yn = (line.innerHTML.indexOf('ADD') == -1) ? 1 : 0;
		
		if(window.XMLHttpRequest)
			favsptr = new XMLHttpRequest();
		else if(window.ActiveXObject)
			favsptr = new ActiveXObject("Microsoft.XMLHTTP");
		if(favsptr != null){
			line.innerHTML = yn > 0 ? '<img src="./img/fav.gif" width="13" height="15" border="0" hspace="10" align="middle">REMOVING...' : '<img src="./img/add.gif" width="15" height="15" border="0" hspace="9" align="middle">ADDING...';
			favsptr.onreadystatechange=favsResponse;
			favsptr.open("POST", 'http://www.myholidaypartner.com/add-to-favourites.php', true);
			favsptr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			favsptr.send('yn=' +yn+ '&memberID=' +memb+ '&member=' +addmemb);
		}else if(warning == 0){
			warning = 1;
			alert("Your browser is old or obscure and does not support the advanced features required.\n\nIf you are still using IE5 or IE6 you may need to enable 'Safe ActiveX Controls'");
		}
	}
}
function favsResponse(){
	if(favsptr.readyState!=4) return;
	if(favsptr.status!=200)	return;
	set=favsptr.responseXML.documentElement.getElementsByTagName("yn");
	var yn = set[0].firstChild.nodeValue;
	set=favsptr.responseXML.documentElement.getElementsByTagName("addmemb");
	var addmemb = set[0].firstChild.nodeValue;
	
	var temp = 'favs'+addmemb;
	var line = document.getElementById(temp);
	line.innerHTML = yn > 0 ? '<img src="./img/add.gif" width="15" height="15" border="0" hspace="9" align="middle">ADD TO FAVOURITES' : '<img src="./img/fav.gif" width="13" height="15" border="0" hspace="10" align="middle">REMOVE FROM FAVs';
	favsptr = null;
}
function block(yn, memb, addmemb){
	if(blockptr == null){
		var temp = 'block'+addmemb;
		var line = document.getElementById(temp);
		yn = (line.innerHTML.indexOf('MEMBER') == -1) ? 1 : 0;

		if(window.XMLHttpRequest)
			blockptr = new XMLHttpRequest();
		else if(window.ActiveXObject)
			blockptr = new ActiveXObject("Microsoft.XMLHTTP");
		if(blockptr != null){
			line.innerHTML = yn > 0 ? '<img src="./img/blocked.gif" width="15" height="15" border="0" hspace="9" align="middle">REMOVING BLOCK...' : '<img src="./img/block.gif" width="13" height="15" border="0" hspace="10" align="middle">BLOCKING...';
			blockptr.onreadystatechange=blockResponse;
			blockptr.open("POST", 'http://www.myholidaypartner.com/block.php', true);
			blockptr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			blockptr.send('yn=' +yn+ '&memb=' +memb+ '&addmemb=' +addmemb);
		}else if(warning == 0){
			warning = 1;
			alert("Your browser is old or obscure and does not support the advanced features required.\n\nIf you are still using IE5 or IE6 you may need to enable 'Safe ActiveX Controls'");
		}
	}
}
function blockResponse(){
	if(blockptr.readyState!=4) return;
	if(blockptr.status!=200) return;
	set=blockptr.responseXML.documentElement.getElementsByTagName("yn");
	var yn = set[0].firstChild.nodeValue;
	set=blockptr.responseXML.documentElement.getElementsByTagName("addmemb");
	var addmemb = set[0].firstChild.nodeValue;
	
	var temp = 'block'+addmemb;
	var line = document.getElementById(temp);
	line.innerHTML = yn > 0 ? '<img src="./img/block.gif" width="13" height="15" border="0" hspace="10" align="middle">BLOCK THIS MEMBER' : '<img src="./img/blocked.gif" width="15" height="15" border="0" hspace="9" align="middle">REMOVE BLOCK';
	blockptr = null;
}
function startIM(tID, fID, flags){
	var url = 'http://www.myholidaypartner.com/IMWindow.php?toID=' +tID+ '&frID=' +fID+ '&flags=' +flags;
//	var name = 'Window' + tID;
	var name = '';
	popupIM(url, name, 600, 550);
	return false;
}

function popupIM(url, name, width, height){
	var t = Math.floor(Math.random() * 151);
	var l = Math.floor(Math.random() * 151);
	var settings=
	"toolbar=no,location=no,directories=no,"+
	"status=no,menubar=no,scrollbars=no,"+
	"resizable=yes,top=" +t+ ",left=" +l+ ",width="+width+",height="+height;

	newWindow=window.open(url,name,settings);
	return false;
}

function sendReq(){
	imptr = null;
	if(window.XMLHttpRequest)
		imptr = new XMLHttpRequest();
	else if (window.ActiveXObject)
		imptr = new ActiveXObject("Microsoft.XMLHTTP");
	if (imptr != null){
		imptr.onreadystatechange=checkIMresponse;
		imptr.open("POST", 'http://www.myholidaypartner.com/checkforIMs.php', true);
		imptr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		imptr.send('toID=' +toID);
	}else if(warning == 0){
		warning = 1;
		alert("Your browser is old or obscure and does not support the advanced features required for IMs.\n\nIf you are still using IE5 or IE6 you may need to enable 'Safe ActiveX Controls'");
	}
}

function init(memb, yn){
	rememberMe();
	toID = memb;
	noIMs = yn;
	if(noIMs == 2)
		sendReq();
}

function checkIMresponse(){
	if(imptr.readyState!=4) return;
	if(imptr.status!=200)	return;
	var set=imptr.responseXML.documentElement.getElementsByTagName("frID");
	frID = set[0].firstChild.nodeValue;
	if(frID > 0){
		startIM(toID, frID, 1);
	}
	if(noIMs == 2)
		IMtimerID = setTimeout(sendReq, 60000);
}
function rClick(e){
	var aff = document.getElementById('singles-holiday');
	if(aff && aff.bannerwidth){
		return true;
	}else{
		return false;
	}
}

