function GenerateRandomString()
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 5;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	
	document.getElementById('SecCode').value=randomstring;
}

function CheckEmail(strEmail)
			{
				var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!filter.test(strEmail)) return false; else return true;
			}

function CheckSecString()
{
	if (document.getElementById('SecCode').value!=document.getElementById('SecCodeMatch').value) return false;
	else return true;
}

function DisableFlashElements()
{
	try {document.getElementById('MainAnimation').style.visibility='hidden';} catch(err){};
	try {document.getElementById('Cube_1').style.visibility='hidden';} catch(err){};
	try {document.getElementById('Cube_2').style.visibility='hidden';} catch(err){};
	try {document.getElementById('Cube_3').style.visibility='hidden';} catch(err){};
	try {document.getElementById('Cube_4').style.visibility='hidden';} catch(err){};
	try {document.getElementById('Cube_5').style.visibility='hidden';} catch(err){};
	try {document.getElementById('GalleryFlash').style.visibility='hidden';} catch(err){};	
		
}

function EnableFlashElements()
{
	try {document.getElementById('MainAnimation').style.visibility='visible';} catch(err){};
	try {document.getElementById('Cube_1').style.visibility='visible';} catch(err){};
	try {document.getElementById('Cube_2').style.visibility='visible';} catch(err){};
	try {document.getElementById('Cube_3').style.visibility='visible';} catch(err){};
	try {document.getElementById('Cube_4').style.visibility='visible';} catch(err){};
	try {document.getElementById('Cube_5').style.visibility='visible';} catch(err){};
	try {document.getElementById('GalleryFlash').style.visibility='visible';} catch(err){};
}

function BrochurePopup()
{
	DisableFlashElements();
	GenerateRandomString();
	document.getElementById('BrochureRequestBopupBCG').style.display='';
	document.getElementById('BrochureRequestPopup').style.display='';	
}

function CloseBrochureRequestPopup()
{
	EnableFlashElements();
	document.getElementById('BrochureRequestBopupBCG').style.display='none';
	document.getElementById('BrochureRequestPopup').style.display='none';	
}

function SendBrochureRequest(strFromProduct)
{
	if (CheckSecString()!=true) 	
	{
		document.getElementById('BrochureRequestMessages').innerHTML='Please retype security code properly';
	}
	else
	if (document.getElementById('Phone').value=='')
	{
		document.getElementById('BrochureRequestMessages').innerHTML='Please enter phone number';
	}
	else
	if ((document.getElementById('Address').value=='') | (document.getElementById('Postcode').value==''))
	{
		document.getElementById('BrochureRequestMessages').innerHTML='Please enter address and postcode';
	}
	else if ((document.getElementById('Email').value=='') & (document.getElementById('SubscribeToEmailer').value==1))
	{
		document.getElementById('BrochureRequestMessages').innerHTML='Please enter your email address';
	}
	else if (CheckEmail(document.getElementById('Email').value)==false)
	{
		 document.getElementById('BrochureRequestMessages').innerHTML='Please type in a valid email address';
	}
	else
	{
		strBrochureRequestData=$('#BrochureRequestForm').serialize();
		
		if (strFromProduct=='Yes') strAddPath="../../";else strAddPath="";
		
		$.ajax
		({
			type: "POST",
			url:  strAddPath+"mailer_admin/add_to_requested_brochure_list.php",
			data: 'Action=AddToBrochureList&'+strBrochureRequestData,
			success: function(strMessage)
				{
					if (strMessage=='ok')
					{
						CloseBrochureRequestPopup();
						
						document.getElementById('ThankYouForRequestPopup').style.display="";
						document.getElementById('ThankYouForRequestPopupWrapper').style.display="";
					}	
					else
						alert(strMessage);	
				}
		});	
		
	}

}

function CloseBrochureRequestThankYouPopup()
{
	document.getElementById('ThankYouForRequestPopup').style.display="none";
	document.getElementById('ThankYouForRequestPopupWrapper').style.display="none";
}

function SetCheckboxValue(strNameOfCheckBox,strValue)
		{
			if (document.getElementById(strNameOfCheckBox).checked==true) document.getElementById(strNameOfCheckBox).value=strValue;
			else
			document.getElementById(strNameOfCheckBox).value="";
		}