
/* Dataview Webpart Forms engine*/
function VWSendForm(redirurl, message, action) {

    var theForm = document.forms['aspnetForm'];
    if (theForm.vwFormRedirecturl != null)
        theForm.vwFormRedirecturl.value = redirurl;
    if (theForm.vwFormMessage != null)
        theForm.vwFormMessage.value = message;
    if (theForm.vwFormAction != null)
        theForm.vwFormAction.value = action;
    theForm.submit();
    return true;
}


/* "Siteactions" => "Create new page" openwindow handler*/
function VWCreatePage()
{
    try {
        OpenCreateWebPageDialog('/_layouts/createwebpage.aspx');
        window.setTimeout(IsDlgOpen, 500);        
	}
    catch (e) 
    {
		alert(e);
	}
}

function IsDlgOpen() {
    if (SP.UI.ModalDialog.get_childDialog() == null) {        
        window.document.location.href = window.document.location.href;
    }
    else {
        window.setTimeout(IsDlgOpen, 500);
    }    
}

function scaleSize(maxW, maxH, currW, currH){

    var ratio = currH / currW;

    if(currW >= maxW && ratio <= 1){
        currW = maxW;
        currH = currW * ratio;
    } 
    else if(currH >= maxH){
        currH = maxH;
        currW = currH / ratio;
    }

    return [currW, currH];
}

function resizePicSmall(pic)
{
    var maxH = 122;
    var maxW = 154;
    var h = pic.height;
    var w = pic.width;
    if (maxH < h || maxW < w) {
        var newSize = scaleSize(maxW, maxH, h, w);
        pic.height = newSize[1] + "px";
        pic.width = newSize[0] + "px";
    }
    //alert('New Width: ' + newSize[0] + ', New Height: ' + newSize[1]);

}

function resizePicBig(pic)
{
    var maxH = 445;
    var maxW = 318;
    var h = pic.height;
    var w = pic.width;
    if (maxH < h || maxW < w) {
        var newSize = scaleSize(maxW, maxH, h, w);
        pic.height = newSize[1] + "px";
        pic.width = newSize[0] + "px";
    }
    //alert('New Width: ' + newSize[0] + ', New Height: ' + newSize[1]);

}
