// Leave $ namespace alone
jQuery.noConflict();

//added for cookie support - 04/08/2008 - MU
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

// shorthand for document.ready
jQuery(function($) { // $ == jQuery in this block
	if(typeof(tivo_images_domain_prefix) == 'undefined')
		var tivo_images_domain_prefix = '';
	
	// Used for image loading/preloading
	$.images = {
		path: tivo_images_domain_prefix + '/assets/images/', // path to images
		folders: {
			bodyHome: 'homepage',
			bodyWhat: 'whatistivo',
			bodyShop: 'shop',
			bodyFind: 'findtvshows',
			bodyMytivo: 'mytivo',
			bodySetup: 'setupandsupport',
			bodyAbout: 'abouttivo'
		}
	};
	$.each( $.images.folders, function(section) {
		if ( $('body').is('.' + section) ) {
			$.images.folders.current = section;
			return false;
		}
	});


	$('body')
		.addClass('jsEnabled') // let css know js is enabled
		.check_images_enabled(); // see if images are enabled
	$('body:not(.falltv)')
	   .scalable_bg({ img: $.images.path + 'shared/bg_window.jpg' }); // add the scalable background image to the body


	$('#primary')
		.find('div.section').add_corners('section').end() 			// add corners to div.section
		.find('div.box').add_corners('box').end()					// add corners to div.box
		.find('a.viewCart').add_corners('viewCart').end() 			// add corners to view cart link
		.find('#questions').add_corners('questions').end()			// add corners to questions div
		.find('.buttonSmall, .buttonLarge').make_buttons().end() 	// create the buttons
		.find('div.buttonSmallDisabled').make_buttons_disabled().end()	// create the disabled buttons
		.find('hr.divider').make_dividers().end()					// setup dividers
		.find('ul.tabs').make_tabs().end() 							// setup tabs
		.find('dl.faqs').make_faqs().end()							// setup faqs
		.find('a.tooltip').make_tooltips().end()					// setup tooltips
		.find('a.popup').make_popups().end();						// setup popups


		
$('#secondary')
		.find('.buttonSmall, .buttonLarge').make_buttons().end() 	// create the buttons
		

	$('#tooltip') // modify tooltip div
		.prepend('<div id="tooltipTop" />')
		.append('<div id="tooltipBottom" />');



	$('#nav li ul li ul li') // Link up third level li
		.css('cursor', 'pointer')
		.bind('click', function(event) { //cookie clear code here for clearing tab cookie
								window.location = $('a:first', this).attr('href'); });
	
	if ( $.browser.safari && parseInt( $.browser.version ) <= 418 ) {
		// Safari 2.0.4 needs help positioning the bottom corners on #mainContent
		// due to the buttons size changing after Safari has rended the corners
		// also occurs if images don't have width/height attributes
		$('#bottom').css('bottom', '0px');
		$(window).load(function() {
			$('#bottom').css('bottom', '-6px');
		});
	}


	/*$(window).bind('load', function() { // Add footer links if images are disabled
		window.setTimeout(function() { // IE needs a timeout!
			if ( !$('body').is('.imagesEnabled') )
				$('#nav')
					.clone() // clone the nav
						.find('ul').remove().end() // remove any child navs
						.find('li:last').remove().end() // remove last li (about us) already in the footer
						.find('li, a').andSelf().attr('id', '').end().end() // remove ids from lis and the ul itself
						.find('li')
							.reverse().insertAfter('#footer ul li:first');
		}, 1000);
	}); */
});

