var iData = null;
var inverval = null;
var activeGallery = null;

function terms()
{
    var win = window.open('shop_enter.htm', '', 'toolbars=no,scrollbars=1,height=350,width=350');
}

function letMeIn()
{
    document.getElementById("cindies_enter").innerHTML = "<img src='images/spacer.gif' height='63' width='1'><br><a class='enter' href='http://shop.cindies.com/main.link/cfid/6114063/cftoken/ab9ca2dfd0b4ea64-E6BCFAD6-3048-71EC-193E27A81259D192' target='_blank'>ENTER</a><br><img src='images/spacer.gif' height='64' width='1'>";
}

function persistentDivs() {
    var div = document.getElementById("social");
    div.style.left = (pageWidth() / 2) + 400 + "px";
    div.style.top = "20px";
}

function submitComment()
{
    if ("" != document.getElementById("name").value) {
        if ("" != document.getElementById("email").value) {
            if ("" != document.getElementById("comment").value) {
                //var query = "email.php?name=" + document.getElementById("name").value + "&email=" + document.getElementById("email").value + "&comment=" + document.getElementById("comment").value;
                var query = "utility.aspx?reqtype=send&name=" + document.getElementById("name").value + "&email=" + document.getElementById("email").value + "&comment=" + document.getElementById("comment").value;
                serverCallBack(query);
                interval = setInterval("commentResp()", 100);
            }
            else {
                alert("You must include a comment or question to continue");
            }
        }
        else {
            alert("You must include your email address to continue");
        }
    }
    else {
        alert("You must include your name to continue");
    }
}
function commentResp()
{
    if(iData != null)
    {
        clearInterval(interval);
        
        if("true" == iData)
        {
            document.getElementById('name').value = "";
            document.getElementById('email').value = "";
            document.getElementById('comment').value = "";
            alert("Thank you for sharing your thoughts!\r\n\r\nIf you sent a question, we will respond as promptly as possible");
        }
        else
        {
            alert("An error occurred attemping to submit your request.");
        }
        
        iData = null;
    }
}
function modPhoto(gid, pid)
{
    var query = "utility.aspx?reqtype=mphoto&gid=" + gid + "&pid=" + pid;
    serverCallBack(query);
    interval = setInterval("modPhotoResp()", 100);
}
function modPhotoResp()
{
    if(iData != null)
    {
        clearInterval(interval);
        
        if("true" == iData)
        {
            alert("Photo was successfully modified");
        }
        else
        {
            alert("An error occurred attemping to submit your request.");
        }
        
        iData = null;
    }
}
function remPhoto(gid, pid)
{
    var query = "utility.aspx?reqtype=rphoto&gid=" + gid + "&pid=" + pid;
    serverCallBack(query);
    interval = setInterval("remPhotoResp()", 100);
}
function remPhotoResp()
{
    if(iData != null)
    {
        clearInterval(interval);
        
        if("true" == iData)
        {
            alert("Photo was successfully removed");
        }
        else
        {
            alert("An error occurred attemping to submit your request.");
        }
        
        iData = null;
    }
}
function getPictures(id)
{
    if(activeGallery != null && activeGallery != id)
    {
        document.getElementById("g_" + activeGallery + "_pics").innerHTML = "";
        document.getElementById("g_" + activeGallery + "_1").style.backgroundColor = "#B79667";
        document.getElementById("g_" + activeGallery + "_2").style.backgroundColor = "#B79667";
        document.getElementById("g_" + activeGallery + "_3").style.backgroundColor = "#B79667";
        
        document.getElementById("g_" + activeGallery).href = "javascript:getPictures('" + activeGallery + "');";
        document.getElementById("g_" + activeGallery).innerHTML = "show gallery";
        
        //document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").innerHTML = "";
                
        activeGallery = id;
    }
    else if(activeGallery == null)
    {
        //document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").innerHTML = "";
        activeGallery = id;
    }
    //else
    //{
    //    activeGallery = id;
    //}
    
    var query = "utility.aspx?reqtype=pictures&id=" + id;
    serverCallBack(query);
    interval = setInterval("showPictures()", 100);
}

