function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
		
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function unsetChoice(select) {
	if(select.selectedIndex == '1')
		select.selectedIndex = '0';
}

var cspdSum = 100;
var rvbSum = 100;
var mosaic ={};

mosaic.mouseOver=function(row,col,id,bgColor,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_profile" 
			&& (!(type == "profile_history" && row==1 && col==1))){
		box.style.background=bgColor;
		document.getElementById("kwrd_"+row+col).style.color='#FFFFFF';
		document.getElementById("proName_"+row+col).style.visibility='visible';
	} else if(type == "saved_profile" ) {
		document.getElementById("proName_"+row+col).style.visibility='visible';
	}
	document.getElementById('img_'+id).style.visibility='visible';
	//document.getElementById('img_'+id).style.top = box.offsetTop+box.offsetHeight - 40;
	//document.getElementById('img_'+id).style.left = box.offsetLeft+box.offsetWidth - 40;
	document.getElementById('profiledata').style.visibility='visible';
	document.getElementById('profiledata').style.backgroundColor=bgColor;
	document.getElementById('profiletable_name').innerHTML=document.getElementById('proName_'+row+col).innerHTML;
	document.getElementById('profiletable_summary').innerHTML=document.getElementById('summary_'+row+col).innerHTML;
	document.getElementById('profiletable_category').innerHTML=document.getElementById('category_'+row+col).innerHTML;
	
	document.getElementById('sloganProfile').style.visibility='visible';
	
	if('proximity_profile' == type && !(row == 1 && col == 1)){
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,true,'offer');
	}
}

mosaic.mouseOut=function(row,col,id,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_profile" 
			&& (!(type == "profile_history" && row==1 && col==1))
			&& (!(type == "proximity_search" && row==1 && col==1))
			&& (!(type == "proximity_profile" && row==1 && col==1))){
		box.style.background='#FFFFFF';
		document.getElementById("kwrd_"+row+col).style.color='#ec6e17';
		document.getElementById("proName_"+row+col).style.visibility='hidden';
	} else if(type == "saved_profile" ) {
		document.getElementById("proName_"+row+col).style.visibility='hidden';
	}
	if(!(type == "proximity_search" && row==1 && col==1)
		&& !(type == "proximity_profile" && row==1 && col==1)){
		document.getElementById('img_'+id).style.visibility='hidden';
	}
	document.getElementById('profiledata').style.visibility='hidden';
	
	document.getElementById('sloganProfile').style.visibility='hidden';
	
	if('proximity_profile' == type && !(row == 1 && col == 1)){
		var bgColor =document.getElementById('profiledata').style.backgroundColor;
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,false,'offer');
	}
}

mosaic.mouseOverOffer=function(row,col,id,bgColor,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_offer" && (!(type == "offer_history" && row==1 && col==1))){
		box.style.background=bgColor;
		document.getElementById("kwrd_"+row+col).style.color='#FFFFFF';
		//document.getElementById("offerName_"+row+col).style.visibility='visible';
	}
	document.getElementById('img_'+id).style.visibility='visible';
	//document.getElementById('img_'+id).style.top = box.offsetTop+box.offsetHeight - 40;
	//document.getElementById('img_'+id).style.left = box.offsetLeft+box.offsetWidth - 40;
	document.getElementById('offerdata').style.visibility='visible';
	document.getElementById('offerdata').style.backgroundColor=bgColor;
	document.getElementById('offertable_name').innerHTML=document.getElementById('offerName_'+row+col).innerHTML;
	document.getElementById('offertable_summary').innerHTML=document.getElementById('summary_'+row+col).innerHTML;
	document.getElementById('offertable_category').innerHTML=document.getElementById('category_'+row+col).innerHTML;
	
	document.getElementById('sloganOffer').style.visibility='visible';
	
	if('proximity_offer' == type && !(row == 1 && col == 1)){
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,true,'profile');
	}
}

mosaic.mouseOutOffer=function(row,col,id,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_offer" 
		&& (!(type == "offer_history" && row==1 && col==1))
		&& (!(type == "proximity_offer" && row==1 && col==1))){
		box.style.background='#FFFFFF';
		document.getElementById("kwrd_"+row+col).style.color='#ec6e17';
		//document.getElementById("offerName_"+row+col).style.visibility='hidden';
	}
	if(!(type == "proximity_offer" && row==1 && col==1)){
		document.getElementById('img_'+id).style.visibility='hidden';
	}
	document.getElementById('offerdata').style.visibility='hidden';
	
	document.getElementById('sloganOffer').style.visibility='hidden';
	
	if('proximity_offer' == type && !(row == 1 && col == 1)){
		var bgColor =document.getElementById('offerdata').style.backgroundColor;
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,false,'profile');
	}
}

