function announceAjax() {
    
        if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
                receiveReq.open("GET", "/forum/index.php?act=UserCP&CODE=76", true);
                receiveReq.send(null);
         
        }

}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function getXmlHttpRequestObject() {
        if (window.XMLHttpRequest) {
                return new XMLHttpRequest(); //Not IE
        } else if(window.ActiveXObject) {
                return new ActiveXObject("Microsoft.XMLHTTP"); //IE
        } else {
                alert("Your browser doesn't support the XmlHttpRequest object. Better switch to FireFox.");
        }
}

var receiveReq = getXmlHttpRequestObject();
    
function handleXMLResponse() {
        // This function lets us update multiple elements on the page based on dynamic
        // data from the server-side. We can use this to update 1 or 1 million things.
        // use PHP's urlencode() on HTML that is returned in the <inrhtml> tag.
        // this keeps the script from thinking the new HTML is actually part of the XML structure.
        // we'll then decode it, and insert it into the element from the <element> tag.
        
        //apparently responseXML is buggy, so we have to reparse on client end. this doesn't work in IE!
        
        if (receiveReq.readyState == 4 && document.getElementById) {
            var el = null;
            var ih = null;
            var respXML = (new DOMParser()).parseFromString(receiveReq.responseText, "text/xml");
            
            alert(respXML);
            if (respXML) {
            var respTags = respXML.getElementsByTagName("result");
            for (i = 0; i < respTags.length; i++) {
                el = respTags.item(i).getElementsByTagName("element").item(0).firstChild.nodeValue;
                ih = respTags.item(i).getElementsByTagName("inrhtml").item(0).firstChild.nodeValue;

                while(ih.indexOf("+") > -1) {
                    ih = ih.replace("+", " ");
                }
                
                ih = unescape(ih);
            
                if (document.getElementById) {
                    document.getElementById(el).innerHTML = ih;   
                }
                
            }
            }
        }
}

function handleRateResponse() {
        
        if (receiveReq.readyState == 4 && document.getElementById) {
                
                //locate the elements
                var rstars = document.getElementById("ratestarswrap");
                var trate = document.getElementById("totalrate");
                
                //parse the response since we can't use XML.
                var respText = receiveReq.responseText.split("::::::");
                
                //update the HTML
                if (respText[1] == "error") {
                        rstars.innerHTML = "An error occurred.";
                } else {
                        trate.innerHTML = respText[0];
                        rstars.innerHTML = respText[1];
                }

            
        }        
}

//contact page
function checkcontactform() {
   
   var errmsg = "";
   var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  
   if (document.getElementById) {
        
        document.getElementById("email").value = trim(document.getElementById("email").value);
        
        if (document.getElementById("email").value == "") {
            
            errmsg = "Please enter a valid email.";
            
        } else if (filter.test(document.getElementById("email").value) == false) {
            
            errmsg = "Please enter a valid email.";
        
        }
        
        if (document.getElementById("message").value == "") {
            
            errmsg = "You must enter a message.";
            
        }
        
        if (document.getElementById("category").value == "") {
            
            errmsg = "You must select a category";
            
        }
        
   }
   
   if (errmsg != "") {
    alert(errmsg);
    return false;
   } else {
    return true;
   }
   
}

//PHOTO ALBUMS
function uploadphoto() {
	
	if(document.getElementById) {
	
		if(document.getElementById("Filedata").value == "") {alert("You must select a file.");return false;}
		
		else {
			
		var upbtn = document.getElementById("uploadbtn");
		
		upbtn.disabled = true;
		upbtn.style.color = "#cccccc";
		upbtn.value = "Uploading..."

		return true;
	
		}
			
	} else {
		return false;
	}
	
}
function thumbhover(path) {
    if (document.getElementById) {
        
        var prebox = document.getElementById('photo-preview');
    
        var pimg = document.createElement("img");
        
        pimg.setAttribute("src", path);
        pimg.setAttribute("alt", "Image Preview");
        pimg.setAttribute("id","preview-photo");        
        prebox.appendChild(pimg);
        prebox.removeChild(prebox.firstChild);
    }
}

