
function get_subcats(cat_id){
	
	if(cat_id != ""){
		
		var url = '/ajax/forensic_resources';

		new Ajax.Request(url, {method:'post', parameters:{
			cat_id:				cat_id
			},
			onSuccess: function (call_this){
				document.getElementById("subcats").innerHTML = call_this.responseText;
			}
		});
	}

}


function add_subcats(cat_id){
	
	if(cat_id != ""){
		
		var url = '/ajax/add_resource';

		new Ajax.Request(url, {method:'post', parameters:{
			cat_id:	 cat_id
			},
			onSuccess: function (call_this){
				document.getElementById("subcats").innerHTML = call_this.responseText;
			}
		});
	}

}

function change_forensic_status(id, status){
	var x = confirm('Are you sure you want to do this?');
	
	if(x){
		if(id != ""){
		
		var url = '/ajax/forensic_approve_deny';

		new Ajax.Request(url, {method:'post', parameters:{
			status: 	status,
			id:			id
			},
			
			onSuccess: function (call_this){
				document.getElementById("document_action_"+id).innerHTML = call_this.responseText;
			}
		});
		}
	}	
}

function delete_forensic_document(id){

	var x = confirm("Are you sure you want to delete this? \n\n This process is not reversibe.\n");
	
	if (x){
		var url = '/ajax/forensic_delete_ajax';
		new Ajax.Request(url, {method:'post', parameters:{
			id:					id
			},
			onSuccess: function (call_this){
				document.getElementById("document_action_"+id).innerHTML = call_this.responseText;
				document.getElementById("doc_row_"+id).innerHTML = "";
			}
		});
	}
}

function show_contact_email_form(id){
	
	var url = '/ajax/forensic_contact';
	new Ajax.Request(url, {method:'post', parameters:{
		id: 					id, 
		method_type: 			'show_form'
		},
		onSuccess: function (call_this){
			document.getElementById("forensic_contact_change").innerHTML = call_this.responseText;
		}
	});
}

function update_email(id, form_id){
	
	myform = document.getElementById(form_id);
	var success = false;
	
	if(!emailCheck(myform.email.value)){
		alert('Invalid email format!');
	} else {
		success = true;
	}
	if(success){ 
		var url = '/ajax/forensic_contact';
		new Ajax.Request(url, {method:'post', parameters:{
			id:						id,
			email:					myform.email.value,
			method_type: 			'update_email'
			},
			onSuccess: function (call_this){
				document.getElementById("forensic_contact_change_status").innerHTML = call_this.responseText;
			}
		});
	}
}









function emailCheck(str){

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	// check if string contains @sign
	if (str.indexOf(at)==-1){
	   return false
	}
	// check if @sign not at beginning of string
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	// check if period not at beginning of string
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}

	 return true					
}// end function emailCheck

