var BMI = Class.create();
BMI.prototype = {
	initialize: function() {
	},
	
	computeBmi: function() {
		
		var frm =	$('bmi_form');
		if (!frm.weight.present()){
			alert('Silakan isi weight');
			return;
		}
		
		if (!frm.height.present()){
			alert('Silakan isi height');
			return;
		}		
		
		if (!frm.height.getValue() === 0){
			alert('Silakan isi height dengan nilai lebih besar dari 0');
			return;
		}		
		
		$('bmi_form').submit();
		
		//height= height/100;				
		//var rst = weight/(height*height);
		//$('bmi_result').value = Math.round(rst*10)/10;
		
	}
	
}

// HealthArticle Class
var HealthArticle = Class.create();
HealthArticle.prototype = {
	
	initialize: function(){
		
	},
	
	getTitles: function() {
		
		new Ajax.Request('modules/harticle.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getTitles'
				
			},			
			onSuccess: function(transport){							
					
				$('harticle_right').update(transport.responseText);
					
			}			
		});	

	},
	
	getDetail:function(id) {
		
		new Ajax.Request('modules/harticle.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getDetail',
				id:id
				
			},			
			onSuccess: function(transport){							
					
				$('article_detail').update(transport.responseText);
				_harticle.getComments(id,1);
					
			}			
		});	
		
	},
	
	getComments: function(article_id,page){
		

		new Ajax.Request('modules/harticle.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getComments',
				id :article_id,
				page:page
				
			},			
			onSuccess: function(transport){				
				$('article_comments').update(transport.responseText);					
				//Effect.ScrollTo('article_comments');					
			}			
		});	
		
	},	
	
	validate_email: function(email) {
	 
		 apos=email.indexOf("@");
		 dotpos=email.lastIndexOf(".");
		 if (apos<1||dotpos-apos<2)
		 {		
			return false;
		 }
		 else 
		 { 
			return true;
		 }
		 
	},
		
	postcomment_submit: function(){
		
		var nama = $F('nama');
		var email = $F('email');
		var comment = $F('comment');
		
		if( nama.blank() ){
			alert('Silakan isi nama!');
			return false;
		}
		
		if( email.blank() || !_harticle.validate_email(email) ) {
			alert('Silakan isi email dengan benar ( abc@domain )!');
			return false;
		}
		
		if( comment.blank()){
			alert('Silakan isi testimonialnya!');
			return false;
		}		
		
		return true;
		
	},
	
	togglePostForm: function() {		
		
			Effect.toggle('postcomment_container','blind',{ duration :1.0, afterFinish: function(){ Effect.ScrollTo('postcomment_container'); } });
			
		
	},
	
	
	getAllTitles: function() {
		
		new Ajax.Request('modules/harticle.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getAllTitles'
				
			},			
			onSuccess: function(transport){							
					
				$('harticle_right').update(transport.responseText);
					
			}			
		});	

	}
	
	
}


