﻿
/* Load the popup div with the selected video */
function PlayVideo(video_id) {
    document.getElementById('VideoPopup').innerHTML = document.getElementById('video_' + video_id).innerHTML;
    itstime = showform()
}

function showform() {

	var browser=navigator.appName;
	var version=navigator.appVersion;

	mtop = 0;
	mleft = 325;
	height = 20;
	width = 300;
	//alert(version);
	if(browser == "Microsoft Internet Explorer" && (version.indexOf("MSIE 6.") >= 0 || version.indexOf("MSIE 7") >= 0)){
	    mleft = -325;
	    mtop = -400;
		document.getElementById('popupDiv').style.width = width + "px";
		document.getElementById('popupDiv').style.marginLeft = mleft + "px";
	}
		
//	if(browser == "Microsoft Internet Explorer" && version.indexOf("MSIE 6.") >= 0) {
//		//document.getElementById('popupDiv').style.background = "#e6e6e6";
//		document.getElementById('popupDiv').style.position = "absolute";
//		document.getElementById('popupTable').style.position = "relative";
//		document.getElementById('popupTable').style.marginLeft = "5px";
//		//mtop = 200;
//	}
	
	document.getElementById('popupDiv').style.display = "block";

	if (browser == "Microsoft Internet Explorer") {
	    goresize = setInterval("resizeme()", 50);
	}
	else {
	    goresize = setInterval("resizeme()", 2);
	}
}

function resizeme() {
	var browser=navigator.appName;
	var version=navigator.appVersion;
	if(browser == "Microsoft Internet Explorer"){
	    timesby = 5;
	}
	else if(browser == "Netscape" && version.indexOf("Chrome") >= 0) {
		timesby = 1.5;	
	}
	else{
		timesby = 1;	
	}
	//if(document.getElementById('form').style.width > 700) {
	mtop = mtop - 4*timesby;
	/*mleft = mleft - 4;*/
	height = height + 8*timesby;
	/*width = width + 8;*/
	if (height < 450){
		document.getElementById('popupDiv').style.height = height + "px";
		document.getElementById('popupDiv').style.marginTop = mtop + "px"; 
	}
	else{
		clearInterval(goresize);
		
        if (browser == "Microsoft Internet Explorer") {
            goresizewidth = setInterval("resizemewidth()", 50);
		}
		else {
		    goresizewidth = setInterval("resizemewidth()", 2);
		}
        
        
        
	}
}

function resizemewidth() {
	var browser=navigator.appName;
	var version=navigator.appVersion;
	if(browser == "Microsoft Internet Explorer"){
	    timesby = 3.5;
	}
	else if(browser == "Netscape" && version.indexOf("Chrome") >= 0) {
		timesby = 1.5;	
	}
	else{
		timesby = 1;	
	}
	
	/*mtop = mtop - 3;*/
	mleft = mleft - 5*timesby;
	/*height = height + 6;*/
	width = width + 10*timesby;
	if (width < 700){
	document.getElementById('popupDiv').style.width = width + "px";
	document.getElementById('popupDiv').style.marginLeft = mleft + "px";
	}
	else{
		setTimeout("showtable()", 300)
		clearInterval(goresizewidth);
	}
}

function showtable(){
	document.getElementById('popupTable').style.display = "block";
	document.getElementById('popupCloseButton').style.display = "block";

	//document.getElementById('ctl00_ContentPlaceHolder1_RecipientName').focus() //******************** first element in the popup gets focus
}

function closepopup(act) {
	mtop = 40;
	mleft = 150;
	height = 20;
	width = 200;
	
	document.getElementById('popupDiv').style.width = width + "px";
	document.getElementById('popupDiv').style.height = height + "px";
	document.getElementById('popupDiv').style.marginTop = mtop + "px"; 
	document.getElementById('popupDiv').style.marginLeft = mleft + "px";
	if (act == '1'){
		document.getElementById('popupDiv').style.display = "none";
		document.getElementById('popupTable').style.display = "none";		
	}
	else {
		showform()
	}
	
}

function blankDisplay(id, txt){
    var e = document.getElementById(id);
    if(e != null && e.value == txt)
        e.value = '';
}

function resetDisplay(id, txt){
    var e = document.getElementById(id);
    if(e != null && e.value == '')
        e.value = txt;
}

