//===========================================================================================
// Author:       Edmund I Jones
// Description:  JS file to encapsulate the common functions needed
// Edited:       7th February 2006
//===========================================================================================



function isProper(string)
{
	if (!string) return false;
		var iChars = "|,\<>[]{}`\;()@$#%";

	for (var i = 0; i < string.length; i++)
	{
		if (iChars.indexOf(string.charAt(i)) != -1)
			return false;
	}

	return true;
}


function trim(strText)
{
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

return strText;
}


function isEmail(string) 
{
	if (!string)
	{
		return false;
	}
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	{
	    return true;
	}
	else
	{
		return false;
	}
}


function openURL(url)
{
	
	WARCWindow = window.open(url,'popupWindow2','width=790,height=500,"WARC Knowledge Center",top=20,left=20,resizable=yes,toolbar=yes,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow.opener)
			WARCWindow.opener = self;
}




function ExpandSummary(ArticleID)
{
	var SummaryID;
	SummaryID = "Summary_" + ArticleID;
	DIVId = "Result_" + ArticleID;
	var TL_CornerID;
	TL_CornerID = "Result_Corner_" + ArticleID;
					
	if (document.getElementById(DIVId).className == "Results_Abstract_Closed")
	{
		SendQuery("Results_GetAbstract.asp?AID=" + ArticleID, ArticleID);
		document.getElementById(DIVId).className = 'Results_Abstract_Open';
		document.getElementById(SummaryID).innerHTML  = 'Close Summary';
	}
	else
	{
		SendQuery("Results_GetShortAbstract.asp?AID=" + ArticleID, ArticleID);
		document.getElementById(DIVId).className = 'Results_Abstract_Closed';
		document.getElementById(SummaryID).innerHTML = 'Summary';
						
	}
					
}
				
				
function AddMoreSources()
{
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('------------------------------------------------', 'NA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('AdBand Profiles', 'AdBrands');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Agency magazine', 'AAAA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Advertising Federation of Australia', 'AFA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('ANA', 'ANA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Account Planning Group Australia', 'APG-AUS');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Advertising Research Foundation Workshop', 'ARFW');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('BMRB International', 'BMRB');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Communication Agencies Association of New Zealand', 'CAANZ');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Canadian Congress of Advertising', 'CCA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Canadian Advertising Research Foundation', 'CARF');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Direct marketing Association (US)', 'DMA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Forum for Advertising Research', 'FAR');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Journal of Marketing History', 'HAT');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Young Consumers', 'IJAMC');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('International Newspaper Marketing Association', 'INMA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('IPC Media', 'IPC');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('WARC Conference paper', 'CON');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('WARC Media FAQ', 'MEDIAFAQ');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('WARC Monograph', 'MONO');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Market Research Society', 'MRS');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('News International', 'NI');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Outdoor Advertising Association of America', 'OAAA');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Point of Purchase Advertising International', 'POPAI');
	document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Radio Advertising Bureau (UK)', 'RAB');
					
	alert("Additional sources have been added to the source drop down list.");
}
				
