/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$( window ).load(function() {
$(".content_register").hide();
$("#cancel_upload").live("click",function(){
	parent.location.reload();
	 $.colorbox.close();
});
$(".jedit_link_business").live("click",function(){
   var commentId = $(this).attr("cid");
//	alert(commentId);	
	var comment = $(".comment_content_"+commentId).text();
//	alert(comment);
	$(".edit_delete").hide();
//	var editBox = '<input type="textbox" value="'+comment+'"id="comment_'+commentId+'"><input type="button" value="Save" cid="'+commentId+'" id="save" class="invite_btn"><input type="button" value="Cancel" cid="'+commentId+'" id="cancel" class="cancel_btn">'; 
	var editBox = '<textarea style="width:98%" id="commentarea_'+commentId+'" class="textarea1">'+comment+'</textarea><input type="button" value="Save" cid="'+commentId+'" id="save" class="invite_btn1"><input type="button" value="Cancel" cid="'+commentId+'" id="cancel" class="cancel_btn1">';
	$(".comment_content_"+commentId).html(editBox);
	return false;
});
    /* Invokes editBox on testimonial edit and copies the content to editable textarea */
    $(".jedit_link_testimonial").live("click", function () {

        var testimonialId = $(this).attr("cid");
        
        var content = '';
        if($("#jtestimonial_content_"+testimonialId).length >0){
            content = ($("#jtestimonial_content_"+testimonialId).html()).trim();
        }
        if(content == ''){
           content = $(".testimonial_content_"+testimonialId).html();
        }
        //
        $("#jtestimonial_content_"+testimonialId).html('');
        var testimonial = ($(".testimonial_content_" + testimonialId).text()).trim();
        var editBox =   '<textarea style="width:98%" id="testimonialarea_' + testimonialId + '" class="textarea1">' + content + '</textarea>' +
                        '<input type="button" value="Save" cid="' + testimonialId + '" id="savetestimonial" class="btn primary pull-left marg5right textnormal">' +
                        '<input type="button" value="Cancel" cid="' + testimonialId + '" id="cancel" class="btn grey_btn pull-left textnormal">';
        testimonial = null;
        $(".testimonial_content_" + testimonialId).html(editBox);
        $("#jtestimonial_content_" + testimonialId).html(editBox);
        return false;
    });

$("#save").live("click",function(){
    
	var commentId = $(this).attr("cid");
//	alert(commentId);	
//	var comment = $("#commentarea_"+commentId).text();
	var comment = $("#commentarea_"+commentId).val();
//	alert(comment);
	 $.ajax({
	        url: MAIN_URL+'index/savecommentedit', //your server side script
	        async : false,
	        data: { id: commentId, content: comment}, //our data
	        type: 'POST',
	        success: function (data) { 
//	            alert(data);	         
	        	$(".comment_content_"+commentId).text(data);
	        	$(".edit_delete").show();
	        }
	   });		
	return false;
});

$("#savetestimonial").live("click",function(){
    
	var testimonialId = $(this).attr("cid");
	var testimonial = $("#testimonialarea_"+testimonialId).val();
	 $.ajax({
	        url: MAIN_URL+'index/savetestimonialedit',
	        async : false,
	        data: { id: testimonialId, content: testimonial},
	        type: 'POST',
	        success: function (data) {
                        $(".testimonial_content_"+testimonialId +" #jtestimonial_content_"+testimonialId).html(data);
	        	$(".testimonial_content_"+testimonialId).html(data);
                        $("#jtestimonial_content_"+testimonialId).html(data);
	        	$(".jtestimonial_content_"+testimonialId).html(data);
	        	$(".edit_delete").show();
	        }
	   });		
	return false;
});


//$(document).bind('cbox_closed', function(){
//	alert("aa1");
////	alert($("#filename").val());
//    //location.reload();
//	//$("#profilepic img",opener.document).attr("src",mainUrl + "project/files/"+ $("#filename").val());
//});
//$("#refer_friend").on('click',function(){
//     var mlink=mainUrl+"index/refer_friend";
//     $.colorbox({width:"430px", height:"407px", iframe:true, href:mlink, overlayClose: false});
//     return false;
//});
$("#refer_friend_community").on('click',function(){
    
     var mlink=mainUrl+"index/refer_friend_community/?url="+window.location.href;
     $.colorbox({width:"430px", height:"407px", iframe:true, href:mlink, overlayClose: false});
     return false; 
});
 });

