<?php

function format_login_url($url = "", $is_expired = false) {
	if ($url) {
		$url = "?url=" . urlencode($url);
		if ($is_expired) $url .= "&expired=1";
	} else {
		if ($is_expired) $url = "?expired=1";
	}
	
	return format_link("login.php$url");
}
function format_signin_url($url = "", $is_expired = false) {
	if ($url) {
		$url = "?url=" . urlencode($url);
		if ($is_expired) $url .= "&expired=1";
	} else {
		if ($is_expired) $url = "?expired=1";
	}
	
	return format_link("signin.php$url");
}


function format_logingroup_url($url = "", $is_expired = false) {
	if ($url) {
		$url = "?url=" . urlencode($url);
		if ($is_expired) $url .= "&expired=1";
	} else {
		if ($is_expired) $url = "?expired=1";
	}
	
	return format_link("logingroup.php$url");
}





function format_bookfinish_url() {
	return format_link("bookfinish.php");
}

function format_orderrefills_confirmation_url() {
	return format_link("orderrefills_confirmation.php");
}

function format_orderrefills_url() {
	return format_link("orderrefills.php");
}



function format_logout_url() {
	return format_link("logout.php");
}

function format_pharmacies_url() {
	return format_link("pharmacies.php");
}

function format_ultimatestorelocator_url(){
	//return format_link("ultimate_viewstores.php");
	return format_link("dashboard.php");


}

function format_ultimateloginpage_url(){
	return format_link("ultimate_login.php");

}
function format_nh_url() {
	return format_link("nh.php");
}

function format_counselling_url($din = "", $store = "", $frame = false, $category = "") {
	if ($din&&$store) $url = "?din=" . urlencode($din) . "&amp;store=" . urlencode($store);
	if ($frame) $url .=  "&amp;frame=" . urlencode($frame);
	if ($category) $url .= "&amp;category=" . urlencode($category);
	return format_link("counselling.php$url");
}

function format_video_url($din = "", $store = "", $category = "") {
	if ($din&&$store) $url = "?din=" . urlencode($din) . "&amp;store=" . urlencode($store);
	if ($category) $url .= "&amp;category=" . urlencode($category);
	return format_link("video.php$url");
}

function format_special_url($url = "") {
	if ($url) $url = "?store=" . urlencode($url);
	return format_link("specialevents.php$url");
}

function format_book_url($store = "", $eventid = "") {
	if ($store&&$eventid) $url = "?store=" . urlencode($store) . "&amp;eventid=" . urlencode($eventid);
	return format_link("bookspecial.php$url");
}

function format_viewpharmacies_url($store = "", $rxid = "") {
	if ($store) {
		$url = "?store[]=" . urlencode($store);
		if ($rxid) {
			$url .=  "&amp;rxid=" . urlencode($rxid);
		}
	}
	return format_link("viewpharmacies.php$url");
}

function format_viewnhpatients_url($store="",$nhid= "") {
	if ($nhid) {
		$url = "?nhid=" . urlencode($nhid);
	}
	if ($store) {
			$url .=  "&amp;store=" . urlencode($store);
		}
	return format_link("viewnhpatients.php$url");
}

function format_viewnhprofile_url($store="",$nhid="",$patid="") {
/*	if ($patid) {
		$url = "?patid=" . urlencode($patid);
	}
*/
	if ($nhid) {
		$url = "?nhid=" . urlencode($nhid);
	}
	if ($store) {
			$url .=  "&amp;store[]=" . urlencode($store);
		}
	return format_link("viewpharmacies.php$url");



}

function format_viewnhcomments_url($store="",$nhid="",$patid="",$topic="") {
/*	if ($patid) {
		$url = "?patid=" . urlencode($patid);
	}
*/
	if ($nhid) {
		$url = "?nhid=" . urlencode($nhid);
	}
	if ($store) {
			$url .=  "&amp;store=" . urlencode($store);
		}
	if ($topic) {
			$url .=  "&amp;topic=" . urlencode($topic);
		}


	return format_link("viewnhcomments.php$url");
}



function format_drugpic_url($store = "", $rxid = "") {
	if ($store) {
		$url = "?store=" . urlencode($store);
		if ($rxid) {
			$url .=  "&amp;rxid=" . urlencode($rxid);
		}
	}
	return format_link("drugpic.php$url");
}

function format_orderpharmacies_url($store = "",$patid="",$pnhid="") {
//changed jan 15 2012 for nh ordering
	if ($store){
           $url = "?store[]=" . urlencode($store);
           if ($patid) {
		$url .=  "&amp;patid=" . urlencode($patid);
	    }	
           if ($pnhid) {
		$url .=  "&amp;nhid=" . urlencode($pnhid);
	    }
        } 	
	return format_link("orderpharmacies.php$url");
}



function format_cholesterol_url($mode = "", $rowid = "") {
	if ($mode) {
		$url = "?mode=" . urlencode($mode);
		if ($rowid) {
			$url .=  "&amp;rowid=" . urlencode($rowid);
		}
	}
	return format_link("cholesterol.php$url");
}

function format_bloodpressure_url($mode = "", $rowid = "") {
	if ($mode) {
		$url = "?mode=" . urlencode($mode);
		if ($rowid) {
			$url .=  "&amp;rowid=" . urlencode($rowid);
		}
	}
	return format_link("bloodpressure.php$url");
}

function format_vaccination_url($mode = "", $rowid = "") {
	if ($mode) {
		$url = "?mode=" . urlencode($mode);
		if ($rowid) {
			$url .=  "&amp;rowid=" . urlencode($rowid);
		}
	}
	return format_link("vaccination.php$url");
}





function format_bloodsugar_url($mode = "", $rowid = "") {
	if ($mode) {
		$url = "?mode=" . urlencode($mode);
		if ($rowid) {
			$url .=  "&amp;rowid=" . urlencode($rowid);
		}
	}
	return format_link("bloodsugar.php$url");
}

function format_graph_url($mode = "") {
	if ($mode) $url = "?mode=" . urlencode($mode);
	return format_link("plot.php$url");
}

function format_order_url($store = "", $rxid = "") {
	if ($store) {
		$url = "?store=" . urlencode($store);
		if ($rxid) {
			$url .=  "&amp;rxid=" . urlencode($rxid);
		}
	}
	return format_link("orderrefills.php$url");
}

function format_index_url() {
	return format_link("index.php");
}


function format_link($str) {
	if (defined("SID") && SID) {
		if (strstr($str, "?")!==false) $str .= "&amp;" . SID; else $str .= "?" . SID;
	}
	return $str;
}

function format_url_part($txt) {
	$txt = preg_replace("![\'\"\\\/\\\\]!", "", $txt);
	$txt = preg_replace("/[^a-zA-Z0-9]+/", " ", $txt);
	$txt = trim(strtolower($txt));
	$txt = str_replace(" ", "_", $txt);
	return $txt;
}

?>
