﻿var CurrentPhotoHeight = null
var CurrentPhotoWidth = null
var objtagbox, objtagborder, objtagpanel, obj = null
var clickX, clickY, tagObj, clickH = null
var clickW = null
var tagSize = 0
var newTagSize = 140
var shrinkrement = 70
var photoLocation = null
var guestbookPageNum = 1
var newClickTagSize = 140
var resizeObj = null
var resizeX = null
var resizeY = null
var firstClick = null
var newDraggingHeight=280
var newDraggingWidth=280
var storedWidth, storedHeight = null
var isSquared = null
var xShift = 0
var resizingNow = 0
var pixShift = -1
var dragSetupComplete = false
var LeftEdgeCrop = null
var RightEdgeCrop = null
var TopEdgeCrop = null
var BottomEdgeCrop = null
var PrintWidth = 0
var PrintHeight = 0
var widthMultiplier = 1
var heightMultiplier = 1
var CroppedOnce = 1
var CurrentPhotoIDV = 0
var addoneon = 0
var NewSizeInc = 0
function SetServerSideOverRide(PhotoID, setType){
CroppedOnce=1;
thediv=document.getElementById('cropWarning');
thediv.style.display = "none";
if(setType=='2'){
//alert('1' + setType);
//document.myForm.DropDownList1.selectedIndex=0;
//document.myForm.DropDownList2.selectedIndex=0;
}else{
//alert('2' + setType);
}
//document.getElementById('itemTotal').innerHTML = '$0.00';
}
function CropImage(PhotoID) {
var cropX = LeftEdgeCrop-1;
var cropY = TopEdgeCrop-1;
if((RightEdgeCrop+3)>CurrentPhotoWidth){
RightEdgeCrop=CurrentPhotoWidth;
}else{
RightEdgeCrop=RightEdgeCrop+3;
}
if((BottomEdgeCrop+3)>CurrentPhotoHeight){
BottomEdgeCrop=CurrentPhotoHeight;
}else{
BottomEdgeCrop=BottomEdgeCrop+3;
}
if((RightEdgeCrop)>=CurrentPhotoWidth-2)RightEdgeCrop=CurrentPhotoWidth;
if((BottomEdgeCrop)>=CurrentPhotoHeight-2)BottomEdgeCrop=CurrentPhotoHeight;
var cropWidth = (RightEdgeCrop)-(LeftEdgeCrop-1);
cropWidth = Math.min(cropWidth, CurrentPhotoWidth);
var cropHeight = (BottomEdgeCrop)-(TopEdgeCrop-1);
cropHeight = Math.min(cropHeight, CurrentPhotoHeight);
    var thediv=document.getElementById('confirmLabel');
	thediv.style.display = "";
	thediv=document.getElementById('confirmLoading');
	thediv.style.display = "";
	thediv=document.getElementById('confirmAdded');
	thediv.style.display = "none";
	thediv=document.getElementById('blackout');
	thediv.style.display = "";
	document.getElementById('confirmLabelTitle').innerHTML = 'Cropping Image'
	MyCode.AjaxPhotoService.CropImage(PhotoID, cropX, cropY, cropWidth, cropHeight, CropImageSuccess, null, PhotoID);
	return false;
	}
function CropImageSuccess(result, userContext, methodName)	{
	GetPhotos(userContext);
	return false;
}
function undoCrop(PhotoID) {
    var thediv=document.getElementById('confirmLabel');
	thediv.style.display = "";
	thediv=document.getElementById('confirmLoading');
	thediv.style.display = "";
	thediv=document.getElementById('confirmAdded');
	thediv.style.display = "none";
	thediv=document.getElementById('blackout');
	thediv.style.display = "";
	document.getElementById('confirmLabelTitle').innerHTML = 'Reverting Image'
    MyCode.AjaxPhotoService.GetPhotos(PhotoID, 1, GetPhotosSuccess, null, 1);
	return false;
	}
function GetPhotos(PhotoID) {
    MyCode.AjaxPhotoService.GetPhotos(PhotoID, 0, GetPhotosSuccess, null, 0);
	return false;
	}
