﻿
    function rnd() {
        today=new Date();
        jran=today.getTime();

        ia=9301;
        ic=49297;
        im=233280;
        jran = (jran*ia+ic) % im;
        return jran/(im*1.0);
    }


    function rand(number) {
        return Math.ceil(rnd()*number);
    }

    function OpenWindowDialogPopUp(strPage, strKeys, strParams)
    {
        var myRand = rand(50000);
        //alert(myRand);
        var retVal = window.showModalDialog(strPage + "?" + strKeys+ '&rand='+ myRand, '_blank', strParams);
        //alert(retVal);
        if (retVal == true)
        {
            //alert('Reloading');
            location.reload();
        }
    }	


    function f_open_window_max( aURL)
    {
       var wOpen;
       var sOptions;

       sOptions = 'status=no,menubar=no,scrollbars=yes,resizable=no,toolbar=no';
       sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
       sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
       sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

       wOpen = window.open( aURL, '_blank', sOptions );
       wOpen.focus();
       //wOpen.location = aURL;
       wOpen.moveTo( 0, 0 );
       wOpen.resizeTo( screen.availWidth, screen.availHeight );
       //return wOpen;
    }


	
	function AlertInfo()
	{
	    alert('Only BSC Staff applications will be zipped and shown on the next screen');
	    return true;
	}
	
	
    function OpenWindowSelf2(strPage)
    {
	    window.open(strPage, '_self');
    }	
	
	function fn_DeleteCV(intCounter) 
	{
		
		if (intCounter == 1) {
			blnRetVal = confirm("Are you sure you want to delete this CV?");
			return blnRetVal;
		}
		else if (intCounter == 2) {
			blnRetVal = confirm("Are you sure you want to delete this CV?");
			if (blnRetVal) {
				blnRetVal = confirm("Are you absolutely sure?")	
				return blnRetVal;
			}
			return blnRetVal;
		}
	}

	function fn_DeletePhoto(intCounter) 
	{
		
		if (intCounter == 1) {
			blnRetVal = confirm("Are you sure you want to delete this photo?");
			return blnRetVal;
		}
		else if (intCounter == 2) {
			blnRetVal = confirm("Are you sure you want to delete this photo?");
			if (blnRetVal) {
				blnRetVal = confirm("Are you absolutely sure?")	
				return blnRetVal;
			}
			return blnRetVal;
		}
	}

	
	function fn_SmsSubmit(intSmsAcc) 
	{
		if (intSmsAcc == '1')
			blnRetVal = confirm("Are you sure that you want to sent SMS?");
		else 
			blnRetVal = confirm("Are you sure that you want to sent SMS to " + intSmsAcc + " account?");
			
		if (blnRetVal) {
			blnRetVal = confirm("Are you absolutely sure?")	
			return blnRetVal;
		}
		return blnRetVal;
	}
	
	function fn_BrowserRedirect()
	{
		var browserName=navigator.appName; 
		if (browserName != "Microsoft Internet Explorer"){
			alert(" Current version of 'Spark Online' is supported \n only on 'Microsoft Internet Explorer'");
			window.location="http://www.spark-online.org";
		}
	}

	function OpenWindowSame(strPage, strKeys, strParams) {
		window.open(strPage + "?" + strKeys, '_self', strParams);
	}

	function OpenWindowNew2(strPage, strKeys, strParams)
	{
		window.open(strPage + "?" + strKeys, '_blank', strParams);
	}

	function fn_EventInfo()
	{
		try
		{
			window.open("htmls/docs/EventInfo.html", "_blanc", "status = 0, left=250,top=80,height=500,width=600, resizable = 1, scrollbars=1");
		}
		catch (e) {
			alert(e.message);
		}
	}		

	
	function fn_CheckCourse(ctrl_Object)
	{
		//alert(ctrl_Object);
		var IsNumber = fn_IsNumeric(ctrl_Object.value);
		
		if (!IsNumber) {
			alert('Only numbers are supported like 1,2,3,4,5,etc');
			ctrl_Object.value = 0;
		}
		
	}

	function fn_IsNumeric(sText)
	{
		var ValidChars = "0123456789";
		var IsNumber=true;
		var Char;

		for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
  			Char = sText.charAt(i); 
  			if (ValidChars.indexOf(Char) == -1) 
     			IsNumber = false;
		}
		return IsNumber;
	}

	function fn_CheckSpace(ctrl_Object)
	{
		strValue = ctrl_Object.value;
		if (trim(strValue) == '') {
			//alert('Please provide your comment');
			ctrl_Object.value = '';
		}
	}

	function LTrim( value ) {var re = /\s*((\S+\s*)*)/;	return value.replace(re, "$1");}
	function RTrim( value ) {var re = /((\s*\S+)*)\s*/;	return value.replace(re, "$1");}
	function trim(value) {return LTrim(RTrim(value));}


	function isValidEmail(strValue) {
		
		blnRetVal = (strValue.indexOf(".") > 0) && (strValue.indexOf("@") > 0);
		return blnRetVal;
	}

	function fn_CheckEmail (ctrl_Object) {
		strValue = ctrl_Object.value;
		
		blnRetVal = isValidEmail(ctrl_Object.value)
		
		if (!blnRetVal) {
			alert('Enter valid email, example: info@mail.org');
			ctrl_Object.value = 'info@mail.org';
		}
	}

	function fn_CheckField (ctrl_Object) {
		strValue = trim(ctrl_Object.value);
		
		if (strValue == '') {
			alert('Provide some information for the following field.');
			ctrl_Object.value = 'Enter info';
			//ctrl_Object.focus();
		}
	}

	function fn_SubmitRec() 
	{
		blnRetVal = confirm(" After submission you will not be able to change your data! \n\n Are you sure you want to submit it?");
		if (blnRetVal) {
			blnRetVal = confirm("Are you absolutely sure?")	
			return blnRetVal;
		}
		return blnRetVal;
	}

	function fn_EmailSubmit(intEmailAcc) 
	{
		if (intEmailAcc == '1')
			blnRetVal = confirm("Are you sure that you want to sent email?");
		else 
			blnRetVal = confirm("Are you sure that you want to sent email to " + intEmailAcc + " account?");
			
		if (blnRetVal) {
			blnRetVal = confirm("Are you absolutely sure?")	
			return blnRetVal;
		}
		return blnRetVal;
	}


	function fn_DeleteRec(intCounter) 
	{
		
		if (intCounter == 1) {
			blnRetVal = confirm("Are you sure you want to delete this record?");
			return blnRetVal;
		}
		else if (intCounter == 2) {
			blnRetVal = confirm("Are you sure you want to delete this record?");
			if (blnRetVal) {
				blnRetVal = confirm("Are you absolutely sure?")	
				return blnRetVal;
			}
			return blnRetVal;
		}
	}

	function fn_CheckDigit0_5(ctrl_Object)
	{
		//alert(ctrl_Object);
		strValue = ctrl_Object.value;
		intValue = 0;
		try {
			if (fn_IsNumeric(strValue)) {
				intValue = parseInt(strValue);
				
				if (intValue < 1 || intValue > 5) {
					alert('Enter number between 1 and 5');
					ctrl_Object.value = '1';
					ctrl_Object.focus();
					//ctrl_Object.onfocus();
				}
			}
			else {
				alert('Enter valid number in range between 1 and 5');
				ctrl_Object.value = '1';
				ctrl_Object.focus();
			}
		}
		catch(e) {
			alert('Enter number between 1 and 5');
			ctrl_Object.value = '1';
			ctrl_Object.focus();
		}
	}

