﻿// JScript File
function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
} 

function GetNewMessages()
{
 	window.open('NewMessages.aspx','NewMessages','status=yes,scrollbars=yes,resizable=yes,width=480,height=400,screenX=25,screenY=25,top=25,left=25');
 	//reloadMessageManager();
 	var newMessages = $('#NewMessages');
 	newMessages.removeClass("NewMail").addClass("NoMail");
 	newMessages.html('');
 	var newMessageBox = $('#NewMessageBox');
 	newMessageBox.hide("fast").html('');
} 

function GetChatRequests()
{
    window.open('ChatRequests.aspx', 'ChatRequests', 'status=yes,scrollbars=yes,resizable=yes,width=480,height=400,screenX=25,screenY=25,top=25,left=25');
 	//reloadMessageManager();
} 

function OpenChatRoom(chatAddress,chatWindow)
{
//alert(dialogArguments);
 	window.open(chatAddress,chatWindow,'status=yes,scrollbars=no,resizable=yes,width=725,height=500,screenX=25,screenY=25,top=25,left=25');
} 

function Radio()
{
    window.open('/radio.aspx','radio','status=no,scrollbars=no,resizable=no,width=360,height=170,screenX=25,screenY=25,top=25,left=25');
}

function OpenFlyer(eventID)
{
 	window.open('Flyer.aspx?event_id='+eventID,'Flyer','status=yes,scrollbars=yes,resizable=yes,width=650,height=550,screenX=25,screenY=25,top=25,left=25');
}

function getUserMessageCounters(){
    PageMethods.GetUserMessageCounters(getUserMessageCountersComplete);

}
function getUserMessageCountersComplete(param){
    if(param=="")return;
    var messages=param.split(':');
    if(messages!=null&&messages.get_length()){      
       $("ctl00_loginView_numberOfNewMessagesLabel").innerHTML= messages[0];   
       $("ctl00_loginView_numberOfNewChatRequestsLabel").innerHTML= messages[1];
    }
}

function SendMessage(messageTo, messageGroupID, messageReplyID)
{
 	window.open('SendMessage.aspx?messageTo='+messageTo +'&messageGroupID=' +messageGroupID + '&messageReplyID=' + messageReplyID,'SendMessage','status=no,scrollbars=no,resizable=no,width=400,height=590,screenX=25,screenY=25,top=25,left=25');
}

function BlockMember(username)
{
    window.open('BlockMember.aspx?username=' + username, 'BlockMember', 'status=no,scrollbars=no,resizable=no,width=480,height=400,screenX=25,screenY=25,top=25,left=25');
}

var rowClickEnabled = true;

function RowClickToggle(toggle)
{
    rowClickEnabled = toggle;
}

function RowClick(row)
{
    if(rowClickEnabled)
    {
        scroll(0,0);
        __doPostBack(row,'');
    }
}

function AddToFavouritesMessage(memberName, memberId, addTo, addFavImage)
{
 	window.open('MemberFavouritesAdd.aspx?memberName='+memberName +'&FavouriteMemberID=' +memberId + '&add=' + addTo,'MemberFavouritesAdd','status=no,scrollbars=no,resizable=no,width=350,height=330,screenX=25,screenY=25,top=25,left=25');
 	if(addFavImage)
    {
 	    actImg = document.getElementById(addFavImage);
        actImg.style.display="none";
    }

}  

function OpenChatWindow(windowURL)
{
 	window.open(windowURL, '_blank','status=no,scrollbars=yes,resizable=yes,width=650,height=500,screenX=25,screenY=25,top=25,left=25');
} 

function writeSessionCookie (cookieName, cookieValue) {
 
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
}
function AccessDenied()
{
    alert('Sorry you cannot view the gallery pictures. These pictures are for adults only!!'); 
    writeSessionCookie('AdultAuthorized', 'false');  
    return false;
}
function ConfirmAdult()
{
    if(confirm('Click OK to confirm you are an adult and over the age of consent to view adult material in your country.')) 
    { if (writeSessionCookie('AdultAuthorized', 'true')) 
        {document.location.reload();} 
    }
    else{ AccessDenied();  }
}

function ViewMessagePrivatePics(messageID)
{
    //var xPos = document.documentElement.clientWidth+window.screenX+20;
    //var yPos = window.screenY;
    var xPos = 25;
    var yPos = 25;
 	window.open('MessagePrivatePics.aspx?messageID='+messageID,'ViewMessagePrivatePics','status=no,scrollbars=no,resizable=no,width=400,height=450,screenX='+xPos+',screenY='+yPos+',top='+yPos+',left='+xPos);
} 

function SaveMessage(messageID, msgDirection)
{
 	window.open('SaveMessage.aspx?messageID='+messageID+'&msgDirection='+msgDirection,'SaveMessage','status=no,scrollbars=no,resizable=no,width=200,height=175,screenX=25,screenY=25,top=25,left=25');
}  

