﻿// JScript File

var intSubmitCount = 0;
var browser = navigator.appName;
var version = navigator.appVersion;
var isIE = 0;
if (browser == "Microsoft Internet Explorer") { isIE = 1; }

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters) && (version < 7) && (isIE == 1)) {
        for (var i = 0; i < document.images.length; i++) {
            var img = document.images[i]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
                img.outerHTML = strNewHTML
                i = i - 1
            }
        }
    }
}

if (isIE == 1) { window.attachEvent("onload", correctPNG); }

function isInteger(obj) {
    var i;
    if (obj.length == 0) {
        return false;
    }
    for (i = 0; i < obj.length; i++) {
        var c = obj.charAt(i);
        if (c == ".") {
        }
        else if (((c < "0") || (c > "9"))) {
            return false;
        }
    }
    return true;
}

function OpenPhotoGallery(id, n) {
    var link = "AdPhotoAlbum.aspx?ID=" + id + "&PhotoID=" + n;
    OpenWindowCenter(link, 'PhotoAblbum', 705, 841, 1);
    return;
}

function OpenWindowCenter(url, name, height, width, noresize) {
    var x = (isIE) ? document.body.clientWidth : window.innerWidth;
    var y = (isIE) ? document.body.clientHeight : window.innerHeight;
    var left = (x > width) ? (x - width) / 2 : 50;
    var top = 100;
    var feature = "height=" + height + ",width=" + width + ",status=no,toolbar=no,scrollbars=yes,menubar=no,location=no,dependent=yes,top=" + top + ",left=" + left;
    if (noresize) {
        feature += ",resizable=no";
    } else {
        feature += ",resizable=yes"
    }
    url = (url.indexOf("?") > 0) ? url + "&rand=" + Math.random() : url + "?rand=" + Math.random();
    window.open(url, name, feature);
}

function PetsFillSubType(TypeID) {
    if (TypeID == "") { TypeID = "0"; }
    var subType = eval('subType' + TypeID);
    var subTypeObj = document.AdDetail.SubTypeID;
    subTypeObj.options.length = 0;
    if (subType == "") {
        subTypeObj.options[0] = new Option('Select a class first', '');
        subTypeObj.selectedIndex = 0;
        document.AdDetail.TypeID.focus();
        return;
    }
    var subTypeArr = subType.split('|');
    for (var i = 0; i < subTypeArr.length; i++) {
        subTypeObj.options[i] = new Option(subTypeArr[i], subTypeArr[i]);
    }
    subTypeObj.selectedIndex = 0;
    subTypeObj.focus();
}


function PetsViewPreviousAd(name) {
    var obj = document.getElementById(name);
    if (obj) {
        var adID = obj.value;
        if (adID != "") {
            OpenWindowCenter("AdPrinter.aspx?mode=1&ID=" + adID, 'ViewAd', 750, 630);
        } else {
            alert("Please select one of the previous ads.");
        }
    }
    return false;
}

function PetsSubmitPreviousAd(name, adidValue) {
    var obj = document.getElementById(name);
    var obj2 = document.getElementById(adidValue);
    if (obj) {
        var adID = obj.value;
        if (adID != "") {
            return true;
        } else {
            alert("Please select one of the previous ads.");
        }
    }
    return false;
}

function isEmail(obj) {
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(obj)) {
        return true;
    }
    else {
        return false;
    }
}

function Trim(obj) {
    var a = obj.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
}

function PetsContactUs() {
    if (self.opener) {
        self.opener.location.href = "Email.aspx?mode=2";
        self.opener.focus();
        window.close();
    } else {
        document.location.href = "Email.aspx?mode=2";
    }
}

function PetsOpenInParent(link) {
    if (self.opener) {
        self.opener.location.href = link;
        self.opener.focus();
        window.close();
    } else {
        document.location.href = link;
    }
}

function PetsInfo(n) {
    var link = "Info.aspx?info=" + n;
    if (self.opener && n == 0) {
        self.opener.location.href = link + "&header=1";
        self.opener.focus();
        window.close();
    } else if (n == 0 || n == 3 || n == 11) {
        OpenWindowCenter(link, 'PetsInformation', 600, 700);
    } else if (n == 7) {
        OpenWindowCenter(link, 'PetsInformation', 250, 500);
    } else if (n == 8 || n == 5) {
        OpenWindowCenter(link, 'PetsInformation', 700, 700);
    } else {
        OpenWindowCenter(link, 'PetsInformation', 400, 500);
    }
}

function EmailToSteve() {
    document.location.href = "Email.aspx?mode=4";
}