decisions = {
	soc_upgrade_brotherhood = {
		potential = {
			religion = orthodox
			primary_title = {
				holy_order = yes
			}
		}

		allow = {
			war = no
			NOT = {
				has_character_flag = brotherhood_holy_sepulchre_recruit_flag
			}
			OR = {
				NOT = {
					has_global_flag = brotherhood_holy_sepulchre_cooldown
				}
				had_global_flag = {
					flag = brotherhood_holy_sepulchre_cooldown
					days = 3650
				}
			}
		}
		
		effect = {
			if = {
				limit = {
					primary_title = {
						title = d_holy_sepulchre
					}
				}
				activate_title = { title = d_holy_sepulchre_000 status = yes }
				d_holy_sepulchre_000 = {
					grant_title = ROOT
					religion = orthodox
					copy_title_laws = d_holy_sepulchre
					copy_title_history = d_holy_sepulchre
				}
				activate_title = { title = d_holy_sepulchre status = no }
				d_holy_sepulchre = {
					religion = pagan
					destroy_landed_title = THIS
				}
			}
		
			any_province = {
				kingdom = {
					set_variable = {
						which = "can_brotherhood_holy_sepulchre_recruit"
						value = 0
					}
				}
			}
			any_province = {
				if = {
					limit = {
						religion = orthodox
					}
					kingdom = {
						set_variable = {
							which = "can_brotherhood_holy_sepulchre_recruit"
							value = 1
						}
					}
				}
			}
			any_province = {
				if = {
					limit = {
						kingdom = {
							check_variable = {
								which = "can_brotherhood_holy_sepulchre_recruit"
								value = 1
							}
							NOT = {
								has_title_flag = brotherhood_holy_sepulchre_recruit_flag
							}
						}
					}
					kingdom = {
						set_title_flag = brotherhood_holy_sepulchre_recruit_flag
					}
					ROOT = {
						character_event = {
							id = socbhs.0
							days = 180
							random = 185
						}
					}
				}
			}
			any_province = {
				if = {
					limit = {
						kingdom = {
							NOT = {
								check_variable = {
									which = "can_brotherhood_holy_sepulchre_recruit"
									value = 1
								}
							}
							has_title_flag = brotherhood_holy_sepulchre_recruit_flag
						}
					}
					kingdom = {
						clr_title_flag = brotherhood_holy_sepulchre_recruit_flag
					}
					ROOT = {
						character_event = {
							id = socbhs.1
							days = 180
							random = 185
						}
					}
				}
			}
			set_character_flag = brotherhood_holy_sepulchre_recruit_flag
			set_global_flag = brotherhood_holy_sepulchre_cooldown
			if = {
				limit = {
					ROOT = {
						independent = no
					}
				}
				ROOT = {
					top_liege = {
						character_event = {
							id = soc.4
							days = 0
						}
					}
				}
			}
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	soc_assign_diocese_local_ai = {
		potential = {
			NOT = {
				ai = no
			}
			religion = orthodox
			independent = yes
			primary_title = {
				OR = {
					real_tier = KING
					real_tier = EMPEROR
				}
			}
			NOT = {
				AND = {
					is_title_active = k_orthodox
					k_orthodox = {
						holder_scope = {
							same_realm = ROOT
						}
					}
				}
			}	
		}
		
		allow = {
			NOT = {
				has_character_flag = assign_diocese_flag
			}
		}
		
		effect = {
			any_province = {
				kingdom = {
					if = {
						limit = {
							holder_scope = {
								same_realm = ROOT
							}
						}
						set_pentarch_title = none
						clr_title_flag = ecumenical_patriarch_admininistration_flag
					}
				}
			}
			set_character_flag = assign_diocese_flag
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	soc_assign_diocese_ecumenical_patriarch_ai = {
		potential = {
			NOT = {
				ai = no
			}
			religion = orthodox
			independent = yes
			primary_title = {
				real_tier = EMPEROR
			}
			is_title_active = k_orthodox
			k_orthodox = {
				holder_scope = {
					same_realm = ROOT
				}
			}
		}
		
		allow = {
			NOT = {
				has_character_flag = assign_diocese_flag
			}
		}
		
		effect = {
			any_province = {
				kingdom = {
					if = {
						limit = {
							holder_scope = {
								same_realm = ROOT
							}
						}
						set_pentarch_title = b_hagiasophia
						set_title_flag = ecumenical_patriarch_admininistration_flag
					}
				}
			}
			set_character_flag = assign_diocese_flag
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
}