function CheckSourceList()
{
	if (document.getElementById('Results_NarrowBySourceList').options[self.document.getElementById('Results_NarrowBySourceList').options.selectedIndex].value == "MORE")
	{
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length -1] = null;
						
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('------------------------------------------------', ' ');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('AdBrand Profiles', 'AdBrands');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Agency magazine', 'AAAA');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Advertising Federation of Australia', 'AFA');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('ANA', 'ANA');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Account Planning Group Australia', 'APG-AUS');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Advertising Research Foundation Workshop', 'ARFW');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('BMRB International', 'BMRB');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Communication Agencies Association of New Zealand', 'CAANZ');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Canadian Congress of Advertising', 'CCA');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Canadian Advertising Research Foundation', 'CARF');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Direct marketing Association (US)', 'DMA');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Forum for Advertising Research', 'FAR');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Journal of Marketing History', 'HAT');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Young Consumers', 'IJAMC');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('International Newspaper Marketing Association', 'INMA');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('IPC Media', 'IPC');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('WARC Conference paper', 'CON');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('WARC Media FAQ', 'MEDIAFAQ');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('WARC Monograph', 'MONO');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Market Research Society', 'MRS');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('News International', 'NI');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Outdoor Advertising Association of America', 'OAAA');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Point of Purchase Advertising International', 'POPAI');
		document.getElementById('Results_NarrowBySourceList').options[document.getElementById('Results_NarrowBySourceList').options.length] = new Option('Radio Advertising Bureau (UK)', 'RAB');
					
		alert("Additional sources have been added to the source drop down list.");					
	}
	else
	{
		if (document.getElementById('Results_NarrowBySourceList').options[self.document.getElementById('Results_NarrowBySourceList').options.selectedIndex].value == "NA")
		{
			alert("Please select a valid source from the list.")
			return;
		}
		else
		{
			document.frmResultsSort.submit();
		}
	}
					
}

				
function ToggleFormat()
{
	var Result;			
	if (document.getElementById("Results_OutputType_Current").innerHTML == "PDF")
	{
		document.getElementById("Results_OutputType_Current").innerHTML = "HTML";
		document.getElementById("Results_OutputType_Other").innerHTML = "PDF";
		Result = GetXMLFile("/DataFeeds/Results_ToggleDownloadFormat.asp?Format=HTML")
		alert("Your download format preference has been set to: " + Result);
	}
	else
	{
		document.getElementById("Results_OutputType_Current").innerHTML = "PDF";
		document.getElementById("Results_OutputType_Other").innerHTML = "HTML";
		Result = GetXMLFile("/DataFeeds/Results_ToggleDownloadFormat.asp?Format=PDF")
		alert("Your download format preference has been set to: " + Result);
	}
				
				
}
				
				
function CheckSelection(RemoveID)
{
	CheckID = "RLT_Picked_" + RemoveID;
	//alert(CheckID)
	var url;
	var Result
	var Checkbox = document.getElementById(CheckID);
	if (Checkbox.checked)
	{
		//Add it
		//alert("add");
		var URL;
		URL = "MyFolder_AddSelectionCookie_Print.asp?Add=" + document.getElementById(CheckID).value;
		//alert(URL);
		SendQuery(URL, "");
						
		url = "/DataFeeds/MyFolder_StoreTempTickedSelectionForMyFolder.asp?ID=" + document.getElementById(CheckID).value + "&Action=ADD";
		Result = GetXMLFile(url);	
			
	}
	else
	{
		//Remove it
		var URL;
		URL = "MyFolder_RemoveSelectionCookie_Print.asp?Remove=" + document.getElementById(CheckID).value;
		//alert(URL);
		SendQuery(URL, "");
		
		url = "/DataFeeds/MyFolder_StoreTempTickedSelectionForMyFolder.asp?ID=" + document.getElementById(CheckID).value + "&Action=REMOVE";
		Result = GetXMLFile(url);	
		
	}
	
	
	
	
	
	
	
	
	
	
	
					
}
				
				
function PrintSelection(SuppressOutput)
{
	PageURL = "/ArticleCenter/PrintSelection.asp";
	
	WARCWindow = window.open(PageURL,'popupWindow','width=700,height=450,"WARC.com",top=20,left=20,resizable=no,toolbar=no,menubar=yes,location=no,status=no,directories=no,scrollbars=yes');
		if (!WARCWindow.opener)
			WARCWindow.opener = self;
}
				
				
				
