function template(num,dm,ex){
	
	if(num==2){
		return '<tr id="'+replacedot((dm+ex))+'"><td><strong>'+dm+'.'+ex+'</strong> </td><td class="starter" style="WIDTH: 38%"><img src="http://localhost/smartnet/js/loading.gif" alt="Đang kiểm tra" title="Đang kiểm tra" /></td><td class="starter" style="WIDTH: 18%"></td></tr>\n';
	}
	if(num==3){
		return '<td class="starter">'+dm+'.'+ex+'</td><td class="starter" style="WIDTH: 38%"><b> Đã đăng ký</b></td> <td class="starter" style="WIDTH: 18%"><a style="color:#9a9a9a;" href="javascript:ht_whois(\''+dm+'\',\''+ex+'\')">Bấm vào đây</a></td>\n';
	}
	if(num==4){
		return '<td class="pro">'+dm+'.'+ex+'</td><td  class="pro" style="WIDTH: 38%"><b>Có thể <a href="javascript:void(0)"  onclick="goToByScroll(\'register\');">đăng ký</a></b></td> <td class="pro" style="WIDTH: 18%"></td>\n ';
	}
}
function replacedot(str){
	return str.replace(/[.]/gi,'');
}
$(function(){	
	$('#check').click(function(){
		var domain = $('#domainId').val();
		var ext = $('input[name=ext]');
		var errlogs = '';
		
		if(domain.length < 2){
			errlogs += '+ Tên miền quá ngắn, tối thiểu 3 ký tự \n';			
		}
		if(!validateDomain(domain)){
			errlogs += '+ Tên miền chỉ được chưa các ký tự A-Z, 0-9 và dấu trừ (-) \n';			
		}
		if(domain.indexOf('--') != -1){
			errlogs += '+ tên miền không thể chứa 2 dấu trừ liên tiếp: -- \n';
		}
		if(domain.indexOf('-')==0 || domain.lastIndexOf('-')==domain.length-1){
			errlogs += '+ tên miền không thể bắt đầu hoặc kết thúc bởi dấu trừ: - \n';
		}
		if(errlogs != ''){
			alert(errlogs);
			return false;
		}
		else {
			$('#rowResult').html('');
		//	window.location.hash= '#Result';
			if( domain.indexOf('.') > 0 )
			{
			goToByScroll('Result');
				$("#tableInfo").css({"display":""});
				str= domain.split(".");
				$('#rowResult').html('<tr><td><strong>'+str[0]+'.'+str[1]+'</strong> </td><td class="starter" style="WIDTH: 38%"><img src="http://localhost/smartnet/js/loading.gif" alt="Đang kiểm tra" title="Đang kiểm tra" /></td><td class="starter" style="WIDTH: 18%"></td></tr>');
				$.ajax({
					type:'GET',
					url: 'http://localhost/smartnet/checkdomain.php',
					data: 'ajax=true&act=check&domain='+str[0]+'&ext='+str[1],							
					success:function(html){
						html = $.trim(html);
						ext = new Array(html.slice(domain.length,(html.length -1)),html.slice(domain.length,(html.length)))
						if(html){
							if(html.lastIndexOf('.') == (html.length -1)){
								
								$('#rowResult').html("<tr>"+template(3,domain,ext[0])+"</tr>");
							}
							else{
								$('#rowResult').html("<tr>"+template(4,domain,ext[1])+"</tr>");
							}
						}else{
							$('#rowResult').html('Không kết nối được máy chủ, vui lòng thử lại');								
						}																
					}
				});
				//window.location.href='/?domain='+domain+'#Result';
			}else{				
				var hasChecked = false;
				ext.each(function(){
					if(this.checked){
						hasChecked=true;
						$(template(2,domain,this.id)).appendTo('#rowResult');
					}
				});
				if(!hasChecked){
					alert("Hãy chọn ít nhất một đuôi mở rộng của tên miền (tích chọn)");
					return false;
				}else{
			goToByScroll('Result');
					ext.each(function(){
						if(this.checked){
						$("#tableInfo").css({"display":""});
							$.ajax({
								type:'GET',
								url: 'http://localhost/smartnet/checkdomain.php',
								data: 'ajax=true&act=check&domain='+domain+'&ext='+this.id,							
								success:function(html){
									html = $.trim(html);
									ext = new Array(html.slice(domain.length,(html.length -1)),html.slice(domain.length,(html.length)))
									if(html){
										if(html.lastIndexOf('.') == (html.length -1)){
											
											$('#'+replacedot(domain+ext[0])+'').html(template(3,domain,ext[0]));
										}
										else{
											$('#'+replacedot(domain+ext[1])+'').html(template(4,domain,ext[1]));
										}
									}else{
										$('#rowResult').html('Không kết nối được máy chủ, vui lòng thử lại');								
									}																
								}
							});
						}
					});
				}
			}
		}
	});			
	$('#chkall').click(function(){
		var checked_status = this.checked;
		$('input[name=ext]').each(function(){
			this.checked = checked_status;
		});
	});
});
function ht_whois(domain,ext){
	$('#resultInfo').dialog('open');
	$('#resultInfo').dialog({	
		width: 600,
		height: 500,
		modal:true
	});
	$('#resultInfo').dialog('option', 'title', 'Thông tin tên miền:'+' '+domain+'.'+ext);
	$('#resultInfo').html('<div style="text-align:center;margin-top:200px"><img src="http://localhost/smartnet/js/loading.gif" /></div>');
	$.ajax({
		type: 'GET',
		url: 'http://localhost/smartnet/checkdomain.php',
		data: 'act=info&domain='+domain+'&ext='+ext,
		success: function(html){
		 	$('#resultInfo').html(html);
		}
	});
}
function validateDomain(elementValue){    
   var domainPattern = /^[a-zA-Z0-9-.]+$/ ;
   return domainPattern.test(elementValue); 
}


		function goToByScroll(id){
     	$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}
