
$(document).ready(function(){
	
	//radio单
	$('.radio-signle').click(function(){
		var _this = $(this);
		var _thispar = _this.parent();
		var radio = _this.attr('data-radio');
		var value = _this.attr('data-value');
		if (!_this.hasClass('on')) {
			_this.addClass('on');
			_thispar.siblings().find('.radio-signle').removeClass('on');
			$('input[data-type='+radio+']').val(value);
			radio_if = false;
		}
	});

	$('.search-choose-wrapper .search-choose').click(function() {
		var _this = $(this);
		var to = _this.attr('data-to');
		$('.'+to).fadeIn().removeClass('hide');
	});
	
	$('.mask-type .search-mask-list li').click(function(){
		var _this = $(this);
		var type = $(this).text();		
		var oldType= $('.search-choose-wrapper .search-choose[data-to="mask-type"]').find('input').val();
		$('.search-choose-wrapper .search-choose[data-to="mask-type"]').find('.search-option').text(type);
		$('.search-choose-wrapper .search-choose[data-to="mask-type"]').find('input').val(type);
		_this.parent().parent().parent().fadeOut().addClass('hide');
		if(type!=oldType){
			$("#addr").val("");
			$("#countyId").val("");
			$("#selectArea").text('选择地区');
		}
		sessionStorage.setItem('cdType', type);
	});

	$('.area-search-form input').focus(function() {
		$(this).prev().addClass('hideImportant');
	});
	$('.area-search-form input').blur(function() {
		var _this = $(this);
		var txt = _this.val();
		if (txt == '') {
			_this.prev().removeClass('hideImportant');
		}else{
			_this.prev().addClass('hideImportant');
		}
	});

	$('.search-area').click(function(){
		if($("#cdType").val()==""||$("#cdType").val()==null){
			showMsg('请选择查档类型！');
		}else{
			$('.select-area-layout').removeClass('hide');			
		}
	});
	$('.area-back').click(function(event) {
		$('.select-area-layout').addClass('hide');
	});

	$('.area-recent-list li').click(function(event) {
		var txt = $(this).text();
		$('.select-court-layout').removeClass('hide').addClass('pageIn');
		$('.current-city').text(txt);
		loadCounty(txt);
	});	
	
	$('.area-city-list li').click(function(event) {
		var txt = $(this).text();
		$('.select-court-layout').removeClass('hide').addClass('pageIn');
		$('.current-city').text(txt);
		loadCounty(txt);		
	});
	$('.court-back-btn,.court-back,.court-back2').click(function(event) {
		moveback($('.select-court-layout'));
	});
	function moveback(box){
		var $court = box;
		$court.css({
			'webkitTransform':'translate3d(0,0,0)',
			'transform':'translate3d(0,0,0)'
		});
		$court.removeClass('pageIn').addClass('pageOut');
		$court.on('animationend webkitAnimationEnd',function(){
			$court.removeClass('pageOut').addClass('hide').css({
				'webkitTransform':'translate3d(100%,0,0)',
				'transform':'translate3d(100%,0,0)'
			});
			$court.off('animationend webkitAnimationEnd');
		});
	}

	// 服务信息
	$('.service-layout').click(function(){
		var _this = $(this);
		var _thispar = _this.parent();
		if (!_thispar.hasClass('active')) {
			_thispar.addClass('active');
			_this.find('.icon').removeClass('icon-down-blue2').addClass('icon-top-blue2');
			_this.next().slideDown(300).removeClass('hide');
		}else{
			_thispar.removeClass('active');
			_this.find('.icon').removeClass('icon-top-blue2').addClass('icon-down-blue2');
			_this.next().slideUp(300).addClass('hide');
		}
	});
	$('.service-remark').click(function(){
		$('.remark-page').removeClass('hide').addClass('pageIn');
	});
	$('.remark-back').click(function(){
		moveback($('.remark-page'));
	});
	
	$('.btn-remark').click(function(){
		moveback($('.remark-page'));
	});
	
	//平台确认
	$('.cancel-order').click(function(){
		$('.cancel-page').fadeIn(300).removeClass('hide');
	});
	$('.mask-confirm-btn .btn-yes').click(function(){
		$('.cancel-page').fadeOut(300).removeClass('hide');
	});	
	$('.mask-confirm-btn .btn-cancel').click(function(){
		$('.cancel-page').fadeOut(300).removeClass('hide');
	});	
	//进行查档
	function fadeInBox(box){
		$('.'+box).fadeIn(200).removeClass('hide');
	}
	function fadeOutBox(box){
		$('.'+box).fadeOut(200).addClass('hide');
	}
	
	$('.btn-viewDeliv').click(function(){
		var _this = $(this);
		var box = _this.attr('data-to');
		fadeInBox(box);
	});
	$('.viewDeliv-btn .btn-cancel').click(function(){
		var _this = $(this);
		var box = _this.attr('data-to');
		fadeOutBox(box);
	});
	$('.viewDeliv-btn .btn-yes').click(function(){
		var _this = $(this);
		var box = _this.attr('data-to');
		fadeOutBox(box);
	});		

	$('.btn-delivery').click(function(){
		var _this = $(this);
		var box = _this.attr('data-to');
		fadeInBox(box);
	});
	$('.delivery-btn .btn-cancel').click(function(){
		var _this = $(this);
		var box = _this.attr('data-to');
		fadeOutBox(box);
	});
	$('.delivery-btn .btn-yes').click(function(){
		var _this = $(this);
		var box = _this.attr('data-to');
		fadeOutBox(box);
	});
	
	$('.pay-invoice').click(function(){
		var _this = $(this);
		var box = _this.attr('data-to');
		fadeOutBox(box);		
	});
	//ios or android
	var u = navigator.userAgent;
	var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); 
	if (isAndroid) {
		$('.delivery-form .form-control input').css({
			'padding-top': '0.18rem'
		});
	}
	if (isiOS) {
		document.body.addEventListener('touchstart', function () {});  
		$('.circle').css({
			'top': '2px'
		});
	}	
});


function materialClick(obj){
	var _this = $(obj);
	var _thispar = _this.parent();
	if (!_thispar.hasClass('active')) {
		_thispar.addClass('active');
		_this.find('.icon').removeClass('icon-down-blue2').addClass('icon-top-blue2');
		_this.next().removeClass('hide');
	}else{
		_thispar.removeClass('active');
		_this.find('.icon').removeClass('icon-top-blue2').addClass('icon-down-blue2');
		_this.next().addClass('hide');
	}
}

function getOrderTypeName(orderType){
	if(orderType==1){
		return "工商基本信息";
	}else if(orderType==2){
		return "工商内档信息";
	}else if(orderType==3){
		return "户籍信息";
	}else if(orderType==4){
		return "婚姻信息";
	}else if(orderType==5){
		return "房产信息";
	}else if(orderType==6){
		return "车辆信息";
	}
}

function formSubmit(map, action){
	var form = $("<form></form>");  
    form.attr('action', action);  
    form.attr('method', 'post');  
    for(var obj in map){  
       var input1 = $("<input type='hidden' name='"+obj+"' value='"+map[obj]+"' />");
       form.append(input1);  
    }
    form.appendTo("body");  
    form.css('display', 'none');  
    form.submit();
}

Array.prototype.contains = function(elem) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == elem) {
			return true;
		}
	}
	return false;
}

Array.prototype.indexOf = function(o) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == o) {
			return i;
		}
	}
	return -1;
};

Array.prototype.deleta = function(o) {
	var index = this.indexOf(o);
	if (index != -1) {
		this.splice(index, 1)
	}
	return this;
}