function select_deselectAll (chkVal, idVal) 
{ 
	var frm = document.forms[0];

	if (chkVal)
		alert(" Only the items shown on this page are selected, \n set rows to '-all-'  if you want to select \n all searched items");		
	
	
	// Loop through all elements
	for (i=0; i<frm.length; i++) 
	{
		// Look for our Header Template's Checkbox
		if (idVal.indexOf ('CheckAll') != -1) 
		{
			// Check if main checkbox is checked, then select or deselect datagrid checkboxes 
			if(chkVal == true) 
			{
				frm.elements[i].checked = true;
			} 
			else 
			{
				frm.elements[i].checked = false;
			}
			// Work here with the Item Template's multiple checkboxes
		} 
		else if (idVal.indexOf ('DeleteThis') != -1) 
		{
			// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
			if(frm.elements[i].checked == false) 
			{
				frm.elements[1].checked = false; //Uncheck main select all checkbox
			}
		}
	}

}

function FindObjectSetVal(strElementName, strElementValue)
{
	elemCurr = document.getElementById(strElementName)
	//alert(elemCurr);
	elemCurr.value = strElementValue;
}

function TransferDepartmentID(intDepartmentID)
{
	if (intDepartmentID == null)
	   intDepartmentID = -1;
	window.returnValue = intDepartmentID;
	window.close();
}