// $ != jQuery from here on
jQuery.fn.extend({
	
	// Creates the scalable background image
	scalable_bg: function(options) {
		options = jQuery.extend({
			id: 'scalable_bg',
			img: '',
			exclude: jQuery.browser.msie && parseInt( jQuery.browser.version ) == 6
		}, options || {});
	
		if ( !options.exclude ) {	
			jQuery('<div id="' + options.id + '"><img src="' + options.img + '" /></div>')
				.appendTo(this)
				.bind('mousedown', function() { return false; });
	
			jQuery(window).bind('load resize', function() {
				var prop = jQuery.browser.msie ? 'height' : 'min-height';
				var $img = jQuery('#'+options.id);
				var height = jQuery('#container').height();
				$img
					.css('min-width', 986)
					.css( prop, 1 )
					.css( prop, height );
			});
		}
	
		return this;
	},
	
	// creates necessary markup to create the disabled buttons
	make_buttons_disabled: function () {
		
			return this.each(function() {
			var $this = jQuery(this);
			var className = $this.is('.buttonSmallDisabled') ? 'buttonSmall' : 'buttonLarge';
	
			$this
				.wrap('<span class="' + className + '"><span class="first-child"><span /></span></span>')
				.parent().parent() // .first-child
					.add_corners('button');
			});
	},
	
	
	// creates necessary markup to create the buttons
	make_buttons: function() {
		jQuery.preload( 'bg_button_corners_over.jpg', 'bg_button_large_over.jpg', 'bg_button_small_over.jpg' );
		
		return this.each(function() {
			var $this = jQuery(this);
			var className = $this.is('.buttonSmall') ? 'buttonSmall' : 'buttonLarge';
	
			$this
				.wrap('<span class="' + className + '"><span class="first-child"><span /></span></span>')
				.parent().parent() // .first-child
					.add_corners('button');
			
			// the a tag nor button tag fill the whole button
			// this block links up the surrounding span tag
			// so that when click it will first execute any
			// click handlers attached to the a/button tag
			// if the return value from the handlers is false
			// then the event is stoped ... otherwise the location
			// is changed to the links href
			//$this.parent().parent().parent().bind('click', function(event) {
				//var ret = $this.triggerHandler('click');
				//return ret !== false && $this[0].href && (window.location = $this[0].href) || ret;
			//});
		// new code provided by brandon 03/31
			$this
				.bind('click', function(event) { event.stopPropagation(); }) // prevent the event from propagating to the span
				.parent().parent().parent().bind('click', function(event) {
				var ret = $this.triggerHandler('click');
				return ret !== false && $this[0].href && (window.location = $this[0].href) || ret;
			});
		
			// Fix buttons in IE6
			if ( jQuery.browser.msie && parseInt( jQuery.browser.version ) == 6 )
				$this
					.parent().parent().parent() // .butonLarge or .buttonSmall
						.bind('mouseenter mouseleave', function(event) { jQuery(this).toggleClass('hover'); });
		});
	},
	
	make_dividers: function() {
		return this.each(function() {
			jQuery(this)
				.wrap('<div class="divider" />').parent()
					.addClass( this.className )
					.prepend('<span class="left" /><span class="right" />');
		});
	},
	
	// adds the necessary markup to add corners to elements
	add_corners: function(prefix) {
		return this.prepend('<span class="' + prefix + 'TopLeft" /><span class="' + prefix + 'TopRight" /><span class="' + prefix + 'BottomLeft" /><span class="' + prefix + 'BottomRight" />');
	},
	
	// hook up faqs for expanding and collapsing
	make_faqs: function() {
		return this
			.each(function() {
				jQuery('#'+this.id+'Controls')
					.find('.expand, .collapse')
						.bind('click', function(event) {
							this.blur();
							var id = jQuery(this).parents('.faqControls').attr('id').replace(/(Controls)$/, '');
							jQuery('dt, dd', '#'+id)[ jQuery(this).is('.expand') ? 'addClass' : 'removeClass' ]('opened');
							return false;
						});
			})
			.find('dt')
				.wrapInner('<a href="#" />')
				.find('a')
					.bind('click', function(event) {
					/* -------- 3/17/08 - V1 CARRY OVER  - ALLOWS TO SWAP TEXT WHEN EXPANDING/SHOWING ELEMENTS - START ----- */
						  	var currentText = jQuery(this).html(); 
							if (currentText.match("Show the steps") != null) { jQuery(this).html("Hide the steps"); } 
							else if (currentText.match("Hide the steps") != null) { jQuery(this).html("Show the steps"); } 
					  		/* -------- 3/17/08 - V1 CARRY OVER  - ALLOWS TO SWAP TEXT WHEN EXPANDING/SHOWING ELEMENTS - END ----- */
						jQuery(this)
							.blur()
							.parent()
								.toggleClass('opened')
							.next()
								.toggleClass('opened');
						return false;
					})
				.end()
			.end();
	},
	
	// create tabs and hook up next and previous buttons
	make_tabs: function() {
		jQuery.preload( 'bg_tab_over.jpg' );
		
		//this will set a cookie on the tab
		//var $tabs = this.tabs( { cookie: { expires: 7, path: '/' }}).bind('show.ui-tabs', function(ui) {
		var $tabs = this.tabs().bind('show.ui-tabs', function(ui) {});
		
		/*
		$tabs.each(function() {
			var tab = this;
			var data = jQuery(tab).data('ui-tabs');
			var $panels = data.$panels;
			$panels.find('a.next, a.previous').bind('click', function(event) {
				var current = data.options.selected;
				if ( jQuery(this).is('.next') )
					jQuery(tab).tabs('select', current+1);
				else if ( jQuery(this).is('.previous') )
					jQuery(tab).tabs('select', current-1);
				
				event.preventDefault();
				return false;
			});
		});
		*/
		return this;
	},
	
	// creates the tooltips
	make_tooltips: function() {
		return this.tooltip({
			bodyHandler: function() {
				var elem = this.hash && jQuery(this.hash)[0];
				return '<p>' + (elem && elem.innerHTML || this.tooltipText) + '</p>';
			},
			showURL: false,
			track: true,
			top: 1,
			left: 1
		});
	},
	
	// hooks up links for creating the dialogs that pull in content on the fly
	make_popups: function() {
		return this.bind('click', function(event) {
			var p = this;
			p.blur();
			TiVoPopup.NewPopup(this, true);
			return false;
		});
		return false;
	},
	
	// adds a class of imagesEnabled to the body if images are enbaled
	check_images_enabled: function() {
		jQuery('<img />')
			.bind('load', function() {
				jQuery('body').addClass('imagesEnabled');
				jQuery(this).remove();
			})
			.attr('src',  jQuery.images.path + 'shared/blank.gif?avoidCache=' + Math.random());
		
		return this;
	},
	
	// reverses the array, helpful for inserting a collection of elements
	reverse: function() {
		return this.pushStack(Array.prototype.reverse.call(this, this));
	},
	
	ufo: function(options) {
		return this.each(function() {
			UFO.create(options, this.id);
		});
	}
});