function CheckBoxListSelect(cbControl, CheckBoxControl)
{   
    var chkBoxList = document.getElementById(cbControl);
    var chkBoxCount= chkBoxList.getElementsByTagName("input");
    for(var i=0;i<chkBoxCount.length;i++) 
    {
        chkBoxCount[i].checked = CheckBoxControl.checked;
    }
    
    return false; 
}

function UncheckSelect(cbControl)
{
    var chkBoxSelect = document.getElementById(cbControl);
    if (chkBoxSelect != null)
    {
         chkBoxSelect.checked = false;
    }
}

function confirmSubmit(msg)
{
    var confirmed = confirm(msg);
    if (!confirmed && window.event) 
        window.event.returnValue = false;
    return confirmed;
}

// our dollar function
function $S() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
// and now our improved toggler!
function tog(obj) {
	var el = $S(obj);
	el.style.display = (el.style.display != 'none' ? 'none' : '' );
}

//Gallery Scroll
//function TextScroll(scrollname, div_name, up_name, down_name, scroll_pos, scroll_start_pos) 
//{
//    this.div_name = div_name;
//    this.name = scrollname; 
//    this.scrollCursor = 0; 
//    this.speed = 10; 
//    this.timeoutID = 0; 
//    this.div_obj = null; 
//    this.up_name = up_name; 
//    this.dn_name = down_name; 
//    this.scroll_pos_obj = null; 
//    this.scroll_pos_name = scroll_pos;
//    
//    {
//        if (document.getElementById) 
//        { 
//            div_obj = document.getElementById(this.div_name);
//            if (div_obj) 
//            { 
//                this.div_obj = div_obj; 
//                this.div_obj.style.overflow = 'hidden'; 
//                
//                scroll_pos_obj = document.getElementById(this.scroll_pos_name);
//                if (scroll_pos_obj) 
//                { 
//                    this.scroll_pos_obj = scroll_pos_obj; 
//                    this.scroll_pos_obj.value = scroll_start_pos
//                    this.div_obj.scrollTop = this.scroll_pos_obj.value;        
//                }
//            }           
//            

//            div_up_obj = document.getElementById(this.up_name); 
//            div_dn_obj = document.getElementById(this.dn_name); 
//            if (div_up_obj && div_dn_obj) 
//            { 
//                div_up_obj.onmouseover = function() { eval(scrollname + ".scrollUp();") }; 
//                div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") }; 
//                div_dn_obj.onmouseover = function() { eval(scrollname + ".scrollDown();") }; 
//                div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") }; 
//                
//            }
//        }
//    }

//    this.stopScroll = function() { clearTimeout(this.timeoutID); }
//    this.scrollUp = function() { if (this.div_obj) { this.scroll_pos_obj.value = this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed; this.div_obj.scrollTop = this.scrollCursor; if ((this.div_obj.scrollTop + this.div_obj.offsetHeight) != this.div_obj.scrollHeight) { down_obj = document.getElementById(this.dn_name); down_obj.style.display = 'block'; } if(this.div_obj.scrollTop == 0) { up_obj = document.getElementById(this.up_name); up_obj.style.display = 'none'; } else { this.timeoutID = setTimeout(this.name + ".scrollUp()", 30); }}}
//    this.scrollDown = function() { if (this.div_obj) { this.scroll_pos_obj.value = this.scrollCursor += this.speed; this.div_obj.scrollTop = this.scrollCursor; 
//    if(this.div_obj.scrollTop != 0) 
//    { 
//        up_obj = document.getElementById(this.up_name); 
//        up_obj.style.display = 'block'; 
//    } if ((this.div_obj.scrollTop + this.div_obj.offsetHeight) == this.div_obj.scrollHeight) { down_obj = document.getElementById(this.dn_name); down_obj.style.display = 'none'; } else {this.timeoutID = setTimeout(this.name + ".scrollDown()", 30); }}}
//    this.resetScroll = function() { if (this.div_obj) { this.div_obj.scrollTop = 0; this.scrollCursor = 0; }}
//    
//}

function ScrollPageTop() {
    scroll(0,0);
}

function ScrollDivTop(div_name) {

    $(div_name).scrollTo(0, 0, { duration: 1000, easing: 'easeInOutBack', onAfter: function() {
    }
    })
}

function SetScrollPos(div_name, pos)
{
    var div_obj = document.getElementById(div_name);
    if (div_obj) 
    {
      
      div_obj.scrollTop = pos;

    }
}

