﻿function doTooltip(e, msg) 
{
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) 
		return;
	Tooltip.show(e, msg);
}

function hideTip() 
{
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) 
		return;
	Tooltip.hide();
}

function EditTooltip( strStringName )
{
	//alert( strStringName );
	var strUrl = "popups/FormModalDialog.aspx?iframeContents=";
	strUrl += escape( "TooltipEditor.aspx?tooltip="+strStringName );
	var strRes= showModalDialog( strUrl,'','dialogWidth:600px;dialogHeight:300px;scroll:auto;status:no;resizable:no;');

	if( parseInt( strRes ) > 0 )
	{
		location.reload();
	}
}

function ResultWizard( nSurveyId )
{
	var strUrl = "popups/FormModalDialog.aspx?iframeContents=";
	strUrl += escape( "ResultWizard.aspx?surveyid="+nSurveyId );
	var strRes= showModalDialog( strUrl,'','dialogWidth:510px;dialogHeight:590px;scroll:auto;status:no;resizable:no;');

	try
	{
	
	var aRes = strRes.split( ',' );
	var nReportId = aRes[ 1 ];
	var strReportType = aRes[ 0 ];
	
	if( parseInt( nReportId ) == 0 )
	{
		alert( "ekkert" );
	}
	

		if( parseInt( nReportId ) > 0 )
		{
			if( strReportType == "web" )
			{
				OpenReport( nReportId );
			}
			else if( strReportType == "pdf" )
			{
				OpenPdfReport( nReportId );
			}
			else if( strReportType == "text" )
			{
				GetExportReport( nReportId, strReportType, 600, 800 )
			}
			else
			{
				GetExportReport( nReportId, strReportType, 10, 10 )
			}
		}
			
		if( parseInt( nReportId ) < 0 )
		{
			SendHtmlReport( nReportId );
		}
	}
	catch( e )
	{
		window.location.reload();
	}
	//location.href = "surveyoverview.aspx?surveyid="+nSurveyId
}

	function GetExportReport( nId,  strType, nHeight, nWitdh )
	{
		
		var strUrl = "export.aspx?reportid="+nId+"&type="+strType;
		//alert( strUrl );
		//myWindow = window.open( strUrl, "tinyWindow", 'toolbar,width=1,height=1' ) 
		OpenBrWindow(strUrl,'Test','','"+nHeight+"','"+nWitdh+"','true')
		//myWindow.document.write("Welcome to this new window!")
		//myWindow.document.bgColor="lightblue"
		//myWindow.document.close() 

		//parent.parent.location.href = strUrl;
		//alert( 1 );
	}
function OpenBrWindow( theURL,winName,features, myWidth, myHeight, isCenter ) 
{  
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = ((screen.height-myHeight)/2)-50;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
function SendHtmlReport( nId  )
{
	var strTitle = "Senda skýrslu í pósti";
	var strUrl = "popups/FormModalDialog.aspx?iframeContents=";
	strUrl += escape( "SendReport.aspx?reportid="+nId+"&title="+strTitle );
	showModalDialog( strUrl,'','dialogWidth:555px;dialogHeight:455px;scroll:auto;status:no;resizable:no;');
}

function OpenReport( nId )
{
	var strUrl = "popups/ViewReport.aspx?reportid="+nId;
	//showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strUrl,'','dialogWidth:600px;dialogHeight:800px;scroll:auto;status:no;resizable:no;');			

	var win = window.open( strUrl,'image','width=650,height=800,scrollbars=yes');
}
function OpenPdfReport( nId )
{
	
	var strUrl = "popups/OpenPdfReport.aspx?reportid="+nId;
	
	var win = window.open( strUrl );
}


function confirmDeleteFromMenu( strWarn, strLocation, idparameter, nRecordId, strReferer )
{
	if (confirm(strWarn))
	{
		location.href = (strLocation + "?action=delete&"+idparameter+"="+ nRecordId+"&referer="+strReferer );
	} 
	return;
}


function NewSurveyBasedOnOther123( strId )
{
	var strContent = escape("NewSurveyBasedOn.aspx?surveyid="+strId );
	var strSurveyId = showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strContent,'','dialogWidth:420px;dialogHeight:200px;scroll:auto;status:no;resizable:no;'); 
	if( parseInt( strSurveyId ) > 0 )
		location.href = "surveyoverview.aspx?surveyid="+strSurveyId;
}

function showPostlistDlg3(SurveyID)
{
	alert(SurveyID)
	var strContent = escape( 'PostlistDialog.aspx?surveyid='+ SurveyID );
	var returnVal = showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strContent,'','dialogWidth:520px;dialogHeight:325px;scroll:no;status:no;resizable:no;')
	
	if(returnVal == null)
		alert("cancel")
	else
		alert("work done, reload");
}