var Product = Class.create();
Product.prototype = {
	
	initialize: function() {
	},
	
	loadSlideImages: function() {
		
		new Ajax.Request('modules/product.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getSlideImages'
				
			},			
			onSuccess: function(transport){				
				$('i-prodhl').update(transport.responseText);									
			}			
		});	
	},
	
	startSlideImages: function(last){		
	
		var slider = new SlideShow('slideimage',1,last,5000);
		slider.startSlide();
		
	},
	
	getPrincipals: function() {
		
		new Ajax.Request('modules/product.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getPrincipals'
				
			},			
			onSuccess: function(transport){				
				$('principals').update(transport.responseText);									
			}			
		});	
		
	},
	
	getCatalogMenu : function(id){
		
		new Ajax.Request('modules/product.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getCatalogMenu',
				id:id
				
			},			
			onSuccess: function(transport){				
				$('catalog_menu').update(transport.responseText);		
				Effect.ScrollTo('catalog_menu');
			}			
		});	
	},
	
	
	getDetail: function (id) {
		
			new Ajax.Request('modules/product.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getDetail',
				id :id
				
			},			
			onSuccess: function(transport){				
				$('product_detail').update(transport.responseText);	
				Effect.ScrollTo('product_detail');	
				_product.getComments(id,1);
			}			
		});	
		
	},	
	
	getAllProductsImage: function() {
		
			new Ajax.Request('modules/product.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getAllProductsImage'				
				
			},			
			onSuccess: function(transport){				
				$('product_detail').update(transport.responseText);						
			}			
		});	
		
	},	
	
	
	getComments: function(product_id,page){
		

		new Ajax.Request('modules/product.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getComments',
				id :product_id,
				page:page
				
			},			
			onSuccess: function(transport){				
				$('product_comments').update(transport.responseText);	
				//Effect.ScrollTo('product_comments');								
			}			
		});	
		
	},
	
	
	validate_email: function(email) {
	 
		 apos=email.indexOf("@");
		 dotpos=email.lastIndexOf(".");
		 if (apos<1||dotpos-apos<2)
		 {		
			return false;
		 }
		 else 
		 { 
			return true;
		 }
		 
	},
		
	postcomment_submit: function(){
		
		var nama = $F('nama');
		var email = $F('email');
		var comment = $F('comment');
		
		if( nama.blank() ){
			alert('Silakan isi nama!');
			return false;
		}
		
		if( email.blank() || !_product.validate_email(email) ) {
			alert('Silakan isi email dengan benar ( abc@domain )!');
			return false;
		}
		
		if( comment.blank()){
			alert('Silakan isi testimonialnya!');
			return false;
		}		
		
		return true;
		
	},
	
	togglePostForm: function() {		
		
			Effect.toggle('postcomment_container','blind',{ duration :1.0, afterFinish: function(){  Effect.ScrollTo('postcomment_container'); } });
			
		
	},
	
	toggleSubMenu: function(id) {		
	
		new Effect.toggle(id,'blind',{ duration:0.5});
		
	}
	
}


var News = Class.create();
News.prototype = {
		
	
	initialize: function() {
		
	},		
	
	getHeadline: function(){
		
		new Ajax.Request('modules/news.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getHeadline'
				
			},			
			onSuccess: function(transport){				
				$('news_headline').update(transport.responseText);									
			}			
		});	
	
	}
	
}


var NetworkDis = Class.create();
NetworkDis.prototype = {	
	initialize: function() {
			
	},
	
	getOutletList: function() {
		
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getOutletList'
				
			},			
			onSuccess: function(transport){				
				$('outlet_list').update(transport.responseText);									
			}			
		});	
	
	},
	
	getOutletList2: function() {
		
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getOutletList2'
				
			},			
			onSuccess: function(transport){				
				$('outlet_list').update(transport.responseText);									
			}			
		});	
	
	},
	
	getOutletByImage: function() {
		
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getOutletByImage'
				
			},			
			onSuccess: function(transport){				
				$('outlet_list').update(transport.responseText);									
			}			
		});	
	
	},
	
	
	getLocationList: function() {
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getLocationList'
				
			},			
			onSuccess: function(transport){				
				$('location').update(transport.responseText);									
			}			
		});	
	},
	
	getOutletSearchList: function() {
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getOutletSearchList'
				
			},			
			onSuccess: function(transport){				
				$('outlet').update(transport.responseText);									
			}			
		});	
	},
	
	getNetworkByOutlet:function(id,halaman) {
		
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getNetworkByOutlet',
				id : id,
				halaman : halaman
				
			},			
			onSuccess: function(transport){				
				$('network_dis').update(transport.responseText);									
			}			
		});	
		
	},
	
	getNetworkByLocation:function(id) {
		
		
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getNetworkByLocation',
				id : id
				
			},			
			onSuccess: function(transport){				
				$('network_dis').update(transport.responseText);									
			}			
		});	
		
	},
	
	getNetworkByLocationOutlet:function(location_id, outlet_id, halaman) {
		
		
		new Ajax.Request('modules/network.php', {
			method: 'post',
			parameters: 
			{ 
				mod_action : 'getNetworkByLocationOutlet',
				location_id : location_id,
				outlet_id : outlet_id,
				halaman : halaman
				
			},			
			onSuccess: function(transport){				
				$('network_dis').update(transport.responseText);									
			}			
		});	
		
	}
	
}

