﻿var bSubmitted = false;

function getImg(img, type, width, height)
{
    var path = "";
    var size = "";

    switch (type)
    {
        case "c":
            path = "/ClipArt/";
            break;

        case "b":
            return "<img src=\"thumbnail.ashx?img=" + img + "&size=300&type=b\" style=\"border-style: none;\" alt=\"\" />";
            break;

        case "t":
            return "<img src=\"thumbnail.ashx?img=" + img + "&size=250&type=t\" style=\"border-style: none;\" alt=\"\" />&nbsp;<img src=\"thumbnail.ashx?img=" + img + "&size=250&type=t2\" style=\"border-style: none;\" alt=\"\" />";
            break;

        case "s":
        case "i":
        case "f":
        case "r":
        case "e":
            return getSwf("swfPreview", img, 400, 320, true, type);
            break;
            
        case "cm":
            return getSwf("swfPreview", img, 400, 320, true, type);
            break;
            
        case "m":
            return getSwf("swfPreview", img, 400, 320, true, type);
            break;
            
        case "cs":
            return getSwf("swfPreview", img, 400, 320, true, type);
            break;
            
        case "fs":
            return getSwf("swfPreview", img, 400, 320, true, type, 9);
            break;

        case "x":
        case "ec":
            return getSwf("swfPreview", img, 400, 320, true, "ec");
            break;

        case "p":
            return getSwf("swfPreview", img, 400, 320, true, type, 9);
            break;
            
        case "n":
            return null;
            break;
    }

    if (width > height)
        size = "width: 300px";
    else
        size = "height: 300px";

    return "<img src=\"" + path + img + "\" style=\"border-style: none; " + size + "\" alt=\"\" />";
}

function getSwf(id, swf, width, height, playing, type)
{
    return getSwf(id, swf, width, height, playing, type, 8)
}

function getSwf(id, swf, width, height, playing, type, version)
{
    var protocol = "http";
    var rootPath = protocol + "://" + location.hostname;
    
    if (type == "direct")
        swf = swf;
    else if (type == "face")
        swf = rootPath + "/facepreview.ashx?id=" + swf;
    else if (type == "dialog")
        swf = rootPath + "/dialogpreview.ashx?id=" + swf;
    else if (type == "cs")
        swf = rootPath + "/getcustomtoon.ashx?id=" + swf + "&v=swf&dl=0";
    else if (type == "fs" || type == "r")
        swf = rootPath + "/getcustomtoon.ashx?face=1&id=" + swf + "&v=swf&dl=0&as=1";
    else if (type == "ec")
        swf = rootPath + "/getecard.ashx?id=" + swf + "&as=1";
    else
        swf = rootPath + "/toon.ashx?swf=" + swf + "&t=" + type;
    
    var ret =
        "<object " +
        "classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " +
        "codebase=\"" + protocol + "://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + version + ",0,0,0\" " +
        "id=\"" + id + "\" width=\"" + width + "\" height=\"" + height + "\">" +
        "<param name=\"movie\" value=\"" + swf + "\">" +
        "<param name=\"quality\" value=\"best\">" +
        "<param name=\"wmode\" value=\"opaque\">" +
        "<param name=\"scale\" value=\"showall\">" +
        "<param name=\"width\" value=\"" + width + "\">" +
        "<param name=\"height\" value=\"" + height + "\">" +
        "<param name=\"play\" value=\"" + (playing ? "true" : "false") + "\">" +
        "<param name=\"menu\" value=\"false\">" +
        "<embed wmode=\"opaque\" src=\"" + swf + "\" " +
        "quality=\"best\" scale=\"showall\" " +
        "play=\"" + (playing ? "true" : "false") + "\" menu=\"false\" " +
        "width=\"" + width + "\" height=\"" + height + "\" swliveconnect=\"true\" " +
        "type=\"application/x-shockwave-flash\" name=\"" + id + "\" " +
        "pluginspage=\"" + protocol + "://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">" +
        "</embed></object>";
    
    return ret;
}

function generateImage(file, desc, size, type)
{
    var img = new Image();
    var path = "";

    switch (type)
    {
        case "c":
            path = "/ClipArt/";
            break;

        case "b":
            path = "/Backgrounds/";
            break;
            
        case "t":
            path = "/Templates/";
            file = file + "_t.png";

        case "s":
            path = "/Snippets/";
            file = file + ".png"
            break;
    }
    
    img.src = path + file;
    
    var style = "border-style: none;";

    var height = img.height;
    var width = img.width;

    if (img.width > img.height)
        style += "width: " + size + "px;";
    else
        style += "height: " + size + "px;";

    var ret =
        '<img ' +
            'alt="' + desc + '" ' +
            'src="thumbnail.ashx?img=' + file + '&size=' + size + '&type=' + type + '" ' +
            'style="' + style + '" ' +
            'onmouseover="ddrivetip(getImg(\'' + file + '\',\'' + type + '\', this.width, this.height), \'#EFEFEF\')" ' +
            'onmouseout="hideddrivetip()" />';
    
    return ret;
}

