
// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();
//end CSS Browser Selector

function ajaxExpand(expandContractElement, htmlContainer, strURL, params) {
var xmlHttpReq = false;
var self = this;
var exconElement = document.getElementById(expandContractElement);
if (exconElement.src.indexOf('Images/expand.gif') > 0){
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
	if (self.xmlHttpReq.readyState == 4) {
		if (document.getElementById){
		   document.getElementById(htmlContainer).innerHTML = self.xmlHttpReq.responseText;	
		}   
		else {
			if (document.layers) 
				document[htmlContainer].innerHTML = self.xmlHttpReq.responseText;
			else if (document.all) 
				document.all[htmlContainer].innerHTML = self.xmlHttpReq.responseText;
			}
			exconElement.src = 'http://resources.investorvillage.com/Images/contract.gif';
		}
	}
	self.xmlHttpReq.send(params);
}
else 
	ajaxHide(expandContractElement, htmlContainer);
}

function ajaxGet(strURL, params, callback) {
    var xmlHttpReq = false;
    var self = this;

	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			callback(self.xmlHttpReq.responseText);	
		}
	}
	self.xmlHttpReq.send(params);
}
function ajaxHide(expandContractElement, htmlContainer){
	var exconElement = document.getElementById(expandContractElement);
	
	if (document.getElementById){
	   document.getElementById(htmlContainer).innerHTML = '';	
	}   
	else {
		if (document.layers) 
			document[htmlContainer].innerHTML = '';
		else if (document.all) 
			document.all[htmlContainer].innerHTML = '';
	}
	exconElement.src = 'http://resources.investorvillage.com/Images/expand.gif'
}

function ajaxExecMsg(strURL, params, msg){
var xmlHttpReq = false;
var self = this;

	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			if (msg != '') alert(msg);
		}
	}
	self.xmlHttpReq.send(params);
}

function ajaxRefreshMasterPage(strURL, params){
var xmlHttpReq = false;
var self = this;

	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			document.location.reload();
		}
	}
	self.xmlHttpReq.send(params);
}
function setCookie(name, value, expires, path, domain, secure) {
if (expires){
	expires = expires * 1000 * 60 * 60 * 24;
	var today = new Date();
	today.setTime( today.getTime() );
	var expires_date = new Date( today.getTime() + (expires) );
}
var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires_date.toGMTString() : "") +
      ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
document.cookie = curCookie;
}

function getCookie (cookie_name){
  var results = document.cookie.match (cookie_name + '=(.*?)(;|$)');

  if (results) return (unescape (results[1])); else return null;
}

function deleteCookie(name, path, domain) {
if (getCookie(name))
	document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function initMyLinks(width, numItems, curDomain){
var endOfDiv=0;
var rightPos = 0;
var markerIndex=0;
var parentDiv = document.getElementById('divMyLinks_Wrapper');
var expandDiv = document.getElementById('divMyLinks_Expand');
var MyLinksDiv = document.getElementById('divMyLinks_Title');
for (var i=2; i <=numItems;i++){
	rightPos = eval("document.getElementById('a" + i + "').offsetLeft + document.getElementById('a" + i + "').offsetWidth");
	if (rightPos > width*(markerIndex+1)){
		if (endOfDiv ==0) endOfDiv = eval("(document.getElementById('a" + (i) + "').offsetLeft)");
		markerIndex++;
	}
}
if (endOfDiv) {
	parentDiv.style.width = endOfDiv;
	expandDiv.innerHTML = '&nbsp; <a href="javascript:void(0);" onclick="showMyLinks('+curDomain+')"><img src="http://resources.investorvillage.com/Images/icon-previous_message.gif"></a>';
}
else 
	parentDiv.style.width = width;
}
function showMyLinks(curDomain){
    obj = document.getElementById('divMyLinks');
    obj2 = document.getElementById('spnMyLinks'); 
    obj2.style.visibility='hidden';
    obj.style.display='inline';
    document.getElementById('divMyLinks_Expand').style.visibility='hidden';
    document.getElementById('divMyLinks_Title').style.visibility='hidden';
    document.getElementById('divMyLinks_Add').style.visibility = 'hidden';
    document.getElementById('divMyLinks_Expand').style.display = 'none';
    document.getElementById('divMyLinks_Title').style.display = 'none';
    document.getElementById('divMyLinks_Add').style.display = 'none';
    setCookie('expandMyLinks', 1, 180, '', curDomain, '');
}
function hideMyLinks(curDomain){
    obj = document.getElementById('divMyLinks');
    obj2 = document.getElementById('spnMyLinks'); 
    obj2.style.visibility='visible';
    obj.style.display='none';
    document.getElementById('divMyLinks_Expand').style.visibility='visible';
    document.getElementById('divMyLinks_Title').style.visibility='visible';
    document.getElementById('divMyLinks_Add').style.visibility = 'visible';
    document.getElementById('divMyLinks_Expand').style.display = 'inline';
    document.getElementById('divMyLinks_Title').style.display = 'block';
    document.getElementById('divMyLinks_Add').style.display = 'inline';
    deleteCookie('expandMyLinks', '', curDomain)
}
