 function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function checkData( x, y ) {
	if( y.value == '' ){
		document.getElementById( x + 'Check' ).value='false';
		document.getElementById( 'designername' ).style.backgroundColor="#FFAAAA";
		msg = 'Your Designer Name cannot be blank.';
		document.getElementById( x + 'Img' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px;" alt="fail" border="0">' + msg ;
		return false;
	} else {
		document.getElementById( x ).style.backgroundColor="white";
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if( xmlHttp.responseText == 'does not exist' ){
				document.getElementById( x + 'Check' ).value='true';
				document.getElementById( x + 'Img' ).innerHTML='<img src="images/icons/ok.png" style="height:16px;width:16px; vertical-align:middle;" alt="success" border="0">';
				document.getElementById( x ).style.backgroundColor="white";
				msg = 'Congratulations, that Designer Name is unique.';
			} else if( xmlHttp.responseText == 'exists not active' ){
				document.getElementById( x + 'Check' ).value='false';
				document.getElementById( x + 'Img' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px; vertical-align:middle;" alt="success" border="0">';
				document.getElementById( x ).style.backgroundColor="white";
				msg = 'That Designer Name is inactive. If you would like to continue your registration, please click <a href="continueRegistration.php">here</a>.';
			} else if( xmlHttp.responseText == 'exists and active' ){
				document.getElementById( x + 'Check' ).value='false';
				document.getElementById( x + 'Img' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px; vertical-align:middle;" alt="success" border="0">';
				document.getElementById( x ).style.backgroundColor="white";
				msg = 'That designername name is taken, please select another.';
			} else {
				document.getElementById( x + 'Check' ).value='false';
				document.getElementById( x + 'Img' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px; vertical-align:middle;" alt="success" border="0">';
				document.getElementById( x ).style.backgroundColor="#FFAAAA";
				msg = 'ERROR IN MESSAGE';
			}
			document.getElementById( x + 'Msg' ).style.display = 'block';
			document.getElementById( x + 'Msg' ).innerHTML = msg;
		}
	}
	xmlHttp.open("GET", "dao/checkSignup.php?action=" + x + "Check&val=" + y.value , true);
	xmlHttp.send(null);
}

function createDesignerDBandFTP( dn ){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if( xmlHttp.responseText == 'success' ){
				return true;
			} else {
				return false;
				alert( xmlHttp.responseText );
			}
		}
	}
	xmlHttp.open("GET", "dao/createDesignerFunction.php?dn=" + dn + "&fn=" + document.getElementById( 'fname' ).value , true);
	xmlHttp.send(null);
}

function createdesignerfunction( ) {
	document.getElementById( 'createButton' ).value = "  Please Wait  ";
	document.getElementById( 'createButton' ).disabled = true;
	var errmsg = '';
	lettersNumbersOnly( document.getElementById( 'designername' ) );
	checkPasswords( document.getElementById( 'password' ), document.getElementById( 'password2' ) );
	setTimeout("errmsg = ''", 2000);
	if( !testNull( document.getElementById( 'fname' ) ) ) { errmsg += 'Please provide a valid First Name\n'; document.getElementById( 'fname' ).style.backgroundColor="#FFAAAA"; }
	if( !testNull( document.getElementById( 'lname' ) ) ) { errmsg += 'Please provide a valid Last Name\n'; document.getElementById( 'lname' ).style.backgroundColor="#FFAAAA"; }
	if( !checkEmail( document.getElementById( 'email' ) ) ) { errmsg += 'Please provide a valid email\n';document.getElementById( 'email' ).style.backgroundColor="#FFAAAA"; }
	if( !testNull( document.getElementById( 'password' ) ) ) { errmsg += 'Please be sure to enter your password twice in the same way to be sure that there is a match for both entries.  At this time, it does not match\n'; document.getElementById( 'password' ).style.backgroundColor="#FFAAAA"; }
	if( !testNull( document.getElementById( 'password2' ) ) ) { errmsg += 'Please be sure to enter your password twice in the same way to be sure that there is a match for both entries.  At this time, it does not match\n'; document.getElementById( 'password2' ).style.backgroundColor="#FFAAAA"; }
	if( !testNull( document.getElementById( 'passwordreminder' ) ) ) { errmsg += 'Please provide a password reminder\n'; document.getElementById( 'passwordreminder' ).style.backgroundColor="#FFAAAA"; }
	if( document.getElementById( 'designernameCheck' ).value == 'false' ) { errmsg += 'Your Designer Name has an error\n'; }
	if( document.getElementById( 'passwordsCheck' ).value == 'false' ) { errmsg += 'Your passwords are blank or do not match\n'; }
	if( document.getElementById( 'ua' ).checked == false ) { errmsg += 'You must agree to the User Agreement'; }
	if( errmsg == '' ) { 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				if( xmlHttp.responseText == 'success' ){
					// CUSTOM = DESIGNER; ITEM_NUMBER = PERIOD IN MONTHS
					document.getElementById( 'paypalCustom' ).value = document.getElementById( 'designername' ).value;
					// document.getElementById( 'paypalItem_Number' ).value = document.getElementById( 'designername' ).value;
					document.getElementById( 'paypalEmail' ).value = document.getElementById( 'email' ).value;
					document.getElementById( 'paypalFirstName' ).value = document.getElementById( 'fname' ).value;
					document.getElementById( 'paypalLastName' ).value = document.getElementById( 'lname' ).value;
					document.payPalForm.submit();
				} else {
					document.createdesigner.createbutton.value=" Continue -> ";
					document.createdesigner.createbutton.disabled = false;
					alert( xmlHttp.responseText );
				}
			}
		}
		url = "dao/createDesignerFunction.php?dn=" + document.getElementById( 'designername' ).value + 
		"&fn=" + document.getElementById( 'fname' ).value +
		"&ln=" + document.getElementById( 'lname' ).value +
		"&em=" + document.getElementById( 'email' ).value +
		"&pwd=" + document.getElementById( 'password' ).value +
		"&signupcost=" + document.getElementById( 'amount' ).value +
		"&signupmonths=" + document.getElementById( 'paypalItem_Number' ).value +
		"&pwr=" + document.getElementById( 'passwordreminder' ).value;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	} else {
		document.createdesigner.createbutton.value=" Continue -> ";
		document.createdesigner.createbutton.disabled = false;
		alert( errmsg );
	}	
}

