/* ARKITECH JavaScript */

var Images = [
 '/images/portal/html/portal/content2_r1_c1.jpg',
 '/images/portal/html/portal/content2_r1_c2.jpg',
 '/images/portal/html/portal/content2_r1_c4.jpg',
 '/images/portal/html/portal/content2_r1_c5.jpg',
 '/images/portal/html/portal/content2_r1_c6.jpg',
 '/images/portal/html/portal/content2_r3_c6.jpg',
 '/images/portal/html/portal/content2_r4_c6.jpg',
 '/images/portal/html/portal/content2_r2_c1.jpg',
 '/images/portal/html/portal/content2_r5_c2.jpg',
 '/images/portal/bgTitleSection.jpg',
 '/images/portal/title_small1.jpg',
 '/images/portal/bgProcessed.jpg',
 '/images/portal/Success.jpg',
 '/images/portal/Warning.jpg',
 '/images/portal/bgError.jpg',
 '/images/portal/bgError_small.jpg',
 '/images/portal/bgSuccess_small.jpg',
 '/images/portal/bgNoCount_small.jpg',
 '/images/portal/login_indication.gif'
];
for(im=0; im<Images.length; im++) {
 _im = new Image(0,0);
 _im.src = Images[im];
}

function replaceText(text){
  while(text.lastIndexOf("&") > 0){
	  text = text.replace('&', '[i-Stats]');
  }
  return text;
}

var web_referrer = replaceText(document.referrer);

istat = new Image(1,1);
istat.src = "http://www.scdeo.com/cms/include/web/stats/counter.php?CMSDir=cms&IsScript=1&sw="+screen.width+"&sc="+screen.colorDepth+"&referer="+web_referrer+"&page="+location.href;

/* Poll Module Functions*/
SetSurvey = function() {
 if($('#TypeVote_frm').val() == '1') {
   $('#Step1_Ly').slideDown('slow');
   $('#Step2_Ly').slideUp('slow');
   $('#Accept_Ly').slideDown('slow');
   $('#SelOptionBoolMain_Ly').slideDown('slow');
 } else if($('#TypeVote_frm').val() == '2') {
   $('#Step1_Ly').slideUp('slow');
   $('#Step2_Ly').slideDown('slow');
   $('#Accept_Ly').slideDown('slow');
   $('#SelOptionBoolMain_Ly').slideDown('slow');
 } else if($('#TypeVote_frm').val() == '3') {
   $('#Step1_Ly').slideDown('slow');
   $('#Step2_Ly').slideDown('slow');
   $('#Accept_Ly').slideDown('slow');
   $('#SelOptionBoolMain_Ly').slideDown('slow');
 } else {
   $('#Step1_Ly').slideUp('slow');
   $('#Step2_Ly').slideUp('slow');
   $('#Accept_Ly').slideUp('slow');
   $('#SelOptionBoolMain_Ly').slideUp('slow');
 }
}

setPower = function() {
 if($('#IncludePower_frm').get(0).checked == true) {
    $('#Power_Ly').css('display','block');
  } else {
    $('#Power_Ly').css('display','none'); 
  }
}

laPlancha = function() {
 if($('#PlanchaNumero_frm').val() !== 'null') {
  var IdSel = 'preg_'+$('#PlanchaNumero_frm').val()+'_Ly';
   $('#'+IdSel).animate( { backgroundColor:'#DFFFDF' } , 'fast' );
   $('#'+IdSel).animate( { backgroundColor:'#FFFFFF' } , 1000 );
  // $('#button_1_frm').val('Votar por la Plancha '+$('#PlanchaNumero_frm').val());
 } else {
   var IdSel = 'preg_null_Ly';
   $('#'+IdSel).animate( { backgroundColor:'#CCCCCC' } , 'fast' );
   $('#'+IdSel).animate( { backgroundColor:'#FFFFFF' } , 1000 );
   //$('#button_1_frm').val('Votar en blanco');
 }
}

ToggleBtn = function(TheId,TheId2Toog) {
 if($('#'+TheId).get(0).checked == true) {
  $('#'+TheId2Toog).get(0).disabled = false;
  $('#'+TheId2Toog).css('backgroundColor','#009900');
  $('#'+TheId2Toog).css('color','#FFFFFF');
 } else if($('#'+TheId).get(0).checked == false) {
  $('#'+TheId2Toog).get(0).disabled = true;
  $('#'+TheId2Toog).css('backgroundColor','#FFFFFF');
  $('#'+TheId2Toog).css('color','#CCCCCC');
 }
}

