/*
 All Function use for public
*/
function getUrlAjax() {
	return jQuery("#hdn_url_ajax").val();
}

function fRankingProductLike(product_id){
	var url_ajax = getUrlAjax();
	jQuery.post(url_ajax, {
		key_word : 'fRankingProductLike',
		product_id : product_id
	}, function(r) {
		jQuery("#id_label_count_like").html(r);
	});	
}

function fRankingProductUnLike(product_id){
	var url_ajax = getUrlAjax();
	jQuery.post(url_ajax, {
		key_word : 'fRankingProductUnLike',
		product_id : product_id
	}, function(r) {
		jQuery("#id_label_count_unlike").html(r);
	});	
}

function fLinkUnlikeMoby(s_like_mode, iLink){
	var url_ajax = getUrlAjax();
	jQuery.post(url_ajax, {
		key_word : 'fLinkUnlikeMoby',
		s_like_mode : s_like_mode,
		iLink : iLink
	}, function(r) {
		jQuery("#id_label_count_"+s_like_mode).html(r);
	});	
}
function fChangeImage(id_hdn_img, obj_div){
	var url = jQuery("#"+id_hdn_img).val();
	jQuery("#id_img_show_detail").attr("src", url);
	
	jQuery(".div_group_media div").removeClass('div_more_img_active');
	jQuery(".div_group_media div").addClass('div_more_img');
		
	jQuery(obj_div).removeClass('div_more_img').addClass('div_more_img_active');
}

function fSelModelOnChange_bk(obj_sel){
	var id_model_sel = jQuery(obj_sel).attr("id");
	var val = jQuery(obj_sel).val();
	
	var id_product_sel = id_model_sel.replace("sel_model_compare_","sel_product_compare_");
	if(val == 0 ) {
		jQuery("#"+id_product_sel).attr("disabled",true);
		jQuery("#"+id_product_sel + " [value='0']").attr("selected",true);
		jQuery("#"+id_product_sel + " option").hide();
		jQuery("#"+id_product_sel + " [value='0']").show();
		var src_default = jQuery("#id_hdn_default_compare").val();
		var id_img = id_model_sel.replace("sel_model_compare_","id_img_compare_product_");
		jQuery("#"+id_img).attr("src", src_default);
	}else{
		jQuery("#"+id_product_sel + " option").hide();
		jQuery("#"+id_product_sel).attr("disabled",false);
			
		if(jQuery("#hdn_count_child_" + val).val() > 0 ){
			jQuery("#"+id_product_sel + " ."+val).show();
			jQuery("#"+id_product_sel + " .noproduct").hide();
		}else{
			jQuery("#"+id_product_sel + " .noproduct").show();
		}
	}
}

function fSelModelOnChange(obj_sel){
	var id_model_sel = jQuery(obj_sel).attr("id");
	var val = jQuery(obj_sel).val();
	
	var id_product_sel = id_model_sel.replace("sel_model_compare_","sel_product_compare_");
	if(val == 0 ) {
		jQuery("#"+id_product_sel).attr("disabled",true);
		jQuery("#"+id_product_sel + " [value='0']").attr("selected",true);
		jQuery("#"+id_product_sel + " option").hide();
		jQuery("#"+id_product_sel + " [value='0']").show();
		var src_default = jQuery("#id_hdn_default_compare").val();
		var id_img = id_model_sel.replace("sel_model_compare_","id_img_compare_product_");
		jQuery("#"+id_img).attr("src", src_default);
	}else{
		var sListOptionCateID = jQuery("#sel_store_cate_id_"+val).html();
		
		jQuery("#"+id_product_sel).attr("disabled",false);
		jQuery("#"+id_product_sel + " option.product_sel").remove();
		jQuery("#"+id_product_sel).append(sListOptionCateID);
		
	}
}
function fSelProductOnChange(obj_sel){
	
	jQuery("#id_div_compare_product").show();
	
	var id_product_sel = jQuery(obj_sel).attr("id");
	var id_img = id_product_sel.replace("sel_product_compare_","id_img_compare_product_");
	
	var id = jQuery(obj_sel).val();
	var src = jQuery('#hdn_compare_'+id).val();
	jQuery("#"+id_img).attr("src", src);
}

function clearListCompare(arr_model, list_compare){
	var url = jQuery("#id_hdn_url_clear").val();
	jQuery.post(url, {
		a : 1
	}, function(r) {
		saveRootCateId(arr_model, list_compare);
	});	
}

function saveRootCateId(arr_model, list_compare){ 
	var aProductId = list_compare.split(",");
	var iProductID_1 = 0;
	var iProductID_2 = 0;
	var iProductID_3 = 0;
	if(aProductId[0] > 0 ){
		iProductID_1 = aProductId[0];
	}
	
	if(aProductId[1] > 0 ){
		iProductID_2 = aProductId[1];
	}
	
	if(aProductId[2] > 0 ){
		iProductID_3 = aProductId[2];
	}
	
	var url_ajax = getUrlAjax();
	jQuery.post(url_ajax, {
		key_word : 'saveRootCateId',
		model_1 : arr_model[0],
		model_2 : arr_model[1],
		model_3 : arr_model[2],
		sel_1 : iProductID_1,
		sel_2 : iProductID_2,
		sel_3 : iProductID_3
	}, function(r) {
		window.location.href = '/catalog/product_compare/index/items/'+list_compare;
		hideLoading();	
	});
}

