Is it legal for employer to withhold employee's salary to collect H1B sponsorship charges?

I got selected for H1B visa lottery in April/2014 and my employer paid for sponsorship fee. They had me sign a contract which binds me for work for 1 year for this employer. The contract says that if I quit job before 1 full year, I’ll have to pay sponsorship fee back to the employer. this is what it exactly says-

G agrees that if his employment with Employer terminates prior to one year from the date hereof, he will repay 100% of the Payments. Notwithstanding anything to the contrary stated herein, if the termination of employment is the result of the death, disability or termination without cause by Employer, there shall be no obligation of Gautam to repay any portion of the Payments.

Actually, during my job, my employer asked me to improve something and I did. However, they were not satisfied and fired me without prior warning. They held my pay for 2 weeks. I found it unjustified. I couldn’t do anything at that point of time because I was freaking out. I want to know if it was legal on their part?