PasswordStrength = function() {

    if($('#Pass1_Frm').get(0).value.length < '6') {
        $('#StrengthPass_Ly').html('Fortaleza de la contrase&ntilde;a: <img src="images/low_pass.gif" border="0" align="absmiddle" /> <strong>Debil</strong>');
    } else if($('#Pass1_Frm').get(0).value.length > '7' && $('#Pass1_Frm').get(0).value.length < '12') {
        $('#StrengthPass_Ly').html('Fortaleza de la contrase&ntilde;a: <img src="images/mid_pass.gif" border="0" align="absmiddle" /> <strong>Media</strong>');
    } else if($('#Pass1_Frm').get(0).value.length > '12') {
        $('#StrengthPass_Ly').html('Fortaleza de la contrase&ntilde;a: <img src="images/high_pass.gif" border="0" align="absmiddle" /> <strong>Alta</strong> ');
    } else if($('#Pass1_Frm').get(0).value == '') {
        $('#StrengthPass_Ly').html('');
    }

}

SetToggleAnswerInYes = function() {
    
    if($('#AllReforms_id_1').get(0).checked == true) { 
     
     for(i=1; i<=document.forms[0].NumQuestions.value; i++) {
     	document.forms[0].elements['opt'+i][0].checked = true;
		SetColorInEle('selInput1_'+i, '#CAFFCC');
		SetColorInEle('selInput2_'+i, '#FFFFFF');
     }
	 if($('#NoOption_Ly').get(0).style.display == 'none') {
     	$('#NoOption_Ly').slideDown('slow');
	 }
     
    } else if($('#AllReforms_id_2').get(0).checked == true) {
    
     for(i=1; i<=document.forms[0].NumQuestions.value; i++) {
     	document.forms[0].elements['opt'+i][0].checked = false;
		SetColorInEle('selInput1_'+i, '#FFFFFF');
     }
     
     //$('#SelOptionBoolMain_Ly').slideUp('slow');
     if($('#NoOption_Ly').get(0).style.display == 'none') {
     	$('#NoOption_Ly').slideDown('slow');
	 }

    }
    
}

SetColorInEle = function(TheTdSel, TheColor) {
	$('#'+TheTdSel).animate( {backgroundColor:TheColor} , 'slow');
}

setOption = function() {
 
 var Msg0 = 'Elija la Plancha de su Preferencia';
 var Msg1 = 'Elija si aprueba o no todas las Reformas a los Estatutos';
 var Msg2 = 'Elija una de las respuestas a la Pregunta Número ';
 var Msg3 = 'Indique la Opción por la cual desea votar';
 
 if($('#TypeVote_frm').val() == '1') { // Voto Plancha
  
  if($('#PlanchaNumero_frm').val() == '') {
   alert(Msg0);
   $('#PlanchaNumero_frm').get(0).focus();
   return false;
  }
  
  return true;
  
 } else if($('#TypeVote_frm').val() == '2') { // Preguntas
 
  // Todas las reformas
  cnt = 0;
  for(i=0; i<document.forms['frmVotation'].AllReforms.length; i++) {
   if(document.forms['frmVotation'].AllReforms[i].checked == true) { cnt++ }
  }
  if(cnt == 0) {
   alert(Msg1);
   return false;
  }
  
  if($('#AllReforms_id_2').get(0).checked == true) {
    
    for(j=1; j<=document.forms['frmVotation'].NumQuestions.value; j++) {
    
     cnt0 = 0;
     for(k=0; k<document.forms['frmVotation'].elements['opt'+j].length; k++) {
      if(document.forms['frmVotation'].elements['opt'+j][k].checked == true) {
       cnt0++;
      }
     }
     if(cnt0 == 0) { alert(Msg2+''+j); return false; }
    
    }
    
  }
  
  return true;
 
 } else if($('#TypeVote_frm').val() == '3') { // Plancha Preguntas
 
  if($('#PlanchaNumero_frm').val() == '') {
   alert(Msg0);
   $('#PlanchaNumero_frm').get(0).focus();
   return false;
  }
 
  // Todas las reformas
  cnt = 0;
  for(i=0; i<document.forms['frmVotation'].AllReforms.length; i++) {
   if(document.forms['frmVotation'].AllReforms[i].checked == true) { cnt++ }
  }
  if(cnt == 0) {
   alert(Msg1);
   return false;
  }
 
  if($('#AllReforms_id_2').get(0).checked == true) {
    
    for(j=1; j<=document.forms['frmVotation'].NumQuestions.value; j++) {
    
     cnt0 = 0;
     for(k=0; k<document.forms['frmVotation'].elements['opt'+j].length; k++) {
      if(document.forms['frmVotation'].elements['opt'+j][k].checked == true) {
       cnt0++;
      }
     }
     if(cnt0 == 0) { alert(Msg2+''+j); return false; }
    
    }
    
  } 
  
  return true;
  
 } else {
 
  alert(Msg3);
  $('#TypeVote_frm').get(0).focus();
  return false;
  
 }

}