function loadCommonDomain(){
			$('#left').css({"margin-left":"-300px"});
				$("#left").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 700 );
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
			setTimeout('faceRight();', 1500); 
			$('#all').fadeIn(2000);
			$('.domain_search').fadeIn(4000);
			$('a[href=#top]').click(function(){
						$('html, body').animate({scrollTop:0}, 'slow');
					return false;
				});
            var h_left;
            h_left = $(window).height();
            heightleft=h_left + "px";
            //alert(heightleft);
			if (h_left> 600){
            $("#left").css("height",heightleft);
			$(".left").css("height",heightleft);
			$("#right").css("min-height",heightleft);}
			else {
			 $("#left").css("height",600+"px");
			 $(".left").css("height",600+"px");
			 $("#right").css("min-height",heightleft);}
            
			//left menu
			$(".menu li a")
			.mouseover(function () {
				//$.fn.soundPlay({url: 'sound.mp3', playerId: 'embed_player', command: 'play'});
				$(".menu_blt", this).fadeIn(250);
				$(this).addClass("hover");
			$(this).stop().animate({ paddingRight: "30px" }, 150 )
			})
			.mouseout(function () {
			 //$.fn.soundPlay({playerId: 'embed_player', command: 'stop'});
				$(".menu_blt", this).fadeOut(400);
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
				$(this).removeClass("hover");
			$(this).stop().animate({ paddingRight: "20px" }, 200 )
			});
			
			//fade links
				var nav_clr;
				nav_clr =  $('.color03').css("color");
				$('.nav a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				
				
			// Expand Panel
			$("ul.domain_box").css("height","30px")
			$("#close").css("display","none");
			$("#open").click(function(){
				$("ul.domain_box").animate({"height": "+=100px"});
				$("#close").css("display","block");
				$("#open").css("display","none");
			});	
			
			// Collapse Panel
			$("#close").click(function(){
				$("ul.domain_box").animate({"height": "-=100px"});
				$("#open").css("display","block");
				$("#close").css("display","none");
			});		
			
		 
}

