//===========================================================================================
// Author:       Edmund I Jones
// Description:  JS file to encapsulate the functions needed for searching
// Edited:       3rd December 2001
//===========================================================================================



//===========================================================================================
// Functions to submit searches
//-----------------------------


function SubmitWordSearch()
{
	result1 = trim(document.frmWordSearchValues.txtWordSearch.value)
	
	if (result1 == "Enter search term" || result1 == "")
	{
		alert("Please enter a word or phrase to search on.")
		return;
	}
	
	result = isProper(document.frmWordSearchValues.txtWordSearch.value)
	
	if (result != true)
	{
		alert("Invalid characters used in word search '|,\<>[]{}`\;()@&$#%'")
	}
	else
	{
		document.frmWordSearch.txtWordSearched.value = result1;
		document.frmWordSearch.submit();
	}
	
	return;
}




function SubmitWordSearch2(GroupState)
{
	result1 = trim(document.frmWordSearchValues.txtWordSearch.value)
	
	if (result1 == "Enter Keyword Search" || result1 == "")
	{
		alert("Please enter a word or phrase to search on.")
		return;
	}
	
	result = isProper(document.frmWordSearchValues.txtWordSearch.value)
	
	if (result != true)
	{
		alert("Invalid characters used in word search '|,\<>[]{}`\;()@&$#%'")
		return;
	}
	
	document.frmWordSearch.txtPosition.value = "1"
	
	
	if (GroupState==0)
	{
		document.frmWordSearch.txtGroupByCS.value = "";
		document.frmWordSearch.txtGroupByPublication.value = "";
		document.frmWordSearch.txtGroupByAuthor.value = "";
	}
	else if (GroupState==1)
	{
		document.frmWordSearch.txtGroupByCS.value = "1";
		document.frmWordSearch.txtGroupByPublication.value = "";
		document.frmWordSearch.txtGroupByAuthor.value = "";
	}
	else if (GroupState==2)
	{	
		document.frmWordSearch.txtGroupByAuthor.value = "1";
		document.frmWordSearch.txtGroupByCS.value = "";
		document.frmWordSearch.txtGroupByPublication.value = "";
	}
	else if (GroupState==3)
	{
		document.frmWordSearch.txtGroupByPublication.value = "1";
		document.frmWordSearch.txtGroupByCS.value = "";
		document.frmWordSearch.txtGroupByAuthor.value = "";
	}
	else
	{
		//document.frmWordSearch.txtGroupByCS.value = "0";
		document.frmWordSearch.txtGroupByCS.value = document.frmWS_V3_OPS.txtGroupByCS.value;
	}
	
	document.frmWordSearch.txtYearLimited.value = document.frmWS_V3_OPS.selDate.options[self.document.frmWS_V3_OPS.selDate.options.selectedIndex].value;
		
	document.frmWordSearch.submit();
}



function WS_V3_Reset()
{
	
	
	result1 = trim(document.frmWordSearchValues.txtWordSearch.value)
	
	if (result1 == "Enter Keyword Search" || result1 == "")
	{
		alert("Please enter a word or phrase to search on.")
		return;
	}
	
	result = isProper(document.frmWordSearchValues.txtWordSearch.value)
	
	if (result != true)
	{
		alert("Invalid characters used in word search '|,\<>[]{}`\;()@&$#%'")
		return;
	}
	document.frmWordSearch.txtPosition.value = "1"
	
	
	document.frmWordSearch.txtGroupByCS.value = "";
	document.frmWS_V3_OPS.txtGroupByCS.value = "";
	document.frmWordSearch.txtYearLimited.value = "";
	document.frmWordSearch.txtGroupByPublication.value = "";
	document.frmWordSearch.txtGroupByAuthor.value = "";
		
	document.frmWordSearch.submit();
}



