/*[common scripts]*/
/*[shortcuts]*/
$ID = function (sId) { return document.getElementById(sId);}
$TN = function (sTagName) { return document.getElementsByTagName(sTagName);}

/*[get elements by class name]*/
$CN = function (sClassName, sTagName, obj) {
	var testClass = new RegExp('(^|\\s)' + sClassName + '(\\s|$)');
	var sTagName = sTagName || '*';
	var obj = obj || document;
	var elements = (sTagName == '*' && obj.all) ? obj.all : obj.getElementsByTagName(sTagName);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)) { returnElements.push(current);}
		}
	return returnElements;
}
/*[add class name]*/
addCN = function (obj, sClassName){
	var sCurrentClass = obj.className;
	if(!new RegExp(sClassName, 'i').test(sCurrentClass)){
		obj.className = sCurrentClass + ((sCurrentClass.length > 0)? ' ' : '') + sClassName;
	}
}
/*[remove class name]*/
removeCN = function (obj, sClassName){
	var oClassToRemove = new RegExp((sClassName + '\s?'), 'i');
	obj.className = obj.className.replace(oClassToRemove, '').replace(/^\s?|\s?$/g, '');
}

/*[check class name]*/
checkCN = function (obj, sClassName) { var re = new RegExp('\\b'+sClassName+'\\b'); return re.test(obj.className); }

var ieVers;
/*[check for IE version]*/
checkIEVersion = function () { /*[Returns the version of Internet Explorer or a -1 (another browser)]*/
  ieVers = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})');
    if (re.exec(ua) != null)
      ieVers = parseFloat( RegExp.$1 );
  }
}
checkIEVersion();

/*[add onload events as needed]*/
addOnLoadEvent = function (func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) { oldonload();}
      func();
    }
  }
}
/*[usage]*/
/*
addOnLoadEvent( funcName );
addOnLoadEvent( funcName(vars) );
addOnLoadEvent( function() {} );
*/

/*[load external scripts as needed (mind the protocol)]*/

loadExtScript = function(url) {
	extScript = document.createElement('script');
	extScript.type = 'text/javascript';
	extScript.src = url;
	pHead = $TN('head');
	pHead[0].appendChild(extScript);
};
addOnLoadEvent( function() { if (document.forms.length > 0) { loadExtScript(document.location.protocol+'//www.adside.com/js/validate.js');} } );
addOnLoadEvent( function() { if ($ID('example')) { loadExtScript('../js/popups.js');} } );

setupLogin = function () {
	/*[setup login form]*/
	if (document.login) {
		if (document.location.href.indexOf('contextgain') != -1) {
			document.login.service.value = 1;
		} else if (document.location.href.indexOf('publisher') != -1) {
			document.login.service.value = 3;
		} else {
			document.login.service.value = 2; /*[default is advertiser]*/
		}
	}
}

addOnLoadEvent(setupLogin);

/*[reset password]*/
resetPassword = function () {
	if (document.login.action.indexOf('contextgain') != -1) {
		document.login.action = 'http://admin.doclix.com/contextgain/forgot_password.jsp';
	} else if (document.login.action.indexOf('advertiser') != -1) {
		document.login.action = document.location.protocol+'//advertiser.doclix.com/adserver/advertiser/forgot_password.jsp';
	} else if (document.login.action.indexOf('publisher') != -1) {
		document.login.action = document.location.protocol+'//publisher.doclix.com/adserver/publisher/forgot_password.jsp';
	}
	document.login.submit();
}
/*[write email address]*/
emLink = function (rcpnt,text,subject,domain) {
	var at = '@';
	!domain ? dom = 'adside.com' : dom = domain+'.com';
	!text ? text = rcpnt+at+dom : text = text;
	!subject ? sbj = '' : sbj = '?Subject='+subject; 
	document.write('<a href="mailto:'+rcpnt+at+dom+sbj+'">'+text+'</a>');
}

/*[write phone/fax number]*/
phoNum = function (a,d3,d4,x) {
	a = a || '646';
	x ? x = ' ext. '+ x : x = '';
	document.write('<span style="white-space:nowrap;color:inherit !important;">1 ('+a+') '+d3+'-'+d4+x+'</span>');
}

/*[login button mouseover and service switch]*/
addOnLoadEvent( function () {
	if ($ID('signIn')) {
		var signIn = $ID('signIn');
		signIn.onmouseover = function () {
			this.src = this.src.replace(/button_signin/,'button_signin_over');
		}
		signIn.onmouseout = function () {
			this.src = this.src.replace(/button_signin_over/,'button_signin');
		}
	}
	if ($ID('service')) {
		var serviceSelect = $ID('service');
		var serv_act = serviceSelect.value;
		var serv_act_1 = 'http://admin.doclix.com/contextgain/account/login.jsp';
		var serv_act_2 = document.location.protocol+'//advertiser.doclix.com/adserver/advertiser/login.jsp';
		var serv_act_3 = document.location.protocol+'//publisher.doclix.com/adserver/publisher/login.jsp';
		if (serv_act == '1') {
			document.login.action = serv_act_1;
		} else if (serv_act == '2') {
			document.login.action = serv_act_2;
		} else if (serv_act == '3') {
			document.login.action = serv_act_3;
		}
		serviceSelect.onchange = function () {
			serv_act = this.value;
			if (serv_act == '1') {
				document.login.action = serv_act_1;
			} else if (serv_act == '2') {
				document.login.action = serv_act_2;
			} else if (serv_act == '3') {
				document.login.action = serv_act_3;
			}
		}
	}
} );


