﻿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)
//	{
//	}
}