function hidePhotoCommentBox() {
    
    var divElement = document.getElementById("leavecomment");
    var formElement = document.getElementById("commentform");
    
    divElement.style.display = "none";
    while (formElement.childNodes.length > 0) {
        formElement.removeChild(formElement.firstChild);
    }
        
    divElement.removeChild(formElement);
}

function showPhotoCommentBox(mid, pid) {
    
    var divElement = document.getElementById("leavecomment");
    var formElement = document.getElementById("commentform");
    
    if (formElement) {
       
       hideCommentBox();
       
    } else {
        
        divElement.style.display = "block";
        
        var newFormField = document.createElement("form");
        newFormField.setAttribute("id", "commentform");
        newFormField.setAttribute("name", "commentform");
        newFormField.setAttribute("method", "post");
        newFormField.setAttribute("action", "/forum/index.php");
        divElement.appendChild(newFormField);
        
        var newInputField = document.createElement("input");
        newInputField.setAttribute("type", "hidden");
        newInputField.setAttribute("id", "act");
        newInputField.setAttribute("name", "act");
        newInputField.setAttribute("value", "Comment");
        newFormField.appendChild(newInputField);
        
        var newInputField2 = document.createElement("input");
        newInputField2.setAttribute("type", "hidden");
        newInputField2.setAttribute("id", "code");
        newInputField2.setAttribute("name", "code");
        newInputField2.setAttribute("value", "12");
        newFormField.appendChild(newInputField2);
        
        var newInputField3 = document.createElement("input");
        newInputField3.setAttribute("type", "hidden");
        newInputField3.setAttribute("id", "id");
        newInputField3.setAttribute("name", "id");
        newInputField3.setAttribute("value", mid);
        newFormField.appendChild(newInputField3);

        var newInputField4 = document.createElement("input");
        newInputField4.setAttribute("type", "hidden");
        newInputField4.setAttribute("id", "id");
        newInputField4.setAttribute("name", "pid");
        newInputField4.setAttribute("value", pid);
        newFormField.appendChild(newInputField4);
        
        var newBox = document.createElement("textarea");
        newBox.setAttribute("id", "comment");
        newBox.setAttribute("name", "comment");
        newBox.setAttribute("onClick","this.value=''");
        newBox.value = "Leave a comment on this photo.";
        newBox.className = "textarea";
        newFormField.appendChild(newBox);
        
        var newButton = document.createElement("input");
        newButton.setAttribute("type", "submit");
        newButton.setAttribute("id", "submitbtn");
        newButton.setAttribute("name", "submitbtn");
        newButton.setAttribute("value", "Leave Comment");
        newButton.className = "button";
        newFormField.appendChild(newButton);
        
        var clearDiv = document.createElement("div");
        clearDiv.setAttribute("class", "cleardiv");
        clearDiv.className = "cleardiv";
        divElement.appendChild(clearDiv);
        
    }
    
}

//PICTURES PAGE
function SetPicRate(vid, rate) {
        
        if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
                receiveReq.open("GET", "/forum/index.php?act=daily_image&vid=" + vid + "&rate=" + rate, true);
                receiveReq.onreadystatechange = handleRateResponse;
                receiveReq.send(null);
        }
}

//VIDEO PAGE
function SetRate(vid, rate) {
        
        if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
                receiveReq.open("GET", "/forum/index.php?act=videos&rateit=1&vid=" + vid + "&rate=" + rate, true);
                receiveReq.onreadystatechange = handleRateResponse;
                receiveReq.send(null);
        }
}

function hoverRateStar(id) {
    var maxstars = 5;
    
    if (document.getElementById) {

        for (i=1; i<=id; i++) {
            document.getElementById('ratestar' + i).className = "ratestar-red";
        }
        
        if (id < maxstars) {
            for (i=(id + 1); i<=maxstars; i++) {
               document.getElementById('ratestar' + i).className = "ratestar"; 
            }
        }
        
    }
}
function clearRateStars() {
      var maxstars = 5;
    
    if (document.getElementById) {
        
        for (i=1; i<=maxstars; i++) {
            document.getElementById('ratestar' + i).className = "ratestar";
        }
    }
}