function resetField( x ) {
	document.getElementById( x + 'Check' ).value = 'false';
	document.getElementById( x + 'Img' ).innerHTML = '<img src="images/blank.gif" height=16 width=16>';
}

function resetField2( x ) {
	document.getElementById( x + 'Check' ).value = 'false';
	document.getElementById( x + 'Msg' ).innerHTML = '';
	document.getElementById( x + 'Img' ).innerHTML = '<img src="images/blank.gif" height=16 width=16>';
}


function checkPasswords( x, y ){
	if( x.value == '' || y.value == '' ){
		document.getElementById( 'passwordsCheck' ).value = 'false';
		return false;
	} else if( x.value.length < 6 ) {
		document.getElementById( 'password' ).style.backgroundColor='#FFAAAA';
		document.getElementById( 'password2' ).style.backgroundColor='#FFAAAA';
		document.getElementById( 'pwdImg' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px;">';
		document.getElementById( 'pwdImg2' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px;"><br><font color="red">Your password must be at least 6 characters.</font>';
		document.getElementById( 'passwordsCheck' ).value = 'false';
		return false;
	} else if( x.value != y.value ){
		document.getElementById( 'password' ).style.backgroundColor='#FFAAAA';
		document.getElementById( 'password2' ).style.backgroundColor='#FFAAAA';
		document.getElementById( 'pwdImg' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px;">';
		document.getElementById( 'pwdImg2' ).innerHTML='<img src="images/icons/fail.png" style="height:16px;width:16px;"><br><font color="red">Your passwords do not match.</font>';
		document.getElementById( 'passwordsCheck' ).value = 'false';
		return false;
	} else {
		document.getElementById( 'password' ).style.backgroundColor='white';
		document.getElementById( 'password2' ).style.backgroundColor='white';
		document.getElementById( 'pwdImg' ).innerHTML = '<img src="images/icons/ok.png" style="height:16px;width:16px;">';
		document.getElementById( 'pwdImg2' ).innerHTML = '<img src="images/icons/ok.png" style="height:16px;width:16px;">';
		document.getElementById( 'passwordsCheck' ).value = 'true';
		return true;
	}
}

Ext.onReady(function(){
//	new Ext.ToolTip({
//		target: 'pswdHelp',
//		html: '6 character minimum.  Case-sensitive.',
//		showDelay: 100
//	});
//
//	new Ext.ToolTip({
//		target: 'orgNameHelp',
//		html: 'Not all characters are valid.<br>Please only use letters, numbers and underscores ( _ ).',
//		showDelay: 100
//	});

	Ext.QuickTips.init();
});

function testUNandPassword( ){
	document.createdesigner.continueregistrationbutton.value=" Please Wait ... ";
	document.createdesigner.continueregistrationbutton.disabled = true;

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			o = Ext.decode( xmlHttp.responseText );
			if( o.success == true ){
				document.getElementById( 'paypalFirstName' ).value = o.fname;
				document.getElementById( 'paypalLastName' ).value = o.lname;
				document.getElementById( 'paypalEmail' ).value = o.email;
				document.getElementById( 'amount' ).value = o.signupcost;
				document.getElementById( 'paypalItem_Number' ).value = o.signupmonths;
				//document.getElementById( 'paypalItem_Number' ).value = document.getElementById( 'designername' ).value;
				document.getElementById( 'paypalCustom' ).value = document.getElementById( 'designername' ).value;
				document.payPalForm.submit();
			} else {
				alert( "That username and password does not match an incomplete registration." );
				document.createdesigner.continueregistrationbutton.value=" Continue Registration -> ";
				document.createdesigner.continueregistrationbutton.disabled = false;
			}
		}
	}
	xmlHttp.open("GET", "dao/checkSignup.php?action=continueRegistration&dn=" + document.getElementById( 'designername' ).value + "&p=" + document.getElementById( 'password' ).value , true);
	xmlHttp.send(null);
}