function Replace(str,oldWord,newWord){
	return str.split(oldWord).join(newWord);
}
function NoTags(Text){
	re=/(<([^>]+)>)/gi;
	return Text.replace(re,' ');
}
function EnglishOnly(Text){//----------------------- Used by JavaScript functions
	T='';
	for(i=0;i<Text.length;i++){
		L=Text.substr(i,1);
		T+=('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.indexOf(L)>-1)?L:'-';
	}
	return T;
}
function EnglishOnlyField(Field){
	T=EnglishOnly(Field.value);
	if(Field.value!=T)Field.value=T;
	return T;
}
function FixFloat(T){//----------------------- Used by JavaScript functions
	R='';
	MinusChar=(T.indexOf('-')<0)?'':'-';
	for(i=0;i<T.length;i++){
		L=T.substr(i,1);
		if(',،٫زو.'.indexOf(L)>-1&&R.indexOf('.')<0)R+='.';
		if('0123456789'.indexOf(L)>-1)R+=L;
	}
	while(R.charAt(0)=='0'){
		R=R.substr(1);
	}
	if(!R)R='0';
	if(R.charAt(0)=='.')R='0'+R;
	return MinusChar+R;
}
function FloatField(Field){
	T=FixFloat(Field.value);
	if(Field.value!=T)Field.value=T;
	return parseFloat(T);
}
function FloatNum(T){
	return parseFloat(FixFloat(T));
}
function FixInt(T){//----------------------- Used by JavaScript functions
	T=''+T;
	while(T.charAt(0)=='0'){
		T=T.substr(1);
	}
	T=parseInt(T);
	return isNaN(T)?0:T;
}
function IntField(Field){
	T=FixInt(Field.value);
	if(Field.value!=T)Field.value=T;
	return parseInt(T);
}
function IntAbsField(Field){
	T=Math.abs(FixInt(Field.value));
	if(Field.value!=T)Field.value=T;
	return parseInt(T);
}
function IntNum(T){
	return parseInt(FixInt(T));
}
function IntAbsNum(T){
	return Math.abs(parseInt(FixInt(T)));
}
function ChangeDate(ID){
	if(ID!=0){
		ID=1;
		NextDate=0;
	}else{
		NextDate=1
	}
	$('.Date span').addClass('Hide');
	$('.Date .Date'+ID).removeClass('Hide');
	$.cookie('UserDate',ID,{path:'/'});
}
function ChangeCurrency(ID){
	ID=IntAbsNum(ID);
	if(ID>=Currencies)ID=0;
	NextCurrency=ID+1;
	$('.Currency span').addClass('Hide');
	$('.Currency .Currency'+ID).removeClass('Hide');
	$('#CurrenciesList option:eq('+ID+')').attr('selected','selected');
	$.cookie('UserCurrency',ID,{path:'/'});
}
function createRequestObject(){
	return(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
}
function expandIt(BlockName){
	document.getElementById(BlockName).style.display=(document.getElementById(BlockName).style.display=="inline")?"none":"inline";
}
function DialogMiddle(ID){
	$(ID).stop().animate({"top":$(window).scrollTop()+$(window).height()/2-$(ID).height()/2,"left":$(window).width()/2-$(ID).width()/2},1000);
}
function CreateDialog(ID){
	$(document).ready(function(){
		$(ID).dialog({
			autoOpen:false,
			resizable:false,
			show:"fade",
			hide:"clip",
			modal:true
		});
	});
	$(window,document).scroll(function(){
		DialogMiddle($(ID).parent());
	});
	$(window).resize(function(){
		DialogMiddle($(ID).parent());
	});
}
function HeightCSS(ID){
	return FixInt($(ID).css("margin-top"))+FixInt($(ID).css("margin-bottom"))+FixInt($(ID).css("padding-top"))+FixInt($(ID).css("padding-bottom"))+FixInt($(ID).css("border-top-width"))+FixInt($(ID).css("border-bottom-width"));
}
function WidthCSS(ID){
	return FixInt($(ID).css("margin-right"))+FixInt($(ID).css("margin-left"))+FixInt($(ID).css("padding-right"))+FixInt($(ID).css("padding-left"))+FixInt($(ID).css("border-right-width"))+FixInt($(ID).css("border-left-width"));
}
function RequiredField(ID,Type,MSG){
	StopMe=0;
	switch(Type){
		case'EMail':
			if(!$(ID).val().match(/^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i))StopMe=1;
		break;
		case'Select'://<Select> ... </Select>
			if($(ID).val()==0)StopMe=1;
		break;
		/*
		case'6OrMore'://PassWord
			if($(ID).val().length<6)StopMe=1;
		break;
		*/
		case'Editor':
			ID=Replace(ID,'#','')//Remove #
			IFrame=$.browser.msie?eval('frames["'+ID+'_ifr"].document'):eval('document.getElementById("'+ID+'_ifr").contentDocument');
			MyText=IFrame.getElementsByTagName("body")[0].innerHTML.toLowerCase();
			if(MyText=='<p><br mce_bogus="1"></p>'||MyText=='<p><br></p>'||MyText=='<p>&nbsp;</p>'||MyText=='')StopMe=1;
		break;
		default://Text
			if(!$(ID).val())StopMe=1;
		break;//Not important
	}
	if(StopMe){
		if(MSG)alert(MSG);
		if(Type=='Editor'){
			$('#'+ID).tinymce().focus();
		}else{
			$(ID).focus();
		}
	}
	return StopMe;
}
