The deconfinement and Hagedorn phase transitions in weakly coupled large N gauge theories