/* Global Clientside functions */

/* begin user event notification */
function userNotify(type){
	try{
		if(type == 'error'){
			$("#syserror").fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200);
		}else if(type == 'alert'){
			$("#sysalert").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400);
		}else{
			$("#sysok").fadeOut(400).fadeIn(400);
		}
	}catch(err){}
}
/* //end user event notification */

/* animated anchor scrolling */

function enable_smooth_scroll() {
    function filterPath(string) {
        return string
                .replace(/^\//,'')
                .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                .replace(/\/$/,'');
    }

    var locationPath = filterPath(location.pathname);
    
    var scrollElement = 'html, body';
    $('html, body').each(function () {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }    
    });
    
    $('a[href*=#]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if  (   locationPath == thisPath
                && (location.hostname == this.hostname || !this.hostname)
                && this.hash.replace(/#/, '')
            ) {
                if ($(this.hash).length) {
                    $(this).click(function(event) {
                        var targetOffset = $(this.hash).offset().top;
                        var target = this.hash;
                        event.preventDefault();
                        $(scrollElement).animate(
                            {scrollTop: targetOffset},
                            500,
                            function() {
                                location.hash = target;
                        });
                    });
                }
        }
    });
}

/* //end animated anchor scrolling */

/* start coupon printing */
function printCoupon(couponHTML)
{
    //alert("testing inside printCoupon");
    var a;
    if(couponHTML.match('demoMastCoupon')){
        a = window.open('','','scrollbars=yes,width=620,height=325');
    }
    else{
        a = window.open('','','scrollbars=yes,width=350,height=325');
    }
    a.document.open("text/html");
    a.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">');
    a.document.write('<html><head><link rel="stylesheet" href="http://www.tiredealersite.com/assets/sharedcss/forms.css" />');
    a.document.write('<style type="text/css">#frame{background-image:none;background-color:#FFFFFF;}</style>');
    a.document.write('</head><body style="padding-left:10px;background-image:none;background-color:#FFFFFF;">');	
    a.document.write(couponHTML);
    a.document.write('</body></html>');
    a.document.close();
    a.print();
}
/* end coupon printing */


/* specific div printing */
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open('','printwin','left=100,top=100,width=700,height=800')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print Page</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}
/* // specific div printing */


//  //////////////////////////////////////////////////////////
//  jQuery DOM loaded
// ///////////////////////////////////////////////////////////
	//jQuery(function($) {
					
	/* start google analytics trigger */
		//$("#MainMenu li a").click(function(){
			// pageTracker._trackPageview();
			// pageTracker._setAllowAnchor(true);
	//	});	 
	/* end google analytics trigger */

//}); // end jQuery DOM loaded functions
	// /////////////////////////////////////////////////////////