acceptNum = function(evt){	
 evt = (evt) ? evt : window.event
 var charCode = (evt.which) ? evt.which : evt.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57)) {
	return false;
 }
 return true;
}

GetName = function() {
 if($('#documento_frm').val() !== '') {
 	$('#Progress_img').css('display','inline');
     $.ajax({
      url: 'script/GetName.php',
      type: 'POST',
      data: 'rsNumDoc='+$('#documento_frm').val(),
      success: function(rp) {
      	var rsCompString = rp.split('|');
        if(rsCompString[0] == '0') {
         alert('La cedula ingresada no existe');
         $('#Progress_img').css('display','none');
		 $('#IncludePower_frm').get(0).disabled = false;
        } else if(rsCompString[0] == '1') {
		 if($('#TableLogin_Tbl').get(0).style.width == '550px') {
        	$('#TableLogin_Tbl').animate( { width:'450px' } ,1000);
		 }
		
         $('#IncludePower_frm').get(0).checked = false;
		 $('#IncludePower_frm').get(0).disabled = true;
         $('#Power_Ly').css('display','none');
         $('#ccApoderated_frm').val('');
         $('#Name_Ly').html(rsCompString[1]);
         $('#Progress_img').css('display','none');
        } else if(rsCompString[0] == '2') {
         $('#Name_Ly').html(rsCompString[1]);
         $('#Progress_img').css('display','none');
		 $('#IncludePower_frm').get(0).disabled = false;
        }
      }
     });
 } else {
  $('#Progress_img').css('display','none');
  $('#Name_Ly').html('');
 }
}

GetPowerCheck = function() {
  if($('#ccApoderated_frm').val() == '') {
   $('#Progress_img2').css('display','none');
  } else {
	$('#Progress_img2').css('display','inline');
    $.ajax({
      url: 'script/GetName.php',
      type: 'POST',
      data: 'CheckApoderated=1&rsNumDoc='+$('#ccApoderated_frm').val(),
      success: function(rp) {
      	var rsCompString = rp.split('|');
      
        if(rsCompString[0] == '0') {
         alert('La cedula ingresada no existe');
         $('#Progress_img2').css('display','none');
        } else if(rsCompString[0] == '1') {
         $('#resApoderated_Ly').html(rsCompString[1]);
         $('#Progress_img2').css('display','none');
        }
      }
     });   
  }
}

GetListPowered = function() {
 
 if($('#documento_frm').val() !== '') {
 
   if($('#IncludePower_frm').get(0).checked == true) {
    
    var obj = $('#Sel_Apoderated_frm').get(0);
    obj.options[0] = new Option('Cargando...','');
    
    $.ajax({
     type: 'POST',
     data: 'rsNumDoc='+$('#documento_frm').val(),
     url: 'script/GetPowers.php',
     success: function(rp) {
       if(rp == 'not_exists') {
        alert('No tiene apoderados en su lista');
		if($('#TableLogin_Tbl').get(0).style.width == '450px') {
          $('#TableLogin_Tbl').animate( { width:'550px' } ,1000);
		}
       } else {
        obj.options.length = 0;
        obj.options[0] = new Option('-Elija Apoderado-','');
        eval(rp);
        obj.disabled = false;
        $('#TableLogin_Tbl').animate( { width:'550px' } ,1000);
       }
     }
    });
      
   } else {
   
    var obj = $('#Sel_Apoderated_frm').get(0);
    obj.options[0] = new Option('','');
    obj.disabled = true;
    $('#TableLogin_Tbl').animate( { width:'450px' } ,1000);
   
   }
 
 }
 
}


/* Portal Functions*/
DeleteItem = function(ArrayParam) {

 (ArrayParam[0] == 'Entry') ? rsEntryConfirm = 'Desea eliminar este articulo?' : rsEntryConfirm = 'Desea eliminar este comentario?';
 (ArrayParam[0] == 'Entry') ? rsDelMech = 'Entry' : rsDelMech = 'Comment';
 
 $('#'+ArrayParam[4]).css('background-color','#FFD7D7');

 if(confirm(rsEntryConfirm)) {
  
  location.replace('/OpBlog.php?Action=Delete&Type='+rsDelMech+'&IdBlog='+ArrayParam[1]+'&IdEntry='+ArrayParam[2]+'&IdComment='+ArrayParam[3]);
  
 } else {
  $('#'+ArrayParam[4]).css('background-color','#F9F9F9');
  return false;
 }

}

