/*======================================================================*\
|| #################################################################### ||
|| # SAO KIM CMS V2.0												  # ||  
|| # ---------------------------------------------------------------- # ||
|| # All Ajavascript code in this file is ©2009-2010 Sao Kim Co., Ltd.# ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- SAOKIM CMS IS NOT FREE SOFTWARE --------------- # ||
|| # http://www.saokimad.com | http://www.saokim.com.vn               # ||
|| #################################################################### ||
\*======================================================================*/

function registerNewletter()
{
	var nlt_email	=	jQuery("#nlt_email").val();
	if(isEmail(nlt_email)==false){
		alert("Vui lòng nhập email đúng định dạng!");	
	}
	else{
		jQuery.ajax({
			   type:"POST",
			   dataType:"html",
			   url:"contact.php?act=newletter",
			   data:"&nlt_email="+nlt_email,
			   success: function(html){
					alert(html);
				}
			});	
	}
}

function showGalleryDetail(gallery_id,target)
{
	jQuery("#"+target).html("<div class=\"loading\"></div>");
	jQuery.ajax({
			   type:"POST",
			   dataType:"html",
			   url:"gallery.php?a=7&gallery_id="+gallery_id,
			   data:"",
			   success: function(html){
					jQuery("#"+target).html(html);
				}
			});		
}

function loadMusic()
{
	var path	=	"http://www.saokim.com.vn/music/";
	var playlist = new Array(3);  
	playlist[0] = "playlist_01.xspf";  
	playlist[1] = "playlist_02.xspf";  
	playlist[2] = "playlist_03.xspf";  
	randno = Math.floor ( Math.random() * playlist.length ); 
  document.write('<object type="application/x-shockwave-flash" width="200" height="15" data="'+path+'player_slim.swf?autoplay=true&repeat=false&shuffle=false&playlist_url='+path+playlist[randno]+'"><param name="movie" value="'+path+'player_slim.swf?autoplay=true&repeat=false&shuffle=false&playlist_url='+path+playlist[randno]+'" /></object>');
}
function loadBanner(baseUrl)
{
	// JAVASCRIPT VARS
	// cache buster
	var cacheBuster = "?t=" + Date.parse(new Date());		
	// stage dimensions
	var stageW = 1000;//"100%";
	var stageH = 350;//"100%";
	
	// ATTRIBUTES
	var attributes = {};
	attributes.id = 'FlabellComponent';
	attributes.name = attributes.id;
	
	// PARAMS
	var params = {};
	params.bgcolor = "#5F6468";
	params.wmode   = "transparent";
	
	/* FLASH VARS */
	var flashvars = {};				
	
	/// if commented / delete these lines, the component will take the stage dimensions defined 
	/// above in "JAVASCRIPT SECTIONS" section or those defined in the settings xml			
	flashvars.componentWidth = stageW;
	flashvars.componentHeight = stageH;
	
	/// path to the content folder(where the xml files, images or video are nested)
	/// if you want to use absolute paths(like "http://domain.com/images/....") then leave it empty("")
	flashvars.pathToFiles = "";
	flashvars.xmlPath = baseUrl+"/templates/banner/xml/banner.xml";
	
	/** EMBED THE SWF**/
	swfobject.embedSWF(baseUrl+"/templates/preview.swf"+cacheBuster, attributes.id, stageW, stageH, "9.0.124", baseUrl+"/templates/js/expressInstall.swf", flashvars, params);
	
}

function loadMenu(menuActive,baseUrl)
{
	var flashmnu= jQuery("<ul>").attr("class", "newsticker");
    flashmnu.append("<li><a href='"+baseUrl+"/noithat/' class='noithat' target='_blank'>&nbsp;Nội thất</a>");
    flashmnu.append("<li><a href='"+baseUrl+"/lichtet/' class='lichtet'  target='_blank'>&nbsp;Lịch tết</a></li>");
    flashmnu.appendTo("#flashmnu").newsTicker();
    flashmnu.append("<li><a href='"+baseUrl+"/blog/'>Blog</a></li>");
	if(menuActive=='contact')
		flashmnu.append("<li class='active'><a href='"+baseUrl+"/lienhe.html'>Liên hệ</a></li>");	
	else
	flashmnu.append("<li><a href='"+baseUrl+"/lienhe.html'>Liên hệ</a></li>");	
}

/////////////NO RIGHT CLICK//////////////////////
var message="Function Disabled!";
function clickIE4()
{
	if (event.button==2){
		//alert(message);
		return false;
	}
}

function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
	{
		if (e.which==2||e.which==3){
		//alert(message);
		return false;
		}
	}
}

function noCopy()
{
  if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
	}
	else if (document.all&&!document.getElementById){
		document.onmousedown=clickIE4;
	}
	document.oncontextmenu=new Function("return false")	
}



