﻿

function LoadCountry()
{
	    var url = '/Geography/Geography.ashx?GetCountry&Formathtml&Custom=/Group_Country';
	    new Ajax.Updater('ContentCountry', url); 
}
function changeCountry(Name)
{
    if(Name != '0')
    {
        var x=$("country");
        var by=x.options[x.selectedIndex].value;
        var Nombre=x.options[x.selectedIndex].innerHTML;
        //document.getElementById('txtCountry').value=by;
        CountryValue=by;
        var url = '/Geography/Geography.ashx?GetStateByCountry&Format=html&Custom=/Group_State&Name='+Nombre;
        new Ajax.Updater('ContentState', url);
        document.getElementById('ContentState').style.display = 'block';
    }
    else
    {
        document.getElementById('ContentState').innerHTML = '<label id="lblState">Ciudad</label><input id="txtState2" name="state" class="Input" value=""></input>';
    }
}
function changeState()
{
    var x=$("state");
    var by=x.options[x.selectedIndex].value;
    var Nombre=x.options[x.selectedIndex].innerHTML;
    //document.getElementById('txtState').value=by;
    StateValue=by;
    
}

function showaddfriendnew(GroupId, Access, Name)
{   
var elem = document.createElement('a');
var attr = document.createAttribute('rel');
attr.value = 'shadowbox;width=418;height=370';	            
elem.setAttributeNode(attr);

var attr3 = document.createAttribute('href');
attr3.value = '/LayerAddMember.aspx?ChildContactId='+GroupId+'&Access=' +Access + '&Name=' + Name;
elem.setAttributeNode(attr3);

Shadowbox.open(elem);
}



function Del(Id, CommunityId)
{

    if(confirm('Are you sure you want to delete this group?'))
    {    
    var url = '/GroupService.asmx/DelGroup';
        new Ajax.Request(url, {
		    method: 'post', 
		    parameters: { 
			    Id: Id, 
			    CommunityId: CommunityId
		    },
		    onSuccess: function(transport) {
			    if(transport.status == 200)
			    {
				    if (transport.responseXML.getElementsByTagName("ut_response")[0].attributes[0].value == 'fail')
				    {
					    var errorCode = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[0].value;
					    var errorMge = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[1].value;
					    alert(errorCode+'-'+errorMge);
    					
				    }
				    else
				    {
    					
					    document.getElementById('gallery_' + Id).style.display = 'none';
				    }
			    }
		    }
	    });
	}
	else
	{
	return;
	}
}

function ExMember(ParentContactId, ChildContactId, CommunityId, UserName)
{

    if(confirm('Are you sure you want to stop being a member?'))
    {    
    var url = '/GroupService.asmx/IsNotMember';   
        new Ajax.Request(url, {
		    method: 'post', 
		    parameters: { 
			    ParentContactId: ParentContactId, 
			    ChildContactId: ChildContactId, 
			    CommunityId: CommunityId
		    },
		    onSuccess: function(transport) {
			    if(transport.status == 200)
			    {
				    if (transport.responseXML.getElementsByTagName("ut_response")[0].attributes[0].value == 'fail')
				    {
					    var errorCode = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[0].value;
					    var errorMge = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[1].value;
					    alert(errorCode+'-'+errorMge);
    					
				    }
				    else
				    {
    					
					    window.location='/Groups.aspx?UserName='+ UserName;
				    }
			    }
		    }
	    });

	}
	else
	{
	return;
	}
}

function LoadSwfUpload(Token)
{
var swfu;
		
			swfu = new SWFUpload({
				// Backend Settings
				upload_url: "GroupAvatarUpload/upload.aspx",	// Relative to the SWF file
                post_params : {token : Token },

				// File Upload Settings
				file_size_limit : "5 MB",
				file_types : "*.jpg",
				file_types_description : "JPG Images",
				file_upload_limit : "1",    // Zero means unlimited

				// Event Handler Settings - these functions as defined in Handlers.js
				//  The handlers are not part of SWFUpload but are part of my website and control how
				//  my website reacts to the SWFUpload events.
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,

				// Button settings
				button_image_url : "XPButtonNoText_160x22.png",	// Relative to the SWF file
				button_placeholder_id : "spanButtonPlaceholder",
				button_width: 160,
				button_height: 22,
				button_text : '<a id="BuscarFotos" href="javascript:void(0)" class="cssBuscarFotos" style="color:#006699;font-weight:bold; border:1px solid;float:left;display:block;width:100px;outline:none;" >Upload photo</a>',
				button_text_style : '.cssBuscarFotos{outline:none;text-align:left; color:#006699;font-family:Verdana;font-weight:bold;height:31px;margin-top:17px;text-decoration:none;cursor:pointer;}.cssBuscarFotos:hover{color:#006699;font-family:Verdana;font-weight:bold;height:31px;margin-top:17px;text-decoration:underline;cursor:pointer;}',
				button_text_top_padding: 1,
				button_text_left_padding: 0,
                button_cursor : SWFUpload.CURSOR.HAND,
                button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT ,
				// Flash Settings
				flash_url : "swfupload.swf",	// Relative to this file

				custom_settings : {
					upload_target : "divFileProgressContainer"
				},

				// Debug Settings
				debug: false
			});
		
		
}