function checkLogin(entity_type,entity_id,flag_for_testimonials)
{
    flag_for_testimonials   =   typeof(flag_for_testimonials)=='unidentified'?'':flag_for_testimonials
    if($("#login_status").val()==0){
     var mlink=mainUrl+"index/loginpopup/"+entity_type+'/'+entity_id+'/'+flag_for_testimonials;
//     $.pgwModal({
//         url:mlink,
//         loadingContent: '<span style="text-align:center">Loading in progress</span>',
//   // closable: false,
//    titleBar: false
//     });
//      var SM = new SimpleModal({"width":600});
//      SM.addButton("Action button", "btn primary", function(){
//          this.hide();
//      });
//      SM.addButton("Cancel", "btn");
//      SM.show({
//        "model":"modal-ajax",
//        "title":"Title",
//        "param":{
//          "url":mlink,
//          "onRequestComplete": function(){ /* Action on request complete */ }
//        }
//      });
    // Custombox.open({target:mainUrl+"index/loginpopup",width:"430px", height:"407px", iframe:true,overlayClose: false});
     $.colorbox({width:"430px", height:"407px", iframe:true, href:mlink, overlayClose: false});

     return false;
    }
    else if(flag_for_testimonials !=''){
        showTestimonialsBox(entity_id);
    }
    else{
        showTestimonialsBox(entity_id);
    } 
   // window.parent.location.reload();
}

//function checkLoginBeforeTestimonial(entity_type,entity_id)
//{
//    if($("#login_status").val()==0){
//     var mlink=mainUrl+"index/loginpopup/"+entity_type+'/'+entity_id;
//     $.colorbox({width:"430px", height:"400px", iframe:true, href:mlink, overlayClose: false});
//     return false;
//    }
//    else{
//        showTestimonialBox(entity_type,entity_id);
//    }        
//}

function checkLoginInquire(entity_type,entity_id,flag)
{
    
  //  flag_for_testimonials   =   typeof(flag_for_testimonials)=='unidentified'?'':flag_for_testimonials
    if($("#login_status").val()==0){
     var mlink=mainUrl+"index/loginpopup/"+entity_type+'/'+entity_id+'/'+flag;
     $.colorbox({width:"430px", height:"407px", iframe:true, href:mlink, overlayClose: false});
     return false;
    }
//    else if(flag_for_testimonials !=''){
//        showTestimonialsBox(entity_id);
//    }
//    else{
//        showTestimonialsBox(entity_id);
//    }     
    
    else{ 
        showInquireBox(entity_type,entity_id);   
    }
   // window.location.reload();
}


function showCommentBox(entity_type,entity_id)
{    
     var mlink=mainUrl+"index/commentbox/"+entity_type+"/"+entity_id;
     $.colorbox({width:"430px", height:"400px", iframe:true, href:mlink, overlayClose: false});
     return false;
}
function showTestimonialsBox(entity_id,entity_flag)
{    
     var mlink=mainUrl+"index/testimonialbox/"+entity_id;
     $.colorbox({width:"430px", height:"400px", iframe:true, href:mlink, overlayClose: false});
     return false;
}

function showInquireBox(entity_type,entity_id)
{    
     var mlink=mainUrl+"index/inqurebox/"+entity_type+"/"+entity_id;
     $.colorbox({width:"520px", height:"450px", iframe:true, href:mlink, overlayClose: false});
     return false;
}

function showProfileChangeBox(id)
{   
     var mlink=mainUrl+"index/profilechange/"+id;
     $.colorbox({width:"400px", height:"390px", iframe:true, href:mlink, overlayClose: false});
     return false;  
}

function showDiv(showing,hiding)
{
    $("."+showing).show();
    $("."+hiding).hide();
    
}

function checkLogin1(entity_type,entity_id,flag)
{
    if($("#login_status").val()==0){
     var mlink=mainUrl+"index/loginpopup/"+entity_type+"/"+flag;
     $.colorbox({width:"430px", height:"407px", iframe:true, href:mlink, overlayClose: false});
     return false;
    }  
    else{
    	return true;
    }
    	
}
function checkLogin2(entity_type,entity_id,flag,rateField)
{
    if($("#login_status").val()==0){
     var mlink=mainUrl+"index/loginpoprate/"+entity_type+"/"+flag+"/"+rateField;
     $.colorbox({width:"430px", height:"407px", iframe:true, href:mlink, overlayClose: false});
     return false;
    }  
    else{
    	return true;
    }
    	
}

function showCommunityprofileChangeBox(id)
{   
     //var mlink=mainUrl+"user/communityprofilechange/"+id;
    // $.colorbox({width:"400px", height:"390px", iframe:true, href:mlink, overlayClose: false});
    // return false;  
}



