jQuery(document).ready(function(){
	//check if giff id exist
	jQuery('#giff_id').blur(function() {
		jQuery.get("ajax/check-giff-id.php", { id: jQuery('#giff_id').val()},	function(data){
				if(data == 'exist') {
					alert('รหัส Giffarine นี้มีในระบบแล้ว');
					jQuery('#giff_id').val('');
					jQuery('#giff_id').css('background', 'yellow');
					jQuery('#giff_id').focus();
				}else{
					jQuery('#giff_id').css('background', 'white');
				}
		});
	});
});


jQuery(document).ready(function(){
	jQuery('.activateLink').click(function() {
		thisLink = jQuery(this);
		if(confirm("ยืนยันสมาชิกใหม่สายงานท่านใช่หรือไม่?\nยืนยันคลิก OK  ไม่ยืนยันคลิก Cancel")){
			window.location.href = thisLink.attr('href') + '&confirm=yes';
			return false;
		}else{
			window.location.href = thisLink.attr('href') + '&confirm=no';
			return false;
		}
	});
});

jQuery(document).ready(function(){
	jQuery('.approveLink').click(function() {
		thisLink = jQuery(this);
		if(confirm("ยืนยันสมาชิกในสายงานเลื่อนตำแหน่งใช่หรือไม่?\nยืนยันคลิก OK  ไม่ยืนยันคลิก Cancel")){
			window.location.href = thisLink.attr('href') + '&confirm=yes';
			return false;
		}else{
			window.location.href = thisLink.attr('href') + '&confirm=no';
			return false;
		}
	});
});

//run cron
jQuery(document).ready(function(){ 
	jQuery.get("http://www.bizbyyou.com/members/cron-trig.php");
});

//check pv
jQuery(document).ready(function(){
	jQuery('.pvQueing').click(function() {
			jQuery.get(this.href,	function(data){
				if(data == 'nok'){
					alert('ยอด PV ทั้งหมดเป็นข้อมูลล่าสุดแล้ว');
				}else{
					alert(data);
					window.location='check-pv.php?pv_refresh=yes';
				}
			});
			return false;
	});
});

//check available name (custom homepage)
jQuery(document).ready(function(){
	jQuery('#ChkHmAvl').click(function() {
		if(jQuery('#custom_hompage_name').val() != ''){
			jQuery.get("ajax/check-homepage-name.php", { hp_name: jQuery('#custom_homepage_name').val()},	function(data){
					if(data == 'exist') {
						alert('โฮมเพจชื่อนี้ มีในระบบแล้ว');
						jQuery('#custom_homepage_name').val('');
						jQuery('#custom_homepage_name').css('background', 'yellow');
						jQuery('#custom_homepage_name').focus();
					}else{
						alert('ชื่อนี้ยังว่าง / เป็นชื่อเดิมที่คุณใช้');
						jQuery('#custom_homepage_name').css('background', 'white');
					}
			});
		}else{
			alert('กรุณากรอกให้เรียบร้อย');
		}

	});
});

//giff pass box
jQuery(document).ready(function(){
	jQuery('.editGiffPass').click(function(){
		var pass = prompt("กรุณากรอก Giffarine password ที่ได้รับจากการสมัคร\n(หลังจากคลิก OK จะทำการเซฟทันที กรุณาตรวจสอบให้เรียบร้อย)", "");
		if(pass != null && pass !=""){
			jQuery.get(this.href, { password: pass},	function(data){
				if(data != 'ok'){
					alert('ไม่สำเร็จ ลองใหม่อีกครั้ง');
				}else{
					alert('แก้ไขเรียบร้อย');
					window.location.href = 'check-pv.php';
				}
			});
			return false;
		}else{
			return false;
		}
	});
});