function videohover(id) {
        if (document.getElementById) {		
                recentli = document.getElementById("recentli" + id);
                recentli.style.backgroundColor = "#ffffff";
        }

} 

function videohoverout(id) {
        if (document.getElementById) {
                recentli = document.getElementById("recentli" + id);
                recentli.style.backgroundColor = "#f0f0f0";
        }		
}

function showRelated() {
        if (document.getElementById) {		
                related = document.getElementById("otherrelated");
                random = document.getElementById("otherrandom");
                web = document.getElementById("otherweb");
                
                crelated = document.getElementById("chooserelated");
                crandom = document.getElementById("chooserandom");
                cweb = document.getElementById("chooseweb");
                
                crelated.style.fontWeight = "bold";
                crandom.style.fontWeight = "normal";
                cweb.style.fontWeight = "normal";
                
                related.style.display = "block";
                random.style.display = "none";
                web.style.display = "none";
        }
}

function showRandom() {
        if (document.getElementById) {		
                related = document.getElementById("otherrelated");
                random = document.getElementById("otherrandom");
                web = document.getElementById("otherweb");
                
                crelated = document.getElementById("chooserelated");
                crandom = document.getElementById("chooserandom");
                cweb = document.getElementById("chooseweb");
                
                if(crelated) {crelated.style.fontWeight = "normal"};
                crandom.style.fontWeight = "bold";
                cweb.style.fontWeight = "normal";
                
                related.style.display = "none";
                random.style.display = "block";
                web.style.display = "none";
        }
}

function showWeb() {
        if (document.getElementById) {		
                related = document.getElementById("otherrelated");
                random = document.getElementById("otherrandom");
                web = document.getElementById("otherweb");
                
                crelated = document.getElementById("chooserelated");
                crandom = document.getElementById("chooserandom");
                cweb = document.getElementById("chooseweb");
                
                if(crelated) {crelated.style.fontWeight = "normal"};
                crandom.style.fontWeight = "normal";
                cweb.style.fontWeight = "bold";
                
                related.style.display = "none";
                random.style.display = "none";
                web.style.display = "block";
        }
}

function videoAds() {        
   $('#videoads').toggle();
}
function videoAdsClose() {
    $('#videoads').hide();
}
//INVITE PAGE
 function addinvitee(email) {

    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
    if (filter.test(email) == false) {
	
        alert("That email address is invalid.");
        return false;
    
    } else {
        
        var divElement = document.getElementById("invite-status");
        //var lpid = divElement.lastchild.id;
        //var lpidarr = lpid.split("-");
        //var pid = lpidarr[1] + 1;
        var pid = 2;
        var newP = divElement.createElement("p");
        newP.setAttribute("id","p-" + pid);
        divElement.appendChild(newP);
        
    }
}

//PROFILE COMMENTS
function hideCommentBox() {
    
    var divElement = document.getElementById("leavecomment");
    var formElement = document.getElementById("commentform");
    
    divElement.style.display = "none";
    while (formElement.childNodes.length > 0) {
        formElement.removeChild(formElement.firstChild);
    }
        
    divElement.removeChild(formElement);
}

