iBox.addEvent(iBox, 'hide', function () {

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        document.body.onscroll = "";
        if (document.body.onresize) {

            document.body.onresize = "";
        }
        else if (document.body.attachEvent) {

            document.body.detachEvent('onresize', sc);
            window.onresize = "";
            document.body.detachEvent('onscroll', rs);
        }

        //document.body.onscroll = rs;
    }
    else {
        window.onresize = "";
        window.onscroll = "";
    }
});

function sc() {
    //alert(parseInt(document.getElementById('iboxDiv').style.height));
    //alert('h');
    //document.getElementById('ibox_content').style.position = "absolute";
    //document.getElementById('ibox_wrapper').style.position = "absolute";
    if (document.getElementById('iboxDiv')) {
        if (parseInt(document.getElementById('iboxDiv').style.height) < '250') {
            if ((parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) < 0)
                document.getElementById('ibox_wrapper').style.top = parseInt(document.getElementById('ibox_wrapper').style.top) + (parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) + "px";
            document.getElementById('ibox_content').style.height = parseInt(document.getElementById('iboxDiv').style.height) + 50 + "px";

            document.getElementById('ibox_wrapper').style.height = parseInt(document.getElementById('iboxDiv').style.height) + 100 + "px";

        }
        else {
            if ((parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) < 0)
                document.getElementById('ibox_wrapper').style.top = parseInt(document.getElementById('ibox_wrapper').style.top) + (parseInt(document.getElementById('ibox_wrapper').style.height) - 250 + 100) + "px";
            document.getElementById('ibox_content').style.height = 250 + 50 + "px";

            document.getElementById('ibox_wrapper').style.height = 250 + 100 + "px";
        }
    }
    // document.getElementById('ibox_content').height = parseInt(document.getElementById('iboxDiv').style.height) + 50 + "px";
    // document.getElementById('ibox_wrapper').height = parseInt(document.getElementById('iboxDiv').style.height) + 100 + "px";
    //alert(parseInt(document.getElementById('ibox_content').style.height));
    if (window.scrollTop == 0)
    { }
    else {
        //  iBox.reposition();
    }
}
function rs() {

    if (document.getElementById('iboxDiv')) {
        if (parseInt(document.getElementById('iboxDiv').style.height) < '250') {
            if ((parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) < 0)
                document.getElementById('ibox_wrapper').style.top = parseInt(document.getElementById('ibox_wrapper').style.top) + (parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) + "px";
            document.getElementById('ibox_content').style.height = parseInt(document.getElementById('iboxDiv').style.height) + 50 + "px";

            document.getElementById('ibox_wrapper').style.height = parseInt(document.getElementById('iboxDiv').style.height) + 100 + "px";

        }
        else {
            if ((parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) < 0)
                document.getElementById('ibox_wrapper').style.top = parseInt(document.getElementById('ibox_wrapper').style.top) + (parseInt(document.getElementById('ibox_wrapper').style.height) - 250 + 100) + "px";
            document.getElementById('ibox_content').style.height = 250 + 50 + "px";

            document.getElementById('ibox_wrapper').style.height = 250 + 100 + "px";
        }
    }

    if (window.scrollTop == 0)
    { }
    else {
        //  iBox.reposition();
    }
}
function changelocation(url) {

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("POST", url, false);
    xmlhttp.send();
    previewhtml = xmlhttp.responseText;

    document.getElementById('ibox_content').innerHTML = previewhtml;
    // alert(document.getElementById('dyn').style.height);
    if (document.getElementById('iboxDiv')) {
        if (parseInt(document.getElementById('iboxDiv').style.height) < '250') {
            if ((parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) < 0)
                document.getElementById('ibox_wrapper').style.top = parseInt(document.getElementById('ibox_wrapper').style.top) + (parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) + "px";
            document.getElementById('ibox_content').style.height = parseInt(document.getElementById('iboxDiv').style.height) + 50 + "px";

            document.getElementById('ibox_wrapper').style.height = parseInt(document.getElementById('iboxDiv').style.height) + 100 + "px";

        }
        else {
            if ((parseInt(document.getElementById('ibox_wrapper').style.height) - parseInt(document.getElementById('iboxDiv').style.height) + 100) < 0)
                document.getElementById('ibox_wrapper').style.top = parseInt(document.getElementById('ibox_wrapper').style.top) + (parseInt(document.getElementById('ibox_wrapper').style.height) - 250 + 100) + "px";
            document.getElementById('ibox_content').style.height = 250 + 50 + "px";

            document.getElementById('ibox_wrapper').style.height = 250 + 100 + "px";
        }
    }
    //iBox.show('test.html');
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        document.body.onscroll = rs;
        if (document.body.onresize) {

            document.body.onresize = sc;
        }
        else if (document.body.attachEvent) {

            document.body.attachEvent('onresize', sc);
            window.onresize = sc;
            document.body.attachEvent('onscroll', rs);
        }

        //document.body.onscroll = rs;
    }
    else {
        window.onresize = sc;
        window.onscroll = rs;
    }
}