/* Expand errors popup div */
function expandErrorElement(id) {
    var s = document.getElementById(id);
    var browser = navigator.appName;
    var version = navigator.appVersion;
    /* move div in IE7 */
    if (browser == "Microsoft Internet Explorer" && version.indexOf("MSIE 7") >= 0) {
        s.style.marginLeft = "-355px"
    }
    expandElement(id);
}

/* */
function focusContactElement() {
    document.getElementById("contactBackground").style.left = "0px";
}

function focusElement() {
    document.getElementById("pageBackground").style.left = "0px";
}

function hideBackground() {
    document.getElementById("contactBackground").style.left = "-9999px";
}

/* Expand popup div */
function expandElement(id) {
    var s = document.getElementById(id);
    if (s != null) { s.style.display = "block"; document.getElementById("pageBackground").style.left = "0px"; }
}

/* Close popup div */
function closeElement(id) {
    var s = document.getElementById(id);
    if (s != null) { s.style.display = "none"; document.getElementById("pageBackground").style.left = "-9999px"; }
}

/* Close multiple popup divs */
function closeElements(ids) {
    for (var i = 0; i < ids.length; i++) {
        closeElement(ids[i].id);
    }
}

/* Reset validators */
function resetValidator(validator, _valid) {
    ValidatorEnable(validator, _valid);
    if (_valid) {
        validator.isvalid = true;
        ValidatorUpdateDisplay(validator);
    }
}

/* Get Elements By Class Name */
document.getElementsByClassName = function (cl) {
    var retnode = [];
    var myclass = new RegExp('\\b' + cl + '\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
};

function closePopups() {
    closeElements(document.getElementsByClassName("accessories-expand"));
    closeElements(document.getElementsByClassName("email-expand"));
    closeElements(document.getElementsByClassName("cart-panel-expand"));
    closeElements(document.getElementsByClassName("payment-options-expand"));
    closeElements(document.getElementsByClassName("product-image-large"));
    closeElements(document.getElementsByClassName("password-expand"));
    closeElements(document.getElementsByClassName("whats-bids-expand"));
}


function trimString(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}

function updateDateField(day, mth, yr, hid) {
    var d = document.getElementById(day);
    var m = document.getElementById(mth);
    var y = document.getElementById(yr);
    var h = document.getElementById(hid);
    if (d != null && m != null && y != null && h != null) {
        if (d.selectedIndex == 0 && m.selectedIndex == 0 && y.selectedIndex == 0){
            h.value = ""
        }
        else{
            h.value = d.options[d.selectedIndex].value + "/" + m.options[m.selectedIndex].value + "/" + y.options[y.selectedIndex].value;
        }
    }
}

//Finds y value of given object
function findPos(obj) {
    var elem = document.getElementById(obj);
    var curtop = 0;
    if (elem.offsetParent) {
        do {
            curtop += elem.offsetTop;
        } while (elem = elem.offsetParent);
        return [curtop];
    }
}

//forgot password
function forgotPassword(elem, emailAdr, forgot) {
    if (document.getElementById(emailAdr) != null && trimString(document.getElementById(emailAdr).value).length > 0) {
        if (document.getElementById(forgot) != null) { document.getElementById(forgot).value = document.getElementById(emailAdr).value; }
    }
    expandElement(elem);
}

//// jQuery.support.transition
//// to verify that CSS3 transition is supported (or any of its browser-specific implementations)
//$.support.transition = (function () {
//    var thisBody = document.body || document.documentElement,
//    thisStyle = thisBody.style,
//    support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined;

//    return support;
//})();

////$(window).load(function () {

////    /*
////    Mouse Over for Image Items
////    jQuery fallback from CSS3
////    */
////    //    if (!jQuery.support.transition) {
////    var animatedDiv = 'ul.level-2';
////    var triggerContainer = 'ul#menu > li';

////    //$(animatedDiv).css('bottom', -$(animatedDiv).outerHeight());

////    $(triggerContainer).children(animatedDiv).hide();

////    $(triggerContainer).mouseover(function () {
////        $(this).children(animatedDiv).show(200);
////    }).mouseleave(function () {
////        $(this).children(animatedDiv).delay(500).hide(200);
////    });
////    //    }
////});