function GetPhotosSuccess(result, userContext, methodName){
   cancelChoice();
    SetPhotoSize(result[2], result[3], PrintWidth, PrintHeight)
    var rcp = $find('ResizableControlBehavior1');
    rcp.set_MaximumWidth(result[2]-3);
    rcp.set_MaximumHeight(result[3]-3);
    //rcp.set_Size( { width: CurrentPhotoWidth, height: CurrentPhotoHeight } );
    setupDragging(CurrentPhotoHeight, CurrentPhotoWidth, CurrentPhotoHeight-3, CurrentPhotoWidth-3);
    clearTagBox();
    thediv=document.getElementById('backImage');
    thediv.innerHTML=result[0];
    thediv=document.getElementById('photoOverlay');
    thediv.style.backgroundImage="url(" + result[1] + ")";
    if(userContext==0){
    //CroppedOnce=1;
    thediv=document.getElementById('rotateControls');
	thediv.style.display = "none";
	thediv=document.getElementById('undoCrop');
	thediv.style.display = "";
	
	
	var csPrintWidth = document.myForm.DropDownList1.options[document.myForm.DropDownList1.selectedIndex].value;
	var csPrintHeight = document.myForm.DropDownList2.options[document.myForm.DropDownList2.selectedIndex].value;

	var canvasType = getCheckedValue(document.forms['myForm'].elements['Type']);
	
	if (canvasType==1){
	
	document.getElementById("galleryOverlay").style.display="none";
	
	}else{
	
	document.getElementById("galleryOverlay").style.display="";
	//var reduceIt = 0;
	
	if (canvasType==2)oPrintWidth=parseFloat(csPrintWidth)+1.2;
	if (canvasType==2)oPrintHeight=parseFloat(csPrintHeight)+1.2;
	//if (canvasType==2)reduceIt=1.2;
	
	if (canvasType==3)oPrintWidth=parseInt(csPrintWidth)+3;
	if (canvasType==3)oPrintHeight=parseInt(csPrintHeight)+3;
	//if (canvasType==3)reduceIt=3;
	
	var percentWidthof=csPrintWidth/oPrintWidth;
	var percentHeightof=csPrintHeight/oPrintHeight;
	
	//alert(csPrintHeight + ' - ' + oPrintHeight);
	
newWidth=Math.floor(parseInt(result[2]));
newHeight=Math.floor(parseInt(result[3]));

var leftOverlayShift=(675-newWidth)/2;

var galleryDistanceFromLeft=((newWidth-(newWidth*percentWidthof))/2);
var galleryDistanceFromTop=((newHeight-(newHeight*percentHeightof))/2);

document.getElementById("galleryBox").style.width=newWidth+"px";
document.getElementById("galleryBox").style.height=newHeight+"px";
document.getElementById("galleryBox").style.top="49px";
document.getElementById("galleryBox").style.left=leftOverlayShift+"px";

document.getElementById("galleryOverlay").style.width=(percentWidthof*100)+"%";
document.getElementById("galleryOverlay").style.height=(percentHeightof*100)+"%";
document.getElementById("galleryOverlay").style.top=galleryDistanceFromTop+"px";
document.getElementById("galleryOverlay").style.left=galleryDistanceFromLeft+"px";

}
	
	
	
	
	
	
	
	
	
	}else{
	document.getElementById("galleryOverlay").style.display="none";
	//CroppedOnce=1;
	thediv=document.getElementById('rotateControls');
	thediv.style.display = "block";
	thediv=document.getElementById('undoCrop');
	thediv.style.display = "none";
	}
	if(userContext==1){

    obj=document.getElementById("backImage")
    getDetails(obj);
    }
    return false;
}
function RotateImage(PhotoID, RotationDirection){
    var thediv=document.getElementById('confirmLabel');
	thediv.style.display = "";
	thediv=document.getElementById('confirmLoading');
	thediv.style.display = "";
	thediv=document.getElementById('confirmAdded');
	thediv.style.display = "none";
	thediv=document.getElementById('blackout');
	thediv.style.display = "";
	document.getElementById('confirmLabelTitle').innerHTML = 'Rotating Image'
	//alert(PhotoID);
MyCode.AjaxPhotoService.RotateImage(PhotoID, RotationDirection, OnRotateImageSuccess, null, PhotoID);
return false;
}
function OnRotateImageSuccess(result, userContext, methodName) 
{
MyCode.AjaxPhotoService.GetPhotos(userContext, 1, GetPhotosSuccess, null, 1);
}
function AddNewSizeSuccess(result, userContext, methodName)	{
	var thediv=document.getElementById('confirmLabel');
	thediv.style.display = "";
	thediv=document.getElementById('confirmLoading');
	thediv.style.display = "none";
	thediv=document.getElementById('confirmAdded');
	thediv.style.display = "";
	document.getElementById('progressTitle').innerHTML = '<h1>Photo ' + userContext.b + ' of ' + (userContext.c+1) + '</h1>';
	    document.getElementById('confirmLabelTitle').innerHTML = 'New Size Added!'
	    document.getElementById('confirmAddedInfoTop').innerHTML = 'Another size has been added to your order. Once you save the changes on this page, you will be asked to customize the settings.'
	    thediv=document.getElementById('blackout');
	    thediv.style.display = "";
		return false;
	}
