function preloadImages()
{
}

function TrackEmail(adid,email)
{
	var popup = window.open("../features/track_emailadv.aspx?email="+email+"&adid="+adid,"email","status=yes,scrollbars=yes,resizable=yes,toolbar=no,directories=no,menubar=no,width=100,height=100,screenx=0,screeny=0,left=0,top=0"); 
        if(popup)
	popup.close();

	window.location.href = email;
}

function SearchAndReplace(Content, SearchFor, ReplaceWith) {

   var tmpContent = Content;
   var tmpBefore = new String();   
   var tmpAfter = new String();
   var tmpOutput = new String();
   var intBefore = 0;
   var intAfter = 0;

   if (SearchFor.length == 0)
      return;


   while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {
   
      // Get all content before the match
      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
      tmpBefore = tmpContent.substring(0, intBefore);
      tmpOutput = tmpOutput + tmpBefore;

      // Get the string to replace
      tmpOutput = tmpOutput + ReplaceWith;


      // Get the rest of the content after the match until
      // the next match or the end of the content
      intAfter = tmpContent.length - SearchFor.length + 1;
      tmpContent = tmpContent.substring(intBefore + SearchFor.length);

   }

   return tmpOutput + tmpContent;

}

var _ONE=0;
function Switch(item,OldChar,NewChar)
{
  var _ret="";
  var _flag=0;
  var _item=item.split("");
  for(var i=0;i<_item.length;i++)
  {
    if(!_flag&&_item[i]==OldChar)
	{
	  _item[i]=NewChar;
      _flag=_ONE;
	}
	_ret+=_item[i];
  }
  return(_ret);
}

function TrackVisit(adid,url)
{
        _ONE=0;
	var switch2_before=url;
	switch2_after=Switch(switch2_before,"&","%26");
        var popup = window.open("../features/track_visitadv.aspx?url="+switch2_after+"&adid="+adid);
        
	//results=SearchAndReplace(url, "&", "%26")
	//var popup = window.open("../features/track_visitadv.aspx?url="+results+"%26adid="+adid);
 	
 	//document.write(switch2_after);
 	
 	//var popup = window.open("../features/track_visitadv.aspx?url="+url+"&adid="+adid);
	if(popup && popup.focus)
		popup.focus();
}

function TrackPrint(adid, webstoryid)
{
	var popup = window.open("../features/track_print.aspx?webstoryid="+webstoryid+"&adid="+adid,"print","status=yes,scrollbars=yes,resizable=yes,toolbar=no,directories=no,menubar=no,width=10,height=10,screenx=0,screeny=0,left=0,top=0"); 
}

function TrackPrint2(adid, webstoryid)
{
	var popup = window.print("../features/track_print.aspx?webstoryid="+webstoryid+"&adid="+adid,"print","status=yes,scrollbars=yes,resizable=yes,toolbar=no,directories=no,menubar=no,width=10,height=10,screenx=0,screeny=0,left=0,top=0"); 
}

function OpenPop(id, adgroupid) 
{
	if(adgroupid == null)
		adgroupid = 0;

	var link = "../popup/index.aspx?webstoryid=" + id + "&adgroupid=" + adgroupid;
	OpenInPop(link);
}

function OpenPopStory(id,adid)
{
	if(adid == null)
		adid = 0;
	var link = "../popup/index.aspx?webstoryid="+id+"&adid="+adid;
	OpenInPop(link);
}

function OpenInPop(link)
{
	var w = window.open(link,"popup","status=yes,scrollbars=yes,resizable=yes,toolbar=no,directories=no,menubar=no,width=620,height=550,screenx=250,screeny=0,left=250,top=0"); 
	if(w)
		w.focus();
}

function OpenArticle(adGroupID, articleID, pageID)
{
	window.location.href = "../ss/index.aspx?area=ss&type=art&adgroupid="+adGroupID+"&webstoryid="+pageID+"&articleID="+articleID;
	OpenPop(articleID, adGroupID);
}

function OpenPopAndParent(childid,parentid)
{
	var link = location.href;
	//alert (link);
	var newstring ="";
	
	if(link.indexOf("webstoryid=" != -1))
	{
		var array = link.split("&");
		for(i = 0; i< array.length; i++)
		{
			if(array[i].indexOf("webstoryid=") == -1)
			{
				newstring += array[i] + "&";
			}
		}
	}
	else
	{
		newstring = link;
	}
	
	newstring = newstring + "webstoryid=" + parentid;
	//alert(newstring);
	window.location.href = newstring;
	OpenPop(childid);
}