/* ============================================================ */
/*  Authour Name :  Nirmal Tailor                               */
/*  FUNCTION - TO CHECK ALL VARIABLES IN VIEW LISTING PAGE      */
/* ============================================================ */

$(document).ready(function(){
	$('.checkAll').click(function(){
		if($(this).attr('checked')){
			$('.delAll').attr('checked',true);
		}else{
			$('.delAll').attr('checked',false);
		}
	});
});
function common_function(optns){
	var frm = $("<form>", {'method':'post'});
	for(key in optns){
		$("<input>", {'type':'hidden', 'name':key, 'value':optns[key]}).appendTo(frm);
	}
	frm.appendTo("body");
	frm.submit();
}
function confrim_del(optns){
	if(confirm("Do you really want to delete?")){
		common_function(optns);
	}else{
		return false;
	}
}
function change_status(id, table_name, current_status){
	$('#status_'+id).removeAttr('onclick');
	$.ajax(
		{
			type: "POST",
			url: "../scripts/ajax/index.php",
			data: "method=change_status&id="+id+"&table_name="+table_name+"&current_status="+current_status,
			success: function(msg){
				if(msg=='OK'){
					var status = (current_status=='accepted')?'images/pending.png':'images/accepted.png';
					$('#status_'+id).attr('src',status);
					$('#status_'+id).unbind('click');
					$('#status_'+id).click(function(){change_status(id, table_name, current_status=='accepted'?'pending':'accepted')});
					alert("SUCCESS!! \n\n\Status change successfull...");
				}else if(msg=='CANCEL'){
					alert("ERROR!! \n\n\Ooops problem in change status. \n\n\ Please try again");
				}else{
					alert(msg);	
				}
			}
		}
	);
} 


function popup_videoplayer(video_id){
	var popwindow = window.open('index.php?view=playvideo&id='+video_id,'VideoPlayer','width=400,height=300,status=0,address=0,resize=1');
	if(!popwindow){
		alert("Your POP UP Blocker blocked the video player\n\nPlease disable any POP UP Blocker,\nor hold down CNTRL key while clicking on button/link");
	}
}
function popup_video(video_id){
	//alert(video_id);exit;
	var popwindow = window.open('index.php?view=play_bit_video&id='+video_id,'VideoPlayer','width=400,height=300,status=0,address=0,resize=1');
	if(!popwindow){
		alert("Your POP UP Blocker blocked the video player\n\nPlease disable any POP UP Blocker,\nor hold down CNTRL key while clicking on button/link");
	}
}
function change_status_employer_pending(id, table_name, current_status){
	$('#status_'+id).removeAttr('onclick');
	$.ajax(
		{
			type: "POST",
			url: "../scripts/ajax/index.php",
			data: "method=change_status_employer_pending&id="+id+"&table_name="+table_name+"&current_status="+current_status,
			success: function(msg){
				if(msg=='OK'){
					var status = (current_status=='Active')?'images/inactive.png':'images/active.png';
					$('#status_'+id).attr('src',status);
					$('#status_'+id).unbind('click');
					$('#status_'+id).click(function(){change_status(id, table_name, current_status=='Active'?'Inactive':'Active')});
					alert("SUCCESS!! \n\n\Status change successfull...");
				}else if(msg=='CANCEL'){
					alert("ERROR!! \n\n\Ooops problem in change status. \n\n\ Please try again");
				}else{
					alert(msg);	
				}
			}
		}
	);	
}

function fill_combo_state(country_id){	
	$.ajax(
		{
			type: "POST",
			dataType: 'json',
			url: "../scripts/ajax/index.php",
			data: "method=get_state_list&country_id="+country_id,	
			success: function(data){				
				$('#state_id').find('option').remove().end();
				var newopt='<option value="">-- Select --</option>';				
				$('#state_id').append(newopt);				
				for(i=0; i<data.DATA.length; i++){						
					if(data.DATA[i].id == $('#selected_id').val()){
						var newopt='<option value="'+data.DATA[i].id+'" selected="selected">'+data.DATA[i].name+'</option>';					
					}else{
						var newopt='<option value="'+data.DATA[i].id+'">'+data.DATA[i].name+'</option>';						
					}					
					$('#state_id').append(newopt);					
				}
				/*if($('#selected_id').val() == 0){						
					var newopt='<option value="0" selected="selected" onclick="OtherState(this.value);" onfocus="OtherState(this.value);">Other</option>';
					OtherState(0);
				}else{
					var newopt='<option value="0" onclick="OtherState(this.value);">Other</option>';	
				}				
				$('#state_id').append(newopt);*/
			}
		}
	);	
}

function OtherState(val){
	if(val == "0"){
		document.getElementById('other_state').style.display="";	
	}else{
		document.getElementById('other_state').style.display="none";	
	}
}
