File: //home/mykensington.co.uk/public_html/weblinks/show_cats_and_sects_mockup.js
<!--
// This files controls the sites and categories that will appear on the
// User creates advert page.
// setup the list of sites we can put adverts on.
allSites = new Array(
'please select\.\.\.' ,
'mycamden' ,
'mypaddington' ,
'myhampstead' ,
'mytowerhamlets' ,
'mychelsea' ,
'mycityoflondon' ,
'myclapham' ,
'mydocklands' ,
'myhackney' ,
'myhammersmith' ,
'myislington' ,
'mylambeth' ,
'mykensington' ,
'mynottinghill' ,
'myshoreditch' ,
'mysouthwark' ,
'mysouthbank' ,
'mywandsworth' ,
'mywestend' ,
'myaberdeen' ,
'mybelfast' ,
'mybrum' ,
'mybrighton' ,
'mybristol' ,
'mycardiff' ,
'myedinburgh' ,
'myglascow' ,
'myhighlands' ,
'myinverness' ,
'myleeds' ,
'myliverpool' ,
'myleicester' ,
'mymanchester' ,
'mynewcastle' ,
'mynorwich' ,
'mynottingham' ,
'myoxford' ,
'myplymouth' ,
'mysheffield' ,
'mysouthhampton',
'mygreenwich',
'myenfield'
);
// setup the possible section we can publish to.
allCats = new Array(
array = new Array('Homes & Property', 'Property for Rent offered', 'Property for Rent wanted', 'Furniture for sale', 'Removals and Domestic Storage'),
array = new Array('Business Zone', 'Business Services', 'Jobs wanted', 'Jobs offered', 'Recruitment'),
array = new Array('Services', 'Goods delivered to your door'),
array = new Array('Arts & Entertainment','Cinema memorabilia', 'Art for Sale', 'Books for sale', 'Video\/DVDs for sale', 'Private tuition'),
array = new Array('Health & Beauty','Beauty', 'Mobile Hairdressers', 'Services and Complementary Health'),
array = new Array('Kids & Youth','Schools', 'Play groups', 'Associations', 'Nannies', 'Baby Sitters', 'Toys for sale', 'Tuition'),
array = new Array('Fashion & Lifestyle', 'Clothes for Sale'),
array = new Array('Football & Sport','Sports', 'Clubs'),
array = new Array('Community', 'Groups and Organisations', 'Charities', 'Help wanted', 'Help needed', 'Dog walkers','Baby sitters','Psychology', 'Tuition'),
array = new Array('Personal Services', 'Escorts', 'Personal Services', 'Massage parlours'),
array = new Array('Web Links', 'Local Sites')
);
// draw the list of avialable sites onto the page.
function drawSites()
{
var numberOfSites = allSites.length;
//alert(numberOfSites);
var tempCount = 0;
document.writeln('<select name="site" size="1" onchange="document.createAd.sitex.value=this.options[this.selectedIndex].value">');
while(tempCount < numberOfSites)
{
if(tempCount == 0)
{
document.writeln('<option value="'+allSites[tempCount]+'" selected>'+allSites[tempCount]+'</option>');
}
else
{
document.writeln('<option value="'+allSites[tempCount]+'">'+allSites[tempCount]+'</option>');
}
tempCount = tempCount+1;
}
document.writeln('</select>');
}
// draw the list of avialable categories onto the page.
function drawCats()
{
var numberOfCats = allCats.length;
var tempCount = 0;
while(tempCount < numberOfCats)
{
{
document.writeln('<a class=WriteAdCategoryLinks href="#" onclick="javascript:drawSubCats(\''+tempCount+'\'); document.createAd.catx.value=\''+allCats[tempCount][0]+'\'; this.style.backgroundColor=\'yellow\'">'+allCats[tempCount][0]+'</a><br>');
}
tempCount = tempCount+1;
}
}
// draw the list of avialable subcategories onto the page.
function drawSubCats(cat)
{
var numberOfSubCats = allCats[cat].length;
//alert(numberOfSubCats);
var tempCount = 1;
allLinks = new String();
while(tempCount < numberOfSubCats)
{
allLinks = allLinks+"<a class=WriteAdSubCategoryLinks href=# onclick='javascript: document.createAd.subcatx.value=\""+allCats[cat][tempCount]+"\"; showWhere(); this.style.backgroundColor=\"yellow\"'>"+allCats[cat][tempCount]+"</a><br>";
tempCount = tempCount+1;
}
document.all.subcat.innerHTML = allLinks;
}
// draw the bit of text that shows you where the advert will get written to
function showWhere()
{
var site = document.createAd.sitex.value;
var cat = document.createAd.catx.value;
var subcat = document.createAd.subcatx.value;
document.all.createWhere.innerHTML = site+" >> "+cat+" >> "+subcat;
}
// check that the first stages have been comepleted before they continue
function checkFirstStage()
{
var site = document.createAd.sitex.value;
var cat = document.createAd.catx.value;
var subcat = document.createAd.subcatx.value;
if(site == "" || cat == "" || subcat == "")
{
alert("you must complete the above stages before you can compose your advert");
document.createAd.site.focus();
}
}
// Draw the links for the side of the show adverts page.
function drawCatLinks()
{
var numberOfCats = allCats.length;
var tempCount = 0;
while(tempCount < numberOfCats)
{
var linker = document.location.pathname+"?cat="+escape(allCats[tempCount][0])+"&";
document.writeln('<a class=ShowAdCategoryLinks href='+linker+'>'+allCats[tempCount][0]+'</a><br>');
tempCount = tempCount+1;
}
}
// Draw the subcat links down the right
function drawSubCatLinks()
{
if(document.location.search.indexOf("cat=")!= -1)
{
var cat = unescape(document.location.search.substring(document.location.search.indexOf("cat=")+4, document.location.search.indexOf("&")));
//alert(cat);
document.all.whichCat.innerHTML = "<font class=ShowAdCategoryTitle>"+cat+" - Classifieds</font>";
var numberOfCats = allCats.length;
var tempCount = 0;
while(tempCount < numberOfCats)
{
if(allCats[tempCount][0] == cat)
{
var numberOfEles = allCats[tempCount].length;
var eleCount = 1;
while(eleCount < numberOfEles)
{
var linker = document.location.pathname+"?cat="+document.location.search.substring(document.location.search.indexOf("cat=")+4, document.location.search.indexOf("&"))+"&subcat="+escape(allCats[tempCount][eleCount]);
document.writeln('<a class=ShowAdSubCategoryLinks href='+linker+'>'+allCats[tempCount][eleCount]+'</a><br>');
eleCount = eleCount+1;
}
}
tempCount = tempCount+1;
}
}
}
// draw the preview of the advert.
function drawPreview()
{
// var emailAdd = document.createAd.emailadd.value;
var webAdd = document.createAd.webAdd.value;
// var adtitle = document.createAd.adtitle.value;
var adtext = document.createAd.adtext.value;
// var tel = document.createAd.tel.value;
var previewCode = "<font class=AdTitle>"+webAdd+"</font><br><font class=AdText>"+adtext+"</font>"
document.all.preview.innerHTML = previewCode;
}
// draw adverts for the selected site and category and subcategory.
function drawAdverts()
{
// count the total number of adverts in the file
var numberOfAdsinFile = allAds.length;
var tempCount = numberOfAdsinFile-1;
var numberOfAdsMatching = 0;
// find out the required section
if(document.location.search.indexOf("subcat=")!= -1)
{
var subcat = unescape(document.location.search.substring(document.location.search.indexOf("subcat=")+7, document.location.search.length));
}
if(document.location.search.indexOf("cat=")!= -1)
{
var cat = unescape(document.location.search.substring(document.location.search.indexOf("cat=")+4, document.location.search.indexOf("&")));
}
var subcat = "Local Sites";
var cat = "Web Links";
//alert(subcat);
//alert(cat);
// go through the ads and draw the ones which are in the required section
while(tempCount > 1)
{
if(eval('allAds['+tempCount+'][1]') == subcat && eval('allAds['+tempCount+'][0]') == cat)
{
numberOfAdsMatching = numberOfAdsMatching+1;
//alert("found one");
//thisTitleEscaped = new String(allAds[tempCount][2]);
//thisTitle = unescape(thisTitleEscaped);
thisTextEscaped = new String(allAds[tempCount][3]);
re = new RegExp ('%0D%0A', 'g');
thisTextBreaked = thisTextEscaped.replace(re, '<BR>');
thisText = unescape(thisTextBreaked);
//thisEmail = new String(allAds[tempCount][4]);
thisWebEscaped = new String(allAds[tempCount][5]);
thisWeb = unescape(thisWebEscaped);
//thisTelEscaped = new String(allAds[tempCount][6]);
//thisTel = unescape(thisTelEscaped);
//document.writeln("<font class=AdTitle>"+thisTitle+"</font><br>");
//document.writeln("<font class=AdEmail>email: <a href=mailto:"+thisEmail+">"+thisEmail+"</a></font><br>");
document.writeln("<font class=AdWeb><a href=http://"+thisWeb+">"+thisWeb+"</a></font><br>");
document.writeln("<font class=AdText>"+thisText+"</font><br><br>");
//document.writeln("<font class=AdTel>tel: "+thisTel+"</font><br><br><br>");
}
tempCount = tempCount-1;
}
if(numberOfAdsMatching == 0 && subcat)
{
document.writeln("<font size=1><b>Be the first to get a listing in "+cat+" >> "+subcat+"<br><a href=category_select.htm>Click here to add your listing...</a></b></font>");
}
}
// unescape everything so that you don't get any errors when publishing
function unescapeEverything()
{
if(document.createAd.webAdd.value == "")
{
alert("web address is required.");
return;
};
if(document.createAd.email.value == "")
{
alert("email field is required.");
return;
};
if(document.createAd.amount(document.createAd.amount.selectedIndex).value == 0)
{
alert("you must choose a payment plan");
return;
};
if(document.createAd.contact.value == "")
{
alert("contact field is required.");
return;
};
if(document.createAd.tel.value == "")
{
alert("telephone number is required.");
return;
};
if(confirm("do you agree with the weblink?\n\nmake sure your weblink is exactly as you want it before publishing, \nyou will not be able to go back and change it."))
{
document.createAd.M_adtext.value = escape(document.createAd.adtext.value);
document.createAd.M_webAdd.value = escape(document.createAd.webAdd.value);
document.createAd.M_emailadd.value = escape(document.createAd.email.value);
document.createAd.email.value = escape(document.createAd.email.value);
document.createAd.M_tel.value = escape(document.createAd.tel.value);
document.createAd.M_contact.value = escape(document.createAd.contact.value);
document.createAd.name.value = escape(document.createAd.contact.value);
document.createAd.M_catx.value = escape(document.createAd.catx.value);
document.createAd.M_sitex.value = escape(document.createAd.sitex.value);
document.createAd.M_subcatx.value = escape(document.createAd.subcatx.value);
document.createAd.M_site.value = escape(document.createAd.site.value);
document.createAd.M_siteext.value = location.host;
document.createAd.submit();
}
}
//-->
function ValidateEMail(obj)
{
var bVali = true;
if (obj.value != "") {
aMail = obj.value.split("@")
if (aMail.length != 2) {
bVali = false;
} else {
usuaExp = /[a-z_0-9\.]/;
if (!usuaExp.test(aMail[0])) {
bVali = false;
} else {
aHost = aMail[1].split(".");
if (aHost.length < 2) {
bVali = false;
}
}
}
}
if (!bVali) {
alert("email address is invalid!");
obj.focus();
}
}