function RemFraming() {
  cropPos1 = 0;
  cropPos2 = 0;
  cropPos3 = 0;
  cropPos4 = 0;
  topMat.id=0;
  middleMat.id=0;
  bottomMat.id=0;
  topMatWidth=0;
  middleMatWidth=0;
  bottomMatWidth=0;
  moulding_delete('frame');
  moulding_delete('fillet');
  moulding_delete('liner');
  groove=0;
  if(glass)
    glass.id=null;
  art_project.tmatHolder.hide();
  art_project.mmatHolder.hide();
  art_project.bmatHolder.hide();
  art_project.vgHolder.hide();
  update();
}

function Mail() {
  var filename = '../resources/uploaded/framed_art_' + rand() + '.png';
  var image_url = generateUrlForSave(800, 600) + "&save_to=" + filename + "&mailto=1";
  wnd = window.open(image_url, '','width=400, height=430, top=' + (document.body.clientHeight - 410)/2 + ', left=' + (document.body.clientWidth - 421)/2);
}

function saveimage() {
  var w;
  var h;
  w=$("img_w").value;
  h=$("img_h").value;
  Save(w, h);
}

function printimage()
{
  var w;
  var h;
  w=$("img_w").value;
  h=$("img_h").value;
  Print(w, h);
}

//Loads the help window
function Help() {
  var p = window.open("help.html#" + chelp, "help", "width=500, height=400, scrollbars=yes");
  p.focus();
}

function onuploadimage(W) {
  
   if(document.uploadForm.up_img_w.value<100) {
    alert('Please enter a width measurement of 100mm or greater.');
  return 0;
  }
  if(document.uploadForm.up_img_w.value>1220) {
    alert('The maximum size you may order is 1220mm X 915mm or 915mm X 1220mm.');
  return 0;
  }
  if(document.uploadForm.up_img_h.value>1220) {
    alert('The maximum size you may order is 1220mm X 915mm or 915mm X 1220mm.');
  return 0;
  }
  if(document.uploadForm.up_img_w.value>915 && document.uploadForm.up_img_w.value<1221) {
	  if (document.uploadForm.up_img_h.value>915){
    alert('The maximum size you may order is 1220mm X 915mm or 915mm X 1220mm.');
  return 0;
  }}
  if(document.uploadForm.up_img_h.value<100) {
    alert('Please enter a height measurement of 100mm or greater.');
  return 0;
  }
  if(document.uploadForm.up_img_h.value>915 && document.uploadForm.up_img_h.value<1221) {
	  if (document.uploadForm.up_img_w.value>915){
    alert('The maximum size you may order is 1220mm X 915mm or 915mm X 1220mm.');
  return 0;
  }}
  if (isNaN(document.uploadForm.up_img_h.value)) {
    alert('Please enter a height measurement in numerics.');
  return 0;
  }
  if (isNaN(document.uploadForm.up_img_w.value)) {
    alert('Please enter a width measurement in numerics.');
  return 0;
  }
  if(W)
    showFramer('about:blank','framer');
  document.uploadForm.submit();
  return 1;
}

//Deletes the frame
mould_delete = function(mType) {
  moulding_delete(mType);
  update();
}

moulding_delete = function(mType) {
  eval(mType).width = 0;
  eval(mType).id = 0;
  eval(mType).maxlength = 0;
  eval('art_project.' + mType + 'Holder').hide();
  if(eval(mType).type == 'cframe') {
    frame.frameWidth = 0;
    frame.frameHeight = 0;
    frame.cFrameSpaceT = 0;
    frame.cFrameSpaceR = 0;
    frame.cFrameSpaceB = 0;
    frame.cFrameSpaceL = 0;
  }
  if(eval(mType).type == 'cframe' || eval(mType).type == 'frame')
  {
    glass = null;
    updateInfo();
  }
  
  if($("mprofile"))
    $("mprofile").innerHTML = "";
  if($("mprofileinformation"))
    $("mprofileinformation").innerHTML = "";
}

function SaveFraming(ind) {
  framing[ind] = new Array();
  framing[ind]['cropPos1'] = cropPos1;
  framing[ind]['cropPos2'] = cropPos2;
  framing[ind]['cropPos3'] = cropPos3;
  framing[ind]['cropPos4'] = cropPos4;
  framing[ind]['topMat'] = new Mat();
  framing[ind]['middleMat'] = new Mat();
  framing[ind]['bottomMat'] = new Mat();
  Object.extend(framing[ind]['topMat'], topMat);
  Object.extend(framing[ind]['middleMat'], middleMat);
  Object.extend(framing[ind]['bottomMat'], bottomMat);
  framing[ind]['topMatWidth'] = topMatWidth;
  framing[ind]['middleMatWidth'] = middleMatWidth;
  framing[ind]['bottomMatWidth'] = bottomMatWidth;
  framing[ind]['frame'] = new Frame();
  framing[ind]['fillet'] = new Frame();
  framing[ind]['liner'] = new Frame();
  Object.extend(framing[ind]['frame'], frame);
  Object.extend(framing[ind]['fillet'], fillet);
  Object.extend(framing[ind]['liner'], liner);
  framing[ind]['groove'] = groove;
  framing[ind]['grooveDeltaX'] = grooveDeltaX;
  framing[ind]['grooveDeltaY'] = grooveDeltaY;
  framing[ind]['glass'] = new Glass();
  Object.extend(framing[ind]['glass'], glass);
}

