
    var preloader = '<table width="100%" height="250" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img src="progress.gif"/></td></tr></table>';

	function init(){
		insertBlur();
		createMenu();
			if (lang == 'el') {
			newTitle = '<div style="display:none;" id="mainTitleContent">Παρακαλώ επιλέξτε από το μενού</div>';
			} else {
			newTitle = '<div style="display:none;" id="mainTitleContent">Please select a menu</div>';
			}
		document.getElementById('mainTitle').innerHTML = newTitle;
		fx4 = new Effect.BlindDown(document.getElementById('mainTitleContent'),{duration: 0.4});
		document.getElementById('mainText').innerHTML = '';
	}

	function createMenu(){

              new Ajax.Request('xmlfeeder.php', {
                method: 'get',
                parameters: 'mode=readmenu',
                onSuccess: function(transport) {
					menuxml = transport.responseXML.documentElement;
					counter = 0;
					do{
						if(menuxml.childNodes[counter].getAttribute('language') == lang){
							curmxml = menuxml.childNodes[counter];
						}
						counter++;
					}while(counter < menuxml.childNodes.length);

					var mHTML = '<div id="menuDIV" style="display:none;">';
					counter = 0;
					do{
						
						if(curmxml.childNodes[counter].childNodes.length > 0){
							oc = 'onclick="if ($(\'art_bio\').style.display != \'none\') { $(\'art_bio\').style.display = \'none\'; } if ($(\'supporters\').style.display != \'none\') { $(\'supporters\').style.display = \'none\'; } expandMenu(\''+counter+'\',\'submenu_\');setTitle(\''+curmxml.childNodes[counter].getAttribute('label')+'\');this.blur();"';
						}else{
							oc = 'onclick="if ($(\'art_bio\').style.display != \'none\') { $(\'art_bio\').style.display = \'none\'; } if ($(\'supporters\').style.display != \'none\') { $(\'supporters\').style.display = \'none\'; } executemenu(\''+curmxml.childNodes[counter].getAttribute('function')+'\');expandMenu(\'999\',\'submenu_\');setTitle(\''+curmxml.childNodes[counter].getAttribute('label')+'\');this.blur();"';
						}
						mHTML += '<div class="menuItem" id="menu_'+counter+'"><a href="javascript:void(0);" '+oc+'>'+curmxml.childNodes[counter].getAttribute('label')+'</a></div>';
						if(curmxml.childNodes[counter].childNodes.length > 0){
							mHTML += '<div style="display:none" id ="submenu_'+counter+'">';
							ccounter = 0;
							do{
								mHTML += '<div class="subMenuItem">&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="executemenu(\''+curmxml.childNodes[counter].childNodes[ccounter].getAttribute('function')+'\');setSubTitle(\''+curmxml.childNodes[counter].childNodes[ccounter].getAttribute('label')+'\');this.blur();">'+curmxml.childNodes[counter].childNodes[ccounter].getAttribute('label')+'</a></div>';
								ccounter++;
							}while(ccounter < curmxml.childNodes[counter].childNodes.length);
							mHTML += '</div>';
						}
						counter++;
					}while(counter < curmxml.childNodes.length);
					mHTML += '</div>';
					document.getElementById('menuContainer').innerHTML = mHTML;
					var fx = new Effect.BlindDown(document.getElementById('menuDIV'),{duration: 0.6});
					
				}
		});	
	}
	
	function setTitle(string){
		newTitle = '<div style="display:none;" id="mainTitleContent">'+string+'</div>';
		document.getElementById('mainTitle').innerHTML = newTitle;
		fx4 = new Effect.BlindDown(document.getElementById('mainTitleContent'),{duration: 0.4});
	}
	
	function setSubTitle(string){
		var ct = document.getElementById('mainTitleContent').innerHTML;
		sct = ct.split(".");
		if(sct.length == 2){
			newTitle = sct[0]+". "+string;
		}else{
			newTitle = ct+'. '+string;
		}
		
		document.getElementById('mainTitleContent').innerHTML = newTitle;
	}
	
	function expandMenu(indexer,prefixer,nonmenu){
		if(indexer != '999' && nonmenu != false){
			if (lang == 'el') {
			document.getElementById('mainText').innerHTML = 'Επιλέξτε μια από τις υποκατηγορίες...';
			} else {
			document.getElementById('mainText').innerHTML = 'Please select one of the sub-categories...';
			}
		}
		alldivs = document.getElementsByTagName('div');
		counter = 0;
		do{
			curdiv = alldivs[counter].id;
			curdivlen = curdiv.split(prefixer);
			if(curdivlen.length == 2){
				curdivind = curdiv.split(prefixer);
				if(curdivind[1] == indexer){
					if(document.getElementById(curdiv).style.display == 'none'){
						fx1 = new Effect.BlindDown(document.getElementById(curdiv),{duration:0.4});
					}else{
						fx2 = new Effect.BlindUp(document.getElementById(curdiv),{duration:0.4});
					}
				}else{
					fx3 = new Effect.BlindUp(document.getElementById(curdiv),{duration:0.4});
				}
			}
			counter++;
		}while(counter < alldivs.length);
	}
		
	function insertBlur(){
		var ahrefs = document.getElementsByTagName('a');
		var browserName=navigator.appName; 
		counter = 0;
		do{
			
			var currentOC = ahrefs[counter].getAttribute('onclick');
			
			if(currentOC == null){
				currentOC = '';
			}
			
			if(browserName == "Microsoft Internet Explorer"){
				if(currentOC != ''){
					currentOC = currentOC.toString().split('}')[0].split('{')[1];
				}
				ahref = ahrefs[counter];
				ahref["onclick"] = new Function(''+currentOC+'this.blur();');
			}else{
				ahrefs[counter].setAttribute('onclick',currentOC+'this.blur();');
			}

			counter++;
		}while(counter < ahrefs.length);
		
	}

    var xmlData;

	function executemenu(stringer,extra){

        if ($('art_bio').style.display != 'none') { $('art_bio').style.display = 'none'; }
        if ($('supporters').style.display != 'none') { $('supporters').style.display = 'none'; }
        $('mainText').style.display = 'block';

		document.getElementById('mainText').innerHTML = '';
			switch(stringer){
				case "volunteers": querystring = "mode=volunteers"; break;
				case "profile": querystring = "mode=profile"; break;
				case "support": querystring = "mode=support"; break;
				case "contest": querystring = "mode=contest"; break;
				case "art_dj": querystring = "mode=artists&artcat=1"; break;
				case "art_la": querystring = "mode=artists&artcat=2"; break;
				case "art_ca": querystring = "mode=artists&artcat=3"; break;
				case "art_mo": querystring = "mode=artists&artcat=4"; break;
                case "art_vi": querystring = "mode=artists&artcat=5"; break;
				case "pro_lu": querystring = "mode=lineup"; break;
				case "pro_ma": querystring = "mode=market"; break;
				case "inf_st": querystring = "mode=stages"; break;
				case "inf_ma": querystring = "mode=map"; break;
				case "inf_ti": 	querystring = "mode=tickets"; break;
                case "inf_pr":  querystring = "mode=press"; break;
				case "contact": querystring = "mode=contact"; break;
				case "news_ln": querystring = "mode=latestnews"; break;
				case "news_pr": querystring = "mode=photoreport"; break;
				default: querystring = "";
			}

                if (stringer != 'support') {


              new Ajax.Request('xmlfeeder.php', {
                method: 'get',
                parameters: 'languager='+lang+'&'+querystring,
                onUninitialized : function() {
                $('loading').style.display = 'block';
                },

                onSuccess: function(transport) {

                $('loading').style.display = 'none';
                inhtml = null;
                xmlData = transport.responseXML.documentElement;

				switch(stringer){
				case "volunteers": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "profile": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "contest": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "art_dj": inhtml = createArtists(xmlData); break;
				case "art_la": inhtml = createArtists(xmlData); break;
				case "art_ca": inhtml = createArtists(xmlData); break;
				case "art_mo": inhtml = createArtists(xmlData); break;
                case "art_vi": inhtml = createArtists(xmlData); break;
				case "pro_lu": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "pro_ma": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "inf_ti": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "inf_st": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "inf_ma": inhtml = xmlData.childNodes[0].nodeValue; break;
                case "inf_pr": inhtml = xmlData.childNodes[0].nodeValue; break;
				case "contact": inhtml = xmlData.childNodes[0].nodeValue; break;
                case "support": inhtml = '';
				case "news_ln": inhtml = createNews(transport.responseXML); break;
				case "news_pr": inhtml = xmlData.childNodes[0].nodeValue;
                window.open('http://www.reworks.gr/reworks07/gallery/','reworksgallery','width=780,height=600,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,status=no');
                break;

				}

					if (inhtml == null){ inhtml = 'Coming soon...'; }

					diver = '<div id="mainTextContainer" style="display:none;">'+inhtml+'</div>';
					document.getElementById('Geranoi').style.backgroundImage = "url('gimg/yellowback.jpg')";
					document.getElementById('mainText').innerHTML = diver;

					if(extra != null && stringer == "volunteers"){
						counter = 1;
						do{
							if(counter != 3){
								document.getElementById('f'+counter).value = extra[counter];
							}else{
								if(extra[3] == 'Male'){ indexer = 1; } else { indexer = 0; }
								document.getElementById('f3').options[indexer].selected = true;
							}
							counter++;
						}while(counter <= 8);
					}
                    if (stringer == 'inf_st') { document.getElementById('Geranoi').style.backgroundImage = 'none'; }
					new Effect.BlindDown(document.getElementById('mainTextContainer'),{duration: 0.8});

              }});
} else {
                document.getElementById('Geranoi').style.backgroundImage = 'none';

                if (lang == 'el') {
                frames['SupportFrame'].location.href = 'data/support_el.html';
                } else {
                frames['SupportFrame'].location.href = 'data/support.html';
                }

 				new Effect.BlindDown(document.getElementById('supporters'),{duration: 0.8});

}
	}

var Called = 0;

function createArtists() {

        AllArtists = xmlData.childNodes.length;

	   	if (AllArtists > 0) {

    		rhtml2 = '';
			rhtml2 += '<div style="width:192px; height:300px; float:left;">';

				for (tcounter = 0; tcounter < AllArtists; tcounter++) {

                art_id = xmlData.childNodes[tcounter].childNodes[0].childNodes[0].nodeValue;
                art_name = xmlData.childNodes[tcounter].childNodes[1].childNodes[0].nodeValue;

				rhtml2 += '<div style="width:190px; float: left; margin-left:7px; color:#990000;" class="menuItem" id="art_'+art_id+'"><a onclick="displayArtist('+art_id+'); this.blur();" href="javascript:void(0);">'+art_name+'</a></div>';
     			if (tcounter == 20) {
                rhtml2 += '</div><div style="width:192px; height:300px; float:left;">'; }

				}

			rhtml2 += '</div>';

	   	} else {
			if (lang == 'el') {  rhtml2 = 'Δεν βρέθηκαν καλλιτέχνες';  } else { rhtml2 = 'No artists found'; }
	   	}

		return rhtml2;

}

	function displayArtist(artid){
        frames['ArtistFrame'].location.href = 'artistie.php?artid='+artid+'&lang='+lang;
	}

	function displayArtist2(){
        $('mainText').style.display = 'none';
        $('closebio').style.display = 'block';
        ArtistBio = $('art_bio');
		new Effect.BlindDown(ArtistBio);
	}


	function hideDIV(){

        $('closebio').style.display = 'none';
        ArtistBio = $('art_bio');
		new Effect.BlindUp(ArtistBio);
        setTimeout('$(\'mainText\').style.display = "block";',900);
	}


	function createNews(xmlcode){
		rootart = xmlcode.documentElement;
		
		var rhtml = '';
		
		counter = 0;
		do{
			rhtml += "<div class='newsStyle' id='news_"+counter+"'><strong><a href='javascript:void(0);' onclick='expandMenu(\""+counter+"\",\"mainnews_\",false);this.blur();'>"+rootart.childNodes[counter].childNodes[1].childNodes[0].nodeValue + "</a> - "+rootart.childNodes[counter].childNodes[2].childNodes[0].nodeValue+"</strong></div>";
			rhtml += "<div style='display:none;' id='mainnews_"+counter+"'><br/>"+rootart.childNodes[counter].childNodes[3].childNodes[0].nodeValue + "<br/><br/></div>";
			counter++;
		}while(counter < rootart.childNodes.length);
		
		
		return rhtml;
		
	}
	
	
	function isEmail(es){
		if(es.split('@').length != 2){
			valid = false;
		}else{
			if(es.split('@')[1].split('.').length < 2 || es.split('@')[1].split('.')[0] == '' || es.split('@')[1].split('.')[1] == ''){
				valid = false;
			}else{
				if(es.split('@')[0] == ''){
					valid = false;
				}else{
					valid = true;
				}
			}
		}
		
		return valid;
	}
	
	function submitVolunteerForm(){
		counter = 1;
		hasErrors = false;
		var valuesF = new Array();
		do{
			
			if(counter != 3){
				valuesF[counter] = document.getElementById('f'+counter).value;
			}else{
				valuesF[counter] = document.getElementById('f'+counter).options[document.getElementById('f'+counter).selectedIndex].value;
			}
			
			if(counter == 6){
				if(isEmail(valuesF[6]) == false){
					hasErrorsOnEmail = true;
				}else{
					hasErrorsOnEmail = false;
				}
			}
			
			if(counter != 8 && valuesF[counter] == ''){
				hasErrors = true;
			}
			counter++;
		}while(counter <= 8);
		
		if(hasErrors == true){
			if (lang == 'el') { alert('Όλα τα πεδία με έντονους τίτλους είναι απαιτούμενα'); } else { alert('All fields in bold are required.'); }
		}else{
			if(hasErrorsOnEmail == false){
				counter = 1;
				qString = '';
				do{
					qString += 'f'+counter+'='+valuesF[counter]+'&';
					counter++;
				}while(counter <= 8);
				
				advAJAX.get({
					url: "acceptData.php?"+qString,
					onInitialization:function(){
						document.getElementById('mainText').innerHTML = preloader;
					},
					onFinalization:
						function(obj){
							if(obj.responseXML.documentElement.getAttribute('status') == 1){
								alert('Your application form was sent. \r\n Soon we will contact you. Thank you!');
								executemenu("volunteers");
							}else{
								alert('There was a problem encountered. Please try again.');
								executemenu("volunteers",valuesF);
							}
						}
				});					
				
			}else{
				alert('Invalid e-mail account.');
			}
		}
	}
	
