﻿
/* START - Attach another .js file into this */
function addJavascript(jsname) 
{
var th = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src',jsname);
th.appendChild(s);
}

addJavascript('/include/Silverlight.js');

/* END - Attach another .js file into this */

/********** STRT - Capture Mouse click position **********/
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// Temporary variables to hold mouse x-y pos.s
var mouseX = 0;
var mouseY = 0;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousedown = getMouseXY; // To test uncomment

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (IE) 
  { // grab the x-y pos.s if browser is IE
    //mouseX = event.clientX + document.body.scrollLeft
    //mouseY = event.clientY + document.body.scrollTop
    mouseX = window.event.x+document.documentElement.scrollLeft;
	mouseY = window.event.y+document.documentElement.scrollTop;
  } 
  else 
  {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
   
}
/********** END - Capture Mouse click position **********/


/**************** START - Show Tool Top ************/
var jsShowToolTip = true;

// fix value of a particular javascript variable
function FixValue(showTTip, val)
{
    jsShowToolTip = val;
}

// Used to show/hide an element
function ShowToolTip(id)
{
    //alert(id);
    if (jsShowToolTip) // if true then show else no
        document.getElementById(id).style.display==''?document.getElementById(id).style.display='none':document.getElementById(id).style.display='';
}
/**************** END - Show Tool Top ************/

// Used to show/hide an element
function ShowHide(id)
{
    document.getElementById(id).style.display==''?document.getElementById(id).style.display='none':document.getElementById(id).style.display='';
}

// Show/Hide element at mouse position
function ShowHideAtMousePosition(id)
{
    
    if (document.getElementById(id).style.display=='')
    {
        document.getElementById(id).style.display='none'
    }
    else
    {
        // take care of the mouse click, if it is in the rightmose side of the window
        var winWidth = document.body.clientWidth - 300;
        if (parseInt(mouseX) > parseInt(winWidth))
            mouseX = winWidth;
        mouseY += 10; // just display 10 px lower than actual clicked element otherwise that becomes hidden
        document.getElementById(id).style.display='';
        document.getElementById(id).style.left = mouseX + 'px';
        document.getElementById(id).style.top = mouseY + 'px';;
    }
}

// Toggle one element over another
function ShowMeHideAnother(mee, otherr)
{
    if (mee != vShowHideElementID) // if toShow id is different than earlier one than start fromt he begining
         { vvH = 0; vvW = 0; }
        
    if (document.getElementById(mee).style.display=='') // hide
    {
        //document.getElementById(mee).style.display='none'
        vShowHideElementID = mee; // store id into public variable
        vWidth1 = parseInt(document.getElementById(vShowHideElementID).style.width);
        vHeight1 = parseInt(document.getElementById(vShowHideElementID).style.height);
        
        vvH = vHeight1;
        
	    vHeight = vHeight1/vSplitter;
	    vWidth = vWidth1/vSplitter;
	    
	    vToShow = false;
        ShowHideWithAnimation();
        
    }
    else
    {
        
        // take care of the mouse click, if it is in the rightmose side of the window
        var winWidth = document.body.clientWidth - 300;
        if (parseInt(mouseX) > parseInt(winWidth))
            mouseX = winWidth;
        mouseY += 10; // just display 10 px lower than actual clicked element otherwise that becomes hidden
        
        document.getElementById(mee).style.left = mouseX + 'px';
        document.getElementById(mee).style.top = mouseY + 'px';;
        
        vShowHideElementID = mee; // store id into public variable
        document.getElementById(mee).style.display='';
        
        if (document.getElementById(mee).style.width == '')
        {
            vWidth1 = document.getElementById(vShowHideElementID).clientWidth;
            vHeight1 = document.getElementById(vShowHideElementID).clientHeight;
        }
        else
        {
            vWidth1 = parseInt(document.getElementById(vShowHideElementID).style.width);
            vHeight1 = parseInt(document.getElementById(vShowHideElementID).style.height);
        }
    
	    vHeight = vHeight1/vSplitter;
	    vWidth = vWidth1/vSplitter;
	    document.getElementById(vShowHideElementID).style.height = vHeight;
	    document.getElementById(vShowHideElementID).style.width = vWidth;
	    vToShow = true;
        ShowHideWithAnimation();
        
        // hide others
        document.getElementById(otherr).style.display='none';
        
    }
}

/****** START - Show/Hide with Animation *********/
var vTimer = 0;
var vWidth, vWidth1, vHeight, vHeight1, vvH = 0, vvW = 0;
var vShowHideElementID = '';
var vSplitter = 15;
var vToShow = true;
var vHowFast = 5;
var KeepItGoingTimer = 0;