DeleteMessageInTheme = function(ArrayParam) {
 
 $('#'+ArrayParam[2]).css('background-color','#FFD7D7');

 if(confirm('Realmente desea eliminar este mensaje?')) {
  location.replace('/Discussion.php?Action=DeleteTopic&IdTheme='+ArrayParam[0]+'&IdTopic='+ArrayParam[1]);
 } else {
  $('#'+ArrayParam[2]).css('background-color','#FFFFFF');
  return false;
 }

}

MaxCounter = function(TheId, TheInputCntr, MaxLength) {
 if($("#"+TheId).get(0).value.length > MaxLength) {
  $("#"+TheId).val($("#"+TheId).get(0).value.substring(0, MaxLength));
  $("#"+TheInputCntr).val(0);
  return false;
 } else {
  $("#"+TheInputCntr).val(MaxLength - $("#"+TheId).get(0).value.length);
 }
}

CheckUser = function() {
  if($("#user_frm_reg").val() == '') { 
   $("#Res_ly")
    .css('display', 'inline')
    .css('font','10px Tahoma')
    .css('color','#000000')
    .css('textDecoration','underline')
    .html('<strong>Escriba un usuario</strong>');

  } else {  

    $("#Res_ly")
    .css('border','none')
    .css('display', 'inline')
    .html("<img src=\"images/portal/user_loading.gif\" border=\"0\" align=\"absmiddle\" />");
    
    $.ajax({
      type: 'POST',
      data: 'type=CheckUser&rsUser='+$("#user_frm_reg").val(),
      url: '/script/OpScp.php',
      success: function(rp) {
        if(rp == 'available') {
          $("#Res_ly")
            .css('font', '11px Tahoma')
            .css('color','#008000')
            .css('display', 'inline')
            .css('textDecoration','underline')
            .html("Usuario Disponible");
          $("#Res_ly").animate({'opacity':'hide'}, 7000);
        } else if(rp == 'registered') {
          $("#Res_ly")
            .css('fontFamily', 'Tahoma')
            .css('fontSize', '11px')
            .css('color','#FF0000')
            .css('display', 'inline')
            .css('textDecoration','underline')
            .html("Usuario ya registrado");
          $("#Res_ly").animate({'opacity':'hide'}, 7000);
        }
      }
    });
  }
}

var show5 = function (){
	var Digital=new Date();
	var hours=Digital.getHours();
	var minutes=Digital.getMinutes();
	var seconds=Digital.getSeconds();
	var day=Digital.getDay();
	var month=Digital.getMonth();
	var year=Digital.getYear();
	var daym=Digital.getDate();
	
	if (hours>12){ hours=hours-12 }
	if (hours==0) { hours=12; }
	if (minutes<=9) { minutes="0"+minutes; }
	if (seconds<=9) { seconds="0"+seconds; }
	if (year < 1000) { year+=1900; }
	if (daym<10) { daym="0"+daym; }
	
	var dayarray=new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sabado");
	var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	myclock=hours+":"+minutes+":"+seconds;
	$("#Date_ly").text(dayarray[day] + " " + daym + " de " + montharray[month] + " de " + year +" - "+ myclock);
	setTimeout("show5()",1000);
}

/* Arkitech Ajax Chat */
Chatting = function() {
	var nm = Math.floor(Math.random()*101);
	$('.chatarea').load('script/chat/chat.php?IsRoom='+$("#chat_room_sel").val()+'&t='+new Date().getTime(), function() {
     if($.browser.msie) {
       $("img[rel='usr-ico']").remove();
     }
    });
    var _d = $('.chatarea').get(0).scrollHeight;
    $('.chatarea').get(0).scrollTop = _d;
}

ShowCurrentRoom = function() {
 	var nm = Math.random();
    $('div.CurrentRoom').load('script/chat/chat.php?CurrentRoom&IsRoom='+$("#chat_room_sel").val()+'&t='+new Date().getTime());
}

SendData = function() {
	var msg = $("input[@name='message']").val();
    var user_prv = $("input[@name='privateUser']").val();
    var room = $("input[@name='room_sel']").val();
	if(msg !== '') {
	$("input[name='message']").addClass("SendingMessage");
    $.post(
	 'script/chat/chat.php?t='+new Date().getTime(),
	 {message:msg, user_private:user_prv, room_sel:room},
	 function(_sr) {
      eval(_sr);
	 }
	);
	return false;
    }
}

