/*
 * This method will do the ajax call to /registration/form and that request will return response as the registration form
 * 
 * Parameter: string the invite_id
 * 
 * Return :null
 */


function validInvite(str_invite,str_loading_msg){
	str_loading_msg = typeof(str_loading_msg) != 'undefined' ? str_loading_msg : "Loading.. Please Wait!";

	//crating the query string
	str_request="i="+str_invite;
	str_request=str_request+"&cart_id= "+ $('#cart_id').val();
	
	$.modal.close();
	$('#modalBox').html(	'<div class="loader" id="loader" >'
												+'<div class="loaderanim"></div>'
												+'<div class="loadermid"> '
												+'<div class="titletextloading">'+str_loading_msg+'</div>'
												+'</div>'												
												+'<div class="loaderright"></div>'
												+'</div>'
									);
	$('#loader').modal({close: false ,position: ["10%","40%"]}) ;
	//ajax call
	$.ajax({
   		type: "GET",
	    url:base_url+"/cart/list-items",
	    data: str_request,
    	success: function(str_msg){
			$.modal.close();
			$('#modalBox').html(str_msg);
			obj_modal=$('#modalBox').modal({close: false , position: ["5%","15%"]});
	   }
   });	   
}


function displayCartDetails(str_invite,str_loading_msg){
	str_loading_msg = typeof(str_loading_msg) != 'undefined' ? str_loading_msg : "Loading.. Please Wait!";


	//crating the query string
	str_request="i="+str_invite;
	str_request=str_request+"&cart_id= "+ $('#cart_id').val();	
	$.modal.close();
	$('#modalBox').html(	'<div class="loader" id="loader" >'
												+'<div class="loaderanim"></div>'
												+'<div class="loadermid"> '
												+'<div class="titletextloading">'+str_loading_msg+'</div>'
												+'</div>'												
												+'<div class="loaderright"></div>'
												+'</div>'
									);
	$('#loader').modal({close: false ,position: ["10%","40%"]}) ;
	
	 url=base_url+"/cart/change-cart-state?"+str_request;
	// window.location=url;
	$('#shopping_cart_details').submit();
//	
//	//ajax call
//	$.ajax({
//   		type: "GET",
//	    url: base_url+"/cart/change-cart-state",
//	    data: str_request,
//    	success: function(str_msg){
//			$.modal.close();
//			$('#modalBox').html(str_msg);
//			obj_modal=$('#modalBox').modal({close: false , position: ["5%","15%"]});
//	   }
//   });	   
}

/*
 * This function will display the error after activation ( if any exists ).
 * 
 * Paramater: json error details
 * 
 * Return : null
 */

function invalidInvite(json_error) {

	//parsing the json to object
	var json=json_parse(json_error,'json');
	var str_msg="";
	
//		$('#inviteDetails').html(json_error);
	//		$('#inviteDetails').modal();
	//iterating the object
		for (error in json) {
			if (error != "valid_invite") {
				str_msg = str_msg + json[error];
			}
		}
		$('#dialog').modal({close: false});
		$('#titletext').html("Error");
		$('#content').html(str_msg);
		
}

/*
 * This is to close the modal and reset the dialog div.
 * 
 */

 function resetDialog(){
			  $.modal.close(); 			
              $('#dialog').html("");
 }
 
 /**
  * To display invite activation manually
  * 
  */
 function manualInviteActivation(){
 	var invite_id=$('#activate_invite').val();	
	
	
	if(invite_id=="" || invite_id==get_default_value('activation_invite','activation_code')){
		alertBox('Please Enter The Activation Code');
	}else{
		str_request="i="+invite_id;
		/**
		 * Modal box
		 * 
		 */		
		 	$.modal.close();
			$('#modalBox').html(	'<div class="loader" id="loader" >'
												+'<div class="loaderanim"></div>'
												+'<div class="loadermid"> '
												+'<div class="titletextloading">Loading.. Please Wait!</div>'
												+'</div>'												
												+'<div class="loaderright"></div>'
												+'</div>'
									);
			$('#loader').modal({close: false ,position: ["10%","40%"]}) ;		 

	$("#i").val(invite_id);
	$("#shopping_cart_details").attr("action",base_url+"activate");
	$('#shopping_cart_details').submit();
	
//		$.ajax({
//   		type: "GET",
//	    url: base_url+"/activate/manual",
//	    data: str_request,
//    	success: function(str_msg){
//			$.modal.close();
//				var json=json_parse(str_msg,'json');
//				if(json['valid_invite']){
//					$('#i').val(invite_id);
//					validInvite(invite_id);
//				}else{
//					invalidInvite(str_msg);
//				}
//	   }
//   });	   		
		
			//$('#i').val(invite_id);				
	}
 }
