jQuery(document).ready(function($j) {
	$j("#myQnAList #checkBoxAll").click(function() {
		$j("#myQnAList input[type='checkbox']").attr('checked', $j(this).is(':checked') ? 'checked' : '' );
	});
	
	$j("#delete").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0,
		'onStart': function(formData, jqForm, options) {			
			var checkboxValue = $j("#QnAList input[name='qnaId']").fieldValue();
			if (!checkboxValue[0]) {
				// alert(checkboxValue);
				return false;
			}
			$j("#checkPostDelete input[type='submit']").click(function() {
				$j("#QnAList").submit();
			});
			/*
			$j("#checkPostDelete input[type='submit'].btn").click(function() {
				// $j("#myQnAList #searchForm").attr('action', $j("#myQnAList #deleteDomain").val() + "/mypage/deleteMyQna.as").submit();
			});
			*/
		}
	});
	
	$j("#paymentInfo").ajaxForm({			
		beforeSubmit: function() {			
			var queryString = $j('.iframe').attr('action') + '?' + $j('.iframe').formSerialize();
			var _width = 431;	//default for PG
			var _height = 388; //default for PG
			
			if( $j('#isKorea').val() == 'Y' ){
				//KOREA Only
				_width = 400;
				_height = 244;
			}			
			if( $j('#isPortugal').val() == 'Y' ){
				//KOREA Only
				_width = 431;
				_height = 420;
			}
			if( $j('#isBelgium').val() == 'Y' ){
				//KOREA Only
				_width = 431;
				_height = 420;
			}
			if( $j('#isFrance').val() == 'Y' ){
				//KOREA Only
				_width = 431;
				_height = 420;
			}
			if( $j('#isIran').val() == 'Y' ){
				//IRAN Only
				_width = 680;
				_height = 400;
			}	
			$j.fancybox ({
				'width': _width,
				'height': _height,
				'showNavArrows': false,
				'scrolling': 'no',
				'transitionIn': 'fade',
				'transitionOut': 'fade',
				//'padding': -2,
				'type': 'iframe',
				'href': queryString,
				'onComplete': function() {
					$j.fancybox.hideActivity();
					
					setTimeout(function() {
						parent.$j.fancybox.close();
					}, 1500000);
				}
			});
			$j.fancybox.showActivity();
			return false;
		}
	});
	


	
	$j("#editMyProfile a[href='#changePassword']").fancybox({
		'titleShow': false,
		'showCloseButton':false,
		'showNavArrows': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0,		
		'onComplete': function() {
			$j('#changePassword input#OldPasswd').focus(); 
		}
	});
		
	$j("#changePwdForm").ajaxForm({		
		clearForm: true,		
		success: function(responseText, statusText, xhr, $form) {
			$j.fancybox({
				'titleShow': false,
				'showCloseButton':false,
				'showNavArrows': false,
				'transitionIn': 'fade',
				'transitionOut': 'fade',
				'speedIn': 600,
				'speedOut': 350,
				'scrolling': 'no',
				'padding': 0,
				'content': responseText,
				'onComplete': function() {
					$j.fancybox.hideActivity();
					$j("#changeResult a").fancybox({
						'titleShow': false,
						'showCloseButton':false,
						'showNavArrows': false,
						'transitionIn': 'fade',
						'transitionOut': 'fade',
						'speedIn': 600,
						'speedOut': 350,
						'scrolling': 'no',
						'padding': 0,
						'type':'inline',
						'onComplete': function() {							
							$j.fancybox.hideActivity();
							$j('#changePassword input#OldPasswd').focus(); 
						}
					});
				}
			});
			/*
			$j(".modal .inner").cornerz({
				radius: 8,
				background: '#EBEBEB',
				borderColor: '#D4D4D4'
			});
			*/
			$j.fancybox.showActivity();
		}
	});
	
	$j.validator.addMethod("noSpecialChars", function(value, element) {
		return this.optional(element) || /^[a-z0-9\!\@\*\$\^\%\&]+$/i.test(value);
	});

	$j.validator.addMethod("noSpecialOnEmail", function(value, element) {
		return this.optional(element) || /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*$/i.test(value);
	});
	
	$j("#postQnA #firstCombo").change(function() {
		selectOneDepthCategory();
	});
	
	//윤년 제한
	var leapCheck = function(param){
		//alert(1);
		if( ( 0 == param.year % 4 && 0 != param.year % 100 ) || 0 == param.year % 400 ){
			if( param.day > 29 ) return false;
		} else {
			if( param.day > 28 ) return false;
		}
		return true;
	};
	
	var monthsCheck = function(param){
		var months = [ 0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
		if( param.day > months[Number(param.month)] )
			return false;
		
		return true;		
	};
	
	var currentTimeCompare = function(param){
		var curr = new Date();
		if( curr.getFullYear() < param.year ||
			( curr.getFullYear() == param.year  && curr.getMonth() +1 < param.month ) ||
			( curr.getFullYear() == param.year && curr.getMonth() +1 == param.month && curr.getDate() < param.day ) )
			return false;
		return true;
	};	
	
	$j.validator.addMethod("dateCheck", function(value, element, param) {
		
		if( 0 == param.month.length || 0 == param.year.length || 0 == param.day.length ){
			return true;
		}
		
		if( 2 == param.month && !leapCheck(param) ) 
			return false;
		else if( 2 != param.month && !monthsCheck( param ))
			return false;
		else if( !currentTimeCompare(param) )
			return false;
		
		return true;
	});
	
	$j.validator.addMethod("minorCheck", function(value, element, param) {
		
		if( 0 == param.month.length || 0 == param.year.length || 0 == param.day.length ){
			return true;
		}
		var MAX_DIFF_YEAR = param.max;
		
		var curr = new Date();
		var diffYear  = curr.getFullYear() - param.year;
		var diffMonth = curr.getMonth() +1 - param.month;
		var diffDay   = curr.getDate()     - param.day;
		if( diffYear > MAX_DIFF_YEAR ||
			( diffYear == MAX_DIFF_YEAR && diffMonth > 0 ) ||
			( diffYear == MAX_DIFF_YEAR && diffMonth == 0 && diffDay >= 0 ) ){
			return true;
		}
		return false;
	});
	
	$j("#appInfo a[rel='#popupHowto']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'autoDimensions': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'width':423,		
		'height':213,
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});
	
	$j("#select a[rel='#popupApp']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});
	
	$j("#change a[rel='#popupApp']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});
	
	$j("#deviceInfo a[rel='#popupDevice']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});

	$j("#send a[rel='#resultPopup']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0,
		'hideOnOverlayClick': false
	});
	
	$j("#signinPopup").fancybox({
		'showCloseButton':false,		
		'titleShow': false,	
		'showNavArrows': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0,
		'onComplete': function() {
			$j('#signinForm #email ').focus(); 
		}
	});
	
	$j("#smartPopup").fancybox({
		'showCloseButton':false,		
		'titleShow': false,	
		'showNavArrows': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});
	$j("#smartPopup2").fancybox({
		'showCloseButton':false,		
		'titleShow': false,	
		'showNavArrows': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});
	
	$j("#appInfo a[rel='#popupTry']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'autoDimensions': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'width':423,		
		'height':138,
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});

	$j(".detail-info a[rel='#popupAboutPlay']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'autoDimensions': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'width':534,		
		'height':469,
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});
	
	$j(".main a[rel='#signin']").fancybox({
		'titleShow': false,
		'showNavArrows': false,
		'showCloseButton':false,
		'autoDimensions': false,
		'transitionIn': 'fade',
		'transitionOut': 'fade',
		'width':420,
		'height':469,
		'speedIn': 600,
		'speedOut': 350,
		'scrolling': 'no',
		'padding': 0
	});
});


//팝업창 가운데 띄우기 강D
//url:팝업창 url, popWidth:팝업창 가로사이즈, popHeight:팝업창 세로사이즈, popWindowName:팝업창 윈도우 이름
function makePopup(url, popWidth, popHeight, popWindowName, scrooYn){
    var left = ( screen.width - popWidth )/2;
    var top = ( screen.height - popHeight )/3;
    window.open(url,popWindowName,"width="+popWidth+", height="+popHeight+" , left="+left+",top="+top+" , scrollbars="+scrooYn);
}


