// 전체 호출
var getTIMETABLEview = function (local, line, lineNum, key, time, t) {
	/*
	plocal = (!local) ? plocal : local;
	pline = (!line) ? pline : line;
	plineNum = (!lineNum) ? plineNum : lineNum;
	*/
	plocal = local;
	pline = line;
	plineNum = lineNum;
	pkey = (!key) ? '' : key;
	ptime = (!time) ? 0 : time;

	if(!t) page = 1;

	if(!plocal){
		$('#showBG').show();
		$('#layerCpNulltime').show();

		return false;
	}
	if(!pline){
		$('#showBG').show();
		$('#layerCpNullsearch').show();

		return false;
	}

	// 타임
	getTIMEpush();
	getSTATION();
	getCOPONpush();
}
// 타임
var getTIMEpush = function () {

	jQuery.ajax({
		type: "post",
		url: "./timeSCHEDULE.php",
		cache: true,
		data:
			{
				glocal	: plocal,
				gline	: pline,
				glineNum : plineNum,
				gkey	: pkey
			},
		dataType : "html",
		success: function(html) {
			$('#cpUseTable').html(html);
		}
	});
}
// 쿠폰
var getCOPONpush = function (time, type, t, sv, pkey) {

	ptime = (time) ? time : ptime;
	type	= (type) ? type : ptype;
	if(!t) page = 1;

	if(page == 1&&sv==1){
		$('.gnb li').each(function(){
			$(this).removeClass("now");
		});
		$('.gnb li').eq(2).addClass("now");

		$('a.sort').each(function(){
			$(this).removeClass("now");
		});
		$('a.sort').eq(0).addClass("now");

		$('#hourChoiceShow').find('p').text('전체');
	}

	$('.loading_wrap').show();

	jQuery.ajax({
		type: "post",
		url: "./searchCOPON.php",
		cache: true,
		data:
			{
				glocal	: plocal,
				gline	: pline,
				glineNum : plineNum,
				gkey	: pkey,
				gtime	: ptime,
				page	: page,
				ptype	: type
			},
		dataType : "html",
		success: function(html) {
			$('.loading_wrap').hide();
					
			if(page==1) {
				$('.copon').html(html);
				
				if(sv==1||pkey){
					if(!ie6){
					var destination = $('#cpShowWrap').offset().top;
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 700, function() {
						window.location.hash = '/index.php#cpShowWrap';
					});
					}
				}
			}
			else {
				$('.copon').append(html);
			}
		}
	});
}
var getCOPONnextpage = function () {
	page = page + 1;
	getCOPONpush(ptime, ptype, 1);
	//getTIMETABLEview(plocal, pline, plineNum, pkey, ptime, 1);
}
var getSTATION = function () {
	jQuery.ajax({
		type: "post",
		url: "./barSTATION.php",
		cache: true,
		data:
			{
				glocal	: plocal,
				gline	: pline,
				glineNum : plineNum,
				gkey	: pkey,
				gtime	: ptime
			},
		dataType : "html",
		success: function(html) {
			$('#station').html(html);
			//document.getElementById('subwayPicker').setStation(plocal,pline,plineNum);
		}
	});
}

var pageCount = 0;
var changePage = function (param0,param1,param2)
{
	//var result = document.getElementById('result');
	//if (result) result.innerHTML = param0+"/"+param1+"/"+param2;
	if(param0) {

		plocal = param0;
		pline = param1;
		plineNum = param2;

		getTIMETABLEview(plocal, pline, plineNum);

		$('a.sort').each(function(){
			$(this).removeClass("now");
		});
		$('a.sort').eq(0).addClass("now");

		$('.gnb li').each(function(){
			$(this).removeClass("now");
		});
		$('.gnb li').eq(1).addClass("now");

		$('#hourChoiceShow').find('p').text('전체');

		if(!ie6&&plineNum){
			var destination = $('#time').offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 700, function() {
				window.location.hash = '/index.php#time';
			});
		}
	}
}
var setStation = function ()
{
	var stationName = document.getElementById('keyword').value;
	document.getElementById('subwayPicker').setStation(stationName); 
}
