﻿function popIt(width, height, scrollbars, pname, url) {
    if (!width) width = "500";
    if (!height) height = "500";
    if (!scrollbars) scrollbars = 1;
    var windowString = 'width=' + width + ',height=' + height + ',resizable=0,status=0,toolbar=no,scrollbars=' + scrollbars + ',scrolling=auto';
    var popItWindow = window.open(url, pname, windowString);
    return false;
}

function popup(location) {
    var page = "http://www.americanapparel.ca/";
    page += location;
    windowprops = "width=600,height=600,location=no,scrollbars=yes,menubars=no,toolbars=no,resize=yes";
    window.open(page, "Popup", windowprops);
}

function popUpSize(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=558,height=575,left = 490,top = 362');");
}

function popupWin(location) {
    var page = "http://www.americanapparel.net/sizing_charts/";
    page += location;
    page += "_sc.html";
    windowprops = "width=300,height=200,location=no,scrollbars=no,menubars=no,toolbars=no";
    window.open(page, "Popup", windowprops);
}

function popupStylespreview(style, name, p) {
    var page = "http://www.americanapparel.net/morephotos/viewer.asp?style=";
    page += style;
    page += "&n=";
    page += name;
    if (p) page += "&p=" + p;
    windowprops = "width=449,height=411,location=no,scrollbars=no,menubars=no,toolbars=no,resize=yes";
    var pop = window.open(page, "Popup", windowprops);
    pop.focus();
}

function popuphowto(style, name) {
    var page = "http://www.americanapparel.net/storefront/howtowear/viewer.asp?style=";
    page += style;
    page += "&n=";
    page += name
    windowprops = "width=449,height=450,location=no,scrollbars=no,menubars=no,toolbars=no,resize=yes";
    window.open(page, "Popup", windowprops);
}
function clearfield(val, text) {
    if (val.value == text)
        val.value = "";
    val.style.color = "#333333";
}

function popupVideopreview(location) {
    var page = "http://www.americanapparel.net/storefront/movies/";
    page += location;
    page += "/";
    windowprops = "width=331,height=360,location=no,scrollbars=no,menubars=no,toolbars=no,resize=yes";
    window.open(page, "testmovie", windowprops);
}

function popupVideopreview2(location) {
    var page = "http://www.americanapparel.net/storefront/movies/";
    page += location;
    page += "/";
    windowprops = "width=331,height=380,location=no,scrollbars=no,menubars=no,toolbars=no,resize=yes";
    window.open(page, "testmovie", windowprops);
}

function popupProdinfo(location) {
    var page = "http://www.americanapparel.net/storefront/productinfo/";
    page += location;
    windowprops = "width=475,height=300,location=no,scrollbars=yes,menubars=no,toolbars=no,resize=yes";
    window.open(page, "prodinfo", windowprops);
}

function SwitchLanguages(lid) {
    setCookie('aalang', lid, null);
    window.location.reload(true);
}
function StoreSearch(text) {
    if (ValidateAndClearSearchCookies(text)) { 
        document.storeSearch.submit();
    }
}
function ValidateAndClearSearchCookies(text) {
    var txt = document.storeSearch.s.value;
    if (txt == text || txt.length < 1) {
        return false;
    }
    else{
        setCookie('aaSort', '', 1);
        setCookie('aaRoot', '', 1);
        setCookie('aaGCol', '', 1);
        setCookie('aaPage', '', 1);
        return true;
    }
}
function ClearFilters() {
    setCookie('aaSort', '', 1);
    setCookie('aaGCol', '', 1);
    setCookie('aaFabr', '', 1);
    setCookie('aaFits', '', 1);
}
function AddOnload(myfunc) {
    if (window.addEventListener)
        window.addEventListener('load', myfunc, false);
    else if (window.attachEvent)
        window.attachEvent('onload', myfunc);
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
      ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function getQueryStringValue(key) {
    var val = ''
    var url = parent.document.URL;
    var i0 = url.indexOf('&' + key + '=')
    if (i0 < 0) {
        i0 = url.indexOf('?' + key + '=')
    }
    if (i0 > -1) {
        i0 += key.length + 2;
        var i1 = url.indexOf('&', i0);
        if (i1 < 0) {
            i1 = url.length;
        }
        val = url.substring(i0, i1);
    }
    return val;
}
function SetOpacity(object, oValue) {
    object.style.filter = 'alpha(opacity=' + oValue + ')';
    object.style.MozOpacity = oValue / 100;
    object.style.opacity = oValue / 100;
}
function BlendOpacity(id, msDuration, msStart, t0, t1) {
    var element = document.getElementById(id);
    var opacity = element.style.opacity * 100;
    var msNow = (new Date()).getTime();
    opacity = t0 + (t1 - t0) * (msNow - msStart) / msDuration;
    if (opacity < 0)
        SetOpacity(element, 0)
    else if (opacity > 100)
        SetOpacity(element, 100)
    else {
        SetOpacity(element, opacity);
        element.timer = window.setTimeout("BlendOpacity('" + id + "'," + msDuration + "," + msStart + "," + t0 + "," + t1 + ")", 1);
    }
}
function ImageTransition(styleID, newImage) {
    var foregroundID = 'im_' + styleID
    if (document.all) {
        var thumb = document.getElementById(foregroundID);
        thumb.style.filter = "blendTrans(duration=0.2)";
        thumb.filters.blendTrans.apply();
        thumb.filters.blendTrans.play();
        thumb.src = newImage
    }
    else {
        var backgroundID = 'dv_' + styleID;
        var foreground = document.getElementById(foregroundID);
        if (backgroundID) {
            var background = document.getElementById(backgroundID);
            if (background) {
                background.style.backgroundImage = 'url(' + foreground.src + ')';
                background.style.backgroundRepeat = 'no-repeat';
            }
        }
        SetOpacity(foreground, 0);
        foreground.src = newImage;
        if (foreground.timer) window.clearTimeout(foreground.timer);
        var startMS = (new Date()).getTime();
        foreground.timer = window.setTimeout("BlendOpacity('" + foregroundID + "',200," + startMS + ",0,100)", 10);
    }
}

