function getCookieVal (offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
	var arg=name+"=", alen=arg.length, clen=document.cookie.length, i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal (j);
		i=document.cookie.indexOf(" ", i)+1;
		if (i==0) break;
	}
	return null;
}
var cobrand_c=(GetCookie('mail_com_c'))? GetCookie('mail_com_c'):"US&0&0";
var agentP=(GetCookie("agentP"))? GetCookie("agentP"):0;
var fmCookie=(cobrand_c!=null)? cobrand_c.split("&"):"";
function getRandom(a,b) {return (Math.round(Math.random()*(b-a)))+1;}

var adTokenName = "adToken01";
var adTokenVal  = "newmailcom";

function mailcomAd(aID) {
	var isCompose=((document.location.pathname).indexOf('compose.mail')!=-1 || (document.location.pathname).indexOf('Outblaze.mail')!=-1)? true:false;
	var isAfterSent=((document.location.pathname).indexOf('aftersent.main')!=-1)? true:false;
	var isWelcome=((document.location.pathname).indexOf('frontpage.main')!=-1)? true:false;
	var isReadmail=((document.location.pathname).indexOf('read.mail')!=-1)? true:false;
	var isMailbox=((document.location.pathname).indexOf('mailbox.mail')!=-1)? true:false;
	var isMB2=((document.location.pathname).indexOf('/scripts/mb2/')!=-1)? true:false;
	var isMB2Reply=(isMB2 && (document.location.pathname).indexOf('mode=reply')!=-1)? true:false;
	var isGeneral=(isCompose || isAfterSent || isWelcome || isMailbox || isReadmail || isMB2)? false:true;

	OAS_rn=new String (Math.random());OAS_rns=OAS_rn.substring (2, 11);
	switch (aID) {
		/* search */
		case "search_top":                                                    document.writeln('<iframe src="http://www.mail.com/content/jscontrols/searchbar.aspx" allowTransparency=true scrolling=no height=70 width=515 frameborder=0></iframe>');break;
  
		/* login */
		case "mail_tag001_login_300x250_(300x250)_247RealMediaAdTag":         newAd('other_300x250');break;
		
		/* welcome */
		case "welcome_125x125_a8AdTag":                                       if (isWelcome) newAd('welcome_125x125');break;
		case "mail_tag003_welcome_728x90top_(728x90)_247RealMediaAdTag":      if (isWelcome) newAd('welcome_728x90_top');break;
		case "mail_tag004_welcome_300x250_(300x250)_247RealMediaAdTag":       if (isWelcome) newAd('welcome_300x250_left');break;
		//case "activ8_en-mail_300x250":                                      newAd('welcome_300x250_right');break;

		//case "mail_tag005_welcome_728x90bottom_(728x90)_247RealMediaAdTag": if (isWelcome) newAd('welcome_728x90_bottom');break;
		
		/* new: mailbox */
		case "mailbox_728x90top":                                             if (isMailbox) newAd('inbox_728x90_top');break;
		case "mailbox_728x90bottom":                                          if (isMailbox) newAd('inbox_728x90_bottom');break;
		case "mailbox_125x125left":                                           if (isMailbox) newAd('inbox_125x125');break;
		
		/* readmail */
		case "mail_tag007_readmail_728x90top_(728x90)_247RealMediaAdTag":     if (isReadmail) newAd('readmail_728x90_top');break;
		case "mail_tag008_readmail_728x90bottom_(728x90)_247RealMediaAdTag":  if (isReadmail) newAd('readmail_728x90_bottom');break;
		case "activ8_en-mail_120x600":                                        if (isReadmail) newAd('readmail_120x600');break;
		case "readmail_125x125left":                                          if (isReadmail) newAd('other_125x125');break;
		
		/* compose */
		case "mail_tag009_compose_728x90top_(728x90)_247RealMediaAdTag":      if (isCompose) newAd('compose_728x90_top');break;
		case "mail_tag010_compose_300x250_(300x250)_247RealMediaAdTag":       if (isCompose) newAd('compose_300x250');break;
		case "mail_tag011_compose_728x90bottom_(728x90)_247RealMediaAdTag":   if (isCompose) newAd('compose_728x90_bottom');break;
		case "compose_125x125left":                                           if (isCompose) newAd('other_125x125');break;
		
		/* after sent */
		case "mail_tag012_confirmation_728x90top_(728x90)_247RealMediaAdTag": if (isAfterSent) newAd('aftersent_728x90_top');break;
		case "mail_tag013_confirmation_300x250_(300x250)_247RealMediaAdTag":  if (isAfterSent) newAd('aftersent_300x250');break;
		case "aftersent_728x90_bottom":                                       if (isAfterSent) newAd('aftersent_728x90_bottom');break;
		case "mail_tag014_confirmation_300x250right":                         if (isAfterSent) newAd('aftersent_300x250');break;
		case "confirmation_125x125left":                                      if (isAfterSent) newAd('other_125x125');break;
		
		/* other */
		case "otherpages_125x125_a8AdTag":                                    if (isGeneral) newAd('other_125x125');break;
		case "mail_tag015_otherpages_728x90top_(728x90)_247RealMediaAdTag":   if (isGeneral) newAd('other_728x90_top');break;
		case "mail_tag016_otherpages_728x90bottom_(728x90)_247RealMediaAdTag":if (isGeneral) newAd('other_728x90_bottom');break;
		
		/* interstitial */
		case "mail_tag017_intersitials_300x250_(300x250)_247RealMediaAdTag":  newAd('other_300x250');break;
		case "mail_tag018_intersitials_300x250right":                         newAd('other_300x250');break;
		
		/* logout */
		case "mail_tag019_confirmation_300x250centre":                        newAd('other_300x250');break;
		case "mail_tag019_confirmation_300x250right":                         newAd('other_300x250');break;
		
		/* forum */
		case "mail_tag021_msgboard_728x90top_activ8":                         if (isMB2) newAd('other_728x90_top');break;
		case "mail_tag022_msgboard_468x60bottom_activ8":                      if (isMB2) newAd('other_728x90_bottom');break;
		case "mail_tag023_msgboard_read_120x600_activ8":                      if (isMB2) newAd('other_120x600');break;

		/* error */
		case "error_300x250center":                                           newAd('other_300x250');break;
		case "error_300x250right":                                            newAd('other_300x250');break;

		/* video */
		case "video_728x90_top":    						  newAd('other_728x90_top');break;
		case "video_728x90_bottom": 						  newAd('other_728x90_bottom');break;
		case "video_120x600":       						  newAd('other_120x600');break;
	}
}

coreadsLoaded=true;

/***** VSI analytics code *****/
//document.write('<scr'+'ipt src="http://www.google-analytics.com/urchin.js" type="text/javascript"></scr'+'ipt>');
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
var vsiJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + vsiJsHost + "cdn.mail.com/partner/outblaze/scripts/cobrand.js' type='text/javascript'%3E%3C/script%3E"));
document.write('<scr'+'ipt src="http://mail01.mail.com/templates/common/us/vsi_analysis.js" type="text/javascript"></scr'+'ipt>');
