function PopWin1(Typ, Gp, Inf, Loc) // Type if popup, Group name, Information, Location of calling page
{
var Path = "";
var Pg = "";
if (Loc == 1)
{Path = "../"}
if (Typ == 1)//Picture
{
Pg = "popup_pic.php"
Pg = Path+Pg;
infowin=window.open(Pg+"?T="+Gp+",P="+Inf,"InfoWindow","toolbar=no,directories=no,menubar=no,scrollbars=no,width=400,height=450,top=100,left=100");
}
else if (Typ == 2)//Description, Repertoire
{
Pg = Path+"popup_moreinfo.php?"+Inf; // path, page and query showing group ID
infowin=window.open(Pg,"InfoWindow","toolbar=no,directories=no,menubar=no,scrollbars=yes,width=500,height=450,top=100,left=100");
}
else if (Typ == 3)//Repertoire
{
Pg = Path+"popup_rep.php?"+Inf; // path, page and query showing group ID
infowin=window.open(Pg,"InfoWindow","toolbar=no,directories=no,menubar=no,scrollbars=yes,width=500,height=450,top=100,left=100");
}
}

//function PopWinContactOLD(ID, Gp, A, T, Fx, Mb, Em, Loc)
// GroupID, Title of group, Address, Telephone, Fax, Email, Calling page's number
//{
//var Pg="";
//if (Loc==1)
//{Pg = "../popup_contact.htm"}
//else
//{Pg = "popup_contact.htm"}
//Loc=Pg+"?ID="+ID+",G="+Gp+",A="+A+",T="+T+",X="+Fx+",M="+Mb+",E="+Em
//infowin=window.open(Loc,"InfoWindow","toolbar=no,directories=no,menubar=no,scrollbars=no,width=650,height=520,top=100,left=100");
//}

function PopWinContact(ID, Loc)
{
var Pg="";
if (Loc==1)
{Pg = "../popup_contact.php"}
else
{Pg = "popup_contact.php"}
Loc=Pg+"?ID="+ID
infowin=window.open(Loc,"InfoWindow","toolbar=no,directories=no,menubar=no,scrollbars=no,width=650,height=570,top=100,left=100");
}

function SendEnquiry(Fm)
{
if (Fm.form.ClientEmail.value.indexOf("@")==-1 || Fm.form.ClientEmail.value.indexOf(".")==-1)
{alert("Please enter a valid email address.")}
else
{
Fm.form.ClientName.value = CleanText(Fm.form.ClientName.value, "A")
Fm.form.ClientEmail.value = CleanText(Fm.form.ClientEmail.value, "E")
Fm.form.ClientTel.value = CleanText(Fm.form.ClientTel.value, "AN")
Fm.form.EventDate.value = CleanText(Fm.form.EventDate.value, "AD")
Fm.form.EventLocation.value = CleanText(Fm.form.EventLocation.value, "A")
Fm.form.ClientMessage.value = CleanText(Fm.form.ClientMessage.value, "A")
Fm.form.submit()}
}

function PopWinEx(N, w, h, S) // used to display main example page - needed as it needs to generate further pop-ups
{
infowin=window.open("examples/"+N,"ExampleWindow","toolbar=no,directories=no,menubar=no,scrollbars="+S+",width="+w+",height="+h+",top=50,left=50");
}

function PopWinBook(N, w, h, S) // used to display Booking Checklist pop-up
{
infowin=window.open(N,"BookingChecklist","toolbar=no,directories=no,menubar=no,scrollbars="+S+",width="+w+",height="+h+",top=50,left=50");
}

function PopWin(N, w, h, S) // used to display examples
{
infowin=window.open(N,"InfoWindow","toolbar=no,directories=no,menubar=no,scrollbars="+S+",width="+w+",height="+h+",top=100,left=100");
}

function PopWinFile(N, w, h, S) // used to display guidelines, Keyword tips, FAQ answers,
{
infowin=window.open(N,"FileWindow","toolbar=no,directories=no,menubar=no,scrollbars="+S+",width="+w+",height="+h+",top=100,left=100");
}

function LoadWebsite(N)
{
// For loading a website into a blank window from a popup box
WebWin=window.open(N,"LiveMusicSearchWindow","toolbar=yes,directories=yes,menubar=yes,scrollbars=yes,width=750,height=550,top=50,left=50");
window.close();
}
function ShowMap(L)
// Display the pop-up map
{
if (L==1)
{MapLoc="../ukmap.htm"}
else
{MapLoc="ukmap.htm"}
mapwin=window.open(MapLoc,"MapWindow","toolbar=no,directories=no,menubar=no,scrollbars=yes,width=520,height=600,top=10,left=10");
}

//*************************
// SEARCH *****************
function SubmitSearchResults(Fm, X)
{
alert("OK SO FAR")
}

