// JavaScript Document

function isArtistExist(url)
{
	//var url = '/zenddemo/application/models/DrawingForm.php';
	//var url = '/zenddemo/application/controllers/DrawingController.php';
	var url = url+'/artistavailable';
	
	if ($F('artist_username') != "") {
		var artist_username = $F('artist_username');
		//var pars = 'call=artistAction&artist=' + artist;
		// notice the use of a proxy to circumvent the Same Origin Policy.
		new Ajax.Request(url, {
			method: 'post',
			parameters: {artist_username: artist_username},
			onComplete: showResponse,
			onFailure: reportError,
			onSuccess: function(transport){
				var notice = $('notice');
			}
			
		});
	}
}

function showResponse(originalRequest)
{
	//put returned XML in the textarea
	$('result').innerHTML = " ";
	var status = originalRequest.responseText;
	$('result').innerHTML = status;
	
}

function reportError(request)
{
	alert('Sorry. There was an error.');
}

function isValidLogin(formobj)
{	
	var teststring;
	var error_msg='';
	var iserror=0;
	teststring=/\S/;
	
	if(formobj.login_username && !teststring.test(formobj.login_username.value))
	{
		alert("Please Enter the User Name!");
		formobj.login_username.focus();
		return false;
	}
	
	if(!IsSpecialchr(formobj.login_username.value))
    {
        alert("Username only allow text, numbers and underscore");
        formobj.login_username.focus();
		return false;
    }
	if(formobj.login_password && !teststring.test(formobj.login_password.value))
	{
		alert("Please Enter the Password!");
		formobj.login_password.focus();
		return false;
	}
	return true;
}

function isValidForgotPwd(formobj)
{	
	var teststring;
	var error_msg='';
	var iserror=0;
	teststring=/\S/;
	
	if(formobj.forgot_username && !teststring.test(formobj.forgot_username.value))
	{
		alert("Please Enter the User Name!");
		formobj.forgot_username.focus();
		return false;
	}
	if(!IsSpecialchr(formobj.forgot_username.value))
    {
        alert("Username only allow text, numbers and underscore");
		formobj.forgot_username.focus();
		return false;
    }
	if(formobj.forgot_email && !teststring.test(formobj.forgot_email.value))
	{
		alert("Please Enter the Email!");
		formobj.forgot_email.focus();
		return false;
	}
	return true;
}


function isValid(formobj)
{	
	var teststring;
	var error_msg='';
	var iserror=0;
	teststring=/\S/;
	
	if(formobj.artist_username && !teststring.test(formobj.artist_username.value))
	{
		alert("Please Enter the Artist User Name!");
		formobj.artist_username.focus();
		return false;
	}
	if(!IsSpecialchr(formobj.artist_username.value))
    {
        alert("Username only allow text, numbers and underscore");
		formobj.artist_username.focus();
		return false;
    }
	if(formobj.password && !teststring.test(formobj.password.value))
	{
		alert("Please Enter the Password!");
		formobj.password.focus();
		return false;
	}
	if(formobj.repassword && !teststring.test(formobj.repassword.value))
	{
		alert("Please Enter the Retype Password!");
		formobj.repassword.focus();
		return false;
	}
	if(formobj.repassword.value !=  formobj.password.value)
	{
		alert("Password and Retype Password should be same!");
		formobj.password.focus();
		return false;
	}
	if(formobj.artist_firstname && !teststring.test(formobj.artist_firstname.value))
	{
		alert("Please Enter the Artist First Name!");
		formobj.artist_firstname.focus();
		return false;
	}
	if(formobj.artist_lastname && !teststring.test(formobj.artist_lastname.value))
	{
		alert("Please Enter the Artist Last Name!");
		formobj.artist_lastname.focus();
		return false;
	}
	if(formobj.artist_email && !teststring.test(formobj.artist_email.value))
	{
		alert("Please Enter the Email!");
		formobj.artist_email.focus();
		return false;
	}
	
	if(!document.getElementById('agreement').checked)
	{
		alert("Please Read the guidelines and check the agreement box!");
		formobj.agreement.focus();
		return false;
	}	
	
	/*if(formobj.captcha_text && !teststring.test(formobj.captcha_text.value))
	{
		alert("Please enter captcha text!");
		formobj.captcha_text.focus();
		return false;
	}*/	
	
	return true;
}

function IsSpecialchr(obj)
{
    var ab = /[^a-zA-Z_0-9\s*+-]$/i;
    
    if (ab.test(obj))
        return false;        
    else 
        return true;
    
}