function nextIndex(Level,CurrentIndexItem)
{
		
	if ((document.frmIndex.txtLevel1.value == 'Marketing Intelligence') && ((CurrentIndexItem == 'Advertisers') || (CurrentIndexItem == 'Agency') || (CurrentIndexItem == 'Brands')))
	{
		// The next page should be ordered into lists, thay why there is mroe of this crap!
		document.frmOrderedListView.txtLevel1.value = document.frmIndex.txtLevel1.value
		document.frmOrderedListView.txtLevel2.value = CurrentIndexItem
		document.frmOrderedListView.txtWordSearch.value = document.frmIndex.txtWordSearch.value
		document.frmOrderedListView.selMethod.value = document.frmWordSearch.selMethod.options[self.document.frmWordSearch.selMethod.options.selectedIndex].value
		document.frmOrderedListView.selArea.value   = document.frmWordSearch.selArea.options[self.document.frmWordSearch.selArea.options.selectedIndex].value
		document.frmOrderedListView.submit();
	}
	else
	{
			
		if (Level == 0)
		{
			document.frmIndex.txtLevel1.value = CurrentIndexItem;
			document.frmIndex.txtWordSearch.value = document.frmWordSearchValues.txtWordSearch.value;
		}
		
		if (Level == 1)
		{
			document.frmIndex.txtLevel2.value = CurrentIndexItem;
			document.frmIndex.txtWordSearch.value = document.frmWordSearchValues.txtWordSearch.value;
		}
		
		if (Level == 2)
		{
			document.frmIndex.txtLevel3.value = CurrentIndexItem;
			document.frmIndex.txtWordSearch.value = document.frmWordSearchValues.txtWordSearch.value;
		}
		
		if (Level == 3)
		{
			document.frmIndex.txtLevel4.value = CurrentIndexItem;
			document.frmIndex.txtWordSearch.value = document.frmWordSearchValues.txtWordSearch.value;
		}
		
		if (Level == 4)
		{
			document.frmIndex.txtLevel5.value = CurrentIndexItem;
			document.frmIndex.txtWordSearch.value = document.frmWordSearchValues.txtWordSearch.value;
		}
		
		document.frmIndex.submit();
		
	}
}


function BackToLevel(Level)
{
	if (Level == 0)
	{
		document.frmIndex.txtLevel1.value = "";
		document.frmIndex.txtLevel2.value = "";
		document.frmIndex.txtLevel3.value = "";
		document.frmIndex.txtLevel4.value = "";
	}
		
	if (Level == 1)
	{
		document.frmIndex.txtLevel2.value = "";
		document.frmIndex.txtLevel3.value = "";
		document.frmIndex.txtLevel4.value = "";
	}
		
	if (Level == 2)
	{
		document.frmIndex.txtLevel3.value = "";
		document.frmIndex.txtLevel4.value = "";
	}
		
	if (Level == 3)
	{
		document.frmIndex.txtLevel4.value = "";
	}
		
	if (Level == 4)
	{
		return;
	}
	
	document.frmIndex.submit();
}



function SubmitIndexSearch2(GroupState)
{
	
	
	document.frmIndex.txtPosition.value = "1"
	
	
	if (GroupState==0)
	{
		document.frmIndex.txtGroupByCS.value = "";
		document.frmIndex.txtGroupByPublication.value = "";
		document.frmIndex.txtGroupByAuthor.value = "";
	}
	else if (GroupState==1)
	{
		document.frmIndex.txtGroupByCS.value = "1";
		document.frmIndex.txtGroupByPublication.value = "";
		document.frmIndex.txtGroupByAuthor.value = "";
	}
	else if (GroupState==2)
	{	
		document.frmIndex.txtGroupByAuthor.value = "1";
		document.frmIndex.txtGroupByCS.value = "";
		document.frmIndex.txtGroupByPublication.value = "";
	}
	else if (GroupState==3)
	{
		document.frmIndex.txtGroupByPublication.value = "1";
		document.frmIndex.txtGroupByCS.value = "";
		document.frmIndex.txtGroupByAuthor.value = "";
	}
	else
	{
		//document.frmWordSearch.txtGroupByCS.value = "0";
		document.frmIndex.txtGroupByCS.value = document.frmWS_V3_OPS.txtGroupByCS.value;
	}
	
	document.frmIndex.txtYearLimited.value = document.frmWS_V3_OPS.selDate.options[self.document.frmWS_V3_OPS.selDate.options.selectedIndex].value;
		
	document.frmIndex.submit();
}