function showPostlistDlg2( strId, strNotSavedAlert )
{

	var strContent = escape( 'PostlistDialog.aspx?surveyid='+ strId );
	if(strId == 0)
	{
		alert (strNotSavedAlert);
	}
	else
	{
		document.getElementById('edtPostlist').value=showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strContent,'','dialogWidth:520px;dialogHeight:325px;scroll:no;status:no;resizable:no;')
	}
}

function showPostlistDlg()
{
	document.getElementById('edtPostlist').value=showModalDialog('popups/FormModalDialog.aspx?iframeContents=PostlistDialog.aspx','','dialogWidth:520px;dialogHeight:325px;scroll:no;status:no;resizable:no;')
}

function ImportPostlist()
{
	var strResult = showModalDialog('popups/FormModalDialog.aspx?iframeContents=ImportPostlist.aspx','','dialogWidth:400px;dialogHeight:480px;scroll:auto;status:no;resizable:no;');
	
	
	window.location.reload();
	
	//if( parseInt( strResult ) > 0 )
	//	location.href = "myparticipants.aspx";

}

function AddSurveyFolder( strComingFrom )
{
	var strContent = escape( 'CreateFolder.aspx?comingfrom='+strComingFrom );
	var strFolderId = showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strContent,'','dialogWidth:310px;dialogHeight:200px;scroll:auto;status:no;resizable:no;');			
	//location.href = "MySurveys.aspx";
	if( strFolderId > 0 )
		location.reload();
}
/*function AddSurveyFolder.old( strComingFrom )
{
	//var strContent = escape( 'CreateFolder.aspx?comingfrom='+strComingFrom );
	var strFolderId = showModalDialog('popups/FormModalDialog.aspx?iframeContents=CreateFolder.aspx','','dialogWidth:310px;dialogHeight:220px;scroll:auto;status:no;resizable:no;');			
	//location.href = "MySurveys.aspx";
	
}*/
function EditSurveyFolder( nFolderId, strComingFrom, strReferer )
{
	
	var strContent = escape( 'CreateFolder.aspx?folderid='+nFolderId+'&comingfrom='+strComingFrom+'&referer='+strReferer );
	var strFolderId = showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strContent, parent.parent ,'dialogWidth:310px;dialogHeight:220px;scroll:auto;status:no;resizable:no;');			
	//location.href = "MySurveys.aspx";
}
function DeleteSurveyFolder( strMessage, nFolderId, strComingFrom, strReferer )
{
	if( confirm( strMessage ) )
	{
		//return;
		location.href = "deletefolder.aspx?folderid="+ nFolderId +"&comingfrom="+strComingFrom+"&referer="+strReferer;
	} 
	return;
}
function DeleteQuestionFromMenu( strMessage, nQuestionId, strComingFrom, strReferer )
{
	if( confirm( strMessage ) )
	{
		//return;
		location.href = "deletesavedquestion.aspx?questionid="+ nQuestionId +"&comingfrom="+strComingFrom+"&referer="+strReferer;
	} 
	return;
}

function Activate( nId, strMessage )
{
	if( confirm( strMessage ) )
	{
		location.href = ( "SurveyOverview.aspx?action=activate&surveyid="+ nId );
	} 
	return;
}
function DeActivate( nId, strMessage )
{
	if( confirm( strMessage ) )
	{
		location.href = ( "SurveyOverview.aspx?action=deactivate&surveyid="+ nId );
	} 
	return;
}



function AddPostlist()
{
	var strContent = escape( 'AddPostlist.aspx' );
	var strReturn = showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strContent,'','dialogWidth:310px;dialogHeight:205px;scroll:auto;status:no;resizable:no;');			
	
	if( parseInt( strReturn ) > 0 )
		location.reload();
}
function EditPostlist( nPostlistId )
{
	if( parseInt( nPostlistId ) > 0 )
	{
		var strContent = escape( 'AddPostlist.aspx?postlistid='+nPostlistId );
		var strReturn = showModalDialog('popups/FormModalDialog.aspx?iframeContents='+strContent, parent.parent ,'dialogWidth:310px;dialogHeight:205px;scroll:auto;status:no;resizable:no;');			
	
		if( parseInt( strReturn ) > 0 )
			location.reload();
	}
}
/*function DeletePostlist( strMessage, nFolderId )
{
	if( confirm( strMessage ) )
	{
		//return;
		location.href = "deletepostlist.aspx?folderid="+ nFolderId;
	} 
	return;
}*/


