

function getAvailableWidth()
{
	var docwidth = 0;
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerWidth){ 
	docwidth = window.innerWidth; 
	} 

	//IE Mozilla 
	if (document.body.clientWidth){ 
	docwidth = document.body.clientWidth; 
	} 
	return docwidth;
}


function getAvailableHeight()
{
	var docHeight = 0;
	//opera Netscape 6 Netscape 4x Mozilla 
	if (window.innerHeight){ 
	docHeight = window.innerHeight; 
	} 

	//IE Mozilla 
	if (document.body.clientHeight){ 
	docHeight = document.body.clientHeight; 
	} 
	return docHeight;
}

function setSearchResultsHeight()
{
    if(document.getElementById("divFilterArea"))
    {
        var intFilterAreaHeight =  document.getElementById("divFilterArea").offsetHeight;
	    var intSearchResultsHeight = getAvailableHeight() - intFilterAreaHeight - 168;
	    if(intSearchResultsHeight<108)
		    intSearchResultsHeight=108;
	    document.getElementById("div-datagrid").style.height = intSearchResultsHeight;
    }
}

function setMainTableSize()
{

	//get size of side navigation
	var divNavigationArea = document.getElementById("navigationarea");
	
	//remove from size of available width
	// and assign to main table div
	var divMainTable = document.getElementById("contentarea");
	//var intNewWidth = getAvailableWidth() - 150;
	var intNewWidth = getAvailableWidth() - 200;
	
	//set minimum width;
	if (intNewWidth < 615) intNewWidth = 615;
	divMainTable.style.width = intNewWidth;
	
	//set height of navigation area to push footer to base of page
	var intNavigationHeight = getAvailableHeight()-85;
	divNavigationArea.style.height = 100;//intNavigationHeight;
	
}


//var newwindow;
//function assetmanager(url)
//{
//        newwindow=window.open(url,'name','height=630,width=930,resizable=no, scrollbars=no');
//       if (window.focus) {newwindow.focus()}
//}

var win= null;
function NewWindow(mypage,myname,w,h,scroll){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
      
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}


// ----------------------------------------------------------------------------------------
// previewAsset() - onclick for preview asset link - displays real-size asset in new window
// ----------------------------------------------------------------------------------------
/*function previewAsset(filenameHolder) {
	if(document.getElementById(filenameHolder).value != '') {
		window.open("library\\" + document.getElementById(filenameHolder).value, "_blank", null, null);
	}
	else {
		alert("There is no asset selected");
	}
}*/
//3.3.28
function previewAsset(filenameHolder,directoryHolder) {
	if(document.getElementById(filenameHolder).value != '' && document.getElementById(directoryHolder).value != '') {
		window.open(document.getElementById(directoryHolder).value+"/"+document.getElementById(filenameHolder).value, "_blank", null, null);
	}
	else {
		alert("There is no asset selected");
	}
}

// ----------------------------------------------------------------------------------------
// openAssetManager() - opens the asset manager and populates with latest selected asset
// ----------------------------------------------------------------------------------------
function openAssetManager(controlID, relationID, assetIdHolder) {
	NewWindow('AssetManager/AssetManager.aspx?a=' + document.getElementById(assetIdHolder).value + '&ControlID=' + controlID + '&RelationID=' + relationID,'AssetManager','1016','706','no');
	//return false;
	
	//window.open('AssetManager/AssetManager.aspx?a=' + document.getElementById(assetIdHolder).value + '&ControlID=' + controlID + '&RelationID=' + relationID,'_blank','width=930,height=600,toolbar=0,scrollbars=0,resizable=0,status=0,copyhistory=1,location=0,menubar=0');
}


// ----------------------------------------------------------------------------------------
// openAssetUpload() - opens the asset upload page and populates with latest selected asset
// ----------------------------------------------------------------------------------------
function openAssetUpload(controlID, relationID,assetId,filenameHolder) {
	NewWindow('AssetManager/UploadAsset.aspx?a=' + assetId + '&ControlID=' + controlID + '&RelationID=' + relationID + '&file=' + document.getElementById(filenameHolder).value,'UploadAsset','565','250','no');
}


// ----------------------------------------------------------------------------------------
// openFormBuilder() - opens the form builder and populates with the selected form
// ----------------------------------------------------------------------------------------
function openFormBuilder(pageID, controlID, relationID, assetIdHolder) {
	NewWindow('FormBuilder/FormStructBuilder.aspx?f=' + document.getElementById(assetIdHolder).value + '&p=' + pageID + '&ControlID=' + controlID + '&RelationID=' + relationID,'FormBuilder','940','700','yes');
}

function removeAssetRelation(strRelationId, clientId) {
    var vItem1 = document.getElementById(clientId + '_Relation_' + strRelationId);
    vItem1.value = '0';
    var vItem2 = document.getElementById(clientId + '_Asset_' + strRelationId);
    vItem2.value = 'No selection';
}
