function startUploading()
{
	var frm = document.frm;
	var len = frm.elements.length;
	var counter= 0;
	for(i=0;i<len;i++)
	{
		var e = frm.elements[i];
		
		if (e.name == "mImage[]")
		{
			var filename = e.value;
			var len		 = e.value.length;
			var type	 = e.value.substring((len-4), len); 
			if (filename != "")
			{
				counter= counter + 1;
				/*var element = document.frm.elements[i-1];
				if (element.name == "mImageName[]")
				{
					if(element.value=="")
					{
						alert("Enter the photo title");
						element.focus();
						return false;
					}
				}*/

				if ((type != ".jpg") && (type != ".gif") && (type != ".JPG")&& (type != ".GIF")&&  (type != ".jpeg") && (type != ".JPEG"))
				{
					alert("This is not a valid image type");
					e.focus();
					return false;
				}
			}
		}
	}	
	if(counter==0)
	{
		alert("Choose a photo to upload");
		return false;
	}
	frm.submit();
}

function showsubCats()
{

	var frm = document.frmalbum;
	if ((frm.photoCount.value<12)&&(frm.category_id.value==8))
	{
		alert("Minimum of 12 photos are needed for this category");
	}
	
	var isintheCart = document.frmalbum.isintheCart.value;
	if(isintheCart!=0)
	{
		frm.action = getURL() + "/print/addtoprint/category/"+frm.category_id.value;
	}else
	{
		frm.action = getURL() + "/print/addtoprint/";
	}

	frm.submit();
}

function Chk()
{	
	
	var frm = document.frmalbum;
	var len = frm.elements.length;
	for(i=0;i<len;i++)
	{
		var e = frm.elements[i];
		
		if (e.value == "select")
		{
			alert("Select Size");
			return false;
		}
	}	

	document.frmalbum.submit();
}

function updateCart()
{	
	document.frmalbum.submit();
}


function delfoto(albumid,imageid)
{
	var frm = document.frmalbum;
	var cfm = confirm("Are you sure you want to delete this photo?");
	if(cfm)
	{
		window.location.href= "/print/viewalbum/"+albumid+"/"+imageid+"/delete";
	}
}

function ChangeCategory(categoryValue)
{
	url			=	getURL() + "/print/viewalbum/changeCategory/"+categoryValue;
	var frm = document.frmalbum;
	frm.action = url;
	frm.submit();
	
}
function DeleteAlbum(albumid)
{
	var frm = document.frm;
	var cfm = confirm("Are you sure you want to delete this album?");
	if(cfm)
	{
		frm.album_id.value = albumid;
		frm.action = getURL() +"/print";
		frm.submit();
	}
}

//------------------------------------------------------------------------------
function choosePrevCheckList(albumid,selName)
{
	var divIdName = selName;
	if (document.getElementById(divIdName).checked==true)
	{
		url			=	getURL() + "/print/viewalbum/"+albumid+"/SelectPrevList/";
		document.frmalbum.action = url;
		document.frmalbum.submit();
	}

}
//------------------------------------------------------------------------------

function selectFoto(albumid,imageid,selName)
{	
	var divIdName = selName;
	if (document.getElementById(divIdName).checked==true)
	{
		url			=	getURL() + "/print/viewalbum/"+albumid+"/"+imageid+"/select/";
		fields		=	new Array();

		process		=	'selectPhoto';
		output		=	'text';
		ajaxParams	=	fields.join('&');
		
		responseHandler	=	"processSelectedPhoto";

		ajaxPostRequest(url, ajaxParams);
		return false;
	}else
	{		
		var cfm = confirm("Are you sure you want to remove this photo from print wish list?");
		if(cfm)
		{
			url			=	getURL() + "/print/viewalbum/"+albumid+"/"+imageid+"/select/deleteFoto/";
			fields		=	new Array();

			process		=	'selectPhoto';
			output		=	'text';
			ajaxParams	=	fields.join('&');
			
			responseHandler	=	"processSelectedPhoto";

			ajaxPostRequest(url, ajaxParams);
			return false;
			
		}else
		{
			document.getElementById(divIdName).checked=true;
			return false;
		}

		
	}
	
}
//------------------------------------------------------------------------------
/*function removeFoto(albumid,imageid)
{
	var cfm = confirm("Are you sure you want to remove this photo?");
	if(cfm)
	{
		var url			=	getURL() + "/print/viewalbum/"+albumid+"/"+imageid+"/deleteFoto/";
		document.frmalbum.action = url;
		document.frmalbum.submit();
	}	

}*/
function removePhoto(albumid,imageid,catid)
{
	var cfm = confirm("Are you sure you want to remove this photo?");
	if(cfm)
	{
		var url			=	getURL() + "/print/addtoprint/"+albumid+"/"+imageid+"/deleteFoto/"+catid+"/";
		window.location.href = url;
	}

}
function processSelectedPhoto(responseText)
{ 
	
	document.getElementById("PrevList").innerHTML="";
	if(responseText=="")
	{
		document.getElementById("printtab").style.display="none";
	}else
	{
		document.getElementById("printtab").style.display="block";
	}
	document.getElementById("printtab").innerHTML = responseText;
}

