

Event.observe(window, 'load', function() 
{
	if ($('register-form'))
	{
		var v = new Validation('register-form',{stopOnFirst:false});	
		Validation.addAllThese([
			['validate-password', 'The password should have minimal 6 characters and cannot be the same as your username', {
				minLength : 7,
				notOneOf : ['password','PASSWORD','1234567','0123456'],
				notEqualToField : 'username'
			}],
			['validate-password-confirm', 'Your confirmation password does not match your first password, please try again.', {
				equalToField : 'confirm_password'
			}],
			['validate-unique-username', 'Choose a different username.', {
				notEqualToField : 'username_exists'
			}]														
		]);
		
		
				
	}
	if ($('login-form'))
	{
		
		var v = new Validation('login-form',{stopOnFirst:false});	
	}
	if ($('profile-form'))
	{
		
		var v = new Validation('profile-form',{stopOnFirst:false});	
	}
	if ($('user-change-password-form'))
	{
		
		var v = new Validation('user-change-password-form',{stopOnFirst:false});
		Validation.addAllThese([
			['validate-password', 'Your password must be more than 6 characters and not be password or the same as your name', {
				minLength : 7,
				notOneOf : ['password','PASSWORD','1234567','0123456'],
				notEqualToField : 'username'
			}],
			['validate-password-confirm', 'Your confirmation password does not match your first password, please try again.', {
				equalToField : 'confirm_new_password'
			}]														
		]);
			
	}
	if ($('password-retrieval-form'))
	{
		var v = new Validation('password-retrieval-form',{stopOnFirst:false});		
	}
	if ($('reset-token-form'))
	{
		var v = new Validation('reset-token-form',{stopOnFirst:false});	
		Validation.addAllThese([
			['validate-password', 'Your password must be more than 6 characters and not be password or the same as your name', {
				minLength : 6,
				notOneOf : ['password','PASSWORD','1234567','0123456']
			}],
			['validate-password-confirm', 'Your confirmation password does not match your first password, please try again.', {
				equalToField : 'confirm_password'
			}]														
		]);
				
	}	
	if ($('payment_form'))
	{
		var v = new Validation('payment_form',{stopOnFirst:false});		
	}			
});	

function checkAvailability(){
	new Ajax.Request(
			'is_available.php', 
			{
				method: 'get', 
				parameters: 'username='+$('username').value, 
				onComplete: showResponse
			});

    //eval(new Ajax.Updater('advice-validate-unique-username', 'is_available.php', {method: 'get', parameters:'username='+$('username').value}));
}

function checkCaptcha(){
	//alert($('recaptcha_response_field').value);
	new Ajax.Request(
			'check_captcha.php', 
			{
				method: 'post', 
				parameters: 'recaptcha_challenge_field='+$('recaptcha_challenge_field').value+'&recaptcha_response_field='+$('recaptcha_response_field').value, 
				onComplete: errorCaptcha
			});

    //eval(new Ajax.Updater('advice-validate-unique-username', 'is_available.php', {method: 'get', parameters:'username='+$('username').value}));
}

function errorCaptcha(originalRequest)
{
	//$('advice-validate-captcha').innerHTML = originalRequest.responseText;
	//alert(originalRequest.responseText);
	if (originalRequest.responseText == 'Invalid')
	{
		$('validate_captcha').value = 'Invalid';
		$('validate_captcha2').value = 'Invalid';
	}	
	else
	{
		$('validate_captcha').value = 'Valid';
		$('validate_captcha2').value = '';		
	}
}

function showResponse(originalRequest)
{
	$('advice-validate-unique-username').innerHTML = originalRequest.responseText;
	if (originalRequest.responseText == 'This username is available.')
	{
		$('advice-validate-unique-username').style.color = "green";
		$('username_exists').value = '';
	}
	else
	{
		$('advice-validate-unique-username').style.color = "red";		
		$('username_exists').value = $('username').value;
	}
}

function deleteFile(fileURL)
{
	/*new Ajax.Request(
			'process.php?loc=filedelete&page='+page, 
			{
				method: 'post', 
				parameters: 'fileid='+fileid,
				onComplete: refreshpage
			});	
	*/
	window.location=fileURL;
}

function deleteFile(fileURL)
{
	/*new Ajax.Request(
			'process.php?loc=filedelete&page='+page, 
			{
				method: 'post', 
				parameters: 'fileid='+fileid,
				onComplete: refreshpage
			});	
	*/
	window.location=fileURL;
}

function refreshpage()
{
	window.location.reload();
}

var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 600,
      height: 500,
      name:"_blank",
      location:"no",
      menubar:"no",
      toolbar:"no",
      status:"yes",
      scrollbars:"yes",
      resizable:"yes",
      left:"",
      top:"",
      normal:false
    }
    Object.extend(this.options, options || {});

    if (this.options.normal){
        this.options.menubar = "yes";
        this.options.status = "yes";
        this.options.toolbar = "yes";
        this.options.location = "yes";
    }

    this.options.width = this.options.width < screen.availWidth?this.options.width:screen.availWidth;
    this.options.height=this.options.height < screen.availHeight?this.options.height:screen.availHeight;
    var openoptions = 'width='+this.options.width+',height='+this.options.height+',location='+this.options.location+',menubar='+this.options.menubar+',toolbar='+this.options.toolbar+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',status='+this.options.status
    if (this.options.top!="")openoptions+=",top="+this.options.top;
    if (this.options.left!="")openoptions+=",left="+this.options.left;
    window.open(this.options.url, this.options.name,openoptions );
    return false;
  }
}

function showNewAccount(){
	$('new_account').style.display = '';
	if ($('existing_account')) $('existing_account').style.display = 'none';
	$('user_registration').value = "1";
}

function showExistingAccount(){
	$('existing_account').style.display = '';
	if ($('new_account')) $('new_account').style.display = 'none';
	$('user_registration').value = "2";	
}

function showEditDescription(file_id){
     var url = './edit_description.php';
     var params = 'id='+file_id;
     var target = 'form_overlay';
     var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: params});
}