function Scroll(div_name, up_name, down_name, amount)
{
    var div_obj = document.getElementById(div_name);
    if (div_obj) 
    { 
        div_obj.style.overflow = 'hidden'; 
        div_obj.scrollTop =  div_obj.scrollTop + amount;
        
        var up_obj = document.getElementById(up_name);
        var down_obj = document.getElementById(down_name);
        if(div_obj.scrollTop != 0 && up_obj != null) 
        { 
           up_obj.style.display = 'block'; 
        }
        else
        {
           up_obj.style.display = 'none'; 
        }
        
        if (div_obj.scrollTop + div_obj.offsetHeight +10 >= div_obj.scrollHeight)
        {
            down_obj.style.display = 'none'; 
        }
        else
        {
            down_obj.style.display = 'block'; 
        }
 
    }
}

function isSkypeInstalled() {   
     try {        
        /*@cc_on        
        //The Microsoft way, thanks to the conditional comments only run in IE        
        if (x = new ActiveXObject("Skype.Detection")) return true;        
        @*/        
        //Tested for firefox on win        
        if (navigator.mimeTypes["application/x-skype"]) return true;    
        }    catch(e){}    
        return false;
}
function SkypeCall(o,u)
{
var randomnumber=Math.floor(Math.random()*1111)

$.ajax({
  url: "/SkypeHandler.ashx?u="+u+"&r="+randomnumber,
  cache: false,
  async: false,
  success: function(s){
   switch(s)
   {
    case "-1":
        //error
        alert("An error occurred whilst trying to contact Skype. Please try again later or contact AussieMen.");
        break;
    case "0":
        //open upgrade window
        alert("Message Max Reached! - Upgrade Now!");
        break;
    case "1": //offline
        alert('Skype user is offline.');
        break;
    case "2": //online
        LaunchSkype(o,u);
        break;
    case "3": //away
        alert('Skype user is away.');
        break;
    case "4": //not available
        alert('Skype user not available.');
        break;
    case "5": //not available
        alert('Skype user is set to do not disturb. Please try again later.');
        break;
    case "6": //not available
        alert('Skype user is offline.');
        break;
    case "7": //online
        LaunchSkype(o,u);
        break;
    default:
        alert('Skype user is offline.');
        break;
   }
 }
});
}

function LaunchSkype(o,u)
{
    if(isSkypeInstalled())
    {
        o.href='skype:'+u+'?call';
    }else{
        if(confirm('Looks like you don\'t have Skype. Bummer dude!! Click Ok to get Skype!'))
        {
            window.open('http://videocallswithskype.blogspot.com/','_blank','scrollbars=1,menubar=0');
        }
    }
}

var formatDateFunction = function(formatDate, formatString) {
    if (formatDate instanceof Date) {
        var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
        var yyyy = formatDate.getFullYear();
        var yy = yyyy.toString().substring(2);
        var m = formatDate.getMonth();
        var mm = m < 10 ? "0" + m : m;
        var mmm = months[m];
        var d = formatDate.getDate();
        var dd = d < 10 ? "0" + d : d;

        var h = formatDate.getHours();
        var hh = h < 10 ? "0" + h : h;
        var n = formatDate.getMinutes();
        var nn = n < 10 ? "0" + n : n;
        var s = formatDate.getSeconds();
        var ss = s < 10 ? "0" + s : s;


        formatString = formatString.replace(/dd/i, dd);
        formatString = formatString.replace(/d/, d);
        formatString = formatString.replace(/hh/i, hh);
        formatString = formatString.replace(/h/i, h);
        formatString = formatString.replace(/nn/i, nn);
        formatString = formatString.replace(/n/, n);
        formatString = formatString.replace(/ss/i, ss);
        formatString = formatString.replace(/s/, s);
        formatString = formatString.replace(/yyyy/i, yyyy);
        formatString = formatString.replace(/yy/i, yy);
        formatString = formatString.replace(/mmm/i, mmm);
        formatString = formatString.replace(/mm/i, mm);
        formatString = formatString.replace(/m/, m);


        return formatString;
    } else {
        return "";
    }
}

function DateDeserialize(dateStr) {
    //return formatDateFunction(new Date((eval('new' + dateStr.replace(/\//g, ' '))).toLocaleString()), 'dd-mmm');
    return formatDateFunction(eval('new' + dateStr.replace(/\//g, ' ')), 'dd-mmm');
}



function LaunchGalleryEditor() {

    //Open Gallery Window
    window.open("/PicManager/PicEditor.aspx", "PicEditor", "fullscreen=yes,status=0,toolbar=0,resizable=1,scrollbars=1", null);

}

var ZoomPic = function(pic) {

pic.imgZoom({ instance: true, showOverlay: true, 
        'onZoomedIn': function() {
            $('.flashItem').fadeOut("fast");
        }
        , 'onZoomedOut': function() {
            $('.flashItem').fadeIn("slow");
        } 
    });
}