// Show/Hide element with animation
// Zoom Out and Zoom In effect
function ShowHideWithAnimation()
{
	vTimer += 1;
   
    if (vToShow) // show
    {
        if (parseInt(vTimer) == parseInt(vSplitter))
        { 
            vTimer = 0; 
            document.getElementById(vShowHideElementID).style.height = vHeight1;
	        document.getElementById(vShowHideElementID).style.width = vWidth1;
            
            ClearTimeOutForTimer();
            return false; 
        }
	    vvH += parseInt(vHeight); //parseInt(vHeight*vTimer);
	    vvW += parseInt(vWidth);//parseInt(vWidth*vTimer);
	}
	else // hide
	{
	    if (parseInt(vTimer) == parseInt(vSplitter - 1))
		{ 
		    vTimer = 0; vvH = 0; vvW = 0;
		    document.getElementById(vShowHideElementID).style.display='none';
		    // make the width and height to the original one
		    document.getElementById(vShowHideElementID).style.height = vHeight1;
	        document.getElementById(vShowHideElementID).style.width = vWidth1;
		    
		    ClearTimeOutForTimer();		    
		    return false; 
		}
	    vvH -= parseInt(vHeight);
	    vvW -= parseInt(vWidth);
	    if (vvW < 1 || vvH < 1) // if element is too small and width or height is getting less than 0, make is 1
	    {
	        vvW = 1; vvH = 1;
	    }
	}
	
	document.getElementById(vShowHideElementID).style.height = vvH;
	document.getElementById(vShowHideElementID).style.width = vvW;
	
    KeepItGoingTimer = window.setTimeout("ShowHideWithAnimation()", vHowFast)
	
}

// Clear the timeout that has been used to animate
function ClearTimeOutForTimer()
{
    window.clearTimeout(KeepItGoingTimer);
    KeepItGoingTimer = 0;
    vHeight1 = 0;
    vHeight = 0;
    vvH = 0;
}

/****** END - Show/Hide with Animation *********/

/* START - Show/Hide Drop Effect */
// Used to show/hide an element
function ExpandShrinkDropEffect(id, idNotify, txt)
{
    // id cua the div dung de dong lai
    // idNotify cua hinh anh
    if (document.getElementById(id).style.display == '')
    {
        //document.getElementById(mee).style.display='none'
        vShowHideElementID = id; // store id into public variable
        vHeight1 = parseInt(document.getElementById(vShowHideElementID).style.height);
	    vHeight = vHeight1/vSplitter;
	    vvH = vHeight1;
	    vToShow = false;

        ShowAnimatedDropEffect();
    }
    else
    {
        document.getElementById(id).style.display='';
        vShowHideElementID = id; // store id into public variable
        if (document.getElementById(id).style.height == '')
        {
            vWidth1 = document.getElementById(vShowHideElementID).clientWidth;
            vHeight1 = document.getElementById(vShowHideElementID).clientHeight;
        }
        else
        {
            vWidth1 = parseInt(document.getElementById(vShowHideElementID).style.width);
            vHeight1 = parseInt(document.getElementById(vShowHideElementID).style.height);
        }
        vHeight = vHeight1/vSplitter;
        vWidth = vWidth1/vSplitter;
        document.getElementById(vShowHideElementID).style.height = vHeight;
	    
	    vToShow = true;
        ShowAnimatedDropEffect(); 
        
    }
}

function ShowAnimatedDropEffect()
{
    vTimer += 1;
	if (vToShow) // show
    {
        if (parseInt(vTimer) == parseInt(vSplitter))
        { 
            vTimer = 0; 
            document.getElementById(vShowHideElementID).style.height = vHeight1;
            
            ClearTimeOutForTimer();
            return false; 
        }
	    vvH += parseInt(vHeight);
	}
	else // hide
	{
	    if (parseInt(vTimer) == parseInt(vSplitter - 1))
		{ 
		    vTimer = 0; vvH = 0;
		    document.getElementById(vShowHideElementID).style.display='none';
		    // make the width and height to the original one
		    document.getElementById(vShowHideElementID).style.height = vHeight1;
		    
		    ClearTimeOutForTimer();
		    return false; 
		}
	    vvH -= parseInt(vHeight);
	    if (vvH < 1) // if element is too small and width or height is getting less than 0, make is 1
	    {
	        vvH = 1;
	    }
	}
	//alert(document.getElementById(vShowHideElementID).style.height);
	
	document.getElementById(vShowHideElementID).style.height = vvH;
	KeepItGoingTimer = window.setTimeout("ShowAnimatedDropEffect()", vHowFast)
}

/* END - Show/Hide Drop Effect */