function SearchNow(Fm)
{
var E="";
//Fm.form.FeeFrom.value=ParseInt(Fm.form.FeeFrom.value);
//Fm.form.FeeTo.value=ParseInt(Fm.form.FeeTo.value);
if (isNaN(Fm.form.FeeFrom.value)) {Fm.form.FeeFrom.value=100}
if (isNaN(Fm.form.FeeTo.value)) {Fm.form.FeeTo.value=300}
//if (isNaN(Fm.form.NumFrom.value)) {Fm.form.NumFrom.value=2}
//if (isNaN(Fm.form.NumTo.value)) {Fm.form.NumTo.value=4}
	if (Fm.form.FeeTo.value > 0 && Fm.form.FeeFrom.value == "") {Fm.form.FeeFrom.value = 0}
	//if (Fm.form.FeeTo.value > 0 && Fm.form.FeeFrom.value > 0 && Fm.form.FeeTo.value < Fm.form.FeeFrom.value)
	//{
	//E = Fm.form.FeeTo.value;
	//Fm.form.FeeTo.value = Fm.form.FeeFrom.value;
	//Fm.form.FeeFrom.value = E;
	//}
	if (Fm.form.FeeTo.value=="" && Fm.form.FeeFrom.value)
	{
	Fm.form.FeeTo.value=Fm.form.FeeFrom.value;
	Fm.form.FeeFrom.value=0;
	}

	//Fm.form.NumFrom.value=ParseInt(Fm.form.NumFrom.value);
	//Fm.form.NumTo.value=ParseInt(Fm.form.NumTo.value);
	//if (Fm.form.NumTo.value > 0 && Fm.form.NumFrom.value == "") {Fm.form.NumFrom.value = Fm.form.NumTo.value}
	//if (Fm.form.NumTo.value && Fm.form.NumFrom.value && Fm.form.NumTo.value < Fm.form.NumFrom.value)
	//{
	//E = Fm.form.NumTo.value;
	//Fm.form.NumTo.value = Fm.form.NumFrom.value;
	//Fm.form.NumFrom.value = E;
	//}
	StyleAndEventFill(Fm.form);
	Fm.form.Keywords.value = CleanText(Fm.form.Keywords.value, "AA");
	Fm.form.submit();
}

function StyleAndEventFill(Fm)
{
// *** STYLES PLAYED ***
var Txt="" // to temporarily hold the line of new text
for (Cnt=1; Cnt<13; Cnt++) // *** Make sure the number is high enough for all the check boxes ***
{
if (Fm.elements["GpInfSt"+Cnt].checked==true)
{
Txt+=Fm.elements["GpInfSt"+Cnt].id+" ";
}
}
Fm.elements["GpInfStyle"].value=Txt

// *** TYPE OF EVENT ***
Txt="" // to temporarily hold the line of new text
if (Fm.elements.length<30) // This is for the "cut-down" search pages
{
	for (Cnt=1; Cnt<3; Cnt++) // *** Make sure the number is high enough for all the check boxes ***
	{
	if (Fm.elements["GpInfEv"+Cnt].checked==true)
	{
	Txt+=Fm.elements["GpInfEv"+Cnt].id+" ";
	}
	}
}
else
{
	for (Cnt=1; Cnt<15; Cnt++) // *** Make sure the number is high enough for all the check boxes ***
	{
	if (Fm.elements["GpInfEv"+Cnt].checked==true)
	{
	Txt+=Fm.elements["GpInfEv"+Cnt].id+" ";
	}
	}
}
Fm.elements["GpInfEvents"].value=Txt
}