function GroupComment(ObjectId)
{
var Body = document.getElementById('CommentZone').value;

    var url = '/GroupService.asmx/CommentGroup';   
        new Ajax.Request(url, {
		    method: 'post', 
		    parameters: { 
			    ObjectId: ObjectId, 
			    Body: Body, 
			    ObjectType: 2005
		    },
		    onSuccess: function(transport) {
			    if(transport.status == 200)
			    {
				    if (transport.responseXML.getElementsByTagName("ut_response")[0].attributes[0].value == 'fail')
				    {
					    var errorCode = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[0].value;
					    var errorMge = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[1].value;
					    alert(errorCode+'-'+errorMge);
    					
				    }
				    else
				    {
				        document.getElementById('Body_Comment').innerHTML = Body;
    					document.getElementById('commentario_Begin').style.display = 'none';
					    document.getElementById('commentario_End').style.display = 'block';
				    }
			    }
		    }
	    });

}

function GroupCommentDel(ObjectId, Id)
{

    var url = '/GroupService.asmx/DelCommentGroup';   
        new Ajax.Request(url, {
		    method: 'post', 
		    parameters: { 
			    ObjectId: ObjectId, 
			    Id: Id, 
			    ObjectType: 2005
		    },
		    onSuccess: function(transport) {
			    if(transport.status == 200)
			    {
				    if (transport.responseXML.getElementsByTagName("ut_response")[0].attributes[0].value == 'fail')
				    {
					    var errorCode = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[0].value;
					    var errorMge = transport.responseXML.documentElement.getElementsByTagName("error")[0].attributes[1].value;
					    alert(errorCode+'-'+errorMge);
				    }
				    else
				    {
    					document.getElementById('Comment_' + Id).style.display = 'none';
    					document.getElementById('Separator_' + Id).style.display = 'none';
				    }
			    }
		    }
	    });

}

function countChars(e)
{
    var element = document.getElementById('CommentZone').value
    n = element.length;
    t = 164;
    if (n > t)
    {
        document.getElementById('CommentZone').value = document.getElementById('CommentZone').value.substring(0, t);
        document.getElementById('cont').innerHTML = 'You have  ' + num + ' characters';
    }
    else
    {
        num = t - n;
        document.getElementById('cont').innerHTML = 'You have  ' + num + ' characters';
    }
    if(e)
    { 
        e = e;
        characterCode = e.which ;
    }
    else
    {
        e = event;
        characterCode = e.keyCode;
    }
    
    /*if (n >= 39 || characterCode == 13)
    {
        document.getElementById('line').style.height = '120px';
    }
    else
    {
        document.getElementById('line').style.height = '23px';
    } */

} 

function refresh()
{
 if (document.getElementById('CommentZone').value == 'Click here to comment ')
    document.getElementById('CommentZone').value = '';
}

function checkEmpty()
{
    var element = document.getElementById('CommentZone').value;
    if(element == '')
    {
        document.getElementById('CommentZone').value = 'Click here to comment ';
    }
}    

function LoadTabs()
{

var CountPhoto = parseInt(document.getElementById('CountPhoto').value);
var CountVideo = parseInt(document.getElementById('CountVideo').value);
var CountPost = parseInt(document.getElementById('CountPost').value);

    if (CountPhoto != 0)
    {
        document.getElementById('T1').className = 'Disable';
    }
    else
    {
        if (CountVideo != 0)
        {
            document.getElementById('T2').className = 'Disable';
        }
        else
        {
            document.getElementById('T3').className = 'Disable';
        }
    }
}


function ChangeTabs(Id)
{
var CountPhoto = parseInt(document.getElementById('CountPhoto').value);
var CountVideo = parseInt(document.getElementById('CountVideo').value);
var CountPost = parseInt(document.getElementById('CountPost').value);

    if (CountPhoto != 0)
    {
        document.getElementById('T1').className = 'Enable';
        document.getElementById('B1').style.display = 'none';
    }
    if (CountVideo != 0)
    {
        document.getElementById('T2').className = 'Enable';
        document.getElementById('B2').style.display = 'none';
    }
    if (CountPost != 0)
    {
        document.getElementById('T3').className = 'Enable';
        document.getElementById('B3').style.display = 'none';
    }
    
    document.getElementById('T' + Id).className = 'Disable';
    document.getElementById('B' + Id).style.display = 'block';
    
}      