function SubmitIndexSearchL1(Level1)
{
	document.frmIndex.txtLevel1.value = Level1;
	document.frmIndex.txtLevel2.value = "";
	document.frmIndex.txtLevel3.value = "";
	document.frmIndex.txtLevel4.value = "";
		
	document.frmIndex.txtWordSearch.value = trim(document.frmWordSearchValues.txtWordSearch.value);
	document.frmIndex.txtPosition.value	  = "0";
	document.frmIndex.submit();
		
}
	
	
	
	
function SubmitIndexSearchL3(Level1,Level2,Level3)
{
	document.frmIndex.txtLevel1.value = Level1;
	document.frmIndex.txtLevel2.value = Level2;
	document.frmIndex.txtLevel3.value = Level3;
	document.frmIndex.txtLevel4.value = "";
		
	document.frmIndex.txtWordSearch.value = trim(document.frmWordSearchValues.txtWordSearch.value);
	document.frmIndex.txtPosition.value	  = "0";
	document.frmIndex.submit();
}




//==========================================================================================
// Functions to validate information
//----------------------------------

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 clearBox()
{
	if (document.frmWordSearchValues.txtWordSearch.value == "Enter search term")
	{
		document.frmWordSearchValues.txtWordSearch.value="";
	}
	else
	{
		// Do nothing
	}
	
}

function checkEnter(e)
{ 
var characterCode							//literal character code will be stored in this variable

	 if(e && e.which)
	 {										//if which property of event object is supported (NN4)
		e = e
		characterCode = e.which				//character code is contained in NN4's which property
	 }
	 else
	 {							
		e = event						
		characterCode = e.keyCode			//character code is contained in IE's keyCode property
	 }
	 
	 
	 if(characterCode == 13)
	 {										//if generated character code is equal to ascii 13 (if enter key)
		//document.forms[0].submit()			//submit the form
		SubmitWordSearch()
		return false 
	 }
	 else
	 {
		return true 
	 }
}




//==========================================================================================
// Functions to view articles and related details
//-----------------------------------------------

function openArticle(url,ID)
{
	articleURL = url
	url = "/ArticleCenter/default.asp?OrgURL=" + articleURL + "&type=ART" + "&ID=" + ID;
	
	WARCWindow = window.open(url,'popupWindow','width=810,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 openAbstract(url,ID)
{
	
	articleID = ID
	articleURL = url
	abstractURL = "/ArticleCenter/default.asp?OrgURL=" + articleURL + "&type=ABS" + "&ID=" + ID;
	WARCWindow2 = window.open(abstractURL,'popupWindow','width=810,height=500,"WARC Knowledge Center",top=20,left=20,resizable=yes,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow2.opener)
			WARCWindow2.opener = self;
}


function openPDF(ID)
{
	articleID = ID
	pdfURL = "/ArticleCenter/default.asp?ID=" + ID + "&type=PDF";

	WARCWindow3 = window.open(pdfURL,'popupWindow','width=810,height=500,"WARC Knowledge Center",top=20,left=20,resizable=yes,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow3.opener)
			WARCWindow3.opener = self;
}


function openHelp(url)
{
	
	WARCHelpWindow = window.open(url,'popupWindow','width=600,height=270,"WARC Knowledge Center",top=20,left=20,resizable=yes,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCHelpWindow.opener)
			WARCHelpWindow.opener = self;
}


function openSample()
{
	URL = "/ArticleCenter/Samples.asp";

	WARCWindow3 = window.open(URL,'popupWindow','width=700,height=500,"WARC Knowledge Center",top=20,left=20,resizable=yes,toolbar=no,menubar=yes,location=no,status=yes,directories=no,scrollbars=yes');
		if (!WARCWindow3.opener)
			WARCWindow3.opener = self;
}


function openURL(url)
{
	
	WARCWindow = window.open(url,'popupWindow','width=750,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 openData(DataItem,YearVal)
{
	var URL;
	URL = "/Viewer/Default.asp?DataItem=" + DataItem + "&YearVal=" + YearVal
	WARCWindow = window.open(URL,'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;
			
}



//Google code
_uacct = "UA-183038-12";
urchinTracker();