
/**
 * all function fnAjaxInsertUsers
 * Created By: Tanvi
 * Created On: 11 May 2010
 * Last Modified By:
 * Last modified On:
 * Purpose : to getCannedResponse
 */
//---------------------------------------------------------------------------------------------------- 

function fnAjaxInsertvideo()
{
	//alert('test');
	//alert(jQuery("#gid").val());
		var strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
		var strSiteUrl = jQuery("#hdnSiteUrl").val();
		var strNewRedirectUrl = jQuery("#hdnNewRedirectUrl").val();
		jQuery('#sp_loading_icon').show();
		var strURL = strAjaxURL + "video.php";
		var strPostData = "gid="+jQuery("#gid").val()+"&fileuploadname="+jQuery("#fileuploadname").val();
		//alert(strPostData);
		// For Loading
		/*jQuery(document).ready(function() {     
         jQuery.blockUI({ 
            message: $('#loader')
        }); 
		}); */
		
		//-------------	
		jQuery.ajax({
		  type: "POST",				
		  data: strPostData,
		  url: strURL,
		  cache: false,
		  success: function(response){
			  alert(response);
			  
			  }
		});
}

function fnAjaxInsertUsers(txtemail,txtusername,txtpassword,txtuser_terms_of_use,strsecurity_code)
{
	
		var strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
		var strSiteUrl = jQuery("#hdnSiteUrl").val();
		var strNewRedirectUrl = jQuery("#hdnNewRedirectUrl").val();
		jQuery('#sp_loading_icon').show();
		var strURL = strAjaxURL + "add_users.php";
		var strPostData = "txtemail="+txtemail+"&txtusername="+txtusername+"&txtpassword="+txtpassword+"&txtuser_terms_of_use="+txtuser_terms_of_use+"&strsecurity_code="+strsecurity_code;
		//alert(strPostData);
		// For Loading
		/*jQuery(document).ready(function() {     
         jQuery.blockUI({ 
            message: $('#loader')
        }); 
		}); */
		
		//-------------	
		jQuery.ajax({
		  type: "POST",				
		  data: strPostData,
		  url: strURL,
		  cache: false,
		  success: function(response){
			  //alert(response);
			arrResponse = response.split("###");
			//alert(arrResponse[1]+'sdf');
		        if(arrResponse[1] == "1") {
					
				jQuery("#success_sp").html(arrResponse[0]);
				jQuery("#error").html('');
				jQuery("#txtemail").val('');jQuery("#txtusername").val('');jQuery("#txtpassword").val('');jQuery("#security_code").val('');$('input:checkbox').removeAttr('checked');
				jQuery('#reg-register').hide();
				jQuery('#sp_loading_icon').hide();
				return false;
				/*location.href=strNewRedirectUrl;
				setTimeout($.unblockUI, 10);*/
				}
				else
				{
					//alert('failure'+response);
					fnRefreshCaptcha();
					jQuery("#error").html(arrResponse[0]);
					jQuery("#success_sp").html('');
					jQuery('#sp_loading_icon').hide();
					return false;
				}
		  }
		});
}

/**
 * all function fnAjaxSelectUsers
 * Created By: Tanvi
 * Created On: 11 May 2010
 * Last Modified By:
 * Last modified On:
 * Purpose : to getCannedResponse
 */
//---------------------------------------------------------------------------------------------------- 
function fnAjaxSelectUsers(txtusername,txtpassword,txtrememberme)
{
	
		strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
		strSiteUrl = jQuery("#hdnSiteUrl").val();
		strNewRedirectUrl = jQuery("#hdnNewRedirectUrl").val();
		jQuery('#signin_loading_icon').show();
		strURL = strAjaxURL + "select_users.php";
		strPostData = "txtrememberme="+txtrememberme+"&txtusername="+txtusername+"&txtpassword="+txtpassword;
		
		// For Loading
		/*jQuery(document).ready(function() {     
         jQuery.blockUI({ 
            message: $('#loader')
        }); 
		}); */
		
		//-------------	
		jQuery.ajax({
		  type: "POST",				
		  data: strPostData,
		  url: strURL,
		  cache: false,
		  success: function(response){	
		  
		        if(response == 1) {
				
				location.href = strNewRedirectUrl;
				setTimeout($.unblockUI, 10);
				}
				else
				{
					jQuery("#error_signin").html(response);
					jQuery('#signin_loading_icon').hide();
					return false;
			
				}
		  }
		});
}