function fCompareKymco(){
		
	
	var model_1 = jQuery("#sel_model_compare_1").val();
	var model_2 = jQuery("#sel_model_compare_2").val();
	var model_3 = jQuery("#sel_model_compare_3").val();
	
	
	var sel_1 = jQuery("#sel_product_compare_1").val();
	var sel_2 = jQuery("#sel_product_compare_2").val();
	var sel_3 = jQuery("#sel_product_compare_3").val();
	
	var list_compare = '';
	if(sel_1 > 0 ){
		list_compare = sel_1;
	}
	if(sel_2 > 0 ){
		list_compare = list_compare + ',' +sel_2;
	}
	if(sel_3 > 0 ){
		list_compare = list_compare + ',' +sel_3;
	}
	
	if( (sel_1 ==0 && sel_2 == 0 ) || (sel_1 ==0 && sel_3 == 0 ) || (sel_2 ==0 && sel_3 == 0 ) || (sel_1 ==0 && sel_2 == 0 && sel_3 == 0)){
			alert(jQuery("#hdn_translate_select_2_product").val());		
	}else{
		if(model_1 == 3 || model_2 == 3 || model_3 == 3 || model_1 == 48 || model_2 == 48 || model_3 == 48){
			loadLoading();
			var arr_model = new Array();
				arr_model[0] = model_1;
				arr_model[1] = model_2;
				arr_model[2] = model_3;
				
			clearListCompare(arr_model, list_compare);
		}else{
			alert(jQuery("#hdn_translate_select_kymco").val());		
		}
			
	}
}

function loadLoading(){
	var s_div = '<div id="id_div_popup_show_product" class="c-opacity" onclick="closePopupZoom();"></div>';
	jQuery("body").append(s_div);
	
	jQuery("#id_contain_loading").removeClass("no-display");
	setFixedScreen("id_img_loading");
}

function hideLoading(){
	jQuery("#id_contain_loading").addClass("no-display");
	jQuery("#id_div_popup_show_product").remove();
}

function setFixedScreen(s_id_object) {
	jQuery("body").append('<div id="id_test_fix" class="test_fix"></div>');
	var widthForm = jQuery("#"+s_id_object).css("width");
		widthForm = widthForm.replace("px","");
			
	var heightForm = jQuery("#"+s_id_object).css("height");
		heightForm = heightForm.replace("px","");
	
	var left = (getRealScreenWidth() - widthForm)/2;
	var top = (getRealScreenHeight() - heightForm)/2;	
	
		jQuery("#"+s_id_object).css("position","fixed");
		jQuery("#"+s_id_object).css("left",left);
		jQuery("#"+s_id_object).css("top",top);
		jQuery("#"+s_id_object).css("display","inline");
		jQuery("#id_test_fix").remove();
}

function getRealScreenWidth() 
{
	var width = jQuery("#id_test_fix").css("width");
		width = width.replace("px","");
	return width;
}

function getRealScreenHeight() 
{
	var height = jQuery("#id_test_fix").css("height");
		height = height.replace("px","");
	return height;
}

function fWriteFile(){
	var url_ajax = getUrlAjax();
	var html = jQuery("#id_div_write_file").html();
	//alert(html); return false;
	jQuery.post(url_ajax, {
		key_word : 'fWriteFile',
		html : html
	}, function(r) {
		
	});	
}

function fOnMouseOverMenuTop(id_li_over, class_over){
	var class_new = class_over+"_selected";
	jQuery("#"+id_li_over).removeClass(class_over).addClass(class_new);
}

function fOnMouseOutMenuTop(id_li_over, class_over){
	var class_new = class_over+"_selected";
	jQuery("#"+id_li_over).removeClass(class_new).addClass(class_over);
}

function fNextPageMap(id_div){
	var html = jQuery("#"+id_div).html();
	
	jQuery("#id_div_tooltip").html(html);
}

function setValueMe(obj_check){
	if(jQuery(obj_check).is(':checked')){
		jQuery(obj_check).val('1');
	}else{
		jQuery(obj_check).val('0');
	}
}

function fActionContactForm(iNum){
	jQuery("#id_radio_contact_"+iNum).attr("checked",true);
	jQuery("#hdn_type_contact").val(jQuery("#id_radio_contact_"+iNum).val());
	jQuery("#hdn_type_val_num").val(iNum);
	if( iNum == 4){
		var iNumChild1 = jQuery("#id_label_pass").children().length;
		if(iNumChild1 == 0){
			jQuery("#id_label_pass").append(' <label for="password" class="required label_contact"><em>*</em>Password:</label><input name="password" id="password" title="Password" class="input-text required-entry validate-password" type="password" />');
		}
		
		var iNumChild2 = jQuery("#id_label_pass_confirm").children().length;
		if(iNumChild2 == 0){
			jQuery("#id_label_pass_confirm").append('<label for="confirmation" class="required label_contact"><em>*</em>Password Confirm:</label><input type="password" class="input-text required-entry validate-cpassword" id="confirmation" title="Confirm Password" name="confirmation"/>');
		}
		
	}else{
		jQuery("#id_label_pass").html("");
		jQuery("#id_label_pass_confirm").html("");
	}
	
	var sTextTitle = jQuery("#menu_li_contact_"+iNum +" a").html();
	//alert(sTextTitle);
	jQuery(".tittle_contact").html(sTextTitle);
}

