function browserCheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

var browser=browserCheck()
var jsDOM0 = (document.all);
var jsDOM1 = (document.getElementById);
var jsDOM = jsDOM0 || jsDOM1;
var jsDebug = 0;

var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body


function getObj (name)
{
    if (typeof name == "object") return name;
    if (jsDOM1) return document.getElementById(name);
    if (jsDOM0) return eval('document.all.'+name);
    else return null;
}
	
function hideSelects(a) {
	if (document.getElementById) {
		var tags = ['select', 'iframe', 'object'];
		for (var t in tags) {
			var elms = document.getElementsByTagName(tags[t]);
			for (var e = 0; e < elms.length; e++) {
				elms[e].style.visibility = a ? 'visible' : 'hidden';
			}
		}
	}
}

function divShow(a) {
	hideSelects(0);
	document.getElementById(a).style.display='block'
}

function divHide(a) {
	document.getElementById(a).style.display='none'
	hideSelects(1);
}

// * * * photoShow * * *
function photoShow(a) {
	hideSelects(0);
	
	wTop=document.all? (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop) : pageYOffset;	

	document.getElementById('photoshowimg').src=a
	document.getElementById('photoshow').style.top=(wTop+100)+"px"
	document.getElementById('photoshow').style.display='block'
}

function photoHide() {
	document.getElementById('photoshow').style.display='none'
	hideSelects(1);
}

// * * * titleDiv * * *

fromX = -5 //How much from the actual mouse X should the description box appear?
fromY = 20 //How much from the actual mouse Y should the description box appear?

var px = browser.ns4||window.opera?"":"px";

//Capturing mousemove
var descx = 0
var descy = 0
function titleMouseMove(e) {
	descx=browser.ns4||browser.ns6?e.pageX:event.x;
	descy=browser.ns4||browser.ns6?e.pageY:event.y
}

function titleShow(text, w){
	oTitleDiv = getObj ('titleDiv');
	
	 if(oTitleDiv){
		if (browser.ns4) {
			oTitleDiv.write(text);oTitleDiv.close()
		} else {
			oTitleDiv.innerHTML = text
		}

		if(browser.ie5||browser.ie6||browser.ie7) {
			//descy = descy+document.body.scrollTop
			descx = descx+(document.body.clientWidth-500)/2;
		}
		
		oTitleDiv.style.left = (descx+fromX)+px
		oTitleDiv.style.top = (descy+fromY)+px
		if (parseInt(w)>0) {
			oTitleDiv.style.width=parseInt(w)+px
		} else {
			oTitleDiv.style.width=""
		}
		oTitleDiv.style.top = (descy+fromY)+px
		oTitleDiv.style.display = "block"
    }
	
}

function titleHide() {
	oTitleDiv = getObj ('titleDiv');
	if (oTitleDiv) oTitleDiv.style.display = "none"
}

function titleSetPopup(){
	if(bw.ns4)document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = titleMouseMove;
}	

titleSetPopup()


//////////////////////////////////////////////////////

function dynamicDropdown(parentAssetType, parentAssetId, childFormField, childAssetType, childParentColumn, childDefaultText, clearFields, clearTexts, childDefaultValue) {
	document.getElementById('frm_base').src='common/dynamic_dropdown.php?parentAssetType='+parentAssetType+'&parentAssetId='+parentAssetId+'&childFormField='+childFormField+'&childAssetType='+childAssetType+'&childParentColumn='+childParentColumn+'&childDefaultText='+childDefaultText+'&clearFields='+clearFields+'&clearTexts='+clearTexts+'&childDefaultValue='+childDefaultValue+'';
}

var rbWidths=new Array(12, 7, 10, 9, 10, 9, 10, 9, 10, 11);
var rbWidthsT=new Array(12, 19, 29, 38, 48, 57, 67, 76, 86, 97);

function rbCreate(rating, field, text, missing) {
	var o="";
	if (!text) text="Rating";
	if (rating==0 && !field) {
		document.write('<div class="rbi"></div>');
	} else if (!field) {
		for (var i=0; i<5.5; i=i+0.5) {
			if (i>=rating) {
				var ratingStars=i/0.5;
				break;
			}
		}
		document.write('<div class="rbi r'+ratingStars+'" onMouseOver="titleShow(\''+text+': '+rating+'\')" onMouseOut="titleHide();"></div>');
	} else if (field) {
		o='<div class="rb_sel_wrapper'+(missing==1?" missing":"")+'" onMouseOver="titleShow(\'Click To Set Rating.\')" onMouseOut="titleHide();; rbUpdate(\''+field+'\')"><div class="rb_sel_10" id="rb_'+field+'"></div><div class="rb_sel_out">';
		var tw=0;
		for (i in rbWidths) {
			tw=tw+rbWidths[i];
			o+='<div class="br_sel_selector" style="width: '+rbWidths[i]+'px;" onMouseOver="document.getElementById(\'rb_'+field+'\').style.width=\''+tw+'px\'" onClick="rbSet(\''+field+'\', '+i+')">&nbsp;</div>';
		}
		o+='</div><div class="rbi r0"></div>';
//		if (missing==1) {
//			o+='<div><strong>Please Select!</strong></div>';
//		}
		o+='</div>';
		o+='<input name="'+field+'" id="'+field+'" type="hidden" value="'+rating+'">';
		document.write(o);
		rbUpdate(field);
	}
}