var finish;
var size;
var qty;
var imgid1;
var categ;
function getPriceDetails(imgid,albumid)
{
	
	 strFinish	 =	"document.frmalbum.mPrintfinish" + imgid + ".value";
	 finish		 = eval(strFinish);
	 strSize	 =    "document.frmalbum.mPrintsubcategory" + imgid+".value";
	 size		 = eval(strSize);
	 strQty		 =  "document.frmalbum.mQty" + imgid+".value";	
	 qty		 = eval(strQty );
	 strCateg    =  "document.frmalbum.Categ" + imgid+".value";	
	 categ       = eval(strCateg );
	 strimgid    =  "document.frmalbum.imageID" + imgid+".value";	
	 imagID      = eval(strimgid );
	 imgid1		 = imgid; 
	if(size=="select")
	{
		alert("Select Size");
		url			      =	getURL() + "/print/addtoprint/"+albumid+"/dispSize/";
		responseHandler	  =	"processSizeDetails";

	}else
	{
		url			    =	getURL() + "/print/addtoprint/"+albumid+"/";
		responseHandler	=	"processPriceDetails";

	}

	 actionValue = document.frmalbum.actionValue.value;
	 dataFrom    = document.frmalbum.action.value;
	 if(dataFrom=="update")
	{
			 strPricingType =  "document.frmalbum.pricingType" + imgid+".value";	
			 pricingType    =   eval(strPricingType);
	}else
	{
			 pricingType = document.frmalbum.pricingType.value;
	}
	if(qty==0)
	{
		 alert("Quantity cant be empty");
		 document.frmalbum.focus();
		 return false;
	}
	
	fields		=	new Array();
	process		=	'selectPhoto';
	output		=	'text';
	fields.push("Categ="+categ);
	fields.push("mPrintfinish="+finish);
	fields.push("mPrintsubcategory="+size);
	fields.push("qty="+qty);
	fields.push("id="+imgid);
	fields.push("imageid="+imagID);
	fields.push("act="+"ajax");
	fields.push("actionValue="+actionValue);
	fields.push("dataFrom="+dataFrom);
	fields.push("pricingType="+pricingType);
	ajaxParams	=	fields.join('&');
	

	ajaxPostRequest(url, ajaxParams);
	return false;

}