function AddNewSize(PhotoID, CurrentPhoto, PhotoCount) {
    var jObj = new Object();
    jObj.a = PhotoID;
    jObj.b = CurrentPhoto;
    jObj.c = PhotoCount+NewSizeInc;
    NewSizeInc ++;
	MyCode.AjaxPhotoService.AddNewSize(PhotoID, AddNewSizeSuccess, null, jObj);
	return false;
	}
	function updateTotal() {
	
	CheckSizes();
	
	
	var csPrintWidth = document.myForm.DropDownList1.options[document.myForm.DropDownList1.selectedIndex].value;
	var csPrintHeight = document.myForm.DropDownList2.options[document.myForm.DropDownList2.selectedIndex].value;
	
	if(csPrintWidth>0 && csPrintHeight>0){
	
	var canvasType = getCheckedValue(document.forms['myForm'].elements['Type']);
	
	var canvasCoating = getCheckedValue(document.forms['myForm'].elements['Eco']);
	
	var canQuantity = document.myForm.QuantityTextBox.value;
	
	if(canvasType>1){
	
	if (canvasType==2)PrintWidth=parseFloat(csPrintWidth)+1.2;
	if (canvasType==2)PrintHeight=parseFloat(csPrintHeight)+1.2;
	
	if (canvasType==3)PrintWidth=parseInt(csPrintWidth)+3;
	if (canvasType==3)PrintHeight=parseInt(csPrintHeight)+3;
	
	canvasCoating=1;
	
	setCheckedValue(document.forms['myForm'].elements['Eco'], 1);
	document.forms['myForm'].elements['Eco'].disabled=true;
	document.getElementById('noEco').style.color='grey';
	document.getElementById('yesEcoLabel').innerHTML="(included free)";
	}else{
	
	if (canvasType==1)PrintWidth=parseFloat(csPrintWidth);
	if (canvasType==1)PrintHeight=parseFloat(csPrintHeight);
	
	document.forms['myForm'].elements['Eco'].disabled=false;
	document.getElementById('noEco').style.color='black';
	document.getElementById('yesEcoLabel').innerHTML="(+$0.03/sq inch)";
	}
	
	if(!IsNumeric(canQuantity)){
	document.myForm.QuantityTextBox.value='1';
	canQuantity=1;
	}

    if(csPrintWidth>0 && csPrintHeight>0){
	MyCode.AjaxPhotoService.UpdateTotal(canQuantity, csPrintWidth, csPrintHeight, canvasCoating, canvasType, UpdateTotalSuccess, null, canQuantity);
	}
	}
	return false;
	}
function UpdateTotalSuccess(result, userContext, methodName){
if(result!='$0.00'){
document.getElementById('itemTotal').innerHTML = result;
thediv=document.getElementById('unavailableWarning');
thediv.style.display = "none";
//************had problem with this line on first run...check it out
//if(obj)getDetails(obj);
}else{
document.getElementById('itemTotal').innerHTML = result;
thediv=document.getElementById('cropWarning');
thediv.style.display = "none";
if(userContext>0){
thediv=document.getElementById('unavailableWarning');
thediv.style.display = "";
}
CroppedOnce=1;
clearTagBox();
}
return false;
	}
	
	function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function RemoveImage(PhotoID, CurrentPhoto, PhotoCount, SessionID) {
    var jObj = new Object();
    jObj.a = PhotoID;
    jObj.b = CurrentPhoto;
    jObj.c = PhotoCount;
    //alert(PhotoID + " - " + CurrentPhoto + " - " +  PhotoCount);
	MyCode.AjaxPhotoService.RemoveImage(PhotoID, SessionID, RemoveImageSuccess, null, jObj);
	return false;
	}
