/*
JS Strict Data Types was created by David Hurth, 2008 and is part of the Ajaxonomy Developer Toolkit (available at ajaxonomy.com)
This is Beta version 1.1 of JS Strict Data Types.
The latest version of JS Strict Data Types is available http://ajaxonomy.com and our Google Code Project Page at http://code.google.com/p/jsstrictdatatype/.
This code is free to use/modify for both Personal and Commercial use providing that you leave this notice in tact.
Licensed under Version 3 of the GNU Lesser GPL http://www.gnu.org/licenses/gpl.html.
*/
(function() {
  var global = this;
  var DataTypeCheck = function(Compared, DataType){
  	if(DataType == "Int"){
		if(isNaN(Compared)){
			alert("Type Mismatch - Expecting Integer");
			return false;
		} else {
			if(Math.floor(Compared) == Compared){
				return true;
			} else {
				alert("Type Mismatch - Expecting Integer");
				return false;
			}
		}
  	} else if(DataType == "Float"){
  		if(isNaN(Compared)){
			alert("Type Mismatch - Expecting Float");
			return false;
		} else {
			return true;
		}
  	} else if(DataType == "String"){
  		if(!isNaN(Compared) && Compared != true && Compared != false){
			alert("Type Mismatch - Expecting String");
			return false;
		} else {
			return true;
		}
  	} else if(DataType == "Boolean"){
  		if(Compared != true && Compared != false && Compared != 1 && Compared != 0){
			alert("Type Mismatch - Expecting Boolean");
			return false;
		} else {
			return true;
		}
  	}

  }
  var SetValue = function(Compared, DataType){
		if (DataTypeCheck(Compared, DataType)){
			return Compared;
		}
  }
//  Math Functions
  	var Mathadd = function(Compared, MyValue, DataType){
		if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
			return (MyValue + Compared);
		}
	}
	var Mathsub = function(Compared, MyValue, DataType){
		if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
			return (MyValue - Compared);
		}
	}
	var Mathdiv = function(Compared, MyValue, DataType){
		var ReturnValue = MyValue / Compared;
		if(DataTypeCheck(ReturnValue, DataType)){
			return ReturnValue;
		} else {
			return null;
		}
	}
	var Mathmult = function(Compared, MyValue, DataType){
		var ReturnValue = MyValue * Compared;
		if(DataTypeCheck(ReturnValue, DataType)){
			return ReturnValue;
		} else {
			return null;
		}
	}
//Compare Functions
	var MathCompareNotEq = function(Compared, MyValue, DataType){
		//if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
		if(MyValue != Compared){
			return true;
		} else {
			return false;
		}
	}
	var MathCompareGrt = function(Compared, MyValue, DataType){
		//if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
		if(MyValue > Compared){
			return true;
		} else {
			return false;
		}
	}
	var MathCompareGrtEq = function(Compared, MyValue, DataType){
		//if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
		if(MyValue >= Compared){
			return true;
		} else {
			return false;
		}
	}
	var MathCompareLess = function(Compared, MyValue, DataType){
		//if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
		if(MyValue < Compared){
			return true;
		} else {
			return false;
		}
	}
	var MathCompareLessEq = function(Compared, MyValue, DataType){
		//if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
		if(MyValue <= Compared){
			return true;
		} else {
			return false;
		}
	}
	var MathCompareEq = function(Compared, MyValue, DataType){
		//if(DataTypeCheck(Compared, DataType) && DataTypeCheck(MyValue, DataType)){
		if(MyValue == Compared){
			return true;
		} else {
			return false;
		}
	}
  

global.Int = function(MyVar){
	if(MyVar.value){
		MyVar = MyVar.value;
	}
	if(DataTypeCheck(MyVar, "Int")){
	} else {
		return false;
	}
	this.value = MyVar;
	this.DataType= "Int";
	this.Set = function(Compared){
		this.value = SetValue(Compared, "Int");
	}
	this.add = function(Compared){
		this.value = Mathadd(Compared, this.value, "Int");
	}
	this.sub = function(Compared){
		this.value = Mathmult(Compared, this.value, "Int");
	}
	this.mult = function(Compared){
		this.value = Mathdiv(Compared, this.value, "Int");
	}
	this.div = function(Compared){
		this.value = Mathsub(Compared, this.value, "Int");
	}
	this.CompareNotEq = function(Compared){
		return MathCompareNotEq(Compared, this.value, "Int");
	}
	this.CompareGrt = function(Compared){
		return MathCompareGrt(Compared, this.value, "Int");
	}
	this.CompareGrtEq = function(Compared){
		return MathCompareGrtEq(Compared, this.value, "Int");
	}
	this.CompareLess = function(Compared){
		return MathCompareLess(Compared, this.value, "Int");
	}
	this.CompareLessEq = function(Compared){
		return MathCompareLessEq(Compared, this.value, "Int");
	}
	this.CompareEq = function(Compared){
		return MathCompareEq(Compared, this.value, "Int");
	}
}
global.Float = function(MyVar){
	if(MyVar.value){
		MyVar = MyVar.value;
	}
	if(DataTypeCheck(MyVar, "Float")){
	} else {
		return false;
	}
	this.value = MyVar;
	this.DataType= "Float";
	this.Set = function(Compared){
		this.value = SetValue(Compared, "Float");
	}
	this.add = function(Compared){
		this.value = Mathadd(Compared, this.value, "Float");
	}
	this.sub = function(Compared){
		this.value = Mathsub(Compared, this.value, "Float");
	}
	this.mult = function(Compared){
		this.value = Mathdiv(Compared, this.value, "Float");
	}
	this.div = function(Compared){
		this.value = Mathsub(Compared, this.value, "Float");
	}
	this.CompareNotEq = function(Compared){
		return MathCompareNotEq(Compared, this.value, "Float");
	}
	this.CompareGrt = function(Compared){
		return MathCompareGrt(Compared, this.value, "Float");
	}
	this.CompareGrtEq = function(Compared){
		return MathCompareGrtEq(Compared, this.value, "Float");
	}
	this.CompareLess = function(Compared){
		return MathCompareLess(Compared, this.value, "Float");
	}
	this.CompareLessEq = function(Compared){
		return MathCompareLessEq(Compared, this.value, "Float");
	}
	this.CompareEq = function(Compared){
		return MathCompareEq(Compared, this.value, "Float");
	}
}
global.String = function(MyVar){
	if(MyVar.value){
		MyVar = MyVar.value;
	}
	if(DataTypeCheck(MyVar, "String")){
	} else {
		return false;
	}
	this.value = MyVar;
	this.length = this.value.length;
	this.DataType= "String";
	this.Set = function(Compared){
		this.value = SetValue("" + Compared + "", "String");
		this.length = this.value.length;
	}
	this.append = function(Compared){
		Compared = new String(Compared);
		this.value = "" + this.value + "" + Compared.value + "";
		this.length = this.value.length;
	}
	this.CompareNotEq = function(Compared){
		return MathCompareNotEq(Compared, this.value, "String");
	}
	this.CompareEq = function(Compared){
		return MathCompareEq(Compared, this.value, "String");
	}
}
global.Boolean = function(MyVar){
	if(MyVar.value){
		MyVar = MyVar.value;
	}
	if(DataTypeCheck(MyVar, "Boolean")){
	} else {
		return false;
	}
	this.value = MyVar;
	this.length = this.value.length;
	this.DataType= "Boolean";
	this.Set = function(Compared){
		this.value = SetValue(Compared, "Boolean");
	}
	this.append = function(Compared){
		Compared = new String(Compared);
		this.value = "" + this.value + "" + Compared.value + "";
		this.length = this.value.length;
	}
	this.CompareNotEq = function(Compared){
		return MathCompareNotEq(Compared, this.value, "Boolean");
	}
	this.CompareEq = function(Compared){
		return MathCompareEq(Compared, this.value, "Boolean");
	}
}
})();
function ConvertDataType(VarToConvert, ConvertTo){
		if(ConvertTo == "Int"){
			VarToConvert = new Int(VarToConvert);
			return VarToConvert;
		} else if(ConvertTo == "Float"){
			VarToConvert = new Float(VarToConvert);
			return VarToConvert;
		} else if(ConvertTo == "String"){
			VarToConvert = new String("" + VarToConvert + "");
			return VarToConvert;
		} else if(ConvertTo == "Boolean"){
			if(VarToConvert == "true"){
				VarToConvert = 1;
			} else if(VarToConvert == "false"){
				VarToConvert = 0;
			}
			VarToConvert = new Boolean(VarToConvert);
			return VarToConvert;
		}
}
