﻿var intIsChanged = 0;

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 


/******************************************/
//  Flag comment form 

function FlagComment(CmntID, hFieldName, txtFC)
{
    var divBG = document.getElementById("divDB");
    var divFlanCmnt =  document.getElementById("divFlagCmnt");
    var aposition =  document.getElementById(CmntID);
    var txtFlagComment = document.getElementById(txtFC);
    var _hFieldCID = document.getElementById(hFieldName);
    
    _hFieldCID.value = CmntID;
    
    var loc = new Array();
    loc = findPos(aposition);
       
    divBG.className= 'showBG';
    divFlanCmnt.className = 'showFlagCmnt';
    divFlanCmnt.style.left = loc[0] + 'px';
    divFlanCmnt.style.top = loc[1] + 'px';
    document.forms[0].btnFlagCancel.focus();
    txtFlagComment.focus();

}

function hideFlagCmntForm()
{
    var divBG = document.getElementById("divDB");
    var divFlanCmnt =  document.getElementById("divFlagCmnt");
    
    divBG.className= 'hideBG';
    divFlanCmnt.className = 'hideFlagCmnt';
}

function hideFlagCmntFormSubmit()
{
    var divBG = document.getElementById("divDB");
    var divFlanCmnt =  document.getElementById("divFlagCmnt");
    
    divBG.className= 'hideBG';
    divFlanCmnt.className = 'hideFlagCmnt';
    
    alert('This comment has been flagged and will be reviewed.  Thank you.');
}

/************************************/


/************************************/
// Functions for Login Popup

function ShowPopupLoginForm(locationtag)
{
    var divLogin =  document.getElementById("divLogin");
    
    if(locationtag != '')
        var maindiv = document.getElementById(locationtag);
    else
        var maindiv = document.getElementById("maindiv");
    
    var divMDB = document.getElementById("divMDB");
    
    var loc = new Array();
    loc = findPos(maindiv);
    
    var intLeft = (720 / 2);
    
    if(locationtag != '')    
        var intTop = loc[1] - 200 ;
    else
        var intTop = 300  ;
        
    divMDB.className = 'showBG';
    divLogin.className = 'showLoginPopup';
    divLogin.style.left = intLeft + 'px';
    divLogin.style.top = intTop + 'px';
    document.forms[0].txtLoginUser.focus();

}

function HidePopupLoginForm()
{
    var divLogin =  document.getElementById("divLogin");
    var divMDB = document.getElementById("divMDB");
    
    divMDB.className= 'hideBG';
    divLogin.className = 'hideLoginPopup';
}




/************************************/
// Email to Friend Form

function ShowEmailFriendForm(txtTF)
{
    var divEmailFriend =  document.getElementById("divEmailFriend");
    var txtToField = document.getElementById(txtTF);
    var aposition =  document.getElementById("spanSendFriend");
    var divBG = document.getElementById("divDB");
    
    var loc = new Array();
    loc = findPos(aposition);
    
    var intleft = loc[0] - 400;
    var inttop = loc[1] - 335;
    
    divBG.className= 'showBG';
    divEmailFriend.className = 'showSendFriend';
    divEmailFriend.style.left = intleft + 'px';
    divEmailFriend.style.top = inttop + 'px';
    txtToField.focus();

}

function HideEmailFriendForm()
{
    var divEmailFriend =  document.getElementById("divEmailFriend");
    var divBG = document.getElementById("divDB");
    
    divBG.className= 'hideBG';
    divEmailFriend.className = 'hideSendFriend';
}

function HideEmailFriendFormSubmit()
{
    var divEmailFriend =  document.getElementById("divEmailFriend");
    var divBG = document.getElementById("divDB");
    
    divBG.className= 'hideBG';
    divEmailFriend.className = 'hideSendFriend';
    
    alert('An email has been sent to your friend about this blog post.');
}
/************************************/



function findPos(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return [curleft,curtop];
}

function infoChanged()
{
    intIsChanged = 1;
}

function checkIfChanged()
{
    if(intIsChanged == 1)
    {
        if(confirm('You have changed text on this post.  Your changes will not be saved if you navigate away from this page without saving.  Is this what you want to do? (Click OK to leave this page)') == true)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