function showCommentBox(mid, name) {
    
    var divElement = document.getElementById("leavecomment");
    var formElement = document.getElementById("commentform");
    
    if (formElement) {
       
       hideCommentBox();
       
    } else {
        
        divElement.style.display = "block";
        
        var newFormField = document.createElement("form");
        newFormField.setAttribute("id", "commentform");
        newFormField.setAttribute("name", "commentform");
        newFormField.setAttribute("method", "post");
        newFormField.setAttribute("action", "/forum/index.php");
        divElement.appendChild(newFormField);
        
        var newInputField = document.createElement("input");
        newInputField.setAttribute("type", "hidden");
        newInputField.setAttribute("id", "act");
        newInputField.setAttribute("name", "act");
        newInputField.setAttribute("value", "Comment");
        newFormField.appendChild(newInputField);
        
        var newInputField2 = document.createElement("input");
        newInputField2.setAttribute("type", "hidden");
        newInputField2.setAttribute("id", "code");
        newInputField2.setAttribute("name", "code");
        newInputField2.setAttribute("value", "02");
        newFormField.appendChild(newInputField2);
        
        var newInputField3 = document.createElement("input");
        newInputField3.setAttribute("type", "hidden");
        newInputField3.setAttribute("id", "id");
        newInputField3.setAttribute("name", "id");
        newInputField3.setAttribute("value", mid);
        newFormField.appendChild(newInputField3);
        
        var newBox = document.createElement("textarea");
        newBox.setAttribute("id", "comment");
        newBox.setAttribute("name", "comment");
        newBox.className = "textarea";
        newFormField.appendChild(newBox);
        
        var newButton = document.createElement("input");
        newButton.setAttribute("type", "submit");
        newButton.setAttribute("id", "submitbtn");
        newButton.setAttribute("name", "submitbtn");
        newButton.setAttribute("value", "Leave Comment");
        newButton.className = "button";
        newFormField.appendChild(newButton);
        
        var clearDiv = document.createElement("div");
        clearDiv.setAttribute("class", "cleardiv");
        clearDiv.className = "cleardiv";
        divElement.appendChild(clearDiv);
        
    }
    
}

//school comments
function showSchoolCommentBox() {
    
    var divElement = document.getElementById("leavecomment");
    var formElement = document.getElementById("commentform");
    
    if (formElement) {
       
       hideCommentBox();
       
    } else {
        
        divElement.style.display = "block";
        
        var newFormField = document.createElement("form");
        newFormField.setAttribute("id", "commentform");
        newFormField.setAttribute("name", "commentform");
        newFormField.setAttribute("method", "post");
        newFormField.setAttribute("action", "/forum/index.php");
        divElement.appendChild(newFormField);
        
        var newInputField = document.createElement("input");
        newInputField.setAttribute("type", "hidden");
        newInputField.setAttribute("id", "act");
        newInputField.setAttribute("name", "act");
        newInputField.setAttribute("value", "Comment");
        newFormField.appendChild(newInputField);
        
        var newInputField2 = document.createElement("input");
        newInputField2.setAttribute("type", "hidden");
        newInputField2.setAttribute("id", "code");
        newInputField2.setAttribute("name", "code");
        newInputField2.setAttribute("value", "07");
        newFormField.appendChild(newInputField2);
        
        var newBox = document.createElement("textarea");
        newBox.setAttribute("id", "comment");
        newBox.setAttribute("name", "comment");
        newBox.className = "textarea";
        newFormField.appendChild(newBox);
        
        var newButton = document.createElement("input");
        newButton.setAttribute("type", "submit");
        newButton.setAttribute("id", "submitbtn");
        newButton.setAttribute("name", "submitbtn");
        newButton.setAttribute("value", "Post Comment");
        newButton.className = "button";
        newFormField.appendChild(newButton);
        
        var clearDiv = document.createElement("div");
        clearDiv.setAttribute("class", "cleardiv");
        clearDiv.className = "cleardiv";
        divElement.appendChild(clearDiv);
        
    }
    
}

/*upload page*/
function hideUpload() {
    var divElement = document.getElementById("uploadmedia");
    var fieldElement = document.getElementById("uploadstep2");
    
    divElement.style.display = "none";
    while (fieldElement.childNodes.length > 0) {
        fieldElement.removeChild(fieldElement.firstChild);
    }
        
    divElement.removeChild(fieldElement);
}

function uploadVideo() {
    
    if (document.getElementById) {
     
        var divElement = document.getElementById("uploadmedia");
        var fieldElement = document.getElementById("uploadstep2");
    
        if (fieldElement) {
       
                hideUpload();
       
        } else {
                divElement.style.display = "block";
                
                var newFieldset = document.createElement("fieldset");
                newFieldset.setAttribute("class", "user-cp");
                newFieldset.setAttribute("id", "uploadstep2");
                divElement.appendChild(newFieldset);
                                
                var newLegend = document.createElement("legend");
                newLegend.innerHTML = "Step 2";
                newFieldset.appendChild(newLegend);

                var newPDetails = document.createElement("p");
                newPDetails.appendChild(document.createTextNode("Please select a file to upload."));
                newFieldset.appendChild(newPDetails);

                var newPDetails2 = document.createElement("p");
                newPDetails2.appendChild(document.createTextNode("Max file size: 30MB. Allowed file types: .flv, .wmv, .mpg, .avi, .mpeg, .mov"));
                newFieldset.appendChild(newPDetails2);
                
                var newSWFdiv = document.createElement("div");
                newSWFdiv.setAttribute("id","SWFUploadFileListingFiles");
                newFieldset.appendChild(newSWFdiv);
               
                var clearDiv = document.createElement("div");
                clearDiv.setAttribute("class", "cleardiv");
                clearDiv.className = "cleardiv";
                newFieldset.appendChild(clearDiv);

        
        }
            
    }
}