function rbUpdate(field) {	
	value=document.getElementById(field).value;
	for (i=0; i<5.5; i=i+0.5) {
		if (i>=value) {
			var ratingStars=i/0.5;
			break;
		}
	}
	var px=rbWidthsT[ratingStars-1];
	if (!px) px="0";
	document.getElementById('rb_'+field).style.width=px+'px'
}

function rbSet(field, value) {
	document.getElementById(field).value=(value+1)*0.5;
	rbUpdate(field);
}

function cookieWrite(name, value, hours) {
  var expire = "";
  if(hours != null) {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  alert(name + "=" + escape(value) + expire);
  document.cookie = name + "=" + escape(value) + expire;
}

function cookieRead(name) {
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0) { 
    offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function cookieArrayWrite(name, value, hours) {
	var valueJoined=new Array();
	for (var i in value) {
		if (value[i].length>2){
			valueJoined[i]=value[i].join("^");
		}
	}
	valueJoined=valueJoined.join("*");
	cookieWrite(name, valueJoined, 750);
}

function cookieArrayRead(name) {
	value=cookieRead(name);
	value=value.split("*");
	newValue=new Array();
	for (var i in value) {
		if (value[i].length>2){
			newValue[i]=value[i].split("^");
		}
	}
	return newValue;
}

function favoritesAdd(compId, compName, compUrl) {
	var favorites=cookieArrayRead("favorites");
	favoritesHighlight();
	setTimeout(favoritesUnhighlight, 80);
	setTimeout(favoritesHighlight, 160);
	setTimeout(favoritesUnhighlight, 240);
	setTimeout(favoritesHighlight, 320);
	setTimeout(favoritesUnhighlight, 400);
	setTimeout(favoritesHighlight, 480);
	setTimeout(favoritesUnhighlight, 560);
	for (var i in favorites) {
		if (parseInt(favorites[i][0])==parseInt(compId)) {
			setTimeout(titleHide, 750);
			titleShow("Already in favourites!", 150)
			return;
		}
	}
	favorites[favorites.length]=new Array(compId, compName, compUrl);
	cookieArrayWrite("favorites", favorites, 750);
	favoritesUpdate();
	setTimeout(titleHide, 750);
	titleShow("Added!", 100);
}

function favoritesRemove(compId) {
	var favorites=cookieArrayRead("favorites");
	for (var i in favorites) {
		if (parseInt(favorites[i][0])==parseInt(compId)) {
			delete favorites[i];
			cookieArrayWrite("favorites", favorites);
			favoritesUpdate();
			setTimeout(titleHide, 750);
			titleShow("Deleted!", 100)
			return;
		}
	}
	setTimeout(titleHide, 750);
	titleShow("Not in favourites!", 100)
}

function favoritesUpdate() {
	var o="";
	var favorites=cookieArrayRead("favorites");
	if (favorites.length==0) {
		document.getElementById("favoritesPanel").style.display="none";
	} else {
		for (var i in favorites) {
			o=o+'<a href="'+favorites[i][2]+'">'+favorites[i][1]+'</a><a href="#" onClick="favoritesRemove('+favorites[i][0]+'); return false;" class="fav_del">delete</a><div class="clr"></div>';
		}
		document.getElementById("favoritesPanel").style.display="";
		document.getElementById("favoritesDiv").innerHTML=o;
	}
}

function favoritesHighlight() {
	document.getElementById("favoritesPanel").style.backgroundColor="#e5e5e5";
}

function favoritesUnhighlight() {
	document.getElementById("favoritesPanel").style.backgroundColor="";
}

function showClient(id) {
	for (i in clientsIds) {
		document.getElementById('clientDetails'+clientsIds[i]).style.display='none';
	}
	if (id>0) {
		document.getElementById('clientDetails'+id).style.display='';
	}
}



/*
 * This script is written by Geert Van Aken
 * Please read the official documentation for more information
 * about the functions of this file.
 *
 * http://altum.be/products/emailobfuscator
 *
 * Please do not remove this information from the file and
 * report improvements that you make to this sourcecode
 *
 * Version 1.1.0
 * Date    2006/04/11
 */

var monkeyCode = 4 << 4;
var oldStatusText = "";

function EOa() {
  return String.fromCharCode(monkeyCode);
}

function EOd(pText) {
  var splitted = pText.split(",");
  var result = "";

  for (i = 0 ; i < splitted.length ; i++) {
    result += String.fromCharCode(splitted[i]);
  }
  return result;
}

function EOp() {
  var prefix = EOd('109,97,105');
  prefix += EOd('108,116');
  return prefix + EOd('111,58');
}

function EOad(pName, pdomain) {
  EOad(pName, pDomain, null);
}

function EOinitStatus(pName, pDomain) {
  oldStatusText = window.status;
  window.status = Loc(pName, pDomain);
}

function EOrestoreStatus() {
  window.status = oldStatusText;
}

function EOae(pName, pDomain, pSubj, pHover, pText, pClass) {

//  alert("pName = " + pName + "\npDomain = " + pDomain + "\npSubj = " + pSubj + "\npHover = " + pHover + "\npText = " + pText + "\npClass = " + pClass);

  var result = "<a href=\"JavaScript:EOad('" + pName + "','" + pDomain + "'";
  if (pSubj != null && pSubj.length > 2) {
    result += ",'" + pSubj + "'";
  }
  result += ");\"";

  if (pHover != null && pHover.length > 0) {
    result += " title=\"" + EOd(pHover) + "\"";
  }

  if (pClass != null && pClass.length > 0) {
    result += " class=\"" + pClass + "\"";
  }

  result += " onMouseOver=\"EOinitStatus('" + pName + "','" + pDomain + "');return true;\" onMouseOut=\"EOrestoreStatus();\"";

  result += ">" + EOd(pText) + "</a>";

//  alert(result);

  document.write(result);

}

function EOad(pName, pDomain, pSubj) {
  var loc = Loc(pName, pDomain);
  if (pSubj != null && pSubj.length > 0) {
    loc += "?" + EOd('115,117,98,106,101,99,116') + "=" + encodeURIComponent(EOd(pSubj));
  }

  document.location = loc;
}

function Loc(pName, pDomain) {
  var first = EOd(pName);
  var second = EOd(pDomain);
  var loc = EOp() + first + EOa() + second; 
  
  return loc;
}


function Expand(){
	document.getElementById('collapsed').style.display = "none";
	document.getElementById('expanded').style.display = "block";
	setTimeout(titleHide, 100);
	titleShow("Expanding...", 100);
}
function Collapse(){
	document.getElementById('expanded').style.display = "none";
	document.getElementById('collapsed').style.display = "block";
	setTimeout(titleHide, 100);
	titleShow("Collapsing...", 100);
}

function advancedExpand(){
	document.getElementById('advancedExpanded').style.display = "block";
	document.getElementById('collapseAdvancedA').style.display = "block";
	document.getElementById('expandAdvancedA').style.display = "none";
	
	setTimeout(titleHide, 100);
	titleShow("Expanding...", 100);
}
function advancedCollapse(){
	document.getElementById('advancedExpanded').style.display = "none";
	document.getElementById('collapseAdvancedA').style.display = "none";
	document.getElementById('expandAdvancedA').style.display = "block";
	setTimeout(titleHide, 100);
	titleShow("Collapsing...", 100);
}

//setInterval(eee, 5000);

function eee() {
	alert(document.getElementById("lfKeywordPopup").innerHTML);
}

function updateRegions(countryBoxId, regionBoxId, selectedRegion) {
	var country = parseInt(parent.document.getElementById(countryBoxId).value)
	var regionBox = parent.document.getElementById(regionBoxId);
	if (country==0 || !r[country]) {
		regionBox.options.length = 0;
		regionBox.options[regionBox.options.length] = new Option('Not applicable', 0);
		regionBox.disabled=true;
		return;
	}
	regionBox.disabled=false;
	regionBox.options.length = 0;
	regionBox.options[regionBox.options.length] = new Option('Please Select', 0);
	for (var i in r[country]) {
		regionBox.options[regionBox.options.length] = new Option(r[country][i]["name"], i);
	}
	if (selectedRegion>0) {
		regionBox.value=selectedRegion;
	}
}


// HTTPRequest
var requestVar, requestStatus;

function requestLoad(url, stateChange) {
	requestVar=null
	if (window.XMLHttpRequest) {
		// code for Mozilla, etc.
		requestVar=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		// code for IE
		requestVar=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (requestVar!=null) {
		requestVar.onreadystatechange=stateChange
		requestVar.open("GET",url,true)
		requestVar.send(null)
	} else {
		return;
	}
}

function quickResultsShow() {
	if (requestVar.readyState==4) {
		if (requestVar.status==200) {
			document.getElementById("quickResultsDiv").innerHTML=requestVar.responseText
		} else {
			document.getElementById("quickResultsDiv").innerHTML=""
		}
	}
}

function quickResultsGet() {
	var url="inc/search_results.php?";
	url+="lfKeyword="+document.PSearch.lfKeyword.value;
	url+="&lfIndustry="+document.PSearch.lfIndustry.value;
	url+="&lfWebsiteType="+document.PSearch.lfWebsiteType.value;
	url+="&lfPrice="+document.PSearch.lfPrice.value;
	url+="&lfReviewsCount="+document.PSearch.lfReviewsCount.value;
	url+="&lfRating="+document.PSearch.lfRating1.value;
	url+="&lfRegion="+document.PSearch.lfRegion.value;
	url+="&thisCountry="+document.PSearch.c.value;
	requestLoad(url, quickResultsShow);
	return false;
}