mosaic.mouseOverMatching=function(row,col,id,bgColor,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_offer" && (!(type == "offer_history" && row==1 && col==1))){
		box.style.background=bgColor;
		document.getElementById("kwrd_"+row+col).style.color='#FFFFFF';
		document.getElementById("offerName_"+row+col).style.visibility='visible';
	}
	document.getElementById('img_'+id).style.visibility='visible';
	//document.getElementById('img_'+id).style.top = box.offsetTop+box.offsetHeight - 40;
	//document.getElementById('img_'+id).style.left = box.offsetLeft+box.offsetWidth - 40;
	document.getElementById('offerdata').style.visibility='visible';
	document.getElementById('offerdata').style.backgroundColor=bgColor;
	document.getElementById('offertable_name').innerHTML=document.getElementById('offerName_'+row+col).innerHTML;
	document.getElementById('offertable_summary').innerHTML=document.getElementById('summary_'+row+col).innerHTML;
	document.getElementById('offertable_category').innerHTML=document.getElementById('category_'+row+col).innerHTML;
	
	document.getElementById('sloganProfile').style.visibility='visible';
	
	if('proximity_offer' == type && !(row == 1 && col == 1)){
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,true,'profile');
	}
}

mosaic.mouseOutMatching=function(row,col,id,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_offer" 
		&& (!(type == "offer_history" && row==1 && col==1))
		&& (!(type == "proximity_offer" && row==1 && col==1))){
		box.style.background='#FFFFFF';
		document.getElementById("kwrd_"+row+col).style.color='#ec6e17';
		document.getElementById("offerName_"+row+col).style.visibility='hidden';
	}
	if(!(type == "proximity_offer" && row==1 && col==1)){
		document.getElementById('img_'+id).style.visibility='hidden';
	}
	document.getElementById('offerdata').style.visibility='hidden';
	
	document.getElementById('sloganProfile').style.visibility='hidden';
	if('proximity_offer' == type && !(row == 1 && col == 1)){
		var bgColor =document.getElementById('offerdata').style.backgroundColor;
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,false,'profile');
	}
}

mosaic.mouseOverMatchingOffer=function(row,col,id,bgColor,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_profile" && (!(type == "profile_history" && row==1 && col==1))){
		box.style.background=bgColor;
		document.getElementById("kwrd_"+row+col).style.color='#FFFFFF';
		document.getElementById("proName_"+row+col).style.visibility='visible';
	}
	document.getElementById('img_'+id).style.visibility='visible';
	//document.getElementById('img_'+id).style.top = box.offsetTop+box.offsetHeight - 40;
	//document.getElementById('img_'+id).style.left = box.offsetLeft+box.offsetWidth - 40;
	document.getElementById('profiledata').style.visibility='visible';
	document.getElementById('profiledata').style.backgroundColor=bgColor;
	document.getElementById('profiletable_name').innerHTML=document.getElementById('proName_'+row+col).innerHTML;
	document.getElementById('profiletable_summary').innerHTML=document.getElementById('summary_'+row+col).innerHTML;
	document.getElementById('profiletable_category').innerHTML=document.getElementById('category_'+row+col).innerHTML;
	
	document.getElementById('sloganProfile').style.visibility='visible';
	
	if('proximity_profile' == type && !(row == 1 && col == 1)){
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,true,'offer');
	}
}

mosaic.mouseOutMatchingOffer=function(row,col,id,type,gx,gy){
	var box = document.getElementById(id);
	if(type!="saved_profile" 
		&& (!(type == "profile_history" && row==1 && col==1))
		&& (!(type == "proximity_search" && row==1 && col==1))
		&& (!(type == "proximity_profile" && row==1 && col==1))){
		box.style.background='#FFFFFF';
		document.getElementById("kwrd_"+row+col).style.color='#ec6e17';
		document.getElementById("proName_"+row+col).style.visibility='hidden';
	}
	if(!(type == "proximity_search" && row==1 && col==1)
		&& !(type == "proximity_profile" && row==1 && col==1)){
		document.getElementById('img_'+id).style.visibility='hidden';
	}
	document.getElementById('profiledata').style.visibility='hidden';
	
	document.getElementById('sloganProfile').style.visibility='hidden';
	
	if('proximity_profile' == type && !(row == 1 && col == 1)){
		var bgColor =document.getElementById('profiledata').style.backgroundColor;
		mosaic.paintProfileCircle(row,col,gx,gy,bgColor,false,'offer');
	}
}