function RemoveImageSuccess(result, userContext, methodName)	{
	if(userContext.c==1){
	window.location="order.aspx?step=1";
	}else{
	var curImg = userContext.b;
	window.location="order.aspx?step=2&image="+curImg;
	}
	}
function cancelChoice()	{
	var thediv=document.getElementById('confirmLabel');
	thediv.style.display = "none";
	thediv=document.getElementById('confirmLoading');
	thediv.style.display = "none";
	thediv=document.getElementById('confirmAdded');
	thediv.style.display = "none";
	thediv=document.getElementById('blackout');
	thediv.style.display = "none";
	return false;
	}
function CheckSizes(){

	var csPrintWidth = parseInt(document.myForm.DropDownList1.options[document.myForm.DropDownList1.selectedIndex].value);

	var csPrintHeight = parseInt(document.myForm.DropDownList2.options[document.myForm.DropDownList2.selectedIndex].value);
	
	var printRatio=null;
	var photoRatio=null;
	
	if(csPrintWidth>0 && csPrintHeight>0){
	
	var canvasType = getCheckedValue(document.forms['myForm'].elements['Type']);
	
	if (canvasType==2)csPrintWidth=parseFloat(csPrintWidth)+1.2;
	if (canvasType==2)csPrintHeight=parseFloat(csPrintHeight)+1.2;
	
	if (canvasType==3)csPrintWidth=parseInt(csPrintWidth)+3;
	if (canvasType==3)csPrintHeight=parseInt(csPrintHeight)+3;
	
	
	}

printRatio = Math.round((csPrintWidth/csPrintHeight)*100)/100;
photoRatio = Math.round((CurrentPhotoWidth/CurrentPhotoHeight)*100)/100;

if(printRatio!=0){
thediv=document.getElementById('errormessages');
thediv.style.display = "none";
}
if((printRatio!=photoRatio && printRatio!=(photoRatio+.02) && printRatio!=(photoRatio-.02) && printRatio!=(photoRatio+.01) && printRatio!=(photoRatio-.01)) && printRatio!='Infinity' && printRatio!=0){
if(CurrentPhotoIDV>0){
PrintWidth=csPrintWidth;
PrintHeight=csPrintHeight;
undoCrop(CurrentPhotoIDV);
//alert(printRatio + " - " + photoRatio);
}else{
SetPhotoSize(CurrentPhotoWidth, CurrentPhotoHeight, csPrintWidth, csPrintHeight);
}
}else{
SetPhotoSize(CurrentPhotoWidth, CurrentPhotoHeight, csPrintWidth, csPrintHeight);
}
//updateTotal();
	return false;
	}