function xemAnhHot(i,limit,rowPerPage,imagePerRow)
{
	var baseUrl	=	jQuery('#baseUrl').val(); 	
	var data	=	"act=pagingImage&page="+i+"&limit="+limit+"&rowPerpage="+rowPerPage+"&imagePerRow="+imagePerRow;
	var url	=	baseUrl+"/index.php?";   
	loadAjax("POST","html",data,url,'listImage',0);  
}

function loadHotProductTo(target,imagePerRow)
{
	var baseUrl	=	jQuery('#baseUrl').val();
	jQuery('#'+target).load(baseUrl+'index.php?act=pagingImage&page=1&imagePerRow='+imagePerRow);
}

function loadInit()
{
	/*window.onload = function() {
	  document.onselectstart = function() {return false;} // ie
	  document.onmousedown = function() {return false; } // mozilla
	}*/
}

function sendContactForm() 
{  
	var msg			=	"";    
	var baseUrl			=	jQuery("#baseUrl").val();  
	var contact_title	=	jQuery("#contact_title").val();  
	var contact_fullname=	jQuery("#contact_fullname").val();  
	var contact_email	=	jQuery("#contact_email").val();  
	var contact_tel		=	jQuery("#contact_tel").val();  
	var contact_company	=	jQuery("#contact_company").val();  
	var contact_address	=	jQuery("#contact_address").val(); 
	var contact_region	=	jQuery("#contact_region").val(); 
	var contact_content	=	jQuery("#contact_content").val();  
	var contact_referent=	jQuery("#contact_referent").val();    
	var cat_email		=	jQuery("#cat_email").val();   // Gui email ve cho nguoi quan ly danh muc do 
	if(contact_title=="" || contact_title =="Tiêu đề"){  
		msg	+=	"- Ban chua nhap Tieu De \n";  
	}  
	if(contact_fullname=="" || contact_fullname =="Họ tên"){  
		msg	+=	"- Ban chua nhap Ho Ten \n";  
	}  
	if(isEmail(contact_email)==false){  
		msg+=	"- Email lien he khong dung dinh dang \n";  
		jQuery('#contact_email').val("Email");
	}  
	if(contact_tel=="" || contact_tel=="Điện thoại"){
		msg	+=	"- Ban chua nhap dien thoai\n";	
		jQuery('#contact_tel').val("Điện thoại");
	}
	if(contact_address=="" || contact_address=="Địa chỉ"){
		msg +=	"- Ban chua nhap Dia Chi lien he\n";	
	}
	if(contact_region==""){
		msg	+=	"- Ban chua chon lien he voi Van phong HN hay HCM\n";		
	}
	if(contact_content=="" || contact_content =="Nội dung" || contact_content.length < 20){  
		msg	+=	"- Noi dung gui qua ngan, vui long neu ro yeu cau cua ban \n";  
	} 

	if(msg)  {  alert("[ Chua dung ]\n\n"+msg);  }  
	else{   
		var dataString	=	"act=sendAjax&contact_title="+contact_title+"&contact_fullname="+contact_fullname+"&contact_email="+contact_email+"&contact_tel="+contact_tel+"&contact_company="+contact_company+"&contact_content="+contact_content+"&contact_referent="+contact_referent+"&cat_email="+cat_email;  
		dataString	+=	"&contact_region="+contact_region+"&contact_address="+contact_address;
		var url	=	baseUrl+"/contact.php?";  
		jQuery.ajax({
			   type:"POST",
			   dataType:"html",
			   url:url,
			   data:dataString,
			   success: function(html){
					if(html){alert(html);}
					clearAll();
				}
			});
	}    
}    

function clearAll(){  
	jQuery("#contact_fullname").val("Họ tên");  
	jQuery("#contact_email").val("Email");  
	jQuery("#contact_content").val("Nội dung");  
	jQuery("#contact_title").val("Tiêu đề");  
	jQuery("#contact_company").val("Công ty");  
	jQuery("#contact_tel").val("Điện thoại");
	jQuery("#contact_address").val("Địa chỉ");
}

function xemanh(i)
{
	var page	=	i; 
	var baseUrl	=	jQuery('#baseUrl').val(); 
	var id		=	jQuery('#id').val(); 
	var data	=	'ajax=pagingImage&page='+page; 
	var url		=	baseUrl+'/content.php?act=view&id='+id+'&';
	jQuery('#imgLoading').html("Loading..."); 
	//alert(url+data);
	loadAjax("GET","html",data,url,'listImage',0);  				
}

function viewCustPic(i)
{
	var baseUrl		=	jQuery('#baseUrl').val(); 
	var cust_id		=	jQuery('#id').val(); 
	var data	=	'ajax=pagingImage&page='+i; 
	var url		=	baseUrl+'/customer.php?act=view&cust_id='+cust_id+'&';
	jQuery('#imgLoading').html("Loading..."); 
	//alert(url+data);
	loadAjax("GET","html",data,url,'listImage',0);  				
}