jQuery.preload = function() {
	var images = jQuery.makeArray(arguments);
	jQuery(window).bind('load', function() {
		jQuery.each( images, function(index, image) {
			var path = jQuery.images.path + jQuery.images.folders[ jQuery.images.folders.current ] + '/' + image;
			var img = new Image();
			img.src = path;
		});
	});
};

/*
	TiVoPopup
	Wrap Tivo Popup show / close / history / etc. functionality in one central object.
	Written by David Wortham (dwortham@tivo.com) June 10, 2008
*/
TiVoPopup = {
	// variables
	currentIndex: -1,
	historyStack: new Array(),
	
	// functions
	Init: function() {
		this.historyStack = new Array();
		this.currentIndex = -1;
	},
	// Process a popup (cleanup after the AJAX popup content response)
	ProcessPopup: function(a, suppressAStorage) {
		this.historyStack[this.currentIndex] = a;
		if(this.currentIndex < this.historyStack.length) {
			this.historyStack.slice(0, this.currentIndex + 1);
		}
		// used for testing selectedIndex
		//alert("cur index=" + this.currentIndex + ", stack= " + this.historyStack.length);
		// 
		var popupNav = document.createElement('DIV', 'popupNavigation');
		popupNav.id		 				= 'popupNavigation';
		popupNav.className 				= '';
		
		var popupBackControl			= document.createElement('SPAN', 'popupBack');
		popupBackControl.id				= 'popupBack';
		popupBackControl.innerHTML		= '&lt;&nbsp;Back';
		popupNav.appendChild(popupBackControl);
		
		var popupDividerText			= document.createElement('SPAN', 'popupDivider');
		popupDividerText.id				= 'popupDivider';
		popupDividerText.innerHTML		= '&nbsp;|&nbsp;';
		popupNav.appendChild(popupDividerText);
		
		var popupForwardControl			= document.createElement('SPAN', 'popupForward');
		popupForwardControl.id			= 'popupForward';
		popupForwardControl.innerHTML	= 'Forward&nbsp;&gt;';
		popupNav.appendChild(popupForwardControl);

		jQuery("#popupWindow .popupOverlay")
			.find(".popupContainerXXLarge .popupMiddleXXLarge").prepend(popupNav).end()
			.find(".popupContainerXLarge .popupMiddleXLarge").prepend(popupNav).end()
			.find(".popupContainerLarge  .popupMiddleLarge") .prepend(popupNav).end()
			.find(".popupContainerMedium .popupMiddleMedium").prepend(popupNav).end()
			.find(".popupContainerSmall  .popupMiddleSmall") .prepend(popupNav).end();

		try {
			jQuery("#popupDivider").hide();
				
			if(this.historyStack && this.historyStack.length > 0 && this.currentIndex > 0) { // if the history stack is not empty
				jQuery("#popupBack").html('<a href="#" onclick="TiVoPopup.PrevPopup(); return false;">&lt;&nbsp;Back</a>');
				jQuery("#popupBack").show();
				jQuery("#popupDivider").show();
			} else {
				jQuery("#popupBack").html('&lt;&nbsp;Back');
				jQuery("#popupBack").hide();
			}
			
			if(this.historyStack && this.historyStack.length > 0 && this.currentIndex + 1 < this.historyStack.length) { // if the future stack is not empty
				jQuery("#popupForward").html('<a href="#" onclick="TiVoPopup.NextPopup(); return false;">Forward&nbsp;&gt;</a>');
				jQuery("#popupForward").show();
				jQuery("#popupDivider").show();
			} else {
				jQuery("#popupForward").html('Forward&nbsp;&rgt;');
				jQuery("#popupForward").hide();
			}
		} catch(err) {
			if(!console && !console.log)
				/*alert(err)*/;
			else {
				try { console.log(err); } catch(nestedErr) { ; }
			}
		}
	},
	// create a new popup (not back/foreward navigation within the history stack)
	NewPopup: function(a, suppressAStorage) {
		//alert(this.currentIndex);
		this.currentIndex++;
		if(this.currentIndex >= 0) {
			this.historyStack[this.currentIndex] = a;
			var nextA = a;
			if(nextA != null) {
				this.DrawPopup(nextA, true);
			}
		}
		return false;
	},
	// navigate (foreward) to the next popup in the history stack
	NextPopup: function() {
		if(this.currentIndex + 1 < this.historyStack.length)
			this.currentIndex++;
		if(this.currentIndex < this.historyStack.length) {
			var nextA = this.historyStack[this.currentIndex];
			if(nextA != null) {
				this.DrawPopup(nextA, true);
			}
		}
		return false;
	},
	// navigate (backward) to the previous popup in the history stack
	PrevPopup: function() {
		if(this.currentIndex > 0)
			this.currentIndex--;
		if(this.currentIndex > -1) {
			var prevA = this.historyStack[this.currentIndex];
			if(prevA != null) {
				this.DrawPopup(prevA, true);
			}
		}
		return false;
	},
	// make an AJAX request for the HTML content, display the content in a new "Popup" overlay, and call ProcessPopup (for post-AJAX cleanup).
	DrawPopup: function(a, suppressAStorage) {
		var ie6top = document.documentElement.scrollTop + 'px';	//for ie6 to get the height that is needed to position the poup
		//see if the window is already present and visible
		var popup;
		if (document.getElementById('popupWindow') == null) {
			popup = document.createElement('div'); 
			popup.setAttribute('id','popupWindow'); 
			jQuery('body').append(popup); 
		}
		else { jQuery('div#popupWindow').hide(); }
		
		//ajax get the contents and populate the popup container
		jQuery.get(a.href, function(data) {
			//add onclick="javascript:showPopup(this);" to all 'class="popup"' code
			//data = data.replace(/class="popup"/g, 'class="popup" onclick="TiVoPopup.NewPopup(this, true); return false;"'); // only popup links within popups will contain the (..., true) parameter lists
			data = data.replace(/href="\/assets\//g, 'href="' + location.protocol + '//' + location.host + '/assets/');
			jQuery('div#popupWindow')
				//.html(data + " <!--[if lte IE 6.5]><iframe></iframe><![endif]-->")
				.html(data)
				.find('.buttonSmall, .buttonLarge').make_buttons().end() // create the buttons
				.find('dl.faqs').make_faqs().end()
				.find('a.tooltip').make_tooltips().end()
				//.find('a.popup').bind('click', function() {
				//	TiVoPopup.NewPopup(this, true);
				//	return false;
				//}).end()
				.find('a.popup').make_popups().end()
				.css('_top', ie6top).show();
			
			TiVoPopup.ProcessPopup(a, (suppressAStorage != undefined && suppressAStorage != null));
		});
		
		//set the dimensions of the iframe to match the window (IE6 ONLY FIX)
		jQuery('div#popupWindow iframe')
			.css('width',jQuery(window).width() + 'px')
			.css('height',jQuery(window).height() + 'px');
		return false;
	}
};

// Initialize the TiVoPopup handling "object"
TiVoPopup.Init();
// Wrap the functionality of the new TiVoPopup "object" with backwards-compatible function calls
function ShowPopup(a, suppressAStorage) { TiVoPopup.DrawPopup(a, suppressAStorage); return false; }
function ClosePopup() { TiVoPopup.Init(); jQuery('div#popupWindow').hide(); return false; }

// Legacy popup function for Support pages content
function fullwin(targeturl)
  {
	var winprop="";
	var winheight="";
	var height=window.screen.availHeight//screen.height
	var width=window.screen.availWidth//screen.width
	
	 window.open(targeturl ,"",'width='+ window.screen.width +',height=' + window.screen.height + ',status=yes,toolbar=yes,menubar=yes,top=0,left=0,location=yes,resizable=yes,menubar=yes,scrollbars=yes ');

}

function openBrWindow(theURL,winName,features){ 
	var win = window.open(theURL,winName,features);
	if (win.opener == null){
		win.opener = self;
	}
	win.focus();
}

	
function openBrWindowOffset(theURL, winName, width, height) {
	//find the screen height and width
	var screenW = screen.width;
	var screenH = screen.height;
	
	//determine the top left coordinate to center the popup in
	var centerX = (screenW/2) - (width/2);
	var centerY = (screenH/2) - (height/2);
	
	//if the new window is larger than the screen, then offset it to the top left
	if(centerX < 0 || centerY < 0) {
		centerX = 0;
		centerY = 0;
	}
	
	//options for the popup window
	var myWindowOptions = "toolbar=no,menubar=no,resizable=no,autoscroll=no,";
	myWindowOptions += "height=" + height + ",width=" + width + ",left=" + centerX + ",top=" + centerY + ",screenX=" + centerX + ",screenY=" + centerY;
	
	//open the new window
	var myWindow = new Object();
	myWindow = window.open(theURL, winName, myWindowOptions);
	
	//force focus on the new window
	myWindow.focus();
	
}

// TCO basic pop ups
function openPopupWin(style,lnk){ 
	var url = lnk.href;
	if (url) {
		switch (style){
			case "tcoShow" : openBrWindow(url,'name','width=490,height=702,scrollbars=no,resizable=no,status=no,menubar=no,toolbar=no');
			break;
			case "tcoSearch" : openBrWindow(url,'name','width=490,height=532,scrollbars=no,resizable=no,status=no,menubar=no, toolbar=no');
			break;
			case "tcoLinkToThis" : openBrWindow(url,'name','width=790,height=475,scrollbars=no,resizable=no,status=no,menubar=no, toolbar=no');
			break;
			case "mmaCancelOrder" : openBrWindow(url,'name','width=490,height=325,scrollbars=yes,resizable=no,status=no,menubar=no, toolbar=no');
			break;
			case "mmaCancelOrder2" : openBrWindowOffset(url,'name', 490, 144);
			break;
            case "full" : openBrWindow(url,'name','width=1000,height=740,scrollbars=yes,resizable=yes,status=no,menubar=no, toolbar=no');
            break;
            default : openBrWindow(url,'name','width=490,height=675,scrollbars=yes,resizable=yes,status=no,menubar=no, toolbar=no');
		}
	}
}
function select_all(t) {
		t.select();
}

function HideContent(x) {
	document.getElementById(x).style.display = "none";
}
function ShowContent(x) {
	var overlay = document.getElementById(x);
	overlay.style.display = "block";	
}
function loadinparent(url, closeSelf){
	self.opener.location = url;
	if(closeSelf) self.close();
}

// moves popup div out of primary div and into body root level
jQuery(document).ready(function() {
	var theTooltipWin = jQuery('#popupWinTT');
	theTooltipWin.remove();
	jQuery('BODY').append(theTooltipWin);
});
			
//(C) Stephen Daly
// www.stephendaly.org
// Date: 11/3/2008

// Checks if the browsers is IE or another.
// document.all will return true or false depending if its IE
// If its not IE then it adds the mouse event
if (!document.all)
document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getPosition;
/*
// possibly replace the above code with the following: 
if (document.addEventListener){
	document.addEventListener('mousemove', getPosition, false); 
} else if (document.attachEvent){
	document.attachEvent('mousemove', getPosition);
}
*/

var X = 0
var Y = 0
function getPosition(args) 
{
  // Gets IE browser position
  if (document.all) 
  {
	  try {
	X = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; 
	Y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop; 
	  } catch(err) { ; }
  }
  
  // Gets position for other browsers
  else 
  {  
    X = args.pageX 
    Y = args.pageY 
  }  
}

function popUpShow(w){
    var div;
  
    if(document.getElementById) {
	    // Standard way to get element
	    div = document.getElementById(w); 
	    TTdiv = document.getElementById('popupWinTT'); 
    } else if(document.all) {
	    // Get the element in old IE's 
	    div = document.all[w]; 
		TTdiv = document.all['popupWinTT']; 
	}
    
	jQuery('.popupWinTTcontent').each(function() {
		this.style.display = 'none';
	});
    div.style.display = 'block';
    
	TTdiv.style.display = 'block';

    // Off-sets the position 
    X = X +15;
	Y = Y -150;
	
    TTdiv.style.left = X+'px';
    TTdiv.style.top = Y+'px';
	TTdiv.style.position = 'absolute'; 
	TTdiv.style.visibility = 'visible'; 
}

function popUpHide(w){
    var div;
  
    if(document.getElementById) {
	    // Standard way to get element
	    div = document.getElementById(w); 
	    TTdiv = document.getElementById('popupWinTT'); 
    } else if(document.all) {
	    // Get the element in old IE's 
	    div = document.all[w]; 
		TTdiv = document.all['popupWinTT']; 
	}
    
	jQuery('.popupWinTTcontent').each(function() {
		this.style.display = 'none';
	});
    div.style.display = 'none';
    
	TTdiv.style.display = 'none';
	TTdiv.style.visibility = 'hidden'; 
}

// added by rdown for support search form 

function goBrowse(){
	var selObj = document.getElementById('browseForm');
	var selIndex = selObj.selectedIndex;
	var urlValue = selObj.options[selIndex].value;
	//alert(urlValue);
	window.location = urlValue;
}
// used  in store 2.0/global for limiting text characters
function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}