function login()
{
    location.href = "https://" + location.host + "/login.aspx";
}

function logout()
{
    location.href = "https://" + location.host + "/login.aspx?logout=1";
}

function getCheckedValue(rad)
{
	for(var i = 0; i < rad.length; i++)
		if(rad[i].checked)
			return rad[i].value;
	
	return "";
}

function getEmbedObject(name)
{
	if (window.document[name]) 
	{
		return(window.document[name]);
	}
	else if (navigator.appName.indexOf("Microsoft Internet") == -1)
	{
		if (document.embeds[name])
			return(document.embeds[name]);
	}
	else if (navigator.appName.indexOf("Microsoft Internet") > -1)
	{
		return(document.getElementById(name));
	}
	else
	{
		return(null);
	}
}

function getObjectByName(name)
{
	if (document.getElementsByName)    	//IE 5+, NN 6+
	{
		return(document.getElementsByName(name));
	}
	else if (document.all)  			//IE 4
	{
		return(document.all[name]);
	}
	else if (document.layers)			//NN4
	{
	   	return(document.layers[name]);
	}
	else
	{
		return(null);
	}
}

function getObject(name)
{
	if (document.getElementById)    	//IE 5+, NN 6+
	{
		return(document.getElementById(name));
	}
	else if (document.all)  			//IE 4
	{
		return(document.all[name]);
	}
	else if (document.layers)			//NN4
	{
	   	return(document.layers[name]);
	}
	else
	{
		return(null);
	}
}

function checkSubmitted()
{
	if (!bSubmitted)
	{
		bSubmitted = true;
		return(true);
	}
	else
	{
		return(false);
	}
}

function toggleObject(obj)
{
    if (obj.style.display == 'block')
        obj.style.display = 'none';
    else
        obj.style.display = 'block';

    return true;
}

function doNothing()
{
	return;
}

function openSample(title)
{
    sampleWin = window.open('sample.aspx?width=700&height=350&title=' + escape(title), 'sample', 'width=710,height=400,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=no,resizable=no');
	sampleWin.focus();
}

function openSingleSample(title)
{
    sampleWin = window.open('sample.aspx?width=625&height=500&title=' + escape(title), 'sample', 'width=635,height=550,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=no,resizable=no');
	sampleWin.focus();
}

function openHowItWorks(title)
{
    worksWin = window.open('howitworkspop.aspx', 'howitworks', 'width=815,height=525,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=no,resizable=no');
	worksWin.focus();
}

function openSubscription(title)
{
    subWin = window.open('subscription.aspx', 'subscription', 'width=500,height=300,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=no,resizable=no');
	subWin.focus();
}

function openChecklist()
{
    clWin = window.open('pptchecklist.aspx', 'checklist', 'width=600,height=500,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=yes,resizable=yes');
	clWin.focus();
}

function openComparison(section)
{
    compWin = window.open('productgrid.aspx?section=' + section, 'comparison', 'width=825,height=575,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=yes,resizable=yes');
	compWin.focus();
}

function openCustomizer(id, type)
{
    custWin = window.open('trycustomize.aspx?id=' + id + '&type=' + type, 'customizer', 'width=700,height=575,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=yes,resizable=yes');
	custWin.focus();
}

function openYSSample(id)
{
    sampleWin = window.open('yssample.aspx?id=' + id, 'yssample', 'width=675,height=500,status=yes,location=no,menubar=no,personalbar=no,toolbar=no,scrollbars=no,resizable=no');
	sampleWin.focus();
}

function getScreenCenterY()
{
    return getScrollOffset() + (getInnerHeight() / 2);
}  
  
function getScreenCenterX()
{
    return document.body.clientWidth / 2;
}

function getInnerHeight()
{
    var y;  

    if (self.innerHeight) // all except Explorer
    {  
        y = self.innerHeight;  
    }  
    else if (document.documentElement &&
            document.documentElement.clientHeight)  // Explorer 6 Strict Mode  
    {  
        y = document.documentElement.clientHeight;  
    }  
    else if (document.body) // other Explorers  
    {  
        y = document.body.clientHeight;  
    }  
    
    return(y);  
}  
  
function getScrollOffset()
{
    var y;  

    if (self.pageYOffset) // all except Explorer  
    {  
        y = self.pageYOffset;  
    }  
    else if (document.documentElement &&
            document.documentElement.scrollTop)  // Explorer 6 Strict  
    {  
        y = document.documentElement.scrollTop;  
    }  
    else if (document.body) // all other Explorers  
    {  
        y = document.body.scrollTop;  
    }  

    return(y);  
}