function showPictures()
{
    if(iData != null)
    {
        clearInterval(interval);
        
        // 0 - gallery id | ? = pictures
        var pdata = iData.split('|');
        iData = null;
        
        var gdata = pdata[0].split(';');
        
        var imgData = pdata[1].split(';');
        var imgOneId = imgData[0];
        
        //var imgpath = document.getElementByid("ctl00$ContentPlaceholder$1_ipath").value;
        var display = "<table cellpadding='0' cellspacing='0' border='0' width='676'>";
        display += "<tr><td height='10' colspan='2'><img src='images/spacer.gif' height='10' width='1'></td></tr>";
        display += "<tr><td>";
        var j = 1;
        for(var i=1; i<pdata.length; i++)
        {   
            // 0 - id | 1 - file
            var picdata = pdata[i].split(';');
            if(j == 1)
            {
                display += "<a href=\"javascript:getPicture('" + gdata[0] + "','" + picdata[0] + "');\"><img id='img_g" + gdata[0] + "p" + picdata[0] + "' class='thumb' src='imgutility.aspx?size=atgt&img=" + picdata[1] + ".jpg' border='0'></a>";
                j++;
            }
            else if(j == 2 || j == 3 || j == 4 || j ==5)
            {
                display += "<img src='images/spacer.gif' width='7' height='1'><a href=\"javascript:getPicture('" + gdata[0] + "','" + picdata[0] + "');\"><img id='img_g" + gdata[0] + "p" + picdata[0] + "' class='thumb' src='imgutility.aspx?size=atgt&img=" + picdata[1] + ".jpg' border='0'></a>";
                j++;
            }
            else if(j == 6)
            {
                display += "<img src='images/spacer.gif' width='7' height='1'><a href=\"javascript:getPicture('" + gdata[0] + "','" + picdata[0] + "');\"><img id='img_g" + gdata[0] + "p" + picdata[0] + "' class='thumb' src='imgutility.aspx?size=atgt&img=" + picdata[1] + ".jpg' border='0'></a><br><img src='images/spacer.gif' height='5' width='1'><br>";
                j = 1;
            }
        }
        display += "</td></tr></table>";
        
        document.getElementById("g_" + activeGallery + "_pics").innerHTML = display;
        
        document.getElementById("g_" + activeGallery).href = "javascript:closeGallery();";
        document.getElementById("g_" + activeGallery).innerHTML = "close gallery";
        //getPicture(gdata[0],imgOneId);
    }
}

function getPicture(id, imgID)
{
    activeImage = imgID;
    var query = "utility.aspx?reqtype=picture&gallery=" + id + "&id=" + imgID;
    serverCallBack(query);
    interval = setInterval("showPicture()", 100);
}

function showPicture()
{
    if(iData != null)
    {
        clearInterval(interval);
        // 0 - description | 1 - file
        var pdata = iData.split(";");
        iData = null;
        
        var pdisplay = document.getElementById("photo_display");
        pdisplay.style.top = (posTop() + 100) + "px";
        pdisplay.style.left = (pageWidth() / 2) - 270 + "px";
        pdisplay.style.position = "absolute";
                
        var display = "<table cellpadding='0' cellspacing='0' border='0' width='540' bgcolor='#ffffff'>";
        display += "<tr>";
        display += "<td width='1' bgcolor='#000000' rowspan='9'><img src='images/spacer.gif' height='1' width='1'></td>";
        display += "<td width='538' height='1' bgcolor='#000000' colspan='3'><img src='images/spacer.gif' height='1' width='538'></td>";
        display += "<td width='1' bgcolor='#000000' rowspan='9'><img src='images/spacer.gif' height='1' width='1'></td>";
        display += "</tr>";
        display += "<tr>";
        display += "<td width='19' bgcolor='#ffffff' rowspan='7'><img src='images/spacer.gif' height='1' width='19'></td>";
        display += "<td height='9' width='500' bgcolor='#ffffff'><img src='images/spacer.gif' width='500' height='1'></td>";
        display += "<td width='19' bgcolor='#ffffff' rowspan='7'><img src='images/spacer.gif' height='1' width='19'></td>";
        display += "</tr>";
        display += "<tr><td bgcolor='#ffffff' align='center'><span style='font-size:10px;'>click image to close</span></td></tr>";
        display += "<tr><td height='5' bgcolor='#ffffff'><img src='images/spacer.gif' height='5' width='1'></td></tr>";
        display += "<tr><td bgcolor='#ffffff'><a href='javascript:close_photo();'><img src='imgutility.aspx?size=gp&img=" + pdata[1] + ".jpg' border='0'></a></td></tr>";
        display += "<tr><td height='5' bgcolor='#ffffff'><img src='images/spacer.gif' height='5' width='1'></td></tr>";
        display += "<tr><td align='center' bgcolor='#ffffff'><span><b>" + pdata[0] + "</b></span></td></tr>";
        display += "</tr>";
        display += "<tr>";
        display += "<td height='9' width='500' bgcolor='#ffffff'><img src='images/spacer.gif' width='500' height='1'></td>";
        display += "</tr>";
        display += "<tr>";
        display += "<td width='538' height='1' bgcolor='#000000' colspan='3'><img src='images/spacer.gif' height='1' width='538'></td>";
        display += "</tr>";
        display += "</table>";
        
        pdisplay.innerHTML = display;
        pdisplay.style.visibility = "visible";
        
        /*
        document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").innerHTML = display;
        //alert(posTop());
        if(360 < posTop()) {
            document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").style.top = posTop() + 50 + "px";
        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").style.top = "268px";
        }
        */
    }
}

