// JavaScript Document

// Class


function ContactUs(module)
{
	this._ajaxUrl = 'ContactUsProcess.php';
	this._module = module;
	this._errcontainer = j('#errmgs_container');
	this._mgscontainer = j('#mgs_container');
	//this._imgcontainer = j('#image_container');
	this._msgBox = this._mgscontainer.prev('div').prev('div').children('.errorBox');
	
	this._timeOut = null;
	
	
	this._loading = '<img src="images/loading-thickbox.gif" alt="Loading" width="208" height="13" />';
	
	j(this._loading)
		.prependTo('body')
		.hide();
		
		
}

ContactUs.prototype.loading = function()
{
	var obj = this;
	
	/*obj.closeBox();*/
	j.blockUI({
		message: obj._loading,
		css: {
			border: 'none',
			background: 'transparent'
		},
		overlayCSS: {
			'background-color': '#282828',
			opacity: 0.7
		}
	});
}
ContactUs.prototype.closeBox = function()
{
	j.unblockUI();
}

ContactUs.prototype.isEmptyChecks=function(ele,mgs,classname)
{
			var obj = this;
			
	
			if(!j('#'+ele+'').isEmpty()) {
			//alert(j(this)+"If");
			j('#'+ele+'')
					.removeClass('testbdr')
					.after('<img src="images/checkbullet.gif" class="yesno" align="absmiddle" style="padding-left:10px;" />')
					.next().fadeOut(5000, function(){
							j(this).remove();
							
					});
			}
			else
			{
					//alert(j(this)+"Else");
					j('#'+ele+'')
						.after('<img src="images/wrong.jpeg" class="yesno" align="absmiddle" style="padding-left:10px; " />')
						.addClass('testbdr')
						.addClass('c-errors')
						
			}		
}


ContactUs.prototype.SubmitContactForm = function(frm)
{	
	var obj = this;
	var err="";
	this.loading();
	/*j('.req').each(function(i){
							// alert(i);
			if(j(this).isEmpty())
			{
				j(this).next().remove();
				j(this)
					.after('<img src="images/wrong.jpeg" class="yesno" align="absmiddle" style="padding-left:10px;" />')
					.addClass('testbdr')
					.addClass('c-errors')
					.next().fadeOut(50000, function(){
						j(this).remove();
					});
				err+="1";
			}
			
			
		});
	
			
							
					
			j('#user_email').next().remove();				
			if(j('#user_email').emailCheck()) {
					j('#user_email')
							.removeClass('testbdr')
							.after('<img src="images/checkbullet.gif" class="yesno" align="absmiddle" style="padding-left:10px;" />')
							.next().fadeOut(5000, function(){
							j(this).remove();
							});
			}
			else
			{
					
					j('#user_email')
							.after('<img src="images/wrong.jpeg" class="yesno" align="absmiddle" style="padding-left:10px;" />')
							.addClass('testbdr')
							.addClass('c-errors')
							.next().fadeOut(50000, function(){
							j(this).remove();
							});
								err+="1";
			}*/
	
	if(!err)
	{
		var data = j('#'+frm).serializeArray();
		//alert(frm);
		j.ajax({
		url: obj._ajaxUrl,
		data: data,
		type: 'POST',
		dataType: 'json',
		success: function(hdata){
			
				if(hdata.flag)
				{
					window.location.href="redirect.php";
					
					obj._mgscontainer.html(hdata.msg);
					//obj._imgcontainer.html(hdata.photo);
					obj._errcontainer.html();
				}
				else
				{
					obj._errcontainer.html(hdata.msg);	
					
				}
		},
		timeout: 60000,
		error: function(XMLHttpRequest, textStatus, errorThrown){
			obj._msgBox
				.text('Error: A critical error occured.')
				.show();
			clearTimeout(obj._timeOut);
			obj._timeOut = setTimeout(function(){
				obj._msgBox.fadeOut(500);
			}, 3000);
		}		
		});
	}
	obj.closeBox();
	
	
}



