﻿function PrintSeminar(SeminarCode)
{
	whn = 	window.open('SeminarPrint.asp?Code=' + SeminarCode ,'PrintSeminar','');
}
function DeleteItem(FileName, MasterCode, DelList)
{
	AskResult = confirm("حذف شود ؟")

	if(AskResult){
		window.onbeforeunload = '';
		window.location.href=FileName + '?DelList=' + DelList + '&Code=' + MasterCode
	}
}
function PrintJournal()
{
	window.print()
}


function ConfirmUnload()
{
    event.returnValue = "تغییرات نادیده گرفته شود؟";
}
function GetInfo(InputObj, BaseID)
{
	Code = InputObj.value
	document.body.style.cursor='wait';
	
	// Create an instance of the XML HTTP Request object
	var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
		
	// Prepare the XMLHTTP object for a HTTP POST to our validation ASP page
	var sURL = "../Seminars/GetInfo.asp?Code=" + Code + '&BaseID=' + BaseID
	oXMLHTTP.open( "POST", sURL, false );
	
	// Execute the request
	oXMLHTTP.send();
	
	rsl = oXMLHTTP.responseText
	InputObj.parentNode.parentNode.cells(2).childNodes(0).value = rsl
	if(rsl == 'رکورد مورد نظر یافت نشد')
		InputObj.parentNode.parentNode.cells(1).childNodes(0).value = ''
	document.body.style.cursor='auto';
	
}
function ImgOver(ImgObj)
{
	ImgObj.style.borderWidth = 1
	ImgObj.style.borderColor = 'black'
}
function ImgOut(ImgObj)
{
	ImgObj.style.borderWidth = 0
}

function DoPrint()
{
	window.print()
}
function AskDelete(Code)
{
	AskResult = confirm("رکورد حذف شود؟")
	if(AskResult){
		form1.DelValue.value = Code;
		form1.action = "index.asp"
		form1.submit()
	}
}

function AskDeleteDetail(FromAction, MasterCode, Code)
{
	AskResult = confirm("رکورد حذف شود؟")
	if(AskResult){
		window.onbeforeunload = '';
		form1.DelList.value = Code;
		form1.Code.value = MasterCode ;
		form1.action = FromAction
		form1.submit()
	}
}

function GotoLink(FormAction)
{
	if( FormAction != "undefined")
		form1.action = FormAction
	form1.submit();
}

function PickDate(DateFieldName, InitVal, Section)
{
	InitVal = InitVal.replace("/", "");
	InitVal = InitVal.replace("/", "");
	
	X =  window.event.clientX
	Y =  window.event.clientY + 100
	if ( InitVal.length != 8)
		InitVal = '';
	whn = 	window.open('DatePicker.asp?FFN=' + DateFieldName + '&InitDate=' + InitVal + '&Section=' + Section,'DatePicker','width=200,height=185,menubar=no,status=no,titlebar=no,resizable=no,top=' + Y + ',left=' + X );
}

function UploadPic(FileName)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=580,height=150,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ShowTree(FileName, BaseID, FFN, InitCode)
{
		whList = window.open(FileName + '?BaseID=' + BaseID + '&FFN=' + FFN + '&InitGroup=' + InitCode,'PersonTree','width=580,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ShowFile(FileName, FieldName, Code)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=620,height=450,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowFile3(FileName, FieldName, Code)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=620,height=450,menubar=yes,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowFile2(PathName)
{
	whList = window.open(PathName,'','width=620,height=450,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowSizedFile(FileName, FieldName, Code,w, h)
{
	whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width='+ w + ',height=' + h + ',menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function List(BaseID, FormFieldName,Section)
{
		whList = window.open('../Admin/List.asp?BaseID=' + BaseID + '&FFN=' + FormFieldName + '&Section=' + Section + '&briefq=1' ,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function List2(BaseID, FormFieldName,Section, FN, FV)
{
		whList = window.open('../Admin/List.asp?BaseID=' + BaseID + '&FFN=' + FormFieldName + '&Section=' + Section + '&FN=' + FN + '&FV=' + FV,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ListMulti(BaseID, FormFieldName,Section)
{
		whList = window.open('../Admin/ListMulti.asp?BaseID=' + BaseID + '&FFN=' + FormFieldName + '&Section=' + Section ,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

/*
function ShowList(FileName, BaseID, MasterFieldName ,Code, FilterCols, FilterVals)
{
	if(FilterCols == undefined)
		FilterCols = ""
	if(FilterVals == undefined)
		FilterVals = ""
		whList = window.open(FileName + '?BaseID=' + BaseID + '&MasterFieldName=' + MasterFieldName + '&Code=' + Code +'&FN=' + FilterCols + '&FV=' + FilterVals,'','width=500,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}
*/
function ShowList(FileName, BaseID, FilterCols, FilterVals)
{
	if(FilterCols == undefined)
		FilterCols = ""
	if(FilterVals == undefined)
		FilterVals = ""
		whList = window.open(FileName + '?BaseID=' + BaseID + '&FN=' + FilterCols + '&FV=' + FilterVals,'','width=500,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function GetLeftCenter(WinHeight, WinHeight)
{

	if (screen.width == 1024)
	{
		RTop = (768 - WinHeight) / 2
		Result = "top=" + RTop + ",left=213"
	}
	else
	{
		RTop = (600 - WinHeight) / 2
		Result = "top=" + RTop + ",left=20"
	}
		return Result
}


function ShowDetail(BaseID, MasterID, Section)
{
	if(MasterID == '')
		alert('ابتدا ذخیره کنید')
	else	
			whList = window.open('../Detail.asp?BaseID=' + BaseID + '&MasterID=' + MasterID + '&Section=' + Section,'','width=570,height=320,menubar=no,status=no,titlebar=no,resizable=no,' + GetLeftCenter(570,320));
}

function ShowDetail2(BaseID, MasterID, MasterID2)
{
		whList = window.open('Detail.asp?BaseID=' + BaseID + '&MasterID=' + MasterID + '&MasterID2=' + MasterID2,'','width=570,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ShowBrowse(BaseID, MasterID, Section)
{
	if(MasterID == '')
		alert('ابتدا ذخیره کنید')
	else
			whList = window.open('../Admin/Browse.asp?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&Section=' + Section,'','width=590,height=420,menubar=no,status=no,titlebar=no,scrollbars,resizable=no,top=200,left=150');
}

function ShowGeneralList(BaseID, MasterID, Section)
{
	if(MasterID == '')
		alert('ابتدا ذخیره کنید')
	else
			whList = window.open('../GeneralList.asp?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&Section=' + Section,'','width=700,height=370,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}


function ShowPics(BaseID, MasterID, MediaType)
{
		whList = window.open('Album.asp?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&MediaType=' + MediaType,'','width=600,height=510,menubar=no,status=no,titlebar=no,resizable=no,top=100,left=150');
}

function DoMask(MaskFormat, str,textbox,loc,delim)
{
//	try{
	
	DoNothing = 0

	CurrentPos = textbox.value.length;
	var locs = loc.split(',');	

	KeyCode = event.keyCode
	if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey) {
		if ((KeyCode > 47 && KeyCode < 58) || (KeyCode > 95 && KeyCode < 106)) {
			MaxL = MaskFormat.length + locs.length 
			if (textbox.value.length >= MaxL) {
					event.returnValue = false
					return false;
			}
			if (KeyCode > 95) KeyCode -= (95-47);
		} else if (KeyCode != 8 && KeyCode != 46 ) {
			event.returnValue = false
			return false;
		}
	}

	CurrentChar = String.fromCharCode(KeyCode)

	for (var i = 0; i <= locs.length; i++){
		for (var k = 0; k <= str.length; k++){
		 if (k == locs[i]){
		  if (str.substring(k, k+1) != delim){
		    str = str.substring(0,k) + delim + str.substring(k,str.length)
			textbox.value = str
		  }
		 }
		}
	 }

	if(CurrentPos < MaskFormat.length + locs.length)
	{
		if(MaskFormat.charAt(CurrentPos) == 'N')
		{
			if( !isNaN(CurrentChar))
			{
				DoNothing = 0
			}
			else
			{
				DoNothing = 1
			}
		}
		else if(MaskFormat.charAt(CurrentPos) == '/')
		{
			if( CurrentChar == '/')
			{
				DoNothing = 0
			}
			else
			{
				DoNothing = 1
			}
		}
		else if(MaskFormat.charAt(CurrentPos) == 'L')
		{
			if( !isNaN(CurrentChar))
			{
				DoNothing = 1
			}
			else
			{
				DoNothing = 0
			}
		}

	}	
	else
		DoNothing = 1
	

	if(DoNothing == 1)
		event.keyCode = 0
	return true;
//	}
//	catch(e)
//	{
//	}
}

function GoBuy(CityCode, CardCode)
{
	document.location.href = 'Buy1.asp?CityCode='+ CityCode + '&CardCode=' + CardCode
}

function Rate(CardCode)
{
		window.open('GetRate.asp?CardCode=' + CardCode ,'Rate','width=480,height=250,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function checkType(str) {
	if(str=='1') {
		document.getElementById("offline").style.display='';	
		document.getElementById("online").style.display='none';	
	} else if(str=='2')  {
		document.getElementById("offline").style.display='none';	
		document.getElementById("online").style.display='';	
	}
    return true;
}


function CheckDeposit()
{
	 if(deposit.Amount.value == "" || deposit.Amount.value == null || isblank(deposit.Amount.value)){
		alert("مبلغ معتبر نیست");
		deposit.Amount.focus()
		return false;
	 }        		
   
	deposit.OnlineTrans.value = '1'
	deposit.submit();
    return true;

}

function CheckShetabDeposit()
{
	if(bankform.BankName.value == '')
	{
		alert('نام بانک نباید خالی باشد')
		bankform.BankName.focus()
		return;
	}

	if(bankform.Branch.value == '')
	{
		alert('نام شعبه نباید خالی باشد')
		bankform.Branch.focus()
		return;
	}

	if(bankform.ReceiptNumber.value == '')
	{
		alert('شماره فیش نباید خالی باشد')
		bankform.ReceiptNumber.focus()
		return;
	}

	if(bankform.Payment.value == '')
	{
		alert('مبلغ نباید خالی باشد')
		bankform.Payment.focus()
		return;
	}


	bankform.BankTrans.value = '1'
	bankform.submit()
}

function AddSCDeposit()
{
	SpecialCardsform.SCDeposit.value = '1'
	SpecialCardsform.submit()
}

function convertHardCode(message) {
	if(!message.length) return message;
	var pat=/&#[0-9]{4};/g;
	var result = message.match(pat);
	if(!result) return message;
	if(result.length){
		new_message=message;
		for(i=0;i<result.length;i++) {
			rchar=result[i];
			code=rchar.replace("&#","");
			hex_code=parseInt(code).toString(16);
			if(hex_code.length<=3) hex_code="0"+hex_code;
			new_char="%u"+hex_code;
			new_message=new_message.replace(rchar,new_char);
		}
		return unescape(new_message);
	}
	return message;
}
// give text string with numbers and return text with JS fasri numbers.
function numberToFarsi(text,type) {
	//var farsi_nums={0 : "&#1776;",1 : "&#1777;",2 : "&#1778;",3 : "&#1779;",4 : "&#1780;",5 :"&#1781;",6 : "&#1782;",7 : "&#1783;",8 : "&#1784;",9 : "&#1785;"};
	var farsi_nums=new Array("&#1776;","&#1777;","&#1778;","&#1779;","&#1780;","&#1781;","&#1782;","&#1783;","&#1784;","&#1785;");
	var english_nums=",1,2,3,4,5,6,7,8,9,0,";
	var digit="";
	var new_text="";
	text=text+"";
	for(i=0;i<text.length;i++) {
		if(english_nums.indexOf(","+text.charAt(i)+",")!=-1)
		{
			var pos=parseInt(text.charAt(i));
			new_text+=farsi_nums[pos];
		}
		else
			new_text+=text.charAt(i);
	}
	if(type=="js")
		return convertHardCode(new_text);
	else
		return new_text;
}

function EnglishNumber(e)
{
	if (e.keyCode>=48 && e.keyCode<=57){ // Numbers
	}
	else {
		return false;
	}
	return true;
}

function isblank(s) {
	for( var i = 0; i < s.length; i++ ) {
		var c = s.charAt(i);
		if (( c != ' ' ) && ( c != '\n' ) && ( c != '\t' )) return false;
	}
	return true;
}

