/* This notice must be untouched at all times.

id_ph.js    v. 1.01
The latest version is available at
http://www.icondate.com

Copyright (c) 2006 Icondate. All rights reserved.
Created 01.09.2006 by Icondate (Web: http://www.icondate.com )
Last modified: 07.09.2006

This program is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License
at http://www.gnu.org/copyleft/gpl.html for more details.
*/


	var ID_phMinWidth			=	64;					// photo min width
	var ID_phMinHeight			=	64;					// photo min height
	var ID_phCropWidth			=	ID_phMinWidth;		// photo min width
	var ID_phCropHeight			=	ID_phMinHeight;		// photo min height
	var ID_phLeftFrom			=	367;				// photo left from
	var ID_phTopFrom			=	350;				// photo left from
	var ID_phPicWidth			=	document.upload.imgResized.width;
	var ID_phPicHeight			=	document.upload.imgResized.height;

function id_phResetScript(){
	document.upload.imgResized.src='/img/trans.gif';
	document.upload.file.value='';
}

function id_phResetCrop(){
	var ID_phMinWidth			=	64;					// photo min width
	var ID_phMinHeight			=	64;					// photo min height
	var ID_phCropWidth			=	ID_phMinWidth;		// photo min width
	var ID_phCropHeight			=	ID_phMinHeight;		// photo min height
	var ID_phLeftFrom			=	367;				// photo left from
	var ID_phTopFrom			=	350;				// photo left from
	var ID_phPicWidth			=	document.upload.imgResized.width;
	var ID_phPicHeight			=	document.upload.imgResized.height;
	dd.elements.cropScreen.resizeTo(ID_phMinWidth, ID_phMinHeight);
	dd.elements.cropScreen.moveTo(ID_phLeftFrom, ID_phTopFrom);
	ID_phMaxOffRight=document.upload.imgResized.width-dd.elements.cropScreen.w;
	ID_phMaxOffBottom=document.upload.imgResized.height-dd.elements.cropScreen.h;
	if ((ID_phMaxOffRight<0) || (ID_phMaxOffBottom<0))
	{
		ID_phMaxOffRight=0;
		ID_phMaxOffBottom=0;
	}
	dd.elements.cropScreen.maxoffr = ID_phMaxOffRight;
	dd.elements.cropScreen.maxoffb = ID_phMaxOffBottom;
	//id_phSetVars();
	//dd.elements.cropScreen.visibility = "hidden";
	//dd.elements.cropScreen.visible = false;
	dd.elements.cropScreen.hide();
}

function id_phClickUpload ()
{
	document.upload.xl.value=dd.elements.cropScreen.x-ID_phLeftFrom;
    document.upload.xr.value=dd.elements.cropScreen.x+dd.elements.cropScreen.w-ID_phLeftFrom;
	document.upload.yt.value=dd.elements.cropScreen.y-ID_phTopFrom;
    document.upload.yb.value=dd.elements.cropScreen.y+dd.elements.cropScreen.h-ID_phTopFrom;
	
	if ((document.upload.imgResized.width>=ID_phMinWidth) &&
		(document.upload.imgResized.height>=ID_phMinHeight))
	{
		return true;
	}	
	alert(ID_phMesg1);
	return false;
}

function id_phShowPicIfPresent(){
	ims=document.upload.file.value;
	if (ims==""){
		id_phResetScript();
		id_phResetCrop();
    	alert(ID_phMesg1);
	    return false;
	} 
	
	tmpims=ims.toLowerCase();
	if((tmpims.indexOf(".gif")==-1)&&(tmpims.indexOf(".jpg")==-1)&&(tmpims.indexOf(".jpeg")==-1)){
   	    id_phResetScript();
		id_phResetCrop();
		alert(ID_phMesg2);
       	return false;
    }
	
	document.upload.imgResized.src=document.upload.file.value;

	//for (var tempi = 0; tempi < 10; tempi++) 
	
	//id_phResetCrop();
	alert(ID_phMesg4+document.upload.file.value);
	//alert(document.upload.imgResized.src);
	
	if ((document.upload.imgResized.width<=ID_phMinWidth)||
		(document.upload.imgResized.height<=ID_phMinHeight)) {
        id_phResetScript();
		id_phResetCrop();
       	alert (ID_phMesg3a+ID_phMinWidth+ID_phMesg3b);
		return false;
    }
	id_phResetCrop();
	dd.elements.cropScreen.show();
	return true;
}