/*search page*/
function showSearchPictures() {
	
	if (document.getElementById) {
		var vidtab = document.getElementById('video-results');
		var pictab = document.getElementById('pic-results');
		var vidbox = document.getElementById('vid-search-results');
		var picbox = document.getElementById('pic-search-results');
		
		vidtab.className = "unselected";
		pictab.className = "selected";
		vidbox.style.display = "none";
		picbox.style.display = "block";
	}
	
}

function showSearchVideos() {
	
	if (document.getElementById) {
		var vidtab = document.getElementById('video-results');
		var pictab = document.getElementById('pic-results');
		var vidbox = document.getElementById('vid-search-results');
		var picbox = document.getElementById('pic-search-results');
		
		pictab.className = "unselected";
		vidtab.className = "selected";
		picbox.style.display = "none";
		vidbox.style.display = "block";
	}
	
}

	// daily images
	var $dailyimgcontainer = $('.dailyimage-container'),
		$thumbs = $dailyimgcontainer.find('.prevnextthumbs');
	
//	var i = 0;
//	$dailyimgcontainer.mouseover(
//		function() { $thumbs.fadeIn('fast'); }
//	);
//
//	$dailyimgcontainer.mouseout(
//		function() { $thumbs.fadeOut('fast'); }
//	);
//
	$dailyimgcontainer.hover(
		function() { $thumbs.fadeIn('fast'); },
		function() { $thumbs.fadeOut('fast'); }
	);


var awePuShown = false;

function aweDoOpen(url)
{
    if ( awePuShown === true )
    {
        return true;
    }

    var aweWindow = window.open(url, "plPu", "toolbar,status,resizable,scrollbars,menubar,location,height=710,width=800");
    window.setTimeout(window.focus, 500 );

    if ( aweWindow )
    {
        aweWindow.blur();
        awePuShown = true;
    }
    
    return aweWindow;
}


function aweSetCookie(name, value, time)
{
    var expires = new Date();

    expires.setTime( expires.getTime() + time );

    document.cookie = name + "=" + value + "; expires=" + expires.toGMTString() + "; path=/";
}


function aweGetCookie(name)
{

    var cookies = document.cookie.toString().split('; ');
    var cookie, c_name, c_value;

    for (var n=0; n<cookies.length; n++)
    {
        cookie  = cookies[n].split("=");
        c_name  = cookie[0];
        c_value = cookie[1];

        if ( c_name == name )
        {
            return c_value;
        }
    }

    return null;
}


function aweCheckTarget(e)
{
    var cookieValue = aweGetCookie("popundrf");
    var isRefDenied = aweCheckIsRefDenied();

    if ( isRefDenied === true )
    {
        aweSetCookie("popundrf", 1, 60*60*1000);
        return ;
    }

    if ( cookieValue === null )
    {
        aweDoOpen("http://www.facebook.com/pages/First-20000-Fans-Get-a-1000-Home-Depot-Gift-Card/328219849764?v=app_4949752878");

        aweSetCookie("popundrf", 1, 24*60*60*1000);
    }
}


function aweCheckIsRefDenied()
{ 
       return false;
}


function aweInitPu()
{
    if ( document.attachEvent )
    {
        document.attachEvent( "onclick", aweCheckTarget );
    }
    else if ( document.addEventListener )
    {
        document.addEventListener( "click", aweCheckTarget, false );
    }
}

//aweInitPu();