function processSizeDetails(responseText)
{

  sizes  = responseText.split(':');   
  if(sizes.length > 1)
  {
	   strSizeOpt   =   "document.frmalbum.mPrintsubcategory" + imgid1;
	   strSize = eval(strSizeOpt);
	   strSize.options.length = 0;
	   strSize.options[0] = new Option("Select", "select"); 
	  
	   i=1;
	   for (var x =0; x < sizes.length; x=x+2) 
	   { 
		  strSize.options[i] = new Option(sizes[x+1],sizes[x]); 
		// strSize.options[i] = new Option(sizes[x],sizes[x+1]); 
		  
		  if(document.frmalbum.actionValue.value!="")
		  {
			  if(sizes[x] == size)
			  {
				  strSize.selectedIndex = i;
			  }
		   }
		  i++;
	   } 
	}

}
function processPriceDetails(responseText)
{
    message = responseText.split('@'); 
    if(document.frmalbum.alertValue.value=="yes")
	{
	  if(lTrim(rTrim(message[0])) != "none")
	  {
			alert(message[0]);	
	   }
	}
	subCat = message[1].split('|'); 
    sizes  = subCat[0].split(':'); 
  
  if(sizes.length > 2)
  {
	   strSizeOpt   =   "document.frmalbum.mPrintsubcategory" + imgid1;
	   strSize = eval(strSizeOpt);
	   strSize.options.length = 0;
	   strSize.options[0] = new Option("Select", "select"); 
	  
	   i=1;
	   for (var x =0; x < sizes.length; x=x+2) 
	   { 
		  strSize.options[i] = new Option(sizes[x+1],sizes[x]); 
		// strSize.options[i] = new Option(sizes[x],sizes[x+1]); 
		  
		  if(document.frmalbum.actionValue.value!="")
		  {
			  if(sizes[x] == size)
			  {
				  strSize.selectedIndex = i;
			  }
		   }
		  i++;
	   } 
	}
	if(document.frmalbum.action.value=="update")
	{
		var curItemPrice = document.getElementById(imgid1).innerHTML;
		var curSubTotal  = document.getElementById(categ).innerHTML;

		if(curItemPrice<subCat[1])
		{
			var diff   = subCat[1] - curItemPrice;
			var stotal = parseFloat(curSubTotal)+parseFloat(diff);

			document.getElementById(categ).innerHTML = "";
			document.getElementById(categ).innerHTML = formatMoney(stotal);
			
		}else if(curItemPrice>subCat[1])
		{
			var diff   =  curItemPrice - subCat[1];
			var stotal =  parseFloat(curSubTotal) - parseFloat(diff);

			document.getElementById(categ).innerHTML = "";
			document.getElementById(categ).innerHTML = formatMoney(stotal);
		}	
	}

	var curPrice = document.getElementById(imgid1).innerHTML;
	var total	 = document.getElementById("total").innerHTML;
	if(curPrice<subCat[1])
	{
		var diff   = subCat[1] - curPrice;
		var gtotal = parseFloat(total)+parseFloat(diff);

		document.getElementById("total").innerHTML = "";
		document.getElementById("total").innerHTML = formatMoney(gtotal);
		
	}else if(curPrice>subCat[1])
	{
		var diff   =  curPrice - subCat[1];
		var gtotal = parseFloat(total) - parseFloat(diff);

		document.getElementById("total").innerHTML = "";
		document.getElementById("total").innerHTML= formatMoney(gtotal);
	}
	document.getElementById(imgid1).innerHTML=subCat[1];	

}

function getURL()
{
	url		=	document.location.href;
	x		=	url.indexOf(".");
	x		=	url.indexOf("/",x);
	return url.substring(0,x);
}

function deletePhoto(imgid,albumid)
{

	 strFinish	=	"document.frmalbum.mPrintfinish" + imgid + ".value";
	 finish = eval(strFinish);
	 strSize   =    "document.frmalbum.mPrintsubcategory" + imgid+".value";
	 size  = eval(strSize);

	 strQty    =  "document.frmalbum.mQty" + imgid+".value";	
	 qty      = eval(strQty );
	 strCateg    =  "document.frmalbum.Categ" + imgid+".value";	
	 categ      = eval(strCateg );
	 strimgid    =  "document.frmalbum.imageID" + imgid+".value";	
	 imagID      = eval(strimgid );
	 imgid1 = imgid; 

	url			=	getURL() + "/print/addtoprint/"+albumid+"/";
	fields		=	new Array();
	process		=	'selectPhoto';
	output		=	'text';
	fields.push("Categ="+categ);
	fields.push("mPrintfinish="+finish);
	fields.push("mPrintsubcategory="+size);
	fields.push("qty="+qty);
	fields.push("id="+imgid);
	fields.push("imageid="+imagID);
	fields.push("act="+"updatedelete");

	ajaxParams	=	fields.join('&');

	
	responseHandler	=	"processDeleteFOTO";
	var cfm = confirm("Are you sure you want to remove this photo?");
	if(cfm)
	{
		ajaxPostRequest(url, ajaxParams);
		return false;
	}
	return false;

}
function processDeleteFOTO(responseText)
{
	window.location.href = getURL() + "/print/addtoprint/update";
}

function addElement()
{
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);

  newdiv.innerHTML = '<INPUT TYPE="FILE" NAME="mImage[]" class="upload_photo1"><INPUT TYPE="button" name="more" value="+" OnClick="javascript:this.style.display=\'none\';addElement();"  class="uploadmore" ><p>'; 
 // newdiv.innerHTML = 'Element Number '+num+' has been added! <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div "'+divIdName+'"</a>';
  ni.appendChild(newdiv);
}
function removeElement(divNum) {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}