function LoadFraming(ind) {
  cropPos1 = framing[ind]['cropPos1'];
  cropPos2 = framing[ind]['cropPos2'];
  cropPos3 = framing[ind]['cropPos3'];
  cropPos4 = framing[ind]['cropPos4'];
  Object.extend(topMat, framing[ind]['topMat']);
  Object.extend(middleMat, framing[ind]['middleMat']);
  Object.extend(bottomMat, framing[ind]['bottomMat']);
  topMatWidth = framing[ind]['topMatWidth'];
  middleMatWidth = framing[ind]['middleMatWidth'];
  bottomMatWidth = framing[ind]['bottomMatWidth'];
  Object.extend(frame, framing[ind]['frame']);
  Object.extend(fillet, framing[ind]['fillet']);
  Object.extend(liner, framing[ind]['liner']);
  groove = framing[ind]['groove'];
  grooveDeltaX = framing[ind]['grooveDeltaX'];
  grooveDeltaY = framing[ind]['grooveDeltaY'];
  glass = null;
  glass = framing[ind]['glass'];
  update();
}

function showProSize()
{
    if(image.showsize)
    {
        if($('imgInfo'))
        {
            $('imgInfo').remove();
        }
        var dimensions = $('imgHolder').getDimensions();
        var div = '<div id="imgInfo" class="imgInfo">'+image.imageSizeX +'mm X ' + image.imageSizeY +'mm</div>';
            new Insertion.Top('imgHolder', div);
            
        $('imgInfo').setStyle({
            'line-height': dimensions.height + "px",
            width: dimensions.width + "px",
            height: dimensions.height + "px"
        });
    }
    else
    {
        if($('imgInfo'))
        {
            $('imgInfo').remove();
        }
    }
}

function changeWidth(value)
{
	
    if(value)
    {
		   if((maxProY < image.imageSizeY && parseInt(value) > maxProY) || (maxProY >= image.imageSizeY && parseInt(value) > maxProX) )
        {
            alert("Maximum size " + maxProX +"mm X "+ maxProY + "mm. \nPlease enter smaller dimensions");
            return;
        }
         
		 if((minProY < image.imageSizeY && parseInt(value) < minProY) || (minProY <= image.imageSizeY && parseInt(value) < minProX) )
        {
            alert("Minimum size " + minProX +"mm X "+ minProY + "mm. \nPlease enter a larger dimensions");
            return;
        }

        
        var valid = 1;
        var tmpimageSizeX = image.imageSizeX;
        image.imageSizeX  = parseInt(value);
        setDefaultGlass();
        update();
        
        if(!validateBearFrameMore())
        {
            image.imageSizeX = tmpimageSizeX;
            setDefaultGlass();
            update();
            alert("The size you require exceed the maximum size for this moulding width. \nPlease select a frame with a wider profile or select a metal frame in the aluminium category.");
            return;
        }
        
        if(eval(topMat.id) > 0)
        {
            valid = validateBearMatMore('big', false);

            if(valid == -2)
            {
                image.imageSizeX  = tmpimageSizeX;
                update();
                alert("The size you require exceed the maximum size for this moulding width. \nPlease select a frame with a wider profile or select a metal frame in the aluminium category.");
                return;
            }
        }
    }
}
function changeHeight(value)
{
    if(value)
    {
		 if((maxProY < image.imageSizeX && parseInt(value) > maxProY) || (maxProY >= image.imageSizeX && parseInt(value) > maxProX) )
        {
            alert("Maximum size " + maxProX +"mm X "+ maxProY + "mm. \nPlease enter a smaller dimensions");
            return;
        }
		
		 if((minProY < image.imageSizeX && parseInt(value) < minProY) || (minProY <= image.imageSizeX && parseInt(value) < minProX) )
        {
            alert("Minimum size " + minProX +"mm X "+ minProY + "mm. \nPlease enter a larger dimensions");
            return;
        }
        var valid = 1;
        var tmpimageSizeY = image.imageSizeY;
        image.imageSizeY  = parseInt(value);
        setDefaultGlass();
        update();

        if(!validateBearFrameMore())
        {
            image.imageSizeY = tmpimageSizeY;
            setDefaultGlass();
            update();
            alert("The size you require exceed the maximum size for this moulding width. \nPlease select a frame with a wider profile or select a metal frame in the aluminium category.");
            return;
        }
        
        if(eval(topMat.id) > 0)
        {
            valid = validateBearMatMore('big', false);

            if(valid == -2)
            {
                image.imageSizeY  = tmpimageSizeY;
                update();
                alert("The size you require exceed the maximum size for this moulding width. \nPlease select a frame with a wider profile or select a metal frame in the aluminium category.");
                return;
            }
        }
    }
}

function rand() {
 now=new Date();
 num=(now.getMilliseconds()*now.getMinutes())+now.getMonth()*now.getYear();
 num=num+1;
 return num;
}