ListingUser = function() {
	var nm = Math.random();
	$('div.UserOnLine').load('script/chat/chat.php?ListUsers&IsRoom='+$("#chat_room_sel").val()+'&t='+new Date().getTime());
}

CountingUsers = function() {
	var nm = Math.random();
	$("div.CountUsers").load('script/chat/chat.php?TotalUsers&IsRoom='+$("#chat_room_sel").val()+'&t='+new Date().getTime());
}

var nav4 = window.Event ? true : false;
Chat_Send = function(evt) {
 var f = document.forms['frmMainAction'];
 var key = nav4 ? evt.which : evt.keyCode;
 if(key == 13) {
  SendData();
  return false;
 }
}

SetPrivateUser = function(TheParam) {
 if($("input[@name='privateUser']").val() == TheParam || TheParam == 'all') {
  $("input[@name='privateUser']").val('');
  $("#PrivateUserSel_Ly").html('');
 } else {
  $("input[@name='privateUser']").val(TheParam);
  $("#PrivateUserSel_Ly")
   .html('<em>Privado a <strong>'+TheParam+'</strong></em>')
   .Highlight(1000, '#FFFFCE');
 }
}

SetClickInRoom = function(theNameOfRoom, idInputR, idValue, IsPrivate) {
 $("#chat_room_sel_prev").val($("#chat_room_sel").val());
 
 $("#"+idInputR).get(0).checked = true;
 if(IsPrivate == '1') {
  $("#ChatNamePrivate_sp").text(theNameOfRoom);
  if($("#IsPrivate_ly").get(0).style.display == 'none') {
   $("#IsPrivate_ly").BlindDown(500);
  }
  $("#chat_room_sel_tmp").val(idValue);
  $("#chat_is_private_room").val('1');
  $("#chat_room_sel_name").val(theNameOfRoom);
  $("#chat_pass").val('');
 } else {
  $("#ChatNamePrivate_sp").text();
  if($("#IsPrivate_ly").get(0).style.display == 'block') {
   $("#IsPrivate_ly").BlindUp(500);
  }
  $("#chat_room_sel_tmp").val(idValue);
  $("#chat_is_private_room").val('0');
  $("#chat_room_sel_name").val(theNameOfRoom);
  $("#chat_pass").val('');
 }
}

LoadChatRoom = function() {
 if($("#chat_is_private_room").val() == '1') {
  if($("#chat_pass").val() == '') { 
   $("#chat_error_msg")
   .html("Escriba la contrase&ntilde;a para acceder a la sala")
   .fadeIn('slow')
   .animate({ 'opacity':'hide' }, 5000);
   return false;
  }
 }
  hash = hex_md5($("#chat_pass").val());
  $("#chat_change_room_btn").get(0).disabled = true;
  $.ajax({
   url: 'script/chat/chat.php?EntryRoom&t='+new Date().getTime(),
   data: 'Room='+$("#chat_room_sel_tmp").val()+"&Pass="+hash,
   type: 'POST',
   success: function(rp) {
    if(rp == 'password_wrong') {
     $("#chat_error_msg").html("Contrase&ntilde;a incorrecta");
     $("#chat_error_msg").fadeIn('slow');
     $("#chat_error_msg").animate({ 'opacity':'hide' }, 5000);
     $("#chat_change_room_btn").get(0).disabled = false;
    } else if(rp == 'Changed') {
      $("#chat_room_sel").val($("#chat_room_sel_tmp").val());
	  $('#SelectorRoom_List_ldn_ly').animate({ opacity: 'hide' },1000);
      $("#ContentListRoom").html('<div id="LoadingChatContent_Ly"><img src="images/portal/chat/loading_room.gif" border="0" align="absmiddle" /> Cargando salas...</div>');
      if($('#IsPrivate_ly').get(0).style.display == 'block') {
       $('#IsPrivate_ly').BlindUp(500);
      }
      ShowCurrentRoom();
      $("#chat_change_room_btn").get(0).disabled = false;
      $("#chat_pass").val('');
      $("#chat_room_sel_tmp").val('');
    }
   }
  });
}

LoadChatRoomFromPass = function(evt) {
 var f = document.forms['RoomSel_frm'];
 var key0 = nav4 ? evt.which : evt.keyCode;
 if(key0 == 13) {
  LoadChatRoom();
  return false;
 }
}

UnloadChat = function() {
 $.ajax({
  url 		: "script/chat/chat_unload.php",
  data 		: "Unload",
  type		: "POST",
  success	:  function(_lrp) {
   if(_lrp !== 'killed') {
    return false;
   }
  }
 });
 
}
/* End Section Chat  */


