var xmlHttp;
	
function SendEmail(emailTo, emailBody, emailSubject, emailFromRealName, emailFromEmailAddress)
{   
    if (emailTo.length==0 || emailBody.length==0 || emailSubject.length==0 || emailFromRealName.length==0 || emailFromEmailAddress.length==0)
    { 
        return;
    }
      
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/sendEmail.asp";
    url=url+"?emailTo="+emailTo;
	url=url+"&emailBody="+emailBody;
	url=url+"&emailSubject="+emailSubject;
	url=url+"&emailFromRealName="+emailFromRealName;
	url=url+"&emailFromEmailAddress="+emailFromEmailAddress;	
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "SendEmail");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function ShortUrl(longUrl)
{   
    if (longUrl.length==0)
    { 
        return;
    }
      
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 
    
    var url="ajax/ShortUrl.asp";
    url=url+"?longUrl="+longUrl;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "ShortUrl");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function PostTweet(newStatus)
{   
    if (newStatus.length==0)
    { 
        return;
    }
      
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/TwitPost.asp";
    url=url+"?newStatus="+newStatus;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "PostTweet");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function CookieMod(addCookie, cookieKey, cookieVal, cookieExp)
{
    if (addCookie.length==0 || cookieKey.length==0 || cookieVal.length==0)
    { 
        return;
    }
      
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/Cookie.asp";
    url=url+"?addCookie="+addCookie;
    url=url+"&cookieKey="+cookieKey;
    url=url+"&cookieValue="+cookieVal;
    url=url+"&cookieExp="+cookieExp;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "cookieAction");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function ShowRSSFeeds()
{         
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/Rss.asp";
    url=url+"?sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "miscDbInfo");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function ShowMostViewedImages(numImages)
{   
    if (numImages.length==0)
    { 
        return;
    }
        
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/MostViewedImages.asp";
    url=url+"?numImages="+numImages;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "miscDbInfo");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}

function ShowRandomImages(numImages)
{   
    if (numImages.length==0)
    { 
        return;
    }
        
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/RandomImages.asp";
    url=url+"?numImages="+numImages;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "miscDbInfo");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}


function ShowRecentComments(numComments)
{   
    if (numComments.length==0)
    { 
        return;
    }
        
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/RecentComments.asp";
    url=url+"?numComments="+numComments;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "miscDbInfo");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}


function IncrementPictureViewed(permId)
{
    if (permId.length==0)
    { 
        return;
    }
        
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/incrementPictureViewed.asp";
    url=url+"?permId="+permId;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "incrementPictureViewed");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}


function RemoveUser(userId,userName)
{
    if (userId.length==0 || userName.length==0)
    { 
        return;
    }
    
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/removeUser.asp";
    url=url+"?userId="+userId;
    url=url+"&userName="+userName;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "removeUser");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);    
}


function InsertRating(PermID,thumb,UserID,thumbsDown,thumbsUp)
{
    if (PermID.length==0 || thumb.length==0 || UserID.length==0 || thumbsDown.length==0 || thumbsUp.length==0)
    { 
        return;
    }
    
    xmlHttp=GetXmlHttpObject();

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url="ajax/insertRating.asp";
    url=url+"?PermID="+PermID;
    url=url+"&thumb="+thumb;
    url=url+"&UserID="+UserID;
    url=url+"&thumbsDown="+thumbsDown;
    url=url+"&thumbsUp="+thumbsUp;
    url=url+"&sid="+Math.random();
    interrupt(xmlHttp, stateChanged, "insertRating");
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 


function interrupt(xmlHttp, doFunc, divId)
{
    xmlHttp.onreadystatechange=function() { doFunc(xmlHttp, divId); }
}


function stateChanged(xmlHttp, divId) 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        document.getElementById(divId).innerHTML=xmlHttp.responseText;
    } 
}


function GetXmlHttpObject()
{
    var xmlHttp=null;

    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