function SetPhotoSize(width, height, pWidth, pHeight, photoIDV){
if(photoIDV)CurrentPhotoIDV=photoIDV;
CurrentPhotoWidth=width;
CurrentPhotoHeight=height;
PrintWidth=pWidth;
PrintHeight=pHeight;
var printRatio = Math.round((PrintWidth/PrintHeight)*100)/100;
var photoRatio = Math.round((CurrentPhotoWidth/CurrentPhotoHeight)*100)/100;
//alert(CurrentPhotoWidth + ' - ' + CurrentPhotoHeight + ' - ' + PrintWidth + ' - ' + PrintHeight + ' - ' + printRatio + ' - ' + photoRatio);
if(PrintHeight>0 && PrintWidth>0 && (printRatio!=photoRatio && printRatio!=(photoRatio+.02) && printRatio!=(photoRatio-.02) && printRatio!=(photoRatio+.01) && printRatio!=(photoRatio-.01)) && printRatio!='Infinity' && printRatio!=0)
{
//alert(printRatio + ' + ' + photoRatio);
thediv=document.getElementById('cropWarning');
thediv.style.display = "";
CroppedOnce=0;
}else{
clearTagBox();
thediv=document.getElementById('cropWarning');
thediv.style.display = "none";
CroppedOnce=1;
}
if(PrintHeight>PrintWidth){
heightMultiplier=1;
widthMultiplier=CurrentPhotoHeight/PrintHeight*PrintWidth
widthMultiplier=widthMultiplier/CurrentPhotoHeight;
}
if(PrintHeight<PrintWidth){
widthMultiplier=1;
heightMultiplier=CurrentPhotoWidth/PrintWidth*PrintHeight
heightMultiplier=heightMultiplier/CurrentPhotoWidth;
}
if(PrintHeight==PrintWidth && CurrentPhotoHeight<CurrentPhotoWidth){
//alert("changewidthmult");
heightMultiplier=1;
widthMultiplier=CurrentPhotoHeight/PrintHeight*PrintWidth
widthMultiplier=widthMultiplier/CurrentPhotoHeight;

}
if(PrintHeight==PrintWidth && CurrentPhotoHeight>CurrentPhotoWidth){
//alert("changeheightmult");
widthMultiplier=1;
heightMultiplier=CurrentPhotoWidth/PrintWidth*PrintHeight
heightMultiplier=heightMultiplier/CurrentPhotoWidth;
}
}

	
	function isEven(num) {
  return !(num % 2);
}
function getDetails(obj, e){
if(CroppedOnce==1)return false;
firstClick=true;
xShift = Math.max((675 - CurrentPhotoWidth), 0);
xShift = Math.floor(xShift/2);
//if(isEven(CurrentPhotoWidth))xShift--;
//alert(xShift);
//?if(CurrentPhotoWidth<280)clickW=CurrentPhotoWidth;
//?if(CurrentPhotoHeight<280)clickH=CurrentPhotoHeight;
setupDragging(CurrentPhotoHeight, CurrentPhotoWidth, clickH, clickW);
var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if(e){
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
    }
tagObj=obj;
var offArray = ObjectPosition(obj)
var offX = offArray[0]
var offY = offArray[1]
clickX = posx-offX-1; 
clickY = posy-offY-1; 
if(shrinkrement!=70){newClickTagSize=newTagSize}else{newClickTagSize=140};
if ((ie||ns6) && document.getElementById("tagborder")){
objtagborder=document.getElementById("tagborder")
storedWidth=objtagborder.style.width;
storedHeight=objtagborder.style.height;
}
var rcp = $find('ResizableControlBehavior1');
var size = rcp.get_Size();
rcp.set_Size( { width: CurrentPhotoWidth, height: CurrentPhotoHeight } );
//alert(CurrentPhotoWidth);
//showtagbox();
}
function ObjectPosition(obj) {
    var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
      return [curleft,curtop];
}
function getSquareCo() {
/*document.getElementById("status").innerHTML+= 'getSquareCo ';*/
if ((ie||ns6) && document.getElementById("tagpanel")){
objtagpanel=document.getElementById("tagpanel");
if ((ie||ns6) && document.getElementById("tagborder")){
objtagborder=document.getElementById("tagborder")
clickX=parseInt(objtagpanel.style.left);
clickW=parseInt(objtagborder.style.width);
clickX=parseInt(clickX+140-xShift);
clickY=parseInt(objtagpanel.style.top);
clickH=parseInt(objtagborder.style.height);
clickY=parseInt(clickY+140-50);
setupDragging(CurrentPhotoHeight, CurrentPhotoWidth, clickH-3, clickW-3);
}
}
isSquared=false;
}
function skipFirstRun() {
isSquared=true;
resizingNow=0;
(!clickW) ? setupDragging(CurrentPhotoHeight, CurrentPhotoWidth) : setupDragging(CurrentPhotoHeight, CurrentPhotoWidth, clickH, clickW);
}