function fHoverHomePage(){
	/*var o_img_hover = jQuery(".content1_catalogue_layer");
		jQuery(o_img_hover).css("top", 480);*/
	/*var o_div_show = jQuery(".content1_catalogue_layer");
		jQuery(o_div_show).hide();*/
		
	/*var o_div_show = jQuery(".content1_catalogue_layer2");
		jQuery(o_div_show).animate({
							height: 'toggle'
						  }, 500, function() {
							// Animation complete.
						  });*/

	//var o_div_show = jQuery(".content1_catalogue_layer2");
	//var options = {};
	//jQuery(o_div_show).slideToggle( 2000 );

}

var i = 0;

function slidersim()
{	
	var containershow = jQuery("#id_div_hover_show").children();
	var e = containershow.get(i);
	jQuery(e).click();	
	if(i == jQuery(containershow).length)
	{
		i = 0;
	}
	setTimeout( "slidersim()", 5000);	
}

function fShowHover(iImgId){
	i = iImgId;
	i = parseInt(i);
	jQuery(".c_div_thum").removeClass("c_div_thum_active");
	
	var o_this = jQuery("#id_div_thum_"+iImgId);
	jQuery(o_this).addClass("c_div_thum_active");
	
	var containershow = jQuery("#id_div_hover_show").children();
	//var nextno = 0;
	
	
	//if(i != 1)
//	{
//		if( (i-1)%5 == 0)
//		{		
//			for( t=(i-1); t>0; t-- )
//			{
//				jQuery("#id_div_thum_"+t).hide("slide");
//			}
//			
//			for( t=i; t<(i+5); t++ )
//			{
//				jQuery("#id_div_thum_"+t).show("slide");
//			}
//			/*var nextno = (i+5);
//			if(nextno >= jQuery(containershow).length)
//			{
//				nextno = 1;
//			}
//			jQuery("#numtonext").val(nextno);*/
//		}
//	}
//	else
//	{		
//		jQuery(".c_div_thum").hide();
//		for( t=i; t<=5; t++ )
//		{
//			jQuery("#id_div_thum_"+t).show("slide");
//		}
//		//jQuery("#numtonext").val(6);
//	}
	
	//jQuery(".c_img_big").hide();
	jQuery(".c_img_big").delay(250).fadeOut(300)
	/*jQuery(".c_img_big").animate(
	{
		left:4,
		marginLeft:-720*2
	}
	)*/
	//jQuery(".c_img_big").hide();
	/*jQuery(".c_img_big").animate({
   		left: parseInt(jQuery(".c_img_big").css('left'),10) == 0 ?
  		jQuery(".c_img_big").outerWidth() : 0
	});*/
	
	var o_img_show = jQuery("#id_img_big"+iImgId);
	jQuery(o_img_show).delay(250).fadeIn(300);
	/*jQuery(o_img_show).fadeIn(300);
	jQuery(o_img_show).animate(
		{
			marginLeft:0
		}		
	);*/
	/*o_img_show.animate(
   		{marginLeft:-(2*o_img_show.outerWidth())}
	);*/
	
	
	//show('slide', {direction: 'right'}, 1000);
	/*jQuery(o_img_show).animate({
						left: '+=50',
						width: 'toggle'
					  }, 500, function() {
						// Animation complete.
					  });*/		  
}

function nextslider()
{
	var numnext = jQuery("#numtonext").val();
	//i = numnext;
	fShowHover(numnext);
}

/*
 * BEGIN Open PDF
 */
function openPdf(pdf_file) 
{
	var emb = '<iframe scrolling="no" src="http://docs.google.com/gview?url='+pdf_file+'&embedded=true" width="100%" height="100%" style="width:100%;height:100%"  frameborder="0" hspace="0" vspace="0"></iframe>';
	writeConsole(emb);
	
	//var newwind = window.open();
	//jQuery(newwind.document.body).append('<div><object type="application/pdf" data="'+pdf_file+'#" width="100%" height="100%"></object></div>');
	return false;
}

function writeConsole(content)
{
	top.consoleRef=window.open()
	top.consoleRef.document.writeln(
	'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="icon" href="http://s1.mobshop.com/skin/frontend/my_themes/mobshop/favicon.ico" type="image/x-icon" /><link rel="shortcut icon" href="http://s1.mobshop.com/skin/frontend/my_themes/mobshop/favicon.ico" type="image/x-icon" /></head>'
	+'<body style="margin:0;padding:0" onLoad="self.focus()">'
	+content
	+'</body></html>')
	top.consoleRef.document.close();
}
/*
 * END Open PDF
 */

