function surveyClass(method) {
	
	/*
	*
	Just for onfocus event and onblur event in the createSurvey.php file
	*
	*/
	if(method == 'createSurvey'){

		$(document).ready(function(){
			$('#event_id').focus(function(){
				$('.survey_input1').attr('class','survey_input1_green');
			});
			$('#event_id').blur(function(){
				$('.survey_input1_green').attr('class','survey_input1');
			});
		
			$('#survey_title').focus(function(){
				$('.survey_input2').attr('class','survey_input2_green');
			});
			$('#survey_title').blur(function(){
				$('.survey_input2_green').attr('class','survey_input2');
			});
			
			$('#survey_type').focus(function(){
				$('.survey_input4').attr('class','survey_input4_green');
			});
			$('#survey_type').blur(function(){
				$('.survey_input4_green').attr('class','survey_input4');
			});
			
		
			$('#survey_description').focus(function(){
				$('.survey_input3').attr('class','survey_input3_green');
				if($('#survey_description').val() == '' || $('#survey_description').val() == 'Description Here') {
				
					$('#survey_description').attr('class','focused');
					$('#survey_description').val('');
				}
			});
			$('#survey_description').blur(function(){
				$('.survey_input3_green').attr('class','survey_input3');
				
				if($('#survey_description').val() == '') {
				
					$('#survey_description').attr('class','empty');
					$('#survey_description').val('Description Here');
				}		
			});
			
		});
	} else if(method == 'DesignSurvey') { //For surveyQuestions.php file
		
		$(document).ready(function(){
		
			$('a[rel*=facebox]').facebox({
			
			});
		});
	}
	
	var url = 'doajax.php';
	
	/*
	*
	Method to insert the Survey data and Questions into the database
	*
	*/
	this.insertRecord = function(formName) {
		
	var htmlContent = '<div class="pop_content"><div class="success_lg"></div>'+
					  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Success</div>'+
					  '<div class="facebox_success">Successfully Added</div></div>';
		
		$.post(url, 
			   $('#' + formName).serialize(), 
			   function(data){
				   if(data == true) {
					   $.facebox(htmlContent);
					   faceboxDisappear();
					   setTimeout(function(){window.location.href = 'surveyQuestions.php';},2500);
					   
					   /*if(formName == 'surveyForm') {
							this.showAllSurvey();
					   }*/
				   }
			   }
			  );
	}
	
	/*
	*
	Method to Update the Survey data and Questions into the database
	*
	*/
	this.updateRecord = function(formName) {
		
		
	
	var htmlContent = '<div class="pop_content"><div class="success_lg"></div>'+
					  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Success</div>'+
					  '<div class="facebox_success">Successfully Updated</div></div>';
		
		$.post(url, $('#' + formName).serialize(), function(data){
															
															alert('maninderharma');
																if(data == true) {
																   $.facebox(htmlContent);
																   faceboxDisappear();
																   //alert(document.getElementById('operation').value);
																   if(document.getElementById('operation') != null) {
																	   if(document.getElementById('operation').value == 'add') { 
																	   
																			setTimeout(function(){window.location.href = 'surveyQuestions.php';},2500);
																	   } else {
																			setTimeout(function(){window.location.href = 'createSurvey.php';},2500);
																	   }
																   } else {
																	   setTimeout(function(){window.location.href = 'surveyQuestions.php';},2500);
																   }
																}
															});
	}
	
	/*
	*
	Method to Clear the content //Not Working this time
	*
	*/
	this.clearContent = function(text,taId) {
		
		if(taId.value == text) {
			taId.value = '';
			taId.className='focused';
		}
	}
	
	/*
	*
	Method to show all the surveys //Not Working this time
	*
	*/
	this.showAllSurvey = function() {
		
		$.post(url , {'operation' : 'show', 'method' : 'survey'} , function(data) {
																	alert(data);		
																	});
	}
	
	/*
	*
	Method For Editing the Question in the pop up
	*
	*/
	this.showSurveyQuestion = function(id) {
		htmlContent2 = htmlContent1 + '<input type="button" value="Update" class="button button_green" onclick="checkQuestionData(\'edit\');">'+
						'<input type="hidden" name="operation" value="update" />'+
						'&nbsp;&nbsp;<input type="button" value="Close" class="button button_green" onclick="javascript: $.facebox.close();"></div></form></div>';			
		
		//$.post(url , {'operation':'show','method':'question','question_id':id} , function(data) {alert(data);});
		$.post(url , {'operation':'show','method':'question','question_id':id} , function(data) {
																								  
		htmlContent2 = htmlContent1 + '<input type="button" value="Update" class="button button_green" onclick="checkQuestionData(\'edit\');">'+
							'<input type="hidden" name="operation" value="update" /><input type="hidden" name="question_id" value="' + id + '" />'+
							'&nbsp;&nbsp;<input type="button" value="Close" class="button button_green" onclick="javascript: $.facebox.close();"></div></form></div>';			
																		
																		$.facebox(htmlContent2);
																		$('#question_type').val(stripSlashes(data.type));
																		$('#question_text').val(stripSlashes(data.text));
																		$('#question_answer').val(stripSlashes(data.answer));
																		if(data.comment_required == 'y') {
																			
																			$('#commentRequired').attr('checked', true);
																		}
																		$('#question_text').attr('class','');
																		$('#question_answer').attr('class','');
																																
																	}, 'json');
	}
	
	/*
	*
	Method For Making a question Live
	*
	*/
	this.makeLiveSurvey = function(id, tdId, totalRecords) {
		
		var htmlContent = '<div class="pop_content"><div class="success_lg"></div>'+
						  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Success</div>'+
						  '<div class="facebox_success">Success: Your question is now live!</div></div>';
		
		var flag = confirm('Are you sure you want to make this question live?');
		if(flag == true) {
			$.post(url, 
				   {'operation' : 'MakeLive' , 'method' : 'question' , 'question_id' : id}, 
					function(data) {
						if(data == true) {
						   $.facebox(htmlContent);
						   faceboxDisappear();
						   setTimeout(function(){window.location.href = 'surveyQuestions.php';},2500);
						   /*var deactivateButton = '<input type="button" class="button button_red" value="Deactivate" onclick="survey.deactivateQuestion('+ id +',' + tdId + ');" />';
						   $('#questionStatusTd_' + tdId).html(deactivateButton);
						   
						   for(var first=2; first<=totalRecords+1; first++) {
							   
							   if(first == tdId)
									continue;
							   
							   var makeLiveButton = '<input type="button" class="button button_yellow" value="Make Live" onclick="survey.makeLiveSurvey(' + id + ',' + tdId + ',' + totalRecords + ');" />';
							   $('#questionStatusTd_' + tdId).html(makeLiveButton);
							   	
						   }*/
					}
				});
		}
	}
	
	/*
	*
	Method For Deleting a survey From the Database
	*
	*/
	this.deleteSurvey = function(survey_id,id) {
		
		var htmlContent = '<div class="pop_content"><div class="success_lg"></div>'+
						  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Success</div>'+
						  '<div class="facebox_success">Successfully Deleted</div></div>';

		var htmlContent1 = '<div class="pop_content"><div class="warning_lg"></div>'+
						  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Error</div>'+
						  '<div class="warning">Problem in deletion</div></div>';

		
		var flag = confirm('do you really want to delete this survey');
		if(flag == true) {
			
			//window.location.href = 'createSurvey.php?delete=yes&survey_id=' + survey_id;
			$.post(url , 
				   {'operation' : 'delete' , 'method' : 'survey' , 'survey_id' : survey_id} , 
				   function(data) {
					   if(data == true) {
						   
							$('#survey_'+id).hide(1000);
						    $.facebox(htmlContent);
						    faceboxDisappear();
					   } else {
						   
						    $.facebox(htmlContent1);
						    faceboxDisappear();
					   }
					}
			);
		}
	}
	
	/*
	*
	Method For Deactivate a Live Question
	*
	*/
	this.deactivateQuestion =  function(id, tdId,totalRecords) {
		var htmlContent = '<div class="pop_content"><div class="success_lg"></div>'+
						  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Success</div>'+
						  '<div class="facebox_success">Successfully Deactivated</div></div>';
		
		var flag = confirm('Are you sure you want to deactivate this question?');
		if(flag == true) {
			$.post(url, 
				  {'operation' : 'DeactivateQuestion' , 'method' : 'question' , 'question_id' : id},
				  function(data) {
					  	if(data == true) {
							
						   $.facebox(htmlContent);
						   faceboxDisappear();
						   //setTimeout(function(){window.location.href = 'surveyQuestions.php';},2500);
						   var makeLiveButton = '<input type="button" class="button button_yellow" value="Make Live" onclick="survey.makeLiveSurvey(' + id + ',' + tdId + ',' + totalRecords + ');" />';
						   $('#questionStatusTd_' + tdId).html(makeLiveButton);
						}
				  });
		}
	}
	
	/*
	*
	Method For Show and Hiding the Create a new Survey Block
	*
	*/
	this.showHideCreateSurveyBlock = function() {
		if($('#createSurveyBlock').css('display') == 'none') {
		
			$('#createSurveyBlock').show(1000);
		} else {
			
			$('#createSurveyBlock').hide(1000);
		}
	}
	
	/*
	*
	Method For Validating the data of Survey
	*
	*/
	this.checkSurveyData = function(action) {
		
		$('.survey_input1_red').attr('class','survey_input1');
		$('.survey_input2_red').attr('class','survey_input2');
		$('.survey_input3_red').attr('class','survey_input3');
		$('.survey_input4_red').attr('class','survey_input4');
	
		if($('#event_id').val() == '') {
			$('.survey_input1').attr('class','survey_input1_red');
			$('#event_id').focus();
			return false;
		}
		if(isNaN($('#event_id').val())) {
			$('.survey_input1').attr('class','survey_input1_red');
			$('#event_id').focus();
			return false;
		}
		if($('#survey_title').val() == '') {
			$('.survey_input2').attr('class','survey_input2_red');
			$('#survey_title').focus();
			return false;
		}
		if($('#survey_type').val() == '') {
			$('.survey_input4').attr('class','survey_input4_red');
			$('#survey_type').focus();
			return false;
		}
		if($('#survey_description').val() == '' || $('#survey_description').val() == 'Description Here') {
			$('.survey_input3').attr('class','survey_input3_red');
			$('#survey_description').focus();
			return false;
		}
		if(action == 'add') {
			survey.insertRecord('surveyForm');
		} else {
			//survey.updateRecord('surveyForm');
			return true;
		}
	}
	
	/*
	*
	Method For onfocus event of the Create New Question popup
	*
	*/
	this.focusGreen = function(className,id) {
		$('.' + className).attr('class',className+'_green');
		if(id == 'question_text') {
			
			if($('#question_text').val() == '' || $('#question_text').val() == 'Question Here') {
			
				$('#question_text').attr('class','survey_pop_main_textareain');
				$('#question_text').val('');
			}
		} else if(id == 'question_answer') {
		
			if($('#question_answer').val() == '' || $('#question_answer').val() == 'Answer Here') {
			
				$('#question_answer').attr('class','survey_pop_main_textareain');
				$('#question_answer').val('');
			}
		}
	}

	/*
	*
	Method For onblur event of the Create New Question popup
	*
	*/
	this.blurNormal = function(className,id) {
		$('.' + className + '_green').attr('class',className);
		if(id == 'question_text') {
		
			if($('#question_text').val() == '') {
			
				$('#question_text').attr('class','empty');
				$('#question_text').val('Question Here');
			}
		} else if(id == 'question_answer') {		
		
			if($('#question_answer').val() == '') {
			
				$('#question_answer').attr('class','empty');
				$('#question_answer').val('Answer Here');
			}
		}
	}
	
	/*
	*
	Method For open the popup for Adding a new question
	*
	*/
	this.openDialog = function() {
					
		htmlContent2 = htmlContent1 + '<input type="button" value="Add Question" class="button button_green" onclick="checkQuestionData();">'+
						'<input type="hidden" name="operation" value="add" />'+
						'&nbsp;&nbsp;<input type="button" value="Close" class="button button_green" onclick="javascript: $.facebox.close();"></div></form></div>';			  
		$.facebox(htmlContent2);
	}
	
	/*
	*
	Method For deleting a question from the database
	*
	*/
	this.deleteQuestion = function(id) {
		
		var flag = confirm('do you really want to delete this question');
		if(flag == true) {
			
			window.location.href = 'surveyQuestions.php?delete=yes&question_id=' + id;		
		}
	}
	
	/*
	*
	To show all the results(Including Live question result) in the Analyzed page
	*
	*/
	this.showAllResults = function() {
	
		window.location.href = '?show=all';
	}
	
	this.clearResults = function() {
		
		var htmlContent = '<div class="pop_content"><div class="success_lg"></div>'+
						  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Success</div>'+
						  '<div class="facebox_success">Clear all the results of this survey</div></div>';

		var htmlContent1 = '<div class="pop_content"><div class="warning_lg"></div>'+
						  '<div style="font-size:18px; font-weight:bold; margin-bottom:5px;">Error</div>'+
						  '<div class="warning">Problem in clearing the result of this survey.</div></div>';
		
		var flag = confirm('Do you really want to delete all of the survey response data? You will not be able to recover this data at a later time!!');
		if(flag) {
			
			$.post(url, 
				   	{'operation' : 'delete' , 'method' : 'results'}, 
					function(data) {
						if(data == true) {
							
							$.facebox(htmlContent);
							setTimeout(function(){window.location.reload();},2500);
						} else {
							
							$.facebox(htmlContent1);
						}
					});
		}
	}
	/*
	*
	To show only the Live question result
	*
	*/
	this.showLiveResults = function() {
	
		window.location.href = '?show=live';
	}
	/*
	*
	Method to Remove the facebox dialog box
	*
	*/
	function faceboxDisappear() {

		setTimeout(function(){$(document).trigger('close.facebox');},2000);
	}
	/*
	*
	Method to Remove the slashes like stripslashes() function in PHP
	*
	*/
	function stripSlashes(str)
	{
		return str.replace(/\\/g, '');
	}

	
}
/*
*
Method to validate the Questions form in the popup dialog
*
*/
function checkQuestionData(action) {
	
	$('.survey_pop_main_input_red').attr('class','survey_pop_main_input');
	$('.survey_pop_main_textarea1_red').attr('class','survey_pop_main_textarea1');
	$('.survey_pop_main_textarea1_red').attr('class','survey_pop_main_textarea2');

	if($('#question_type').val() == '') {
		$('.survey_pop_main_input').attr('class','survey_pop_main_input_red');
		$('#question_type').focus();
		return false;
	}
	if($('#question_text').val() == '' || $('#question_text').val() == 'Question Here') {
		$('.survey_pop_main_textarea1').attr('class','survey_pop_main_textarea1_red');
		$('#question_text').focus();
		return false;
	}
	if($('#question_answer').val() == '' || $('#question_answer').val() == 'Answer Here') {
		$('.survey_pop_main_textarea2').attr('class','survey_pop_main_textarea2_red');
		$('#question_answer').focus();
		return false;
	}
	if(action == 'edit') {
		survey.updateRecord('questionForm');
	} else {
		survey.insertRecord('questionForm');
	}
}