/**
 * all function fnAjaxSelectUsers
 * Created By: Tanvi
 * Created On: 11 May 2010
 * Last Modified By:
 * Last modified On:
 * Purpose : to getCannedResponse
 */
//---------------------------------------------------------------------------------------------------- 
function fnAjaxForgotPass(txtemail)
{
	//alert('sdf');
		var strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
		var strMessgaeForgotPass = jQuery("#hdnMsgForgotPass").val();
		var strSiteUrl = jQuery("#hdnSiteUrl").val();
		var strNewRedirectUrl = jQuery("#hdnNewRedirectUrl").val();
		jQuery('#fp_loading_icon').show();
		strURL = strAjaxURL + "forgotpass.php";
		strPostData = "txtemail="+txtemail;
		//alert(strPostData);
		// For Loading
		/*jQuery(document).ready(function() {     
         jQuery.blockUI({ 
            message: $('#loader')
        }); 
		}); */
		//alert(strPostData);
		//-------------	
		jQuery.ajax({
		  type: "POST",				
		  data: strPostData,
		  url: strURL,
		  cache: false,
		  success: function(response){	
		  
		        if(response== 1) {
				jQuery("#success_fp").html(strMessgaeForgotPass);
				jQuery("#error_fp").html('');
				jQuery("#txtemail_in").val('');
				jQuery('#fp_loading_icon').hide();
				return false;
				//setTimeout($.unblockUI, 10);
				}
				else
				{
					jQuery("#error_fp").html(response);
					jQuery("#success_fp").html('');
					jQuery('#fp_loading_icon').hide();
					return false;
				}
		  }
		});
}
/**
 * Function Name: fnPostSuggestion
 * Created By: Amit Sankkhala
 * Created On: 14th May 2010
 * Last Modified By:
 * Last modified On:
 * Purpose : Post the suggestion for the approval.
 */