function showHighSlide(baseUrl)
{
	hs.graphicsDir = baseUrl+'/highslide/graphics/';
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.outlineType = 'glossy-dark';
	hs.wrapperClassName = 'dark';
	hs.fadeInOut = true;
	hs.showCredits = false;
	hs.dimmingOpacity = 0.8;
	hs.captionEval = 'this.thumb.alt';
	hs.lang = {
		cssDirection: 'ltr',
		loadingText : 'Loading...',
		loadingTitle : 'Click to cancel',
		focusTitle : 'Click to bring to front',
		fullExpandTitle : 'Expand to actual size (f)',
		previousText : 'Previous',
		nextText : 'Next', 
		moveText : 'Move',
		closeText : 'Close', 
		closeTitle : 'Close (esc)', 
		resizeTitle : 'Resize',
		playText : 'Play',
		playTitle : 'Play slideshow (spacebar)',
		pauseText : 'Pause',
		pauseTitle : 'Pause slideshow (spacebar)',
		previousTitle : 'Previous (arrow left)',
		nextTitle : 'Next (arrow right)',
		moveTitle : 'Move',
		fullExpandText : '1:1',
		number: 'Image %1 of %2',
		restoreTitle : 'Click to close image, click and drag to move. Use arrow keys for next and previous.'
	}
	// Add the controlbar
	if (hs.addSlideshow) hs.addSlideshow({
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			opacity: .6,
			position: 'bottom center',
			hideOnMouseOut: true
		}
	});	
}


function sendComment()
{
	var baseUrl			=	jQuery("#baseUrl").val();
	var comment_author	=	jQuery("#comment_author").val();
	var	comment_author_email	=	jQuery("#comment_author_email").val();
	var comment_author_url		=	jQuery("#comment_author_url").val();
	var comment_content			=	jQuery("#comment_content").val();
	var	comment_referent_id		=	jQuery("#image_id").val();
	var	security_code			=	jQuery("#security_code").val();
	var dataString				=	"&comment_author="+comment_author+"&comment_author_email="+comment_author_email+"&comment_author_url="+comment_author_url+"&comment_content="+comment_content+"&comment_referent_id="+comment_referent_id+"&comment_type=gallery&security_code="+security_code;
	var url				=	baseUrl+"/gallery.html?a=4";
	
	jQuery("#btnSendComment").val("Đang gửi...");
	jQuery("#btnSendComment").attr('disabled',true);
	loadAjax("POST","html",dataString,url,"message",0)
}

function loadComment(image_id)
{
	var JQuery  		= jQuery.noConflict();
	var baseUrl			=	JQuery("#baseUrl").val();
	var data			=	"&image_id="+image_id;
	var url				=	baseUrl+"gallery.html?a=6";
	loadAjax("POST","html",data,url,"comment",1);
}

function clearComment()
{
	clear("comment_content");
	clear("comment_author_email");
	clear("comment_author");
	clear("comment_author_url");
}

function closeComment(target)
{
	jQuery("#"+target).hide('slow');
	jQuery("#"+target).html("<div class=\"author\">Cảm ơn bạn đã gửi ý kiến nhận xét đến Sao Kim</div>");
	jQuery("#"+target).show('slow');
}

function loadGalleryImage(image,height,title)
{
	var baseUrl	=	jQuery("#baseUrl").val();
	//var url	=	baseUrl+"/"+alias+"/mark/"+id;
	var url	=	baseUrl+"/images/gallery/"+image;
	document.write("<object width='700' height='"+height+"' data='"+url+"' type='application/x-shockwave-flash' title='"+title+"'><param name='movie' value='"+url+"' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='width' value='700' /><param name='height' value='"+height+"' /><param name='src' value='"+url+"' /><param name='pluginspage' value='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' /><param name='type' value='application/x-shockwave-flash' /></object>");
}


function googleAnalytics(gcode)
{
	var _gaq = _gaq || [];
  _gaq.push(['_setAccount', gcode]);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
}


function loadMyBanner(baseUrl,xmlFileName)
{
	$(document).ready(function() {
		$.animateBackground=function($colour) {
			$("#home-featured, #home-featured-wrapper, #header ul li.active").animate({ backgroundColor: $colour }, 10);//10mms
		}
		$("#home-featured-wrapper").each(function() {
			$("#header ul li.active").css("background-color",$(this).css("background-color"));
		});
		
		$("#home-featured").each(function() {
			var flashvars = {"xmlPath":""+baseUrl+"/flash/"+xmlFileName};
			var params = {"allowScriptAccess":"sameDomain","wmode":"transparent","allowFullScreen":"true"};
			var attributes = {};
			swfobject.embedSWF(baseUrl+"/flash/main.swf", "home-featured", "970", "387", "9.0.0", false, flashvars, params, attributes);
			
		});	
	});	
}


//+++++ Remove frame
if (self != top) {
    if (document.images)
        top.location.replace(window.location.href);
    else
        top.location.href = window.location.href;
}
