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;  
  groove=0;
  glass.id=null;
  glass=0;
   frame.width = 0;
  frame.id = 0;
  art_project.tmatHolder.hide();
  art_project.mmatHolder.hide();
  art_project.bmatHolder.hide();
  art_project.vgHolder.hide();
   update();
  moulding_delete('frame');
  moulding_delete('fillet');
  moulding_delete('liner');

   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=490, height=460, 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);
}

function zoom_image()
{
  var w;
  var h;
  w=$("img_w").value;
  h=$("img_h").value;
  ZoomImage(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.uploadfile.value=='') {
    alert('Select file to upload.');
  return 0;
  }
  if(document.uploadForm.up_img_w.value=='') {
    alert('Enter image width.');
  return 0;
  }
  if(document.uploadForm.up_img_h.value=='') {
    alert('Enter image height.');
  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('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;
  }
  $("mprofile").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 rand() {
 now=new Date();
 num=(now.getMilliseconds()*now.getMinutes())+now.getMonth()*now.getYear();
 num=num+1;
 return num;
}