// **********
// Text functions
function CleanText(x, Ch)
// x is the text, Ch is to set the type of characters allowed
{
x = RemoveQuotes(x); // change the quote marks first
// now get rid of bad words
x = RemoveBadWords(x)
var x2="" // new value for the text
if (Ch=="A") // Basic text and simple punctuation
{var T = /\w|\s|-|`|,|\.|;|:|\(|\)|~|&|#|!/}
else if (Ch=="AA") // text and space only
{var T= /\w|\s/}
else if (Ch=="NN") // numbers with NO spaces
{var T= /\d|\s/}
else if (Ch=="N") // numbers and space
{var T= /\d|\s/}
else if (Ch=="AN") // Basic Text and numbers (with punctuation)
{var T= /\w|\s|-|`|,|\.|;|:|\(|\)|~|#|!|\*|\d/}
else if (Ch=="AD") // Basic Text and numbers (with punctuation) plus date divider
{var T= /\w|\s|-|`|,|\.|;|:|\(|\)|~|#|!|\*|\d|\//}
else if (Ch=="ANX") // Basic Text and numbers (with punctuation) plus html formatting
{var T= /\w|\s|-|`|,|\.|;|:|\(|\)|~|#|!|\d|<|>/}
else if (Ch=="E") // email address
{var T= /\w|\d|@|-|_|\.|~|#/}
else if (Ch=="W") // web address
{var T= /\w|\d|\/|:|-|_|\.|~|#/}
else
{var T=/\w|-|\s/}

for (C=0; C<x.length; C++)
{
if (x.substr(C,1).search(T)!=-1)
{
x2+=x.substr(C,1)
}
}
return x2;
}

function CleanKeywords(x)
{
var x2="";
var Wd;
x=CleanText(x, "AA") // first remove all non alpha characters
// now get rid of unwanted words
for (C=0; C<x.length; C++)
{
if (x.substr(C,5).search(" and ")!=-1 || x.substr(C,5).search(" the ")!=-1)
{
x2+=" ";
C=C+3;
}
else if (x.substr(C,3).search(" a ")!=-1)
{
x2+=" ";
C=C+1
}
else if (x.substr(C,4).search(" of ")!=-1 || x.substr(C,4).search(" on ")!=-1 || x.substr(C,4).search(" in ")!=-1 || x.substr(C,4).search(" an ")!=-1)
{
x2+=" ";
C=C+2
}
else
{
x2+=x.substr(C,1)
}
}
// now remove double spaces
var x3="";
for (C=0; C<x2.length; C++)
{
if (x2.substr(C,2).search("  ")!=-1)
{
C=C+1;
}
else
{
x3+=x2.substr(C,1)
}
}
return x3;
}

function RemoveBadWords(x)
{
var CleanX = "";
for (C=0; C<x.length; C++)
{
if (x.substr(C,4).search("fuck")!=-1 || x.substr(C,4).search("cum ")!=-1 || x.substr(C,4).search("wank")!=-1 || x.substr(C,4).search("turd")!=-1)
{
C=C+3
}
else if (x.substr(C,5).search("penis")!=-1)
{
C=C+4
}
else if (x.substr(C,6).search("wanker")!=-1 || x.substr(C,6).search("vagina")!=-1 || x.substr(C,6).search(" shit ")!=-1)
{
C=C+5
}
else if (x.substr(C,7).search("bollock")!=-1 || x.substr(C,7).search("bastard")!=-1)
{
C=C+6
}
else
{
CleanX+=x.substr(C,1)
}
}
return CleanX;
}

function RemoveQuotes(x)
{
var x2="";
for (C=0; C<x.length; C++)
{
if (x.substr(C,1)=="'" || x.substr(C,1)=='"') // change both single and double quotes
{x2+="`";}
else
{x2+=x.substr(C,1)}
}
return x2
}

function PreviewText(Txt, T)
{
Txt = CleanText(Txt, "AN");
Txt = RemoveTags(Txt);
if (Txt!="BAD")
{
Txt = escape(Txt);
Txt = ToHTML(Txt);
PreviewWin=window.open("","PreviewWindow","toolbar=no,directories=no,menubar=no,scrollbars=yes,width=500,height=500,top=100,left=100");
PreviewWin.document.write('<head><link href="../lms.css" rel="stylesheet" type="text/css"></head>');
PreviewWin.document.write('<body>')
PreviewWin.document.write('<table width="98%" border="0" cellspacing="0" cellpadding="4"><tr><td>');
PreviewWin.document.write("<h3><center>"+T+"</center></h3><BR>");
PreviewWin.document.write(unescape(Txt));
PreviewWin.document.write('</td></tr><tr><td align="center"><BR><a href="javascript:window.close()"><img src="../images/btn_close.gif" width="77" height="18" border="0"></a></td></tr></table>')
PreviewWin.document.write('</body>')
}
else
{alert("Please do not use script tags")}
}

function RemoveBR(x)
{
// to remove BR tags for display
var x2=""
for (C=0; C<x.length; C++)
{
if (x.substr(C,4).toLowerCase().search("<br>")!=-1)
{C+=3
x2+="\n"}
else
{x2+=x.substr(C,1)}
}
return x2
}

function RemoveTags(x)
{
// to remove tags which are undesirable
var x2=""
for (C=0; C<x.length; C++)
{
if (x.substr(C,7).toLowerCase().search("<script")!=-1)
{return "BAD"}
else
{x2+=x.substr(C,1)}
}
return x2
}

function ToHTML(x)
{
var x2=""
//replace carriage returns with html line breaks
//carriage return is %0D%0A and html line break is %3Cbr%3E 
for (C=0; C<x.length; C++)
{
if (x.substr(C,6).search("%0D%0A")==-1)
{x2+=x.substr(C,1)}
else
{x2+="%3Cbr%3E";
C+=5}
}
return x2
}

//**************************************************************************
// New bits added 29/06/06
//**************************************************************************

function CRtoBR(Txt)
{
// Change Carriage Returns to BR tags for preview display
Txt2 = escape(Txt)
Txt2 = Txt2.replace(/%OD/gi,"<BR>")
Txt2 = Txt2.replace(/%0A/gi,"<BR>")
Txt2 = unescape(Txt2)
return Txt2
}

function PreviewPane(Txt,T)
{
PreviewWin=window.open("preview-pane.php?T="+T+"&Txt="+CRtoBR(Txt),"PreviewWindow","toolbar=no,directories=no,menubar=no,scrollbars=yes,width=500,height=500,top=100,left=100");
}