/*[demo links]*/
showDemo = function () {
				var gap = 20;
				var wH = Math.min(window.screen.availHeight-gap*2,700);
				var wW = Math.min(window.screen.availWidth-gap*2,900);
				xWin = window.open(this.href,'example','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height='+wH+',width='+wW+',top='+gap+',left='+gap+'');
				xWin.focus();
				return false;
			}

addOnLoadEvent( function () {
	if ($ID('demo_l')) {
		//$ID('demo_l').onclick = showDemo;
	}
	if ($ID('demo_r')) {
		$ID('demo_r').onclick = showDemo;
	}
} );


/*[homepage widget]*/

tabWidget = {
	widget : null,
	tabs : [],
	panes : [],
	show : function (n) {
		panes[n].style.display = 'block';
		tabs[n].className = 'tab current';
	},
	hide : function () {
		for (var i = 0; i < panes.length; i++) {
			panes[i].style.display = 'none';
			tabs[i].className = 'tab';
		}
	},
	tab : function (n) {
		tabWidget.hide();
		tabWidget.show(n);
	},
	init : function () {
		widget = $ID('tab_widget');
		tabs = $CN('tab', 'div', widget);
		panes = $CN('pane', 'div', widget);
		for (var i = 0; i < tabs.length; i++) {
			tabs[i].onmouseup = function () {
				tabWidget.tab(parseInt(this.id));
			};
		}
		tabWidget.show(0);
		widget.style.visibility = 'visible';
	}
};

initFAQ = function () {
	var faq = $ID('setupFAQ'), qus = $TN('dt', faq), ans = $TN('dd', faq), cN = 'className';
	for (var i = 0; i < qus.length; i++) {
		if (ans[i]) ans[i].id = i+ '_a';
		qus[i].id = i + '_q';
		qus[i].onclick = function () {
			an = $ID(parseInt(this.id) + '_a');
			if (an[cN] != 'open') {
				an[cN] = 'open';
				this[cN] = 'open';
			} else {
				an[cN] = '';
				this[cN] = '';
			}
		}
	}
}

addOnLoadEvent( function () {
	if ($ID('tab_widget')) {
		tabWidget.init();
	}
	if ($ID('setupFAQ')) {
		initFAQ();
	}
} );


var	sideQuotes = [];
	sideQuotes[0] = 'quote indent" style="padding-top:35px;">"Media campaigns running across the AdSide network have generated highly qualified leads from users interested in our financial information services. We are extremely happy with the results."</div><div class="source">&mdash;FACILITAS</div>';
	sideQuotes[1] = 'quote indent" style="padding-top:35px;">"The AdSide network is designed exclusively for large, premium content publishers, and as such it is able to optimize revenue and uphold advertiser quality at the same time."</div><div class="source">&mdash;Ian Lee, Director of Marketing & Advertising, HealthCastle.com</div>';
	sideQuotes[2] = 'quote indent">"AdSide has created a high-quality content network focused on PPC text ads. The network has advanced the model of contextual and placement targeting into a platform that enables effective and precise ad placement selection."</div><div class="source">&mdash;David Rodnitzky, PPC Associates</div>';
	sideQuotes[3] = 'quote indent">"AdSide provides media agencies like Firstand10 with a unique combination of reach, targeting flexibility, transparency, and guaranteed placements on brand name sites. It helped us successfully plan and execute media campaigns for our clients."</div><div class="source">&mdash;Firstand10</div>';
	sideQuotes[4] = 'quote indent">"Our media buys on AdSide have resulted in conversion success when other networks have failed. The network\'s transparent content targeting model provides us with full control over where our ads are showing. This has generated consistent quality leads."</div><div class="source">&mdash;Online Media Management</div>';
	sideQuotes[5] = 'quote indent" style="padding-top:35px;">"AdSide\'s 2-Step Click model increased the volume of qualified traffic to our site, as well as the average user engagement time&mdash;beyond what we have seen from other established networks."</div><div class="source">&mdash;POINT OF RETURN</div>';
var	h = Math.round(Math.random()*(sideQuotes.length-1)), cont, news;
sideQuote = function () {
if (typeof cont == 'undefined') cont = $ID('quote');
	cont.innerHTML = '<div class="'+sideQuotes[h]+'<div id="bottom"></div>';
	news = window.setTimeout( function () {
	h == sideQuotes.length-1 ? h = 0 : h++;
		sideQuote();
	}, 10000);
}