function EmailSelection(SuppressOutput)
{
	// Need to work out all the article ID's that were selected.
	PageURL = "/ArticleCenter/EmailSelection.asp";
	WARCWindow = window.open(PageURL,'popupWindow','width=700,height=450,"WARC.com",top=20,left=20,resizable=no,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow.opener)
			WARCWindow.opener = self;
					
}
				
				
function AddSelectionToFolder()
{
	// Need to work out all the article ID's that were selected.
	
	// Write all selected items to a cookie so they are persistent accross pages
	// Use these values when storing the data in the database	
		
		
	url = "/DataFeeds/MyFolder_StoreTempTickedSelectionForMyFolder.asp?Action=USE";
	Result = GetXMLFile(url);	
	
	
	document.getElementById("Folder_NumberOfItems").innerHTML = Result;
	alert("Your selected items have been stored in your default folder.")
	return;
			
	
}
				
				
function ViewArticle(ID,Type)
{
	var PageURL;
	var PageURLAttributes;
					
	if (Type == "A")
	{
		PageURLAttributes = "?CType=A&AID=" + ID + "&Tab=A";
	}
	else if (Type == "N")
	{
		PageURLAttributes = "?CType=N&NID=" + ID + "&Tab=A";
	}
	else if (Type == "P")
	{
		PageURLAttributes = "?CType=P&PID=" + ID + "&Tab=A";
	}
	else
	{
		PageURLAttributes = "?CType=A&AID=" + ID + "&Tab=A";
	}
					
					
	PageURL = "/ArticleCenter/Default.asp" + PageURLAttributes;
	WARCWindow = window.open(PageURL,'popupWindow','width=840,height=605,"WARC.com",top=20,left=20,resizable=yes,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow.opener)
			WARCWindow.opener = self;
					
}


function ViewArticleTrack(ID,Type,MarketingCode)
{
	var PageURL;
	var PageURLAttributes;
										
	if (Type == "A")
	{
		PageURLAttributes = "?CType=A&AID=" + ID + "&Tab=A";
	}
	else if (Type == "N")
	{
		PageURLAttributes = "?CType=N&NID=" + ID + "&Tab=A";
	}
	else if (Type == "P")
	{
		PageURLAttributes = "?CType=P&PID=" + ID + "&Tab=A";
	}
	else
	{
		PageURLAttributes = "?CType=A&AID=" + ID + "&Tab=A";
	}
										
										
	PageURL = "/ArticleCenter/Default.asp" + PageURLAttributes + "&M=" + MarketingCode;
	WARCWindow = window.open(PageURL,'popupWindow','width=840,height=605,"WARC.com",top=20,left=20,resizable=yes,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow.opener)
			WARCWindow.opener = self;
										
}
				
				
function ViewMoreLikeThis(ID,Type)
{
	var PageURL;
	var PageURLAttributes;
	
	var Result;
	Result = GetXMLFile("/DataFeeds/MoreLikeThisFromSearch.asp");
					
	if (Type == "A")
	{
		PageURLAttributes = "?CType=A&AID=" + ID + "&Tab=M";
	}
	else if (Type == "N")
	{
		PageURLAttributes = "?CType=N&NID=" + ID + "&Tab=M";
	}
	else if (Type == "P")
	{
		PageURLAttributes = "?CType=P&PID=" + ID + "&Tab=M";
	}
	else
	{
		PageURLAttributes = "?CType=A&AID=" + ID + "&Tab=M";
	}
				
					
	PageURL = "/ArticleCenter/Default.asp" + PageURLAttributes;
	WARCWindow = window.open(PageURL,'popupWindow','width=840,height=550,"WARC.com",top=20,left=20,resizable=yes,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow.opener)
			WARCWindow.opener = self;
					
}



function GetXMLFile(sourceURL)
 {
    var xmlhttp = null;
    var doc = null;

    if (document.all)
      xmlhttp = new ActiveXObject('MSXML2.XMLHTTP');
    else
      xmlhttp = new XMLHttpRequest();

    if (xmlhttp)
    {
      xmlhttp.open('GET', sourceURL, false);
      xmlhttp.send(null);
      doc = xmlhttp.responseText;
    }

    return doc;
}


function SetTopicAlertFromIndex(url)
{
	
	var Result;
	Result = GetXMLFile(url);
	//alert(Result)
	alert("Your alert for this topic has been set, to manage alerts please go to the My WARC section of the site.")

}


function SetTopicAlertFromIndexNonCookie(url)
{
	document.location.href=url;
}

function SignUpForLandingPageAlerts(Page, UserID)
{
	var Result;
	var url;
	url = "/DataFeeds/SignUpForLandingPageAlerts.asp?Page=" + Page + "&UserID=" + UserID;
	Result = GetXMLFile(url);
	//alert(Result)
	alert("Your alert for this page has been set, to manage alerts please go to the My WARC section of the site.")
}



function EraseLoginCookie()
{
	
	
	var result;
	result = confirm("Are you sure you want to erase your cookie?")
	
	if (result==true)
	{
		document.location.href='/MyWARC/EraseCookie.asp';
	}
	else
	{
		return;
	}
	
}


function GotoLogOut()
{
	parent.opener.location.href="/MyWARC/LogOut.asp";
	parent.opener.focus();
	parent.self.close();
}





//Google code
_uacct = "UA-183038-1";
	urchinTracker();