function setsession3() {
    var url, previewhtml;
    var zip_id = parseInt(document.getElementById("zip1").value);
    if (isNaN(zip_id)) {

        alert("Enter valid Zip Code");
        return false;
    }
    else {
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        url = "setsession.asp?zip=" + document.getElementById("zip1").value;

        xmlhttp.open("POST", url, false);
        xmlhttp.send();
        previewhtml = xmlhttp.responseText;
        //alert(previewhtml);
        //changelocation('iboxhtml.html');
        document.getElementById("zip1").value = "";
        if (xmlhttp.responseText != "We currently do not service that area.  Please use another zip code or call our customer care for more information") {

            changelocation('iboxhtml.html&previewhtml='+previewhtml);
        }
        else {
            previewhtml = 'We Currently do not Service your area';
            changelocation('iboxhtml.html&previewhtml=' + previewhtml);
         
        }

        // return false;
    }
}

    function showibox(url) {

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open("POST", url, false);
        xmlhttp.send();
        previewhtml = xmlhttp.responseText;
        iBox.default_width = 450;
        iBox.default_height = 350;
        iBox.show(previewhtml, "Two Ways To Buy!");

    }
       
    function displayzipforminline3(ID) {
    	var pID = ID;
        var html = "<div style='text-align:center;height:275px;padding:20px;'><table><tr valign='top'><td colspan='3'><img src='/Multimedia/www.heartlandind.com/Images/ibox_diy_installed.jpg' border='0' align='middle' alt='Two Ways To Buy - Do-It-Youself - Professionally Installed' /></td></tr><tr valign='top'><td width='226px;'><a href='/Store/SetDiOptions.asp?SearchType=DIY&ProductCategoryID=" + pID + "'><img src='/Multimedia/www.heartlandind.com/Images/shop_diy.png' height='45px' width='160px' border='0' align='middle' alt='Two Ways To Buy - Do-It-Youself - Professionally Installed' /></a></td><td width='8px;'>&nbsp;</td><td width='226px;' style='text-align:center;'><input type='text' name='zip1' id='zip1' style='width:80px;border: #000 1px solid;' /> <input type='button' value='Enter Zip' onclick='return setsession_prodcat3(" + pID + ");'  style='font-family:Trebuchet MS,Verdana,Arial,sans-serif;font-size:11px;font-weight: normal;color:White;background-color:#990000;border-width:1px;cursor:pointer;'  /></td></tr></table></div>";
        iBox.default_width = 500
        iBox.default_height = 350
        iBox.show(html, "Two Ways To Buy!");
    }

	function setsession_prodcat3(ID){
    	var zip = document.getElementById("zip1").value;
		var zip_id = parseInt(zip);
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		var search = 'DIFM';

        if (isNaN(zip_id) || zip.length < 5 || zip.length > 5) {
	        alert("Enter valid Zip Code");
            return false;
        } else {
        	if (isNaN(ID)){
        		var StoreURL = '/Store/';
        	} else {
        		var StoreURL = '/Store/' + ID;
        	}
        	var strPage = '/Store/SetDiOptions.asp?SearchType=' + search + '&Zip1=' + zip;
        	
			try{
				// Opera 8.0+, Firefox, Safari
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				// Internet Explorer Browsers
				try{
					ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
				} catch (e) {
						try{
						ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
					} catch (e){
						// Something went wrong
						alert('Your request can not be processed at this time!');
						return false;
					}
				}
			}
			// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4){
					var strHTML = ajaxRequest.responseText;
					alert(strHTML);
					this.location = StoreURL;
				}
			}
			ajaxRequest.open('Get', strPage, true);
			ajaxRequest.send(null);
			this.location = StoreURL;
		}
	}
	
/**********************These functions have been added to make the zip diy/difm run much smoother*********************/
    function displayzipforminline_default() {
    	//var pID = ID;
        var html = "<div style='text-align:center;height:275px;padding:20px;'><table><tr valign='top'><td colspan='3'><img src='/Multimedia/www.heartlandind.com/Images/ibox_diy_installed.jpg' border='0' align='middle' alt='Two Ways To Buy - Do-It-Youself - Professionally Installed' /></td></tr><tr valign='top'><td width='226px;'><a href='/Store/SetDiOptions.asp?SearchType=DIY&Process=Default'><img src='/Multimedia/www.heartlandind.com/Images/shop_diy.png' height='45px' width='160px' border='0' align='middle' alt='Two Ways To Buy - Do-It-Youself - Professionally Installed' /></a></td><td width='8px;'>&nbsp;</td><td width='226px;' style='text-align:center;'><input type='text' name='zip1' id='zip1' style='width:80px;border: #000 1px solid;' /> <input type='button' value='Enter Zip' onclick='return displayzipforminline_default_process();'  style='font-family:Trebuchet MS,Verdana,Arial,sans-serif;font-size:11px;font-weight: normal;color:White;background-color:#990000;border-width:1px;cursor:pointer;'  /></td></tr></table></div>";
        iBox.default_width = 500
        iBox.default_height = 350
        iBox.show(html, "Two Ways To Buy!");
    }
    
    function displayzipforminline_default_process(){
    	var zip = document.getElementById("zip1").value;
		var zip_id = parseInt(zip);
		var ajaxRequest;  // The variable that makes Ajax possible!
		var ProcessURL = '/Store/SetDiOptions.asp?SearchType=DIFM&Process=Default&Zip1=' + zip;
		
		var search = 'DIFM';

        if (isNaN(zip_id) || zip.length < 5 || zip.length > 5) {
	        alert("Enter valid Zip Code");
            return false;
        } else {
        	var strPage = '/Store/SetDiOptions.asp?SearchType=' + search + '&Zip1=' + zip;
			try{
				// Opera 8.0+, Firefox, Safari
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				// Internet Explorer Browsers
				try{
					ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
				} catch (e) {
						try{
						ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
					} catch (e){
						// Something went wrong
						alert('Your request can not be processed at this time!');
						return false;
					}
				}
			}
			// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4){
					var strHTML = ajaxRequest.responseText;
					//alert(strHTML);
					//this.location = StoreURL;
					this.location = ProcessURL;
				}
			}
			ajaxRequest.open('Get', strPage, true);
			ajaxRequest.send(null);
			this.location = ProcessURL;
		}
    }