function showtagbox(){
if(firstClick){
var rcp = $find('ResizableControlBehavior1');
var size = rcp.get_Size();

if(size.width>CurrentPhotoWidth-3){
rcp.set_Size( { width: CurrentPhotoWidth-3, height: size.height } );
size = rcp.get_Size();
}
if(size.height>CurrentPhotoHeight-3){
rcp.set_Size( { width: size.width, height: CurrentPhotoHeight-3 } );
size = rcp.get_Size();
}
if(isSquared)getSquareCo();
var obj=tagObj;
var tbclickX=Math.floor(clickX);
var tbclickY=Math.floor(clickY);
if ((ie||ns6) && document.getElementById("tagborder")){
objtagborder=document.getElementById("tagborder")
newWidth=parseInt(objtagborder.style.width);
newTopWidth=newWidth;
if((!isEven(newWidth)))++newWidth;
newWidth=Math.floor(newWidth/2)
newTopWidth=Math.floor(newTopWidth/2)
newHeight=parseInt(objtagborder.style.height);
newTopHeight=newHeight;
if((!isEven(newHeight)))++newHeight;
newHeight=Math.floor(newHeight/2)
newTopHeight=Math.floor(newTopHeight/2)

if (tbclickX<newTopWidth) {
tbclickX=newTopWidth;
}
if (tbclickY<newTopHeight) {
tbclickY=newTopHeight;
}
if (tbclickX>(CurrentPhotoWidth-newWidth-3)){
tbclickX=CurrentPhotoWidth-newWidth-3;
}
if (tbclickY>(CurrentPhotoHeight-newHeight-3)){
tbclickY=CurrentPhotoHeight-newHeight-3;
}

}
(newWidth<35 || newHeight<39) ? document.getElementById("handleControls").style.visibility="hidden" : document.getElementById("handleControls").style.visibility="visible";
(newWidth<35 || newHeight<39) ? document.getElementById("handle").style.height="9px" : document.getElementById("handle").style.height="";

/*!document.getElementById("status").innerHTML= '<br> tbclickX:' + tbclickX +
'<br> tbclickY:' + tbclickY + 
'<br> newWidth:' + newWidth + 
'<br><br> newTopWidth:' + newTopWidth +
'<br> newHeight:' + newHeight + 
'<br> newTopHeight:' + newTopHeight;*/


resizingNow = 1;

if ((ie||ns6) && document.getElementById("tagborder")){
objtagborder=document.getElementById("tagborder")
newWidth=Math.floor(parseInt(objtagborder.style.width));
newDraggingWidth=newWidth;
newWidth=Math.floor(newWidth/2)
newHeight=Math.floor(parseInt(objtagborder.style.height));
newDraggingHeight=newHeight;
newHeight=Math.floor(newHeight/2)
newWidth=140-newWidth;
newHeight=140-newHeight;
objtagborder.style.left=newWidth+"px"
objtagborder.style.top=newHeight+"px"
objtagborder.style.visibility="visible"
document.getElementById("photoBlackout").style.visibility="visible";
document.getElementById("tagbox").style.visibility="visible";
document.getElementById("handle").style.display="";
}
/*!document.getElementById("status2").innerHTML= '<br> tbclickX:' + tbclickX +
'<br> tbclickY:' + tbclickY + 
'<br> newWidth:' + newWidth + 
'<br><br> newTopWidth:' + newTopWidth +
'<br> newHeight:' + newHeight + 
'<br> newTopHeight:' + newTopHeight;*/
if ((ie||ns6) && document.getElementById("tagpanel")){
objtagpanel=document.getElementById("tagpanel");
//objtagpanel.style.left=objtagpanel.style.top=-500;
objtagpanel.x=calcShift(obj, "left");
objtagpanel.y=calcShift(obj, "top");
newWidth=tbclickX-140+xShift;
newHeight=50+tbclickY-140;
objtagpanel.style.left=newWidth+"px";
objtagpanel.style.top=newHeight+"px";
objtagpanel.style.visibility="visible";
document.getElementById("photoBlackout").style.visibility="visible";
document.getElementById("tagbox").style.visibility="visible";
document.getElementById("handle").style.display="";
}


/*!document.getElementById("status2").innerHTML+= '<br> tbclickX:' + tbclickX +
'<br> tbclickY:' + tbclickY + 
'<br> newWidth:' + newWidth + 
'<br><br> newTopWidth:' + newTopWidth +
'<br> newHeight:' + newHeight + 
'<br> newTopHeight:' + newTopHeight;*/


clickX=tbclickX;
clickY=tbclickY;
objtagpanel=document.getElementById("tagpanel")
resizeY=objtagpanel.style.top;
resizeX=objtagpanel.style.left;
getSquareCo();
var TheFinalXShift = -(clickX - newTopWidth+1);
var TheFinalYShift = -(clickY - newTopHeight+1);


/*!document.getElementById("status").innerHTML+= '<br> clickX:' + clickX +
'<br> clickY:' + clickY + 
'<br> resizeX:' + resizeX + 
'<br> resizeY:' + resizeY + 
'<br> xShift:' + xShift + 
'<br> calcShift(obj, "left"):' + objtagpanel.x + 
'<br> calcShift(obj, "top"):' + objtagpanel.y+
'<br> TheFinalXShift:' + TheFinalXShift+
'<br> TheFinalYShift:' + TheFinalYShift;*/


LeftEdgeCrop=(-1*TheFinalXShift);
RightEdgeCrop=(-1*TheFinalXShift)+(newTopWidth*2);
TopEdgeCrop=(-1*TheFinalYShift);
BottomEdgeCrop=(-1*TheFinalYShift)+(newTopHeight*2);

/*!document.getElementById("status").innerHTML= '<br>LeftEdgeCrop:' + LeftEdgeCrop +
'<br>' + 'RightEdgeCrop:' + RightEdgeCrop +
'<br>' + 'TopEdgeCrop:' + TopEdgeCrop +
'<br>' + 'BottomEdgeCrop:' + BottomEdgeCrop +
'<br>';*/
var browser=navigator.appName;
if(browser!="Microsoft Internet Explorer")TheFinalXShift=parseInt(TheFinalXShift)+1;

document.getElementById("photoOverlay").style.backgroundPosition=TheFinalXShift + "px " + TheFinalYShift + "px";


	
	var canvasType = getCheckedValue(document.forms['myForm'].elements['Type']);
	
	var csPrintWidth=PrintWidth;
	var csPrintHeight=PrintHeight;
	
	if (canvasType==1){
	
	document.getElementById("galleryBorder").style.display="none";
	
	}else{
	
	document.getElementById("galleryBorder").style.display="";
	//var reduceIt = 0;
	
	if (canvasType==2)csPrintWidth=parseFloat(csPrintWidth)-1.2;
	if (canvasType==2)csPrintHeight=parseFloat(csPrintHeight)-1.2;
	//if (canvasType==2)reduceIt=1.2;
	
	if (canvasType==3)csPrintWidth=parseInt(csPrintWidth)-3;
	if (canvasType==3)csPrintHeight=parseInt(csPrintHeight)-3;
	//if (canvasType==3)reduceIt=3;
	
	var percentWidthof=csPrintWidth/PrintWidth;
	var percentHeightof=csPrintHeight/PrintHeight;
	
	
/*!document.getElementById("status").innerHTML= '<br>PrintWidth:' + PrintWidth +
'<br>' + 'PrintHeight:' + PrintHeight +
'<br>' + 'csPrintWidth:' + csPrintWidth +
'<br>' + 'csPrintHeight:' + csPrintHeight +
'<br>' + 'percentWidthof:' + percentWidthof +
'<br>' + 'percentHeightof:' + percentHeightof +
'<br>' + 'objtagborder.style.width:' + objtagborder.style.width +
'<br>' + 'objtagborder.style.height:' + objtagborder.style.height +
'<br>';*/
	
newWidth=Math.floor(parseInt(objtagborder.style.width));
newHeight=Math.floor(parseInt(objtagborder.style.height));

var galleryDistanceFromLeft=((newWidth-(newWidth*percentWidthof))/2);
var galleryDistanceFromTop=((newHeight-(newHeight*percentHeightof))/2);

document.getElementById("galleryBorder").style.width=(percentWidthof*100)+"%";
document.getElementById("galleryBorder").style.height=(percentHeightof*100)+"%";
document.getElementById("galleryBorder").style.top=galleryDistanceFromTop+"px";
document.getElementById("galleryBorder").style.left=galleryDistanceFromLeft+"px";

}

}
}
function squareUp() {
resizingNow = 0;
pixShift=-1;
if(firstClick){
resizeX=parseInt(objtagborder.style.width);
resizeY=parseInt(objtagborder.style.height);

if(PrintHeight>PrintWidth){
var rcp = $find('ResizableControlBehavior1');
var size = rcp.get_Size();
var compareToWidth=Math.floor(resizeY*widthMultiplier);
var minusMe = 2;
if(isEven(CurrentPhotoWidth)){minusMe=1;
//the big issue i was having with line 122 error.
compareToWidth=compareToWidth-1;
}
var compareToHeight=Math.floor((CurrentPhotoWidth-minusMe)/widthMultiplier);
if(compareToWidth!=resizeX){
if(compareToWidth<=CurrentPhotoWidth-minusMe){
if(compareToWidth<=51){
compareToWidth=51;
resizeY=51/widthMultiplier;
}
rcp.set_Size( { width: compareToWidth, height: resizeY } );
size = rcp.get_Size();
}else{

rcp.set_Size( { width: CurrentPhotoWidth, height: compareToHeight } );
size = rcp.get_Size();
}
/*!document.getElementById("status3").innerHTML= '<br> compareToWidth:' + compareToWidth +
'<br> CurrentPhotoWidth:' + CurrentPhotoWidth + 
'<br> compareToHeight:' + compareToHeight + 
'<br> resizeX:' + resizeX + 
'<br> minusMe:' + minusMe + 
'<br><br> widthMultiplier:' + widthMultiplier +
'<br><br> objtagborder.style.width:' + objtagborder.style.width;*/
newDraggingHeight=resizeY;
newDraggingWidth=resizeX;
}
}



if(PrintHeight==PrintWidth && PrintHeight>=8){
var rcp = $find('ResizableControlBehavior1');
var size = rcp.get_Size();
var compareToWidth=Math.floor(resizeY*widthMultiplier);
var compareToHeight=Math.floor((CurrentPhotoWidth-3)/widthMultiplier);
if(compareToWidth!=resizeX){
if(compareToWidth<=CurrentPhotoWidth-3){
if(compareToWidth<=51){
compareToWidth=51;
resizeY=51/widthMultiplier;
}
rcp.set_Size( { width: compareToWidth, height: resizeY } );
size = rcp.get_Size();
}else{
rcp.set_Size( { width: CurrentPhotoWidth-3, height: compareToHeight } );
size = rcp.get_Size();
}
newDraggingHeight=resizeY;
newDraggingWidth=resizeX;
}
}

if(PrintWidth>PrintHeight){
var rcp = $find('ResizableControlBehavior1');
var size = rcp.get_Size();
var compareToHeight=Math.floor(resizeX*heightMultiplier);
var compareToWidth=Math.floor((CurrentPhotoHeight-3)/heightMultiplier);
if(compareToHeight!=resizeY){
if(compareToHeight<=CurrentPhotoHeight-3){
if(compareToHeight<=64){
compareToHeight=64;
resizeX=64/heightMultiplier;
}
rcp.set_Size( { width: resizeX, height: compareToHeight } );
size = rcp.get_Size();
}else{
rcp.set_Size( { width: compareToWidth, height: CurrentPhotoHeight-3 } );
size = rcp.get_Size();
}
/*!document.getElementById("status2").innerHTML= '<br> compareToHeight:' + compareToHeight +
'<br> CurrentPhotoHeight:' + CurrentPhotoHeight + 
'<br> compareToWidth:' + compareToWidth + 
'<br> resizeY:' + resizeY + 
'<br><br> heightMultiplier:' + heightMultiplier;*/
newDraggingHeight=resizeY;
newDraggingWidth=resizeX;
}
}

//if(document.getElementById('ratio').checked && resizeX!=resizeY){
if(1==2 && resizeX!=resizeY){
var squareSize = Math.min(resizeX, resizeY);
var rcp = $find('ResizableControlBehavior1');
var size = rcp.get_Size();
rcp.set_Size( { width: squareSize, height: squareSize } );
newDraggingHeight=squareSize;
newDraggingWidth=squareSize;
}
//document.getElementById("photoBlackout").style.visibility="visible";
//document.getElementById("photoOverlay").style.visibility="visible";
//alert(CurrentPhotoHeight + ' - ' + CurrentPhotoWidth + ' - ' + newDraggingHeight + ' - ' + newDraggingWidth)
setupDragging(CurrentPhotoHeight, CurrentPhotoWidth, newDraggingHeight, newDraggingWidth);
}
}
var ie=document.all
var ns6=document.getElementById&&!document.all
function calcShift(boxname, shiftdir){
//alert(boxname + " - " + shiftdir);
var addtoleft=0;
var addtotop=0;
if(!ie)addtoleft=3;
if(!ie)addtotop=1;
var totalshift=(shiftdir=="left")? boxname.offsetLeft+addtoleft : boxname.offsetTop+addtotop;
var boxParent=boxname.offsetParent;
while (boxParent!=null){
totalshift=(shiftdir=="left")? totalshift+boxParent.offsetLeft : totalshift+boxParent.offsetTop;
boxParent=boxParent.offsetParent;
}
return totalshift;
}
function clearTagBox() {
if(objtagpanel!=null)hidetagbox();
}
function hidetagbox(e){
objtagpanel=document.getElementById("tagpanel");
objtagpanel.style.visibility="hidden";
objtagpanel.style.left="-2000px";
objtagborder=document.getElementById("tagborder");
objtagborder.style.visibility="hidden";
objtagborder.style.left="-2000px";
document.getElementById("photoBlackout").style.visibility="hidden";
document.getElementById("tagbox").style.visibility="hidden";
document.getElementById("handle").style.display="none";
document.getElementById("tagbox").className="tagbox";
}
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
