
qBlogModuleForm = function() {
	this.responseFormCont = YAHOO.util.Dom.get('response_wrap');
	this.responseForm = YAHOO.util.Dom.get('response_form');
	this.responseText = YAHOO.util.Dom.get('module_response');
	this.postBtn = YAHOO.util.Dom.get('btn_moment_update');
	this.addPhotoBtn = YAHOO.util.Dom.get('add_a_photo');
	
	this.promptText = YAHOO.util.Dom.get('prompt');
	this.promptText.innerHTML = parent.getQBPromptText();

	//get user logged in status
	this.userId = parent.document.getElementById('loggedInUserId').value;
	this.userStatus = parent.document.getElementById('loggedInUserStatus').value;
	
	//get position of widget for login and blocked user popups
	this.containerMod = parent.document.getElementById('qblog_form_iframe');
	var modXPos = YAHOO.util.Dom.getX(this.containerMod);
	var modYPos = YAHOO.util.Dom.getY(this.containerMod);
	
	if(this.userId < 0) {
		//show login popup
		new parent.LoginBoxTrigger(this.responseText,(modXPos-25),modYPos);
		new parent.LoginBoxTrigger(this.postBtn,(modXPos-225),(modYPos-100));
		new parent.LoginBoxTrigger(this.addPhotoBtn,(modXPos-152),(modYPos-100));
	} else if (this.userStatus == 'B' || this.userStatus == 'S2' || this.userStatus == 'S3') {
		//show blocked user popup
		new parent.BlockedUserTrigger(this.responseText,(modXPos-85),(modYPos-100));
		new parent.BlockedUserTrigger(this.postBtn,(modXPos-280),(modYPos-150));
		new parent.BlockedUserTrigger(this.addPhotoBtn,(modXPos-220),(modYPos-153));
	} else {
		YAHOO.util.Event.addListener(this.postBtn, 'click', this.qbValidateForm);
		YAHOO.util.Event.addListener(this.addPhotoBtn, 'click', parent.qbPhotoButtonListener);
		YAHOO.util.Event.addListener(this.responseText, 'click', parent.qbResponseTextListener);
	}
	
	qbResizeIframe();
}
qBlogModuleForm.prototype.qbRemoveResponseTextListener = function() {
	YAHOO.util.Event.removeListener(this.responseText);
}

qBlogModuleForm.prototype.qbShowPhotoUpload = function(){
	YAHOO.util.Dom.get('module_add_photo').style.display = "block";
	qbResizeIframe();
}

qBlogModuleForm.prototype.qbValidateForm = function(){
	//form fields
	this.responseForm = YAHOO.util.Dom.get('response_form');
	this.responseText = YAHOO.util.Dom.get('module_response');
	this.filePhoto = YAHOO.util.Dom.get('file_photo');
	this.certifyCheck = YAHOO.util.Dom.get('certify_check');

	//error messages
	this.responseTextError = YAHOO.util.Dom.get('responseTextError');
	this.imageUploadError = YAHOO.util.Dom.get('imageUploadError');
	this.imageFormatError = YAHOO.util.Dom.get('imageFormatError');
	this.checkRequiredError = YAHOO.util.Dom.get('checkRequiredError');
	
	this.errors = YAHOO.util.Dom.getElementsByClassName('error');
	for(var i=0; i < this.errors.length; i++) {this.errors[i].style.display = "none";}
	
	var isValid = true;
	
	//Make sure text is entered
		if((!this.responseText.value.replace(/\s/g, '').length > 0) || (this.responseText.value == "Enter your answer")) {
			this.responseTextError.style.display = "block";
			isValid = false;
		}

	//Make sure certification is checked and file format is correct if photo is uploaded
	if(this.filePhoto.value.replace(/\s/g, '').length > 0) {
		if (!this.filePhoto.value.match(/(jpg|jpeg|png|gif)$/i)) {
			this.imageFormatError.style.display = "block";
			isValid = false;
		}
		if(!this.certifyCheck.checked) {
			this.checkRequiredError.style.display = "block";
			isValid = false;
		}
	}

	if(isValid){
		parent.qbSubmitForm(this.responseForm);
	}
	
	qbResizeIframe();
}

function qbResizeIframe(){
	var frameHeight = YAHOO.util.Dom.getY('endEl');
	parent.document.getElementById('qblog_form_iframe').height = frameHeight;
}