window.setTimeout("refreshLoader()",60000);

function refreshLoader() 
{ 
	new Ajax.Request('/keepalive.jsp', {asynchronous:true});
	window.setTimeout("refreshLoader()",60000);
}

function submitSearch(el) 
{ 
	document.getElementById('searchType').value=el; 
	document.getElementById('quickSearchForm').submit();
}

function changeImagesArray(array) 
{
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<array.length; i+=2) {
			document[array[i]].src = array[i+1];
		}
	}
}

function changeImages() 
{
	changeImagesArray(changeImages.arguments);
}
	
var quickView=true;

var expandedOn;
var quickOn;
var preloadFlag;

function preloadImages() 
{

	if (document.images) 
	{
		expandedOn = new Image();
		expandedOn.src = "https://media.dlist.com/images/en/tabs_expandedview-on.gif";
		
		quickOn = new Image();
		quickOn.src = "https://media.dlist.com/images/en/tabs_quickview-on.gif";	
		
		preloadFlag=true;
	}	
} 

function toggleView() 
{
preloadImages();
	var i=0;
	var expanded=new Array();
	var quick=new Array();
	
	while (document.getElementById("expandedResult"+i)!=null)
	{
		expanded[i]= document.getElementById("expandedResult"+i)
		i++;
	}
	
	i=0;
	while (document.getElementById("quickResult"+i)!=null)
	{
		quick[i]= document.getElementById("quickResult"+i)
		i++;
	}
	
	if(quickView)
	{
	
		$('toggleImage').src=expandedOn.src;
		quickView=false;
		
		for(var j=0;j<quick.length;j++)
			quick[j].style.display="none";
	
		for(var j=0;j<expanded.length;j++)
			expanded[j].style.display="block";
	}
	else
	{
		quickView=true;
		$('toggleImage').src=quickOn.src;

		for(var j=0;j<expanded.length;j++)
			expanded[j].style.display="none";
			
		for(var j=0;j<quick.length;j++)
		{
			quick[j].style.display="block";
		}
		
	}
}

function updateStates(selectBox)
{	
	var params='ac=getStates&country='+selectBox.value;
	new Ajax.Request('/search.do',
	{
		parameters: params,
		onSuccess: function(transport) { 
			var json = transport.responseText.evalJSON();
					 
			 var options = $('stateSelect').getElementsByTagName('option'), option; 
			 while(options.length>1)
				$('stateSelect').removeChild(options[options.length-1]);

			for(var i=0;i<json.states.length;i++)
			{
	 			option = document.createElement('option');
				option.setAttribute('value', json.states[i].state.abbreviation);
				option.appendChild(document.createTextNode(json.states[i].state.name));
				$('stateSelect').appendChild(option); 						
			}	
		},
		onFailure: function() { alert("There was an error retrieving the states. Please try again."); },
		onException: function(x,y) { alert("There was an error retrieving the states. Please try again."); }
	});		
}
function retrievePriceRange(selectBox)
{	
	var params='ac=getPriceList&location='+selectBox.value;
	var index = selectBox.name.substring(0,selectBox.name.indexOf('.'));
	new Ajax.Request('/flyer.do',
	{
		parameters: params,
		onSuccess: function(transport) { 
			var json = transport.responseText.evalJSON();
					 
			 var options = document.forms[0].elements[index+'.flyerPrice.flyer_price_id'].getElementsByTagName('option'), option; 
			 while(options.length>0)
				document.forms[0].elements[index+'.flyerPrice.flyer_price_id'].removeChild(options[options.length-1]);

			for(var i=0;i<json.priceList.length;i++)
			{
	 			option = document.createElement('option');
				option.setAttribute('value', json.priceList[i].price.price_id);
				option.appendChild(document.createTextNode(json.priceList[i].price.amount));
				document.forms[0].elements[index+'.flyerPrice.flyer_price_id'].appendChild(option); 						
			}	
		},
		onFailure: function() { alert("There was an error retrieving the price. Please try again."); },
		onException: function(x,y) { alert("There was an error retrieving the price. Please try again."); }
	
	});		
}

function addLocation(index)
{
	document.forms[0].elements["ac"].value="step1";
	document.forms[0].elements["action"].value="add";
	document.forms[0].elements["step"].value="1";
	document.forms[0].submit();
}
function removeLocation(index)
{
	document.forms[0].elements["ac"].value="step1";
	document.forms[0].elements["action"].value="remove";
	document.forms[0].elements["step"].value="1";
	document.forms[0].elements["id"].value=index;
	document.forms[0].submit();
}
function calculate(index)
{
	document.forms[0].elements["ac"].value="step1";
	document.forms[0].elements["action"].value="calculate";
	document.forms[0].elements["step"].value="1";
	document.forms[0].submit();
}


function sendEmail() 
{
    //var par = $H({ subject: $('emailSubject'), message: $('emailMessage'), pid: $('pid') }).toQueryString()

	new Ajax.Updater('emailResultDiv', '/sendmessage.do?ac=sendAjax',
	{
		//parameters: 'subject='+$('emailSubject').value+'&message='+$('emailMessage').value+'&pid='+$('pid').value
		parameters: { subject: $('emailSubject').value , message: $('emailMessage').value, pid: $('pid').value }
		
	});
	
	//"org.apache.struts.taglib.html.TOKEN="+$('token').value
}
function saveMobileNum() 
{
    //var par = $H({ subject: $('emailSubject'), message: $('emailMessage'), pid: $('pid') }).toQueryString()
	document.getElementById('acodeDiv').style.display="block";
	document.getElementById('mobileExample').style.display="block";
	if(document.getElementById('notverified')!=null)
	{
		document.getElementById('notverified').style.display="none";
	}
	//document.getElementById('acodeSavedDiv').style.display="none";
	new Ajax.Updater('acodeValue', '/update.do?ac=setMobileAjax',
	{
		//parameters: 'subject='+$('emailSubject').value+'&message='+$('emailMessage').value+'&pid='+$('pid').value
		parameters: { mobile_num: $('mobile_num').value }
		
	});
	
	//"org.apache.struts.taglib.html.TOKEN="+$('token').value
}
function removeMobileNum() 
{
    //var par = $H({ subject: $('emailSubject'), message: $('emailMessage'), pid: $('pid') }).toQueryString()
	//document.getElementById('acodeDiv').style.display="block";
	//document.getElementById('notverified').style.display="none";
	document.getElementById('mobileExample').style.display="block";
	new Ajax.Updater('mobileFormField', '/update.do?ac=removeMobileAjax',
	{
		//parameters: 'subject='+$('emailSubject').value+'&message='+$('emailMessage').value+'&pid='+$('pid').value
	
	});
	
	//"org.apache.struts.taglib.html.TOKEN="+$('token').value
}
function showStatusLog(pid) 
{
    //var par = $H({ subject: $('emailSubject'), message: $('emailMessage'), pid: $('pid') }).toQueryString()
	//document.getElementById('acodeDiv').style.display="block";
	//document.getElementById('notverified').style.display="none";
	document.getElementById('statusLogDiv').style.display="block";
	
	new Ajax.Updater('statusLogDiv', '/viewprofile.do?ac=showStatusLogAjax',
	{
		parameters: { profile_id: pid}
	
	});
	
	//"org.apache.struts.taglib.html.TOKEN="+$('token').value
}
function deleteStatusLog(pid,lid) 
{
    //var par = $H({ subject: $('emailSubject'), message: $('emailMessage'), pid: $('pid') }).toQueryString()
	//document.getElementById('acodeDiv').style.display="block";
	//document.getElementById('notverified').style.display="none";
	//document.getElementById('mobileExample').style.display="block";
	new Ajax.Updater('statusLogDiv', '/viewprofile.do?ac=deleteStatusLogAjax',
	{
		parameters: { profile_id: pid, log_id : lid}
	
	});
	
	//"org.apache.struts.taglib.html.TOKEN="+$('token').value
}

function setStatus() 
{
    //var par = $H({ subject: $('emailSubject'), message: $('emailMessage'), pid: $('pid') }).toQueryString()
	document.getElementById('statusDiv').style.display="block";
	document.getElementById('statusFormDiv').style.display="none";
	if(document.getElementById('statusLogDiv')!=null)
	{
		document.getElementById('statusLogDiv').style.display="none";
	}
	new Ajax.Updater('profileStatus', '/viewprofile.do?ac=setStatusAjax',
	{
		//parameters: 'subject='+$('emailSubject').value+'&message='+$('emailMessage').value+'&pid='+$('pid').value
		parameters: { profile_id: $('profile_id').value , status: $('status').value }
		
	});
	
	//"org.apache.struts.taglib.html.TOKEN="+$('token').value
}
function setStatusForm()
{
	document.getElementById('statusDiv').style.display="none";
	document.getElementById('statusFormDiv').style.display="block";
	
}

function showUserDetail(profile_id) 
{
	document.getElementById('userDetailLink').style.display="none";
	new Ajax.Updater('userDetailDiv', '/viewprofile.do?ac=showUserDetailAjax',
	{
		parameters: { pid: profile_id }
		
	});
}

function prebul()
{

	new Ajax.Updater('previewDiv', '/bulletin/preview.do',
	{
		method: 'post',
		postBody: 'ac=previewBulletin&subject='+$('subject').value+'&message='+$('message').value,
		//onCreate: function() { Effect.BlindUp('previewDiv'); },
		//onSuccess: function() { Effect.BlindDown('previewDiv'); },
		onFailure: function(transport) { alert(transport.responseText); },
		onException: function(x,y) { alert(y); }
	});

}

function delbul(el)
{	
	var params='ac=deleteBulletin&bulletinID='+el;
	new Ajax.Request('/bulletin/list.do',
	{
		parameters: params,
		onSuccess: function() { Effect.toggle($('bid_'+el), 'blind'); },
		onFailure: function() { alert('Unable to delete bulletin. Please try again later.'); }
	
	});		
}

var showing = false;
function changeTab(el)
{
	
	switch(el)
	{
		case 1:
		$('pictabcontent').style.display="block";
		$('ppictabcontent').style.display="none";
		$('vidtabcontent').style.display="none";
		$('pvidtabcontent').style.display="none";			
		$('box1').style.borderBottomWidth="0px";
		$('box2').style.borderBottomWidth="1px";
		$('box3').style.borderBottomWidth="1px";
		$('box4').style.borderBottomWidth="1px";
		break;
		
		case 2:
		$('pictabcontent').style.display="none";
		$('ppictabcontent').style.display="block";
		$('vidtabcontent').style.display="none";
		$('pvidtabcontent').style.display="none";			
		$('box1').style.borderBottomWidth="1px";
		$('box2').style.borderBottomWidth="0px";
		$('box3').style.borderBottomWidth="1px";
		$('box4').style.borderBottomWidth="1px";

		
		break;
		
		case 3:
		$('pictabcontent').style.display="none";
		$('ppictabcontent').style.display="none";
		$('vidtabcontent').style.display="block";
		$('pvidtabcontent').style.display="none";			
		$('box1').style.borderBottomWidth="1px";
		$('box2').style.borderBottomWidth="1px";
		$('box3').style.borderBottomWidth="0px";
		$('box4').style.borderBottomWidth="1px";

		
		break;
		
		case 4:
		$('pictabcontent').style.display="none";
		$('ppictabcontent').style.display="none";
		$('vidtabcontent').style.display="none";
		$('pvidtabcontent').style.display="block";			
		$('box1').style.borderBottomWidth="1px";
		$('box2').style.borderBottomWidth="1px";
		$('box3').style.borderBottomWidth="1px";
		$('box4').style.borderBottomWidth="0px";
		
		break;
	}
}

function tooltip(el) {
	return overlib(el,  SHADOW, SHADOWCOLOR, '#585858', SHADOWOPACITY, 50, FGCOLOR , '#FFFFCC');

}
function tooltip2(el) {
	return overlib(el,  SHADOW, SHADOWCOLOR, '#585858', SHADOWOPACITY, 50, FGCOLOR , '#98c724',BORDER,0);

}

function popUP(mypage, myname, w, h, scroll, titlebar)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}	

function setIM(el)
{
	if(el=='on')
	{
		set_cookie('dlim', 'on', 900, '/');
	}
	else
	{
		set_cookie('dlim', 'off', 900, '/');
	}
	
	window.location.reload();
}

function set_cookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );
	
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function setAutoplay(el)
{
	if(el=='true')
	{
		set_cookie('autoplay', 'true', 900, '/');
	}
	else
	{
		set_cookie('autoplay', 'false', 900, '/');
	}
	
	window.location.reload();
}

function setShuffle(el)
{
	if(el=='true')
	{
		set_cookie('shuffle', 'true', 900, '/');
	}
	else
	{
		set_cookie('shuffle', 'false', 900, '/');
	}
	
	window.location.reload();
}

function numresultsImages(el,pid)
{
	window.location="/search.do?page=1&nr="+el.value+"&profile_id="+pid;
}
function numresults(el)
{
	window.location="/search.do?page=1&nr="+el.value;
}
function openWebchat(cookie)
{
	var w= window.open( "/webchat/wc.php?im="+cookie+"", "WCWindow", "width=870,height=830,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=0" );
	w.focus();
}
function openBackroom(pid)
{
	var w= window.open( "/backroom.do?pid="+pid+"", "Backroom", "width=880,height=900,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=1" );
	w.focus();
}
function openMyBackroom()
{
	var w= window.open( "/backroom.do", "Backroom", "width=880,height=900,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=1" );
	w.focus();
}

var showing=false;
function toggleSlide() {Effect.toggle('searchmenu','blind');if(showing){showing=false;}else{showing=true;}return false;}


window.latestClick = '';

function isNotDblClick(objectID) {
	if(window.latestClick != objectID) {
		window.latestClick = objectID;
		return true;
	} else {
		return false;
	}
}

function dblClick(id,url)
{
	if(isNotDblClick(id)) 
	{
		window.location.replace(url);
	} 
	else 
	{
		return false;
	}
}