//---------------------------------------------------------------------------------------------------- 
function fnPostSuggestion()
{		
	if(jQuery("#taSuggestion").val() == '')
	{
		alert("Please Enter Your Suggestion");
		jQuery("#taSuggestion").focus();
		return false;
	}
	else
	{
		var val = jQuery("#taSuggestion").val();
		var type = "Request ";
		var ret = fnCheckHack(val,type);
		if(ret==false)
		{
			//location.href='index.php' ;	
			jQuery("#taSuggestion").val('');
		}
		else
		{
			jQuery('#suggestion_loading_icon').show();
			strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
			strURL = strAjaxURL + "post_suggestion.php";
			strSuggestion = jQuery("#taSuggestion").val();
			parameters = 'your_suggestion='+encodeURIComponent(strSuggestion);		
			jQuery.ajax({
	  			type: "POST",				
				data: parameters,
			  	url: strURL,
			  	cache: false,
			 	success: function(response){	
	  			jQuery("#taSuggestion").val('');
	  			jQuery('#suggestion_loading_icon').hide();
	  			alert(response);		
	  			}
			});
		}
	}
	
}
//smartB
function fnCheckHack(val,type)
	{
		var regExp = /^[A-Za-z0-9 ^$:;.,\\&\(\)='"|%!?*\/@\-+\{\}\[\]]+$/;
		//alert('tffgfg'+val+'hgg');
		
		if(regExp.test(val))
		{
			if((val.search(/\<a href/)!=-1) || (val.search(/script/)!=-1) || (val.search(/java-script/)!=-1) || (val.search(/alert\(/)!=-1))
			{
				alert(type + "Gig Name Contain Some Malicious Code!"); 
				return false;
			}
			else 
			{
	  			//alert("VALID SSN");
				return true;		
	 		}
		}
		else if(val=='')
		{
			return true;	
		}
		else
		{
			alert(type + "Gig Name Contain Some Malicious Code!");
			return false;			
		}	
	}
	//smartB
/**
 * Function Name: fnUpdateStatus
 * Created By: Amit Sankkhala
 * Created On: 14th May 2010
 * Last Modified By:
 * Last modified On:
 * Purpose : Post the suggestion for the approval.
 */
//---------------------------------------------------------------------------------------------------- 
function fnUpdateStatus(like,likeid,gId, cid, uId,imageurl, divi)
{
		var strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
		var strSiteUrl = jQuery("#hdnSiteUrl").val();
		var strNewRedirectUrl = jQuery("#hdnNewRedirectUrl").val();
		jQuery('#fp_loading_icon').show();
		strURL = strAjaxURL + "change_favourite.php";
		strPostData = "like="+like+"&likeid="+likeid+"&gId="+gId+"&cid="+cid+"&uId="+uId+"&imageurl="+imageurl;
		jQuery.ajax({
		  type: "POST",				
		  data: strPostData,
		  url: strURL,
		  cache: false,
		  success: function(response)
		  {	 		
		  		jQuery('#likes_'+gId).html(response);
				jQuery('#div'+divi).remove();
				if(like=='Like' && divi!='') {
				jQuery('#div'+divi).remove(); }
				/*
				jQuery("#orgResult").hide();
				jQuery("#ajaxResult").show();
				jQuery("#ajaxResult").html(response);*/								
		  }
		});
}
/**************** Facebook Integration *************************/
/**
 * Function Name: facebook_onlogin
 * Created By: Amit Sankkhala
 * Created On: 20th May - 2010
 * Last Modified By:
 * Last modified On:
 * Purpose : Check Facebook Session. If logged in the facebook and not logged in at 5site, then check whether facebook account associated with 5site account. If account is related, the autologin in the 5site else ask to choose 5site username along with terms of service checkbox.
 */
//---------------------------------------------------------------------------------------------------- 
function facebook_onlogin()
{
	var strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
	var strURL = strAjaxURL + 'facebook.php';
	var strSiteUrl = jQuery("#hdnSiteUrl").val();
	intActiveFacebookId = FB.Facebook.apiClient.get_session().uid;
	strPostData = 'facebook_id='+intActiveFacebookId;
	jQuery.ajax({
		  type: "POST",	
		  data: strPostData,
		  url: strURL,
		  cache: false,
		  success: function(response)
		  {	 		
			  if(response.search(/associate/i) != -1)
			  {				  
				  location.href = strSiteUrl + 'connect5site.php?facebookid='+intActiveFacebookId;
			  }
			  else
			  {
				  location.href = strSiteUrl;
			  }
		  }
		});
}

/**
 * all function fnRefreshCaptcha
 * Created By: Tanvi
 * Created On: 28 June 2010
 * Last Modified By:
 * Last modified On:
 * Purpose : to getCannedResponse
 */
//---------------------------------------------------------------------------------------------------- 
function fnRefreshCaptcha()
{
	
		strAjaxURL = jQuery("#hdnSiteAjaxUrl").val();
		strIncludeURL = jQuery("#hdnSiteIncludeUrl").val();
		strSiteUrl = jQuery("#hdnSiteUrl").val();
		strNewRedirectUrl = jQuery("#hdnNewRedirectUrl").val();
		jQuery('#refresh_image').hide();
		jQuery('#sp_loading_icon_refresh').show();
		//strURL = strAjaxURL + "refresh_captcha.php";
		strURL = strIncludeURL + "captcha/CaptchaSecurityImages.php";
		strPostData = "width=100&height=40&characters=5&"+Math.random();
		
		// For Loading
		/*jQuery(document).ready(function() {     
         jQuery.blockUI({ 
            message: $('#loader')
        }); 
		}); */
		
		//-------------	
		jQuery.ajax({
		  type: "POST",				
		  data: strPostData,
		  url: strURL,
		  cache: false,
		  success: function(response){	
		 // alert(response);
		   //Set the content of the DIV element with the response text
		  // document.getElementById('result').innerHTML = receiveReq.responseText;
		   //Get a reference to CAPTCHA image
		   jQuery('#refresh_image').show();
		  var img = jQuery("#refresh_image"); 
		   //Change the image
		  // img.src = '';
		  img.html('<img src="'+strIncludeURL + 'captcha/CaptchaSecurityImages.php?width=100&height=40&characters=5&'+Math.random()+'" alt="captcha" id="imgCaptcha" />');
		  
		 jQuery('#sp_loading_icon_refresh').hide();
		 jQuery("#security_code").val('');
		 //img.src = response;
		  }
		});
}