function loadCommonHosting(){

			$('#left').css({"margin-left":"-300px"});
				$("#left").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 700 );
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
			$('.captionview').css({"margin-right":"-300px"});
				$(".bgimage").animate({
					opacity: 0.3,
				  }, 500 );
			$(".project").hover(
			  function () {
				// $(this).css({"cursor":"pointer"});
				$(this).children(".captionview").animate({
					"margin-right":"0px",
					
				  }, 500 );
				$(this).children(".bgimage").animate({
					opacity: 1,
				  }, 500 );
			  },
			  function () {
				$(this).children(".captionview").animate({
					//width: "0",
					"margin-right":"-300px",
				  }, 500 );
				$(this).children(".bgimage").animate({
					opacity: 0.5,
				  }, 500 );
		  }
			);			
			setTimeout('faceRight();', 1500); 
			$('#all').hide();
			$('#all').fadeIn(2000);
			$('a[href=#top]').click(function(){
						$('html, body').animate({scrollTop:0}, 'slow');
					return false;
				});
            var h_left;
            h_left = $(window).height();
            heightleft=h_left + "px";
            //alert(heightleft);
			if (h_left> 600){
            $("#left").css("height",heightleft);
			$(".left").css("height",heightleft);
			$("#right").css("min-height",heightleft);}
			else {
			 $("#left").css("height",600+"px");
			 $(".left").css("height",600+"px");
			 $("#right").css("min-height",heightleft);}
            
			//left menu
			$(".menu li a")
			.mouseover(function () {
				//$.fn.soundPlay({url: 'sound.mp3', playerId: 'embed_player', command: 'play'});
				$(".menu_blt", this).fadeIn(250);
				$(this).addClass("hover");
			$(this).stop().animate({ paddingRight: "30px" }, 150 )
			})
			.mouseout(function () {
			 //$.fn.soundPlay({playerId: 'embed_player', command: 'stop'});
				$(".menu_blt", this).fadeOut(400);
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
				$(this).removeClass("hover");
			$(this).stop().animate({ paddingRight: "20px" }, 200 )
			});
			
			//fade links
				var nav_clr;
				nav_clr =  $('.color05').css("color");
				$('.nav a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				
			//Hide content and SLide
		 
}
function loadCommonWebsite(){

			$('#left').css({"margin-left":"-300px"});
				$("#left").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 700 );
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
			$('.captionview').css({"margin-right":"-300px"});
				$(".bgimage").animate({
					opacity: 0.3,
				  }, 500 );
			$(".project").hover(
			  function () {
				// $(this).css({"cursor":"pointer"});
				$(this).children(".captionview").animate({
					"margin-right":"0px",
					
				  }, 500 );
				$(this).children(".bgimage").animate({
					opacity: 1,
				  }, 500 );
			  },
			  function () {
				$(this).children(".captionview").animate({
					//width: "0",
					"margin-right":"-300px",
				  }, 500 );
				$(this).children(".bgimage").animate({
					opacity: 0.5,
				  }, 500 );
		  }
			);			
			setTimeout('faceRight();', 1500); 
			$('a[href=#top]').click(function(){
						$('html, body').animate({scrollTop:0}, 'slow');
					return false;
				});
            var h_left;
            h_left = $(window).height();
            heightleft=h_left + "px";
            //alert(heightleft);
			if (h_left> 600){
            $("#left").css("height",heightleft);
			$(".left").css("height",heightleft);
			$("#right").css("min-height",heightleft);}
			else {
			 $("#left").css("height",600+"px");
			 $(".left").css("height",600+"px");
			 $("#right").css("min-height",heightleft);}
            
			//left menu
			$(".menu li a")
			.mouseover(function () {
				//$.fn.soundPlay({url: 'sound.mp3', playerId: 'embed_player', command: 'play'});
				$(".menu_blt", this).fadeIn(250);
				$(this).addClass("hover");
			$(this).stop().animate({ paddingRight: "30px" }, 150 )
			})
			.mouseout(function () {
			 //$.fn.soundPlay({playerId: 'embed_player', command: 'stop'});
				$(".menu_blt", this).fadeOut(400);
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
				$(this).removeClass("hover");
			$(this).stop().animate({ paddingRight: "20px" }, 200 )
			});
			
			//fade links
				var nav_clr;
				nav_clr =  $('.color02').css("color");
				$('.nav a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				
			//Hide content and SLide
		
}
function loadCommonNews(){

			$('#right').css({"margin-left":"0"});
			$('#left').css({"margin-left":"-300px"});
				$("#left").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 500 );
				$(".bgimage").animate({
					opacity: 0.3,
				  }, 500 );
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
			$('a[href=#top]').click(function(){
						$('html, body').animate({scrollTop:0}, 'slow');
					return false;
				});
			setTimeout('faceRight();', 1500); 
            var h_left;
            h_left = $(window).height();
            heightleft=h_left + "px";
            //alert(heightleft);
			if (h_left> 600){
            $("#left").css("height",heightleft);
			$(".left").css("height",heightleft);
			$("#right").css("min-height",heightleft);}
			else {
			 $("#left").css("height",600+"px");
			 $(".left").css("height",600+"px");
			 $("#right").css("min-height",heightleft);}
            
			//left menu
			$(".menu li a")
			.mouseover(function () {
				//$.fn.soundPlay({url: 'sound.mp3', playerId: 'embed_player', command: 'play'});
				$(".menu_blt", this).fadeIn(250);
				$(this).addClass("hover");
			$(this).stop().animate({ paddingRight: "30px" }, 150 )
			})
			.mouseout(function () {
			 //$.fn.soundPlay({playerId: 'embed_player', command: 'stop'});
				$(".menu_blt", this).fadeOut(400);
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
				$(this).removeClass("hover");
			$(this).stop().animate({ paddingRight: "20px" }, 200 )
			});
			
			//fade links
				var nav_clr;
				nav_clr =  $('.color03').css("color");
				$('.nav a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				$('.article_info a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				$('.other_article a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				
			//Hide content and SLide
			$('.images img').captify({});
		 	
	}
function loadCommonFour(){

			$('#right').css({"margin-left":"0"});
			$('#left').css({"margin-left":"-300px"});
				$("#left").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 500 );
				$(".bgimage").animate({
					opacity: 0.3,
				  }, 500 );
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
			$('a[href=#top]').click(function(){
						$('html, body').animate({scrollTop:0}, 'slow');
					return false;
				});
			setTimeout('faceRight();', 1500); 
            var h_left;
            h_left = $(window).height();
            heightleft=h_left + "px";
            //alert(heightleft);
			if (h_left> 600){
            $("#left").css("height",heightleft);
			$(".left").css("height",heightleft);
			$("#right").css("min-height",heightleft);}
			else {
			 $("#left").css("height",600+"px");
			 $(".left").css("height",600+"px");
			 $("#right").css("min-height",heightleft);}
            
			//left menu
			$(".menu li a")
			.mouseover(function () {
				//$.fn.soundPlay({url: 'sound.mp3', playerId: 'embed_player', command: 'play'});
				$(".menu_blt", this).fadeIn(250);
				$(this).addClass("hover");
			$(this).stop().animate({ paddingRight: "30px" }, 150 )
			})
			.mouseout(function () {
			 //$.fn.soundPlay({playerId: 'embed_player', command: 'stop'});
				$(".menu_blt", this).fadeOut(400);
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
				$(this).removeClass("hover");
			$(this).stop().animate({ paddingRight: "20px" }, 200 )
			});
			
			//fade links
				var nav_clr;
				nav_clr =  $('.color04').css("color");
				$('.nav a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				$('.article_info a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				$('.other_article a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				
			//Hide content and SLide
			$('.images img').captify({});
		 	
	}
function loadCommonMarketing(){

			$('#right').css({"margin-left":"0"});
			$('#left').css({"margin-left":"-300px"});
				$("#left").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 500 );
				$(".bgimage").animate({
					opacity: 0.3,
				  }, 500 );
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
			$('.mdescription').hide();
			$(".box01").hover(
			  function () {
				// $(this).css({"cursor":"pointer"});
					 $(this).find(".mdescription").fadeIn(600);
					 $(this).find(".caption01").animate({
							"height":"160px",
				 		}, 100);
				  
				  				$(this).children(".caption01").animate({
					"top":"0",
				  }, 200);
				  
				$(this).children(".bgbox1").animate({
					opacity: 0.7,
				  }, 300 );
			  },
			  function () {
				
				$(this).children(".caption01").animate({
					"top":"130px",
				  }, 200,function(){
					$(this).find(".mdescription").fadeOut(100,function(){
					 $(this).find(".caption01").animate({
					"height":"70px",
				  },80)
					
					});					 
				});
				$(this).children(".bgbox1").animate({
					opacity: 1,
				  }, 300 );
		  }
			);			
			$('a[href=#top]').click(function(){
						$('html, body').animate({scrollTop:0}, 'slow');
					return false;
				});
			setTimeout('faceRight();', 1500); 
            var h_left;
            h_left = $(window).height();
            heightleft=h_left + "px";
            //alert(heightleft);
			if (h_left> 600){
            $("#left").css("height",heightleft);
			$(".left").css("height",heightleft);
			$("#right").css("min-height",heightleft);}
			else {
			 $("#left").css("height",600+"px");
			 $(".left").css("height",600+"px");
			 $("#right").css("min-height",heightleft);}
            
			//left menu
			$(".menu li a")
			.mouseover(function () {
				//$.fn.soundPlay({url: 'sound.mp3', playerId: 'embed_player', command: 'play'});
				$(".menu_blt", this).fadeIn(250);
				$(this).addClass("hover");
			$(this).stop().animate({ paddingRight: "30px" }, 150 )
			})
			.mouseout(function () {
			 //$.fn.soundPlay({playerId: 'embed_player', command: 'stop'});
				$(".menu_blt", this).fadeOut(400);
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
				$(this).removeClass("hover");
			$(this).stop().animate({ paddingRight: "20px" }, 200 )
			});
			
			//fade links
				var nav_clr;
				nav_clr =  $('.color06').css("color");
				$('.nav a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				$('.article_info a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				$('.other_article a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				
			//Hide content and SLide
			$('.images img').captify({});
		 	
	}
	
	/*
	
	/*
 *
 * jquery.sound.js
 * (c) Vipin Kumar Rajput
 *
 */
	function initCommonFunctionHome(){
// Always check out the latest version from
// https://github.com/alexanderdickson/waitForImages
		
			$('#right').css({"margin-left":"-1000px"});
			$('.menu').hide();
			$('.packet').hide();
			$('.footer').hide();
			$('.panel').hide();
			$('.welcome').hide();
			$('.service').hide();
			$('#left').css({"margin-left":"-300px"});
				$("#left").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 300, function() {
					$('.menu').fadeIn(600,function(){
						$('.panel').fadeIn(500);
						$('.footer').fadeIn(600);
					
					});
				  });
		setTimeout('faceRight();', 1000); 
			//  var class= $('.menu li a').hasClass('active');
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
            var h_left;
            h_left = $(window).height();
            heightleft=h_left + "px";
            //alert(heightleft);
			if (h_left> 600){
            $("#left").css("height",heightleft);
			$(".left").css("height",heightleft);
			$("#right").css("min-height",heightleft);}
			else {
			 $("#left").css("height",600+"px");
			 $(".left").css("height",600+"px");
			 $("#right").css("min-height",heightleft);}
            
			//left menu
			$(".menu li a")
			.mouseover(function () {
				//$.fn.soundPlay({url: 'sound.mp3', playerId: 'embed_player', command: 'play'});
				$(".menu_blt", this).fadeIn(250);
				$(this).addClass("hover");
			$(this).stop().animate({ paddingRight: "30px" }, 150 )
			})
			.mouseout(function () {
			 //$.fn.soundPlay({playerId: 'embed_player', command: 'stop'});
				$(".menu_blt", this).fadeOut(400);
			  if($('.menu li a').hasClass('active')){
				$(".menu li a.active .menu_blt").fadeIn(250);
			  }
				$(this).removeClass("hover");
			$(this).stop().animate({ paddingRight: "20px" }, 200 )
			});
			
			//fade links
				var nav_clr;
				nav_clr =  $('.color01').css("color");
				$('.nav a').dwFadingLinks({
					color: nav_clr,
					duration: 300
				});
				
			//detail image content
        $('#slider').nivoSlider();
	}
function faceRight(){
				$("#right").animate({
					//width: "0",
					"margin-left":"0px",
				  }, 700 ,function(){
					$(".packet").fadeIn('slow');
					$(".packet").animate({'margin-left':'180px'},300);
					$(".packet").queue(function () {
					$(this).dequeue();
					});
					$(".packet").animate({'margin-left':'0'},300,function(){
						$(".service").fadeIn('slow');
						$(".service").animate({'margin-left':'195px'},300);
						$(".service").queue(function () {
						$(this).dequeue();
						});
						$(".service").animate({'margin-left':'15px'},300,function(){
								$(".welcome").fadeIn('slow');
						
						});
						
					
					});
					
					
					
						/*$('.welcome').fadeIn(800,function(){
							$('.service').fadeIn(700,function(){
							//$('.packet').fadeIn(600);
								//  $(".packet").toggle( 600 );

							});
						});*/
					 });

}