mosaic.paintProfileCircle=function(row,col,gx,gy,color,fill,type){
	var jg_doc = new jsGraphics(type+'_circle_'+row+''+col);//'trianglearea');
  	if(fill){
  		jg_doc.setColor(color);
  		jg_doc.fillOval(0,0,15,15);
  	}else{
  		jg_doc.setColor('white');
  		jg_doc.fillOval(0,0,15,15);
  		jg_doc.setColor(color);
  		jg_doc.drawOval(0,0,15,15);
  	}
  	jg_doc.paint();
}

function openInNewWindow(href) {
	var newWindow = window.open(href, '_blank');
	newWindow.focus();
	return false;
}

function displayPopup(pageName, internPageName, height, width, toolbar, menubar, scrollbars, resizable, location, directories, status)
{ 
	config='height=' + height + ', width=' + width + ', toolbar=' + toolbar + ', menubar=' + menubar + ', scrollbars=' + scrollbars + ', resizable=' + resizable + ', location=' + location + ', directories=' + directories + ', status=' + status;
	window.open (pageName, internPageName, config);
}

function goToUrl(fName, controller, action) {
	fName.controller.value = controller;
	fName.action.value = action;
	fName.submit();
}

function onOfferProximitySearch(offerId, from, act, controll) {
	if(window.opener.document.getElementById('triangleAreaProfile') != null) {
		window.opener.document.area.value = 'true';
	}
	window.opener.document.mosaicForm.controller.value = controll;
	window.opener.document.mosaicForm.action.value = act;
	window.opener.document.mosaicForm.offerId.value = offerId;
	window.opener.document.mosaicForm.from.value = from;
	window.opener.document.mosaicForm.type.value = "matching";
	window.top.close();
	window.opener.document.mosaicForm.submit();
}

function onProfileProximitySearch(profileId, matching, act, controll) {
	if(window.opener.document.getElementById('triangleAreaOffer') != null) {
		window.opener.document.area.value = 'true';
	}
	window.opener.document.mosaicForm.controller.value = controll;
	window.opener.document.mosaicForm.action.value = act;
	window.opener.document.mosaicForm.profileId.value = profileId;
	window.opener.document.mosaicForm.type.value = matching;
	window.top.close();
	window.opener.document.mosaicForm.submit();
	
	
}

function doSearchProfile()
{
	/*document.searchForm.controller.value = "AdvancedSearch";
	document.searchForm.action.value = "onSearch";
	document.searchForm.submit();
	//top.close();
	window.top.close();
	window.opener.onSearchAction('MosaicProfile');*/
	
	ele = document.searchForm.elements;
	var key = "";
	for(var i=0;i<ele.length;i++) {
		nm = ele[i].name;
		v  = ele[i].value;
		if(nm != "" && (ele[i].type == "text" || ele[i].tagName == "SELECT")) {
			namevalue = nm + "|" + v;
			key += namevalue + "\1";
		}
		
	}
	
	window.top.close();
	window.opener.onSearchAction('MosaicProfile', key);
}

function onSearchAction(control, key)
{
	document.mosaicForm.controller.value = control;
	//document.mosaicForm.action = "index.php";
	document.mosaicForm.key_word.value = key;
	document.mosaicForm.action.value = "onAdvancedSearch";
	document.mosaicForm.submit();
}

function doSearchOffer() {
	
/*	document.searchForm.controller.value = "OfferAdvancedSearch";
	document.searchForm.action.value = "onSearch";
	document.searchForm.submit();
	window.top.close();*/
	ele = document.searchForm.elements;
	var key = "";
	for(var i=0;i<ele.length;i++) {
		nm = ele[i].name;
		v  = ele[i].value;
		if(nm != "" && (ele[i].type == "text" || ele[i].tagName == "SELECT")) {
			namevalue = nm + "|" + v;
			key += namevalue + "\1";
		}
		
	}
	
	window.top.close();
	window.opener.onSearchAction("MosaicOffer", key);
//	window.top.close();
}

function popupDate(mylink){
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	href=mylink;
	else
	href=mylink.href;
	window.open(href, 'datePane', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=250,height=200,left = 515,top = 412');
	return false;
}