// mostly used in CollapsePanelStart.ascx page and Show/Hide code
function ExpandShrink(id, idNotify,img_min,img_max)
{
    // id cua the div dung de dong lai
    // idNotify cua hinh anh
    // If no contents are in the panel, return        
    if (document.getElementById(id) == null)
        {
            alert(body_view);
            return;
        }
    
    // lay header cua part can the hien
    var webPartHeading = 'wPH' + id;
    // kiem tra xem id co bi an khong
    if (document.getElementById(id).style.display == '')
    {
        document.getElementById(id).style.display='none'        
        //document.getElementById(webPartHeading).className = 'WebPartHeadingCollapsed';
        document.getElementById(idNotify).src = img_max;        
    }
    else
    {
        document.getElementById(id).style.display='';
        
        //document.getElementById(webPartHeading).className = 'WebPartHeading';
        document.getElementById(idNotify).src = img_min;        
    }
}


//Just used to change the class of a particular object
function ChangeClass(obj, clas)
{
    obj.className = clas;
}



// Format selected text to the provided tag
function FormatText(tag, formatElement) 
{
    
    var el = document.getElementById(formatElement);
    var tagstart = '['+ tag + ']', tagend = '[/'+ tag + '] ';
    //alert(formatElement);
    if (el.setSelectionRange) 
    {
        
        if (el.selectionStart != el.selectionEnd) // if something is selected
            el.value = el.value.substring(0, el.selectionStart) + tagstart + el.value.substring(el.selectionStart, el.selectionEnd) + tagend + el.value.substring(el.selectionEnd, el.value.length)
        else
        {
            alert('Please select text to format.');
            return;
        }
    }
    else 
    {
        var selectedText = document.selection.createRange().text;
        if (selectedText != "") 
        {
            var newText = tagstart + selectedText + tagend;
            document.selection.createRange().text = newText;
        }
        else
        {
            alert('Please select text to format.');
            return;
        }
    }
}

/* JavaScript trim fucntion */
// Trim function in javascript 
function Trim(str)
{
    while (str.substring(0,1) == ' ') // check for white spaces
    {
        str = str.substring(1, str.length);
    }
    while (str.substring(str.length-1, str.length) == ' ')
    {
        str = str.substring(0,str.length-1);
    }
   
    return str;
}

// open new window with specified path, primarly used in PostArticle.aspx
function openWindow(url)
{
    newwindow = window.open(url, 'uploadedImage', 'width=500,height=400');
    newwindow.focus();
}

// Mouse Over effect
function M_O_O(t, clas)
{
    t.className = clas;
}

// Open a link in 

function openWindowAGV(id)
{
    urll = document.getElementById(id).value;
    if (urll.length <= 0)
    {
        alert('Please specify url to open.');
        return false;
    }
    newwindow = window.open(urll, 'durl');
    newwindow.focus();
}

//  CHANGE THEME //
function ChangeCSS(css)
{
    var cssid = document.getElementsByTagName("link");
    for (var i = 0; i < cssid.length ; i++)
    {
        if (cssid[i].type == 'text/css') // search only css link
        {
            cssid[i].href = "/App_Themes/"+ css;
        }
    }
    
    alert("Currently, Theme will change temporarily for this page. \nIt will not revert back again.");
}

// START - SILVER LIGHT BASE FUNCTION

function createSilverlightPlugin(placeHolder, width, height, xamlfile)
{  
    // Retrieve the div element you created in the previous step.
    var parentElement = document.getElementById(placeHolder);
    Silverlight.createObject
    (
        xamlfile,                       // Source property value.
        parentElement,                  // DOM reference to hosting DIV tag.
        placeHolder,                    // Unique plug-in ID value.
        {                               // Per-instance properties.
            width:width,                // Width of rectangular region of 
                                        // plug-in area in pixels.
            height:height,               // Height of rectangular region of 
                                        // plug-in area in pixels.
            inplaceInstallPrompt:false, // Determines whether to display 
                                        // in-place install prompt if 
                                        // invalid version detected.
            background:'#FFFFFF',       // Background color of plug-in.
            isWindowless:'false',       // Determines whether to display plug-in 
                                        // in Windowless mode.
            framerate:'24',             // MaxFrameRate property value.
            version:'1.0'               // Silverlight version to use.
        },
        {
            onError:null,               // OnError property value -- 
                                        // event handler function name.
            onLoad:null                 // OnLoad property value -- 
                                        // event handler function name.
        },
        null
    );                                  // Context value -- event handler function name.
}

// END - SILVERLIGHT BASE FUNCTION

// This is being used while posting the form, this will get the confirmation and if OK then disable the calling button
function GetConfirmationAndDisableButton(t)
{
    var v = confirm('Are you sure to proceed?');
    if (v)
    {
        //t.disabled = true;
        return true;
    }
    else
    {
        return false;
    }
}