var cMsgNoText = 'You haven\'t written any text in the message body.';
var cMsgInvalidEmail = 'The e-mail address you have provided is not valid';
var cNoReturnEmail = 'You haven\'t provided any e-mail address.';
var cSubPaymentIssue = 'Login or payment issue';
var cSubPhotoshooting = 'Photoshooting';
var cSubTechnicalProb = 'Technical issue';
var cSubPiracyReport = 'Piracy report';
var cTexPaymentIssue = 'Please specify the problem you have, preferably including your login name or the e-mail address you made your purchase with. Also the purchase date might help to identify your problem.';
var cTextPhotoshooting = 'Please specify your interest, intention of the photoshooting and your experience.\nA webpage address where your work could be seen would be appreciated too. :-)';
var cTextTechnicalProb = 'Please specify the problem you have, your operating system and web browser you use.\nTo successfully solve the issue we might need to contact you back so filling your e-mail address in the field above would be welcomed.';
var cTextPiracyReport = 'Please specify the link of the fraudulent website.';
var rEmptyString = /^\s*$/;

function subscriptionValid() {
	var l_field = document.getElementById('pcInterest');
	var l_Interest = l_field.value;
	//Interest
	if (l_Interest<0) {
	  l_field.focus();
		alert('Please select the reason of your message.');
	}
	//Message
	l_field=document.getElementById('message');
	switch (l_Interest) {
		default:
			if (predefinedText(l_field.value)) {
				if (pageTracker)
					pageTracker._trackEvent('Contact', 'Check fail', 'Predefined text');
				l_field.focus();
				alert(cMsgNoText);
				return false;
			}
	}
	//EMail
  l_field=document.getElementById('email');
	switch (l_Interest) {
		case '2': //Memberzone access
			if (!validEmail(l_field.value)) {
  			l_field.focus();
  			l_field.select();	
    		alert(cMsgInvalidEmail);
				return false;
			}						
			break;
		case '3': //Photoshooting
			if (rEmptyString.test(l_field.value)) {
				if (!confirm(cNoReturnEmail))	return false;
			}	else if(!validEmail(l_field.value)) {
  			l_field.focus();
  			l_field.select();	
    		alert(cMsgInvalidEmail);
				return false;
			}							
			break;
		default:
			if ((!rEmptyString.test(l_field.value))&&(!validEmail(l_field.value))) {
  			l_field.focus();
  			l_field.select();	
    		alert(cMsgInvalidEmail);
				return false;
			}				
	}
	//code
  if (!testSubmit(document.getElementById('code').value)) {
		if (pageTracker)
			pageTracker._trackEvent('Contact', 'Check fail', 'Wrong code: '+document.getElementById('code').value);
	  return false;
	}
	return true;		
}

function contactPageLoad() {
  showCodeImage('CodeImage');
  var l_template=urlVars.get('template');
  if (l_template=='galleriesaccess') {
		document.getElementById('pcInterest').value = 2; //memberzone access
		pcInterestChange();
  }
}

function codeImageClick() {
	var l_field = document.getElementById('code');
 	l_field.focus();
  l_field.select();
}

function pcInterestChange() {
	switch (document.getElementById('pcInterest').value) {
		case '2': //Memberzone access
			l_field = document.getElementById('subject');
			if (predefinedSubject(l_field.value)) l_field.value = cSubPaymentIssue;
			l_field = document.getElementById('message');
			if (predefinedText(l_field.value)) l_field.value = cTexPaymentIssue;
			break;
		case '3': //Photoshooting
			l_field = document.getElementById('subject')
			if (predefinedSubject(l_field.value)) l_field.value = cSubPhotoshooting;
			l_field = document.getElementById('message')
			if (predefinedText(l_field.value)) l_field.value = cTextPhotoshooting;
			break;
		case '4': //Technical issue
			l_field = document.getElementById('subject')
			if (predefinedSubject(l_field.value)) l_field.value = cSubTechnicalProb;
			l_field = document.getElementById('message')
			if (predefinedText(l_field.value)) l_field.value = cTextTechnicalProb;
			break;
		case '5':
			l_field = document.getElementById('subject')
			if (predefinedSubject(l_field.value)) l_field.value = cSubPiracyReport;
			l_field = document.getElementById('message')
			if (predefinedText(l_field.value)) l_field.value = cTextPiracyReport;
			break;
		default:
			l_field = document.getElementById('subject')
			if (predefinedSubject(l_field.value)) l_field.value = '';
			l_field = document.getElementById('message')
			if (predefinedText(l_field.value)) l_field.value = '';		
	}
}

function predefinedSubject(in_Subject) {
	if (rEmptyString.test(in_Subject)) return true;
	if (in_Subject==cSubPaymentIssue) return true;
	if (in_Subject==cSubPhotoshooting) return true;
	if (in_Subject==cSubTechnicalProb) return true;
	if (in_Subject==cSubPiracyReport) return true;
}

function predefinedText(in_Text) {
	if (rEmptyString.test(in_Text)) return true;
	in_Text = in_Text.replace(/\s/g,'');
	if (in_Text==cTexPaymentIssue.replace(/\s/g,'')) return true;
	if (in_Text==cTextPhotoshooting.replace(/\s/g,'')) return true;
	if (in_Text==cTextTechnicalProb.replace(/\s/g,'')) return true;
	if (in_Text==cTextPiracyReport.replace(/\s/g,'')) return true;	
}