function OpenWindowNew(strPage, strKeys)
{
	//alert('x');
	window.open(strPage + "?" + strKeys, '_blank');
}

function OpenWindowNew5(strPage)
{
	//alert('x');
	window.open(strPage, '_blank');
}


function OpenWindowMaximized(strPage, strKeys)
{
	sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes,location=yes';
	window.open(strPage + "?" + strKeys, '_blank', sOptions);
}


function f_open_window_max2( aURL, aWinName )
{
	var wOpen;
	var sOptions;

	sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes,location=yes';
	sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
	sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
	sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

	wOpen = window.open( '', aWinName, sOptions );
	wOpen.location = aURL;
	wOpen.focus();
	wOpen.moveTo( 0, 0 );
	wOpen.resizeTo( screen.availWidth, screen.availHeight );
	return wOpen;
}
function OpenWindowATA(strPage, strKeys)
{
	if (strKeys.indexOf("-100") != -1) {
		alert(" Please selected an event from the search menu, \n after press 'SEARCH' button \n after click on the following link");
		return;
	}
	window.open(strPage + "?" + strKeys, '_blank');
}


function OpenWindowNew4(strPage)
{
    window.open(strPage, '_blank', "width=550px; height=300px; screenX=200,screenY=200,left=200,top=200");
}	


function OpenWindowDialog(strPage, strKeys, strParams)
{
	window.showModalDialog(strPage + "?" + strKeys, '_blank', strParams);
}	

function OpenWindowDialog(strPage, strKeys, strParams)
{
	window.showModalDialog(strPage + "?" + strKeys, '_blank', strParams);
}		

function OpenWindowSelf(strPage, strKeys)
{
	window.open(strPage + "?" + strKeys, '_self');
}	



function fn_WHint(strInputText)
{
	try
	{
		strBody = "<html>"
		strBody = strBody + "<title>Infor</title><head><LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"Css/NewStyle.css\"></head>"
		strBody = strBody + "<body class=\"body_popup\">" + strInputText + "</body></html>"
		
		wndX = window.open("test2.html", "_blanc", "status = 0, left=600,top=300,height=150,width=250, resizable = 0, scrollbars=1");
		wndX.document.write(strBody);
	}
	catch (e) {
		alert(e.message);
	}
}
	
function boolLogin() 
{
	//alert('x');
	return true;
}

function boolLogout() 
{
	//alert('outmain');
	//document.Form1._ctl0_txt_Signedout.value = 'true';
	//alert(document.Form1._ctl0_txt_Signedout.value);
	return true;
}

function setValue(index, strRoleID)
{
	intID = index; 
	
	if  (intID == '-100') {
		alert('Please select valid profile for previewing!');
		return;
	}
	OpenWindowNew('Lookup.aspx', 'Person=1&' + strRoleID + '=' + intID);
}		


function OpenWindowNewCV(strKeys, strParams)
{
	if (strKeys == '-100') {
		alert("Before to upload CV, first you must register a profile for the trainer with pressing button 'Save'. If the registration profile is successfully saved than you can upload CV.");
		return;
	}
	window.open('Lookup.aspx' + "?CV=1&PersonID=" + strKeys, '_blank', strParams);
}

function fn_Unregister() 
{
	var blnRetVal;
	blnRetVal = confirm("Are you sure you want to unregister from our system?");
	
	if (blnRetVal) {
		return true;
	}
	return false;
}


function OpenWindowDialogForum(strPage, strKeys, strParams) {
    var myRand = rand(50000);
    //alert(myRand);
    var retVal = window.showModalDialog(strPage + "?" + strKeys + '&rand=' + myRand, '_blank', strParams);
    //alert(retVal);
    if (retVal == true) {
        //alert('Reloading');
        location.reload();
    }
}	