function showPic(pic)
{
    var pdisplay = document.getElementById("photo_display");
    pdisplay.style.top = (posTop() + 100) + "px";
    pdisplay.style.left = (pageWidth() / 2) - 270 + "px";
    pdisplay.style.position = "absolute";
            
    var display = "<table cellpadding='0' cellspacing='0' border='0' width='540' bgcolor='#ffffff'>";
    display += "<tr>";
    display += "<td width='1' bgcolor='#000000' rowspan='9'><img src='images/spacer.gif' height='1' width='1'></td>";
    display += "<td width='538' height='1' bgcolor='#000000' colspan='3'><img src='images/spacer.gif' height='1' width='538'></td>";
    display += "<td width='1' bgcolor='#000000' rowspan='9'><img src='images/spacer.gif' height='1' width='1'></td>";
    display += "</tr>";
    display += "<tr>";
    display += "<td width='19' bgcolor='#ffffff' rowspan='7'><img src='images/spacer.gif' height='1' width='19'></td>";
    display += "<td height='9' width='500' bgcolor='#ffffff'><img src='images/spacer.gif' width='500' height='1'></td>";
    display += "<td width='19' bgcolor='#ffffff' rowspan='7'><img src='images/spacer.gif' height='1' width='19'></td>";
    display += "</tr>";
    display += "<tr><td bgcolor='#ffffff' align='center'><span style='font-size:10px;'>click image to close</span></td></tr>";
    display += "<tr><td height='5' bgcolor='#ffffff'><img src='images/spacer.gif' height='5' width='1'></td></tr>";
    display += "<tr><td bgcolor='#ffffff'><a href='javascript:close_photo();'><img src='imgutility.aspx?size=contact&img=" + pic + "_full.jpg' border='0'></a></td></tr>";
    display += "<tr><td height='5' bgcolor='#ffffff'><img src='images/spacer.gif' height='5' width='1'></td></tr>";
    display += "<tr><td align='center' bgcolor='#ffffff'>&nbsp;</td></tr>";
    display += "</tr>";
    display += "<tr>";
    display += "<td height='9' width='500' bgcolor='#ffffff'><img src='images/spacer.gif' width='500' height='1'></td>";
    display += "</tr>";
    display += "<tr>";
    display += "<td width='538' height='1' bgcolor='#000000' colspan='3'><img src='images/spacer.gif' height='1' width='538'></td>";
    display += "</tr>";
    display += "</table>";
    
    pdisplay.innerHTML = display;
    pdisplay.style.visibility = "visible";
    
    /*
    document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").innerHTML = display;
    //alert(posTop());
    if(360 < posTop()) {
        document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").style.top = posTop() + 50 + "px";
    }
    else {
        document.getElementById("ctl00_ContentPlaceHolder1_photodisplay").style.top = "268px";
    }
    */
}

function close_photo() {
    document.getElementById("photo_display").innerHTML = "";
    document.getElementById("photo_display").style.visible = "hidden";
}

function rollGallery(id, roll)
{
    if(id != activeGallery)
    {
        if(0 == roll)
        {   
            document.getElementById("g_" + id + "_1").style.backgroundColor = "#B79667";
            document.getElementById("g_" + id + "_2").style.backgroundColor = "#B79667";
            document.getElementById("g_" + id + "_3").style.backgroundColor = "#B79667";
        }
        else if(1 == roll)
        {
            document.getElementById("g_" + id + "_1").style.backgroundColor = "#986A3D";
            document.getElementById("g_" + id + "_2").style.backgroundColor = "#986A3D";
            document.getElementById("g_" + id + "_3").style.backgroundColor = "#986A3D";
        }
    }
}

function closeGallery()
{
    document.getElementById("g_" + activeGallery).href = "javascript:getPictures('" + activeGallery + "');";
    document.getElementById("g_" + activeGallery).innerHTML = "show gallery";
    
    document.getElementById("g_" + activeGallery + "_pics").innerHTML = "";
    document.getElementById("g_" + activeGallery + "_1").style.backgroundColor = "#B79667";
    document.getElementById("g_" + activeGallery + "_2").style.backgroundColor = "#B79667";
    document.getElementById("g_" + activeGallery + "_3").style.backgroundColor = "#B79667";
    document.getElementById("photo_display").innerHTML = "";
    activeGallery = null;
}
function serverCallBack(query)
{
    // for non-IE browsers
    if(window.XMLHttpRequest)
    {
        http_req = new XMLHttpRequest();
    }
    // IE
    else if(window.ActiveXObject)
    {
        try
        {
	        http_req = new ActiveXObject("Msxml12.XMLHTTP");
        }
        catch(e)
        {
	        try
	        {
		        http_req = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        catch(e)
	        {
	        }
        }
    }
    // verify the request variable is set
    if(!http_req)
    {
        return false;
    }
    else
    {
        // continue processing
        http_req.onreadystatechange = function()
        {
	        if(http_req.readyState == 4)
	        {
		        if(http_req.status == 200)
		        {
			        iData = http_req.responseText;	
		        }
		        else
		        {
			        return false;
		        }
	        }
        }
        http_req.open('GET', query, true);
        http_req.send(null);
    }	
}