// JavaScript Document
/*
function buySubmit(){

	

	buyname = $('namse').value;
	alert('All fields are compulsory, please enter your Name.');
	buyemailAddress = $('emailAddress').value;
buycontactno= $('contactno').value;
buytickettype= $('tickettype').value;
buyticketamount= $('ticketamount').value;
buyshuttlebus= $('shuttlebus').value;
buypplboarding= $('pplboarding').value;
	
	$('oc_voteStatus').style.display = 'block';
	$('oc_voteStatus').innerHTML = '<img src="http://www.cacimpresario.com/images/loading.gif"> &nbsp;Casting your vote...';
	$('oc_voteHolder').style.display = 'none';
	
	new Ajax.Updater('oc_voteStatus', '../Ticket-Booking/index.php', {
	  parameters: { name:buyname,emailAddress:buyemailAddress,contactno:buycontactno,tickettype:buytickettype,ticketamount:buyticketamount,shuttlebus:buyshuttlebus,pplboarding:buypplboarding,buy:true,ajaxReqt:'impresario' },
	  evalScripts: true
	});	
}
*/
function OCVoteSubmit(){
	if($('voteName').value == ''){
		alert('All fields are compulsory, please enter your Name.');
		return false;
	}
	if($('voteEmail').value != $('voteEmail2').value){
		alert('You seems to have entered 2 different email address, please try again.');
		return false;
	}
	if(!(echeck($('voteEmail').value))){
		alert('Please enter a valid email address, and try again.');
		return false;				  
	}
	
	voteEmail = $('voteEmail').value;
	voteName = $('voteName').value;
	/*for first select
	*/
	if(undefined===window.regRef){
alert('Please choose a song from the list.');
return false;
}
	
	for(OCi=0; OCi!=$('voteSong').options.length; OCi++){
		
	
		if(regRef == undefined){
			alert('Please choose a song from the list.');
			return false;
		}
		if($('voteSong').options[OCi].value == regRef){
			
			if($('voteSong').options[OCi].selected == true){
				
				if($('voteSong').options[OCi].value == 'blank'){
				alert('Please choose a song from the list.');
				return false;
				}
				else{
				voteSong = 	$('voteSong').options[OCi].value;
				}
			}
		}
	}
	

	
	$('oc_voteStatus').style.display = 'block';
	$('oc_voteStatus').innerHTML = '<img src="http://www.cacimpresario.com/images/loading.gif"> &nbsp;Casting your vote...';
	$('oc_voteHolder').style.display = 'none';
	
	new Ajax.Updater('oc_voteStatus', '../Voting/index.php', {
	  parameters: { emailAddress:voteEmail,name:voteName,song:voteSong,castVote:true,ajaxReqt:'impresario' },
	  evalScripts: true
	});	
}

function OpenVoteSubmit(){
	if($('voteName').value == ''){
		alert('All fields are compulsory, please enter your Name.');
		return false;
	}
	if($('voteEmail').value != $('voteEmail2').value){
		alert('You seems to have entered 2 different email address, please try again.');
		return false;
	}
	if(!(echeck($('voteEmail').value))){
		alert('Please enter a valid email address, and try again.');
		return false;				  
	}
	
	voteEmail = $('voteEmail').value;
	voteName = $('voteName').value;
	/*for first select
	*/
	if(undefined===window.regRef){
alert('Please choose a video from the list.');
return false;
}
	
	for(OCi=0; OCi!=$('voteSong').options.length; OCi++){
		
	
		if(regRef == undefined){
			alert('Please choose a video from the list.');
			return false;
		}
		if($('voteSong').options[OCi].value == regRef){
			
			if($('voteSong').options[OCi].selected == true){
				
				if($('voteSong').options[OCi].value == 'blank'){
				alert('Please choose a video from the list.');
				return false;
				}
				else{
				voteSong = 	$('voteSong').options[OCi].value;
				}
			}
		}
	}
	

	
	$('open_voteStatus').style.display = 'block';
	$('open_voteStatus').innerHTML = '<img src="http://www.cacimpresario.com/images/loading.gif"> &nbsp;Casting your vote...';
	$('open_voteHolder').style.display = 'none';
	
	new Ajax.Updater('open_voteStatus', '../Open-Voting/index.php', {
	  parameters: { emailAddress:voteEmail,name:voteName,song:voteSong,castVote:true,ajaxReqt:'impresario' },
	  evalScripts: true
	});	
}

function changeOCVote(regRef, voteName, voteEmail){
	/*
	$('oc_voteStatus').style.display = 'none';
	$('oc_voteHolder').style.display = 'block';
	is important if you don't want to wonder how come the ajax did not get submitted...
	*/
	$('oc_voteStatus').style.display = 'none';
	$('oc_voteHolder').style.display = 'block';
	$('oc_voteHolder').innerHTML = '<img src="http://www.cacimpresario.com/images/loading.gif"> &nbsp;Updating your vote...';
	
	new Ajax.Updater('oc_voteHolder', '../Voting/index.php', {
	  parameters: { emailAddress:voteEmail,name:voteName,song:regRef,changeVote:true,castVote:true,ajaxReqt:'impresario' },
	  evalScripts: true
	});
}
function changeOpenVote(regRef, voteName, voteEmail){
	/*
	$('oc_voteStatus').style.display = 'none';
	$('oc_voteHolder').style.display = 'block';
	is important if you don't want to wonder how come the ajax did not get submitted...
	*/
	$('open_voteStatus').style.display = 'none';
	$('open_voteHolder').style.display = 'block';
	$('open_voteHolder').innerHTML = '<img src="http://www.cacimpresario.com/images/loading.gif"> &nbsp;Updating your vote...';
	
	new Ajax.Updater('open_voteHolder', '../Open-Voting/index.php', {
	  parameters: { emailAddress:voteEmail,name:voteName,song:regRef,changeVote:true,castVote:true,ajaxReqt:'impresario' },
	  evalScripts: true
	});
}
function createOCVoteForm(){
	$('oc_voteStatus').style.display = 'none';
	$('oc_voteHolder').style.display = 'block';
	$('oc_voteHolder').innerHTML = '<img src="http://www.cacimpresario.com/images/loading.gif"> &nbsp;Loading...';
	
	new Ajax.Updater('oc_voteHolder', '../Voting/index.php', {
	  parameters: { createForm:true,ajaxReqt:'impresario' },
	  evalScripts: true
	});	
}
function createOpenVoteForm(){
	$('open_voteStatus').style.display = 'none';
	$('open_voteHolder').style.display = 'block';
	$('open_voteHolder').innerHTML = '<img src="http://www.cacimpresario.com/images/loading.gif"> &nbsp;Loading...';
	
	new Ajax.Updater('open_voteHolder', '../Open-Voting/index.php', {
	  parameters: { createForm:true,ajaxReqt:'impresario' },
	  evalScripts: true
	});	
}
function setOCSelected(regRef){
	window.location = '#regRef='+regRef;
	getHashSelectedOC();	
}
function selectedOCVote(regRef){
	setOCSelected(regRef);
	Effect.ScrollTo('oc_voteHolder', { queue: 'front' });
	new Effect.Highlight('oc_voteHolder', { queue: 'end' });
}
function getHashSelectedOC(){
	jHash = window.location.hash;
	getRef = jHash.split('regRef=');
	if(getRef.length == 1){
		return false;	
	}
	
	regRef = getRef[1];
	if($('voteSong')){
		for(OCi=0; OCi!=$('voteSong').options.length; OCi++){
			if($('voteSong').options[OCi].value == regRef){
				$('voteSong').options[OCi].selected = true;
			}
		}
	}
}



function toogleQnA(question){
	if(document.getElementById('QnA'+question).style.display == 'none'){
		document.getElementById('QnA'+question).style.display = 'block';
	}else{
		document.getElementById('QnA'+question).style.display = 'none';	
	}
}


function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}