// Get base url
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);


//function used to make the color change of button on mouse over.
function roll(img_name1, img_src1)
{
	document[img_name1].src = img_src1;
}

//function used to get the liat of users for the given search string Used at Admin End
function ajax_getUserList(formname,ctrltype)
{
	with(document.forms[formname])
	{
		var strSearchOption=trimAll(drpdwn_SearchOption.value);
		if(strSearchOption=="email")
		{
			document.getElementById("td_userdrpdwn").style.display="none";
			document.getElementById("td_emaildrpdwn").style.display="";
		}
		else
		{
			document.getElementById("td_userdrpdwn").style.display="";
			document.getElementById("td_emaildrpdwn").style.display="none";
		}
	}
}

//function used to get the liat of users for the given search string Used at Admin End
function ajax_searchUser(formname)
{
	with(document.forms[formname])
	{
		var type=trimAll(drpdwn_SearchOption.value);
		//show loading image

		if(type=='lname' || type=='fname')
		{
			if(type=='lname' && trimAll(txt_searchoption.value)=="")
			{
				alert("Please enter last name to search");
				txt_searchoption.focus();
				return false;
			}
			else if(type=='fname' && trimAll(txt_searchoption.value)=="")
			{
				alert("Please enter first name to search");
				txt_searchoption.focus();
				return false;
			}
			else
			{
				document.getElementById("tr_glryLoading").style.display ="";

				if(type=='fname')
				url="getSmgusersearchresult.php?fname="+txt_searchoption.value;
				else if(type=='lname')
				url="getSmgusersearchresult.php?lname="+txt_searchoption.value;

				// Does URL begin with http?
				if (url.substring(0, 4) != 'http')
				{
					url = base_url + url;
				}

				// Create new JS element
				var jsel = document.createElement('SCRIPT');
				jsel.type = 'text/javascript';
				jsel.src = url;

				// Append JS element (therefore executing the 'AJAX' call)
				document.body.appendChild(jsel);
			}
		}
		else
		{
			if(txt_searchoption.value=="")
			{
				alert("Please enter email to search");
				txt_searchoption.focus();
				return false;
			}
			else
			{
				var SearchEmail=txt_searchoption.value;
				url="getSmgusersearchresult.php?email="+SearchEmail;

				// Does URL begin with http?
				if (url.substring(0, 4) != 'http') {
					url = base_url + url;
				}

				// Create new JS element
				var jsel = document.createElement('SCRIPT');
				jsel.type = 'text/javascript';
				jsel.src = url;

				//Append JS element (therefore executing the 'AJAX' call)
				document.body.appendChild(jsel);
			}
		}
	}
}

function funClickOnImage(formname,type)
{
	with(document.forms[formname])
	{
		if(type=="dvd")
		{
			if(document.getElementById("check_photography").checked==true)
			document.getElementById("imgPhotoDVD").onclick();

			if(document.getElementById("check_videomovie").checked==true)
			document.getElementById("imgVideoDVD").onclick();
		}
		else if(type=="harddrive")
		{
			if(document.getElementById("check_photography").checked==true)
			document.getElementById("imgPhotoHD").onclick();

			if(document.getElementById("check_videomovie").checked==true)
			document.getElementById("imgVideoHD").onclick();
		}
	}
}

///function used to submit the form if atleast one check box has been checked 
///when clicking on the go button Used at Admin End
function fun_uploadPhotos(formname)
{
	with(document.forms[formname])
	{
		if(trimAll(drpdwn_users.value)=="" && trimAll(drpdwn_emails.value)=="")
		{
			alert("Please select user");
			drpdwn_users.focus();
			return false;
		}
		else
		{
			if((drpdwn_SearchOption=="fname" || drpdwn_SearchOption=="lname") && trimAll(drpdwn_users.value)=="")
			{
				alert("Please select user");
				drpdwn_users.focus();
				return false;
			}
			else if(drpdwn_SearchOption=="email" && trimAll(drpdwn_emails.value)=="")
			{
				alert("Please select user");
				drpdwn_emails.focus();
				return false;
			}
			else if(trimAll(drpdwn_ImportFrmSrver.value)=="")
			{
				alert("Please select server type");
				drpdwn_ImportFrmSrver.focus();
				return false;
			}
			else if(trimAll(drpdwn_ImportFileFrom.value)=="")//check Import file has been selected.
			{
				alert("Please select the folder name to import");
				drpdwn_ImportFileFrom.focus();
				return false;
			}
			hdn_mode.value="upload";
			var UserId=drpdwn_users.value;

			//Code used to get the orderId takes from the selected folder.
			var strDirName="";
			var ObjImprtDirName=document.getElementById("drpdwn_ImportFileFrom");

			for(optn=0;optn<ObjImprtDirName.options.length;optn++)
			{
				if(ObjImprtDirName.options[optn].selected)
				{
					strDirName=ObjImprtDirName.options[optn].text;
					break;
				}
			}

			if(strDirName!="")
			{
				//directory format may be = > 3176 sachin/etc/etc..
				var arrDirNames=strDirName.split("/");
				var arrSrcDirNametoImprt=arrDirNames[0].split(" "); //3176 sachin

				var OrderId=arrSrcDirNametoImprt[0];//3176
				if(OrderId!="" && isNaN(OrderId))
				{
					OrderId="";
				}
			}
			//Code used to get the orderid ends.

			//Gets the userid,serverid
			if(UserId=="")
			UserId=drpdwn_emails.value;

			var ServerType=drpdwn_ImportFrmSrver.value;
			var FolderName=drpdwn_ImportFileFrom.value;
			document.getElementById("id_printpopup").href="import_smugmug_photos.php?UserId="+UserId+"&ServerType="+ServerType+"&FolderName="+FolderName+"&OrderId="+OrderId;
			initLytebox();
			document.getElementById("id_printpopup").onclick();
		}
	}
}

//function used to list the folders from the 
//selected server Used at Admin End
function funAjaxForLoadFolders(formname,url)
{	
	with(document.forms[formname])
	{
		Ajaxformname=formname;
		url='getServerPartnerUploadFolders.php';

		// removes drop down options
		document.getElementById("drpdwn_ImportFileFrom").options.length=0;

		//add a select option
		var optn = document.createElement("OPTION");
		optn.text = "Select Folder";
		optn.value = "";
		drpdwn_ImportFileFrom.options.add(optn);
		if(trimAll(drpdwn_ImportFrmSrver.value)=="")
		{
			alert("Please select server.");
			drpdwn_ImportFrmSrver.focus();
			return false;
		}
		else
		{	
			//show loading image
			document.getElementById("img_loading").style.display="";

			var SrvrId =trimAll(drpdwn_ImportFrmSrver.value);
			url=url+"?srvrid="+SrvrId;

			//Does URL begin with http?
			if(url.substring(0, 4) != 'http')
			{
				url = base_url + url;
			}

			http_req = null;
			if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
			else if(window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

			if(http_req)
			{			
				http_req.onreadystatechange = funGetNewFldrOptn;
				http_req.open("GET", url, true);
				http_req.send("");
			}
		}
	}
}

//function used to delet previous options from the 
//folder drop down and insert new folder options Used at Admin End
function funGetNewFldrOptn()
{
	if(http_req.readyState==4)
	{
		var strRplytxt = http_req.responseText;
		frmName = document.forms[Ajaxformname];
		
		if(trimAll(strRplytxt)!="")
		{
			var arrFldrValAndTxt = strRplytxt.split("~##~");

			for(var optnCount=0;optnCount<arrFldrValAndTxt.length;optnCount++)
			{
				if(arrFldrValAndTxt[optnCount]!="")
				{
					var arrNmTxt = arrFldrValAndTxt[optnCount].split('~#~');
					var strDrpDwnVal = arrNmTxt[0];
					var strDrpDwnTxt = arrNmTxt[1];

					optn = document.createElement("OPTION");
					optn.text = strDrpDwnTxt;
					optn.value = strDrpDwnVal;
					frmName.drpdwn_ImportFileFrom.options.add(optn);

				}//arrFldrValAndTxt[optn]!="" check ends

			}//for loop ends

		}//trimAll(strRplytxt)!="" check ends

		//show loading image
		document.getElementById("img_loading").style.display="none";
	}
}


//Function used to find the get the order id from the directory name
//function funGetImprtForOrderId()
//{
//	var strDirName="";
//	var ObjImprtDirName=document.getElementById("drpdwn_ImportFileFrom");
//
//	for(optn=0;optn<ObjImprtDirName.options.length;optn++)
//	{
//		if(ObjImprtDirName.options[optn].selected)
//		{
//			strDirName=ObjImprtDirName.options[optn].text;
//			break;
//		}
//	}
//
//	if(strDirName!="")
//	{
//		//directory format may be = > 3176 sachin/etc/etc..
//		var arrDirNames=strDirName.split("/");
//		var arrSrcDirNametoImprt=arrDirNames[0].split(" "); //3176 sachin
//
//		var strImprtForOrderId=arrSrcDirNametoImprt[0];//3176
//		if(strImprtForOrderId!="" && isNaN(strImprtForOrderId))
//		{
//			strImprtForOrderId="";
//		}
//	}
//}


//function used to create the cookie with the given name
function createCookie(name,value,days)
{
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

//function used to read the cookie value
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//function used to delete the given cookie
function eraseCookie(name)
{
	createCookie(name,"",-1);
}

//Function changes the backround style of the selected boxes in Shipping Option and Box option
function funChangeBackGround(formname,cntrltype)
{
	with(document.forms[formname])
	{
		//Ctrlname (radiobutton name) will be passed.
		//Since we are using the images on image click corresponding ctrl will be made selected.
		document.getElementById(cntrltype).checked=true;

		//Array contains the Shipping Cost.
		var ArrShpngPrcs =new Array([10,45,22,5],
									[10,50,25,5],
									[10,72,42,5],
									[10,95,68,5]);

		//Array contains the names of the boxes.
		var arrBoxType=new Array('flatbox','smallbox','mediumbox','largebox');

		for (i=0;i<arrBoxType.length;i++)//for loop runs to find the selected box type
		{
			var cntrlname="radio_"+arrBoxType[i];
			var tdname="td_radio_"+arrBoxType[i];
			var imgtagid="id_"+arrBoxType[i];
			
			document.getElementById(tdname).className="unselectedcolor";
	
			if(cntrlname==cntrltype)
			{
				//Changes the bckgnd color and radibutn img for the selected box.
				document.getElementById(tdname).className="tdselectedcolor";
				document.getElementById(imgtagid).src="../images/smugmug/"+arrBoxType[i]+"-selected.jpg";
				document.getElementById("img_"+arrBoxType[i]).src="../images/smugmug/radio_button4.jpg";
				var arrindx=i;
			}
			else
			{
				document.getElementById(imgtagid).src="../images/smugmug/"+arrBoxType[i]+".jpg";
				document.getElementById("img_"+arrBoxType[i]).src="../images/smugmug/radio_button5.jpg";
			}

		}//for loop ends here.

		
	
		var shiping=document.getElementById("hdn_shiptype").value;
		if(shiping=="Ground")
		shiping="GRND";

		document.getElementById(shiping).checked=true;
		funchangeshipping(formname,shiping);

		OrderFormShpngRateChanges(formname);
	}

}//funChangeBackGround function ends here.

//Function Used to change shipping and its amount.
function funchangeshipping(formname,shiptype)
{
	with(document.forms[formname])
	{
		var showdiv="";
		if(document.getElementById("drpdwn_shippingCountry").value!="US")
		{
			shiptype="self";
			showdiv="none";
		}
		else
			showdiv="";
		

		//Sets the shiptype in the hidden.
		document.getElementById("hdn_shiptype").value=shiptype;

		//Used to change the td background color
		var selectedcntrl="td_"+shiptype;

		//Array contains the shipping types.
		var arrShippingType=new Array('GRND','Next Day Air','2nd Day Air','self');

		//for loop runs to find the selected shipping type.
		for (i=0;i<arrShippingType.length;i++)
		{
			var cntrlname="td_"+arrShippingType[i];
			var imgtagid="id_"+arrShippingType[i];

			if(document.getElementById(imgtagid))
			{
				document.getElementById(cntrlname).className="unselectedcolor";
				if(cntrlname==selectedcntrl)
				{
					//Changes  the background color and ctrl images for the selected ship type.
					document.getElementById(cntrlname).className="tdselectedcolor";
					document.getElementById(imgtagid).src="../images/smugmug/"+arrShippingType[i]+"-selected.jpg";
					document.getElementById("img_"+arrShippingType[i]).src="../images/smugmug/radio_button4.jpg";
					document.getElementById(cntrlname).style.display="";
				}
				else
				{
					if(cntrlname=="td_drop" || cntrlname=="td_2nd Day Air")
					{
						if(document.getElementById(cntrlname).style.display!="none")
						document.getElementById(cntrlname).style.display=showdiv;
					}
					else
					document.getElementById(cntrlname).style.display=showdiv;

					document.getElementById(imgtagid).src="../images/smugmug/"+arrShippingType[i]+".jpg";
					document.getElementById("img_"+arrShippingType[i]).src="../images/smugmug/radio_button5.jpg";
				}
			}
		}//for loop ends here.

		document.getElementById(shiptype).checked=true;var shiplabel="Ground";
		switch(shiptype)//gets the shipping amount according to the shipping type selected.
		{
			case "GRND":
			shipamount=funCheckNumeric(document.getElementById("hdn_ground").value);
			shiplabel="Ground";
			break;
			case "Next Day Air":
			shipamount= funCheckNumeric(document.getElementById("hdn_nextdayair").value);
			shiplabel="Next Day Air";
			break;
			case "2nd Day Air":
			shipamount= funCheckNumeric(document.getElementById("hdn_upssecondday").value);
			shiplabel="2nd Day Air";
			break;
			case "self":
			shipamount= funCheckNumeric(document.getElementById("hdn_selfshipping").value);
			shiplabel="Self-Ship";
			break;
			case "drop":
			shipamount= funCheckNumeric(document.getElementById("hdn_selfshipping").value);
			shiplabel="Self-DropOff";
			break;
		}

		if(shiptype=="self" || shiptype=="drop")//If shipping type is self-ship
		{
			//When pricing plan is package sets the shipping amount to zero.
			if(document.getElementById("radio_package").checked==true)
			{
				shipamount=0;
				document.getElementById("id_refundable").style.display="none";
				hdn_shipamount.value=funCheckNumeric(0);
			}
			else
			document.getElementById("id_refundable").style.display="";
			
			//Changes the place order button.
			document.getElementById("id_placeorderbutton").src="../images/smugmug/PlaceOrder_Selfshipping.jpg";
		}
		else
		{
			document.getElementById("id_refundable").style.display="none";
			document.getElementById("id_placeorderbutton").src="../images/smugmug/PlaceOrder_button.jpg";
			hdn_shipamount.value=funCheckNumeric(shipamount);
		}

		shipamount=shipamount+".00";

		//Displays the Shipping Amount and ShipType
		document.getElementById("td_shipcost").innerHTML="<b>$"+shipamount+"</b>";
		document.getElementById("td_shiptype").innerHTML="<b>"+shiplabel+":</b>";
		funupdateTotal(formname);
	}

}//funchangeshipping ends here

//Function Called Separately from update calculation.
function smgSelfShiping(formname)
{
	with(document.forms[formname])
	{
		if(document.getElementById("radio_package").checked==true)
		{
			var shipamount=0;
			document.getElementById("id_refundable").style.display="none";
			hdn_shipamount.value=funCheckNumeric(shipamount);
			document.getElementById("td_shipcost").innerHTML="<b>$"+shipamount.toFixed(2)+"</b>";
		}
		else
		{
			var shipamount=5;
			document.getElementById("id_refundable").style.display="";
			hdn_shipamount.value=funCheckNumeric(shipamount);
			document.getElementById("td_shipcost").innerHTML="<b>$"+shipamount.toFixed(2)+"</b>";
		}
	}
}//smgSelfShiping ends here


//Function used to calculate the total amount that to be charged.
function funupdateTotal(formname)
{
	with(document.forms[formname])
	{
		var AmountChargedUsingCreditCard="";

		if(document.getElementById("hdn_shiptype").value=="self" || document.getElementById("hdn_shiptype").value=="drop")
		{
			smgSelfShiping(formname);
			document.getElementById("radio_kitboxyes").checked=false;
			document.getElementById("radio_kitboxno").checked=true;

			document.getElementById("tr_digiyes").className="tdDigiImgUnselected";
			document.getElementById("tr_digino").className="tdDigiImgSelected";
			document.getElementById("id_shippingkit").style.display="none";
			document.getElementById("imgdigipackyes").src="../images/smugmug/radio_button5.jpg";
			document.getElementById("imgdigipackno").src="../images/smugmug/radio_button6.jpg";
			document.getElementById("digipaclabel").innerHTML="<b>No thanks.(DigiPac Requires UPS shipping).</b>";
			document.getElementById("hdn_shippingkit").value="0";
		}
		else
		{
			document.getElementById("digipaclabel").innerHTML="<b>No thanks, I'll use my own packaging.</b>";
		}

		//Gets the value of shipping, pricing-plan,digipac kit and mediaformats amount
		var shipamount=funCheckNumeric(document.getElementById("hdn_shipamount").value);
		var packageamount=funCheckNumeric(document.getElementById("hdn_packageamount").value);
		var shippingkitamount=funCheckNumeric(document.getElementById("hdn_shippingkit").value);
		var additionaldigiformatAmount=funCheckNumeric(document.getElementById("hdn_additionalamount").value);
		var CouponAmount=funCheckNumeric(document.getElementById("hdn_couponamount").value);

		//Sums the total amount.
		var totalamount=parseFloat(shipamount)+parseFloat(packageamount)+parseFloat(shippingkitamount);
		totalamount+=parseFloat(additionaldigiformatAmount);

		if(CouponAmount>=totalamount)//Checks whether coupon amount is greate than total amount when gift card used.
		{
			//If coupon is greater then deducts the total amount from coupon amount.
			AmountChargedUsingCreditCard=parseFloat(CouponAmount)-parseFloat(totalamount);
			document.getElementById("coupon_amount").style.display="";
			document.getElementById("creditcard_amount").style.display="";
			document.getElementById("td_couponamt").innerHTML="<b>$"+totalamount.toFixed(2)+"</b>";
			document.getElementById("td_creditcardamt").innerHTML="<b>$0.00</b>";
		}
		else if(CouponAmount!=0)
		{
			//Enter when coupon amount is less than total amount.
			AmountChargedUsingCreditCard=parseFloat(totalamount)-parseFloat(CouponAmount);
			document.getElementById("coupon_amount").style.display="";
			document.getElementById("creditcard_amount").style.display="";
			document.getElementById("td_couponamt").innerHTML="<b>$"+CouponAmount+"</b>";
			document.getElementById("td_creditcardamt").innerHTML="<b>$"+AmountChargedUsingCreditCard.toFixed(2)+"</b>";
		}
		else 
		{
			document.getElementById("coupon_amount").style.display="none";
			document.getElementById("creditcard_amount").style.display="none";
		}
		document.getElementById("td_total").innerHTML="<b>$"+totalamount.toFixed(2)+"</b>";
	}
}


//Function called at the time of pricing plan selection.
function funSelectOrderType(formname,ordertype,packageamount)
{
	with(document.forms[formname])
	{
		//Enters when pricing plan type is package.
		if(ordertype=="package")
		{
			//Changes the checkbox images according to the package type selected.
			document.getElementById("imgstndchkbx").src="../images/smugmug/radio_button1.jpg";
			document.getElementById("imgpckgchkbx").src="../images/smugmug/radio_button4.jpg";

			//select the controls. checks teh package control and unchecks the standard.
			document.getElementById("radio_package").checked=true;
			document.getElementById("radio_standard").checked=false;
			
			//Applies the style to the selected plan types.
			document.getElementById("id_package").className="tdselected";
			document.getElementById("id_packageTypes").style.display="";
			
			//Calls the function which automatically sets the Photo Package type as selected.
			SmgFunPackageOrder('frmsmugmugorder','PHOTO');

			//Applies the style to the box and to the title
			document.getElementById("id_standard").className="tdunselected";
			document.getElementById("id_standard_title").className="Smugmugnormaltxt";
			document.getElementById("id_package_title").className="SmugmugYellowtxt";

			//Enters When Photography media is not selected and selects the photography media automatically.
			if(document.getElementById("check_photography").checked==false)
			{
				//Checks the photograpy media and sets the corresponding radiobutn image.
				document.getElementById("check_photography").checked=true;
				document.getElementById("imgphotochkbx").src="../images/smugmug/check_box_selected.jpg";
				
				//Checks the noramla quality and sets that radiobtn image.
				document.getElementById("radio_normalqlty").checked=true;
				document.getElementById("img_normalqlty").src="../images/smugmug/radio_button4.jpg";
				
				//Displays the correspondng media formats.
				document.getElementById("td_photobckgnd").style.display="";
				document.getElementById("tr_photoOptions").style.display="";
			}

		}//ordertype=="package" check ends here
		else
		{
			//Enters when the Pricing plan is Standard.
			//Sets the checkbox image for standard(selected img) and package(unselected img)
			document.getElementById("imgpckgchkbx").src="../images/smugmug/radio_button1.jpg";
			document.getElementById("imgstndchkbx").src="../images/smugmug/radio_button4.jpg";

			//Selects the corresponding contrl checkbx checked and unchecked.
			document.getElementById("radio_standard").checked=true;
			document.getElementById("radio_package").checked=false;
			
			//Sets the style.
			document.getElementById("id_standard_title").className="SmugmugYellowtxt";
			document.getElementById("id_package_title").className="Smugmugnormaltxt";
			document.getElementById("id_package").className="tdunselected";
			document.getElementById("id_standard").className="tdselected";

			//Hides the package types.and sets the package amount to 0.
			document.getElementById("id_packagetype").style.display="none";
			document.getElementById("hdn_packageamount").value="0";
			document.getElementById("id_packageTypes").style.display="none";
		}//else ends here

		funupdateTotal(formname);
	}
}

//Function called when DigiPack is selected.
function funsendkitbox(formname,option,shippingkitamount)
{
	with(document.forms[formname])
	{
		if(option=="yes")//Enters when digipac is selected.
		{
			//Sets the checkbox image.
			document.getElementById("imgdigipackyes").src="../images/smugmug/radio_button6.jpg";
			document.getElementById("imgdigipackno").src="../images/smugmug/radio_button5.jpg";

			//checks and unchecks the control Yes and No cntrls.
			document.getElementById("radio_kitboxyes").checked=true;
			document.getElementById("radio_kitboxno").checked=false;
			
			//Applies the style.
			document.getElementById("tr_digiyes").className="tdDigiImgSelected";
			document.getElementById("tr_digino").className="tdDigiImgUnselected";
			document.getElementById("id_shippingkit").style.display="";

			//Sets the shipping kit amount.
			document.getElementById("shippingkitamount").innerHTML="<b>$"+shippingkitamount+"</b>";
			document.getElementById("hdn_shippingkit").value=funCheckNumeric(shippingkitamount);

			funupdateTotal(formname);
		}
		else
		{
			//Enters when digipac is Unselected.

			//Sets the checkbox image.
			document.getElementById("imgdigipackno").src="../images/smugmug/radio_button6.jpg";
			document.getElementById("imgdigipackyes").src="../images/smugmug/radio_button5.jpg";

			//checks and unchecks the control Yes and No cntrls.
			document.getElementById("radio_kitboxno").checked=true;
			document.getElementById("radio_kitboxyes").checked=false;

			//Applies the style.
			document.getElementById("tr_digiyes").className="tdDigiImgUnselected";
			document.getElementById("tr_digino").className="tdDigiImgSelected";

			//Hides the shipping kit amount.
			document.getElementById("id_shippingkit").style.display="none";
			document.getElementById("hdn_shippingkit").value="0";

			funupdateTotal(formname);
		}
	}
}


//Function to Display the Photo Digital format Amount.
function smgphotodvdcalculation(formname,mediatype,mediacost)
{
	with(document.forms[formname])
	{
		if(mediatype=="DVD")//Enters when selected media is DVD.
		{
			//Calculation to Display the DVD cost
			//enters when the dvd is selected.
			if(document.getElementById("photo_dvd").checked==true)
			{
				//if the dvd checkbx selected for first time.
				if(document.getElementById("photo_digiformat").style.display=="none")
				{
					//Displays the dropdown.
					document.getElementById("photo_digiformat").style.display="";
					document.getElementById("drpdwn_DVDphotograph").value=1;
				}
				
				document.getElementById("imgPhotoDVD").src="../images/smugmug/check_box_selected.jpg"; 

				//Gets the number of dvds opted
				var dvdcount=document.getElementById("drpdwn_DVDphotograph").value;

				if(dvdcount==1)
				{
					//If count is equal to 1 then it will be at free cost.
					document.getElementById("photodvdcost").innerHTML="<b>Free!</b>";
					document.getElementById("hdn_photoDVDcost").value="0";
				}
				else if(dvdcount>1)
				{
					//If count is greater than 1 then it will calculaes the amount.
					dvdcount-=1;
					var DvdCost=(parseInt(dvdcount)*mediacost).toFixed(2);

					//Displays the cost.
					document.getElementById("photodvdcost").innerHTML="<b>$"+DvdCost+"</b>";
					document.getElementById("hdn_photoDVDcost").value=DvdCost;
				}
			}
			else if(document.getElementById("photo_dvd").checked==false)
			{
				//If DVD is not selected.
				document.getElementById("photo_digiformat").style.display="none";
				document.getElementById("hdn_photoDVDcost").value="0";
			}

		}
		else if(mediatype=="HardDrive")///Enters when selected media is HardDrive
		{
			//Checks the Photograpy resoulution and sets the amount of the HardDrive according to that.
			if(document.getElementById("radio_expert").checked==true && document.getElementById("hardrive_both").checked==true)
			mediacost=document.getElementById("hdn_expertHardDriveamount").value;
			else
			mediacost=document.getElementById("hdn_NormalHardDriveamount").value;

			if(document.getElementById("photo_hardrive").checked==true)
			{
				document.getElementById("imgPhotoHD").src="../images/smugmug/check_box_selected.jpg";

				//IF hardrive is checked it will displays the Pc/Mac option.
				document.getElementById("tr_pcmac").style.display="";
				//document.getElementById("tr_myownhardrive").style.display="";

				if(document.getElementById("photo_HDdigiformat").style.display=="none")
				{
					//Displays the harddrive drpdwn and its cost.
					document.getElementById("photo_HDdigiformat").style.display="";
					document.getElementById("drpdwn_HDphotograph").value=1;
					document.getElementById("photohdcost").innerHTML="<b>$"+mediacost+"</b>";
					document.getElementById("hdn_photoHDcost").value=mediacost;
				}
				else
				{
					//GEts the hardrive count selected.
					var harddrivecount=document.getElementById("drpdwn_HDphotograph").value;

					if(harddrivecount>0)
					{
						//Calculates the cost of the hardrive selected and displays the amount.
						var hardriveCalculatedcost=(parseFloat(harddrivecount)*parseFloat(mediacost)).toFixed(2);
						document.getElementById("photohdcost").innerHTML="<b>$"+hardriveCalculatedcost+"</b>";
						document.getElementById("hdn_photoHDcost").value=hardriveCalculatedcost;
					}
					else
					{
						document.getElementById("hdn_photoHDcost").value="0";
					}
				}//else ends here
			}
			else if(document.getElementById("photo_hardrive").checked==false)
			{
				//Enters when photo harddrive is not selected.
				if(document.getElementById("video_hardrive").checked==false)
				{
					document.getElementById("tr_pcmac").style.display="none";
					//document.getElementById("tr_myownhardrive").style.display="none";
				}

				document.getElementById("photo_HDdigiformat").style.display="none";
				document.getElementById("hdn_photoHDcost").value="0";
			}
		}
		funShowAdditionalAmount(formname);
	}
}//smgphotodvdcalculation ends here.

//Function called when vidio resolution is selected
function smgChangeVideoformatCost(formname,DVDcost,HardDriveCost,type)
{	
	with(document.forms[formname])
	{
		if(type=="expert")
		{
			//Sets radibtn checked and changes the radiobtn image.
			document.getElementById("radio_expert").checked=true;
			document.getElementById("img_expert").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("img_premium").src="../images/smugmug/radio_button1.jpg";

			document.getElementById("video_digiformat").style.display="none";
			document.getElementById("videodvd_display").style.display="none";
			document.getElementById("video_dvd").checked=false;
			document.getElementById("imgVideoDVD").src="../images/smugmug/check_box.jpg";
			document.getElementById("drpdwn_video").value=0;
			
		}
		else if(type=="premium")
		{
			//Sets radibtn checked and changes the radiobtn image.
			document.getElementById("radio_premium").checked=true;
			document.getElementById("img_premium").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("img_expert").src="../images/smugmug/radio_button1.jpg";

			document.getElementById("videodvd_display").style.display="";
			//document.getElementById("video_digiformat").style.display="";
			//document.getElementById("drpdwn_video").value=1;
		}
		
		//When use the same media is selected the photgarpy function is called.
		if(document.getElementById("hardrive_both").checked==true)
		smgphotodvdcalculation(formname,'HardDrive',HardDriveCost);

		funchangeBckgnd(formname,type,'video');
		smgVideoFormatculation(formname,'both');
	}

}//smgChangeVideoformatCost ends.

//Function to Display the Video media Amount.
function smgVideoFormatculation(formname,mediatype)
{
	with(document.forms[formname])
	{

		if(mediatype=="DVD")//Enters when selected media is DVD.
		{
			//Sets the amount according to the resolution selected.
			if(document.getElementById("radio_expert").checked==true)
			var mediacost=document.getElementById("hdn_expertdvdamount").value;
			else
			var mediacost=document.getElementById("hdn_Normaldvdamount").value;
			
			if(document.getElementById("video_dvd").checked==true)
			{
				document.getElementById("imgVideoDVD").src="../images/smugmug/check_box_selected.jpg";

				//Enters when dvd is selected.
				if(document.getElementById("video_digiformat").style.display=="none")
				{
					document.getElementById("video_digiformat").style.display="";
					document.getElementById("drpdwn_video").value=1;
				}
				
				//gets the number of dvds opted.
				var dvdcount=document.getElementById("drpdwn_video").value;
				if(dvdcount==1)
				{
					//If count is 1 then it is free.
					document.getElementById("videodvdcost").innerHTML="<b>Free!</b>";
					document.getElementById("hdn_videoDVDcost").value="0";
				}
				else if(dvdcount>1)
				{
					//Calculates and Displays the amount when count is greater than 1.
					dvdcount-=1;
					var DvdCost=(parseInt(dvdcount)*mediacost).toFixed(2);
					document.getElementById("videodvdcost").innerHTML="<b>$"+DvdCost+" per tape</b>";
					document.getElementById("hdn_videoDVDcost").value=DvdCost;
				}
			}
			else
			{
				//When Dvd is not selected.
				document.getElementById("video_digiformat").style.display="none";
				document.getElementById("hdn_videoDVDcost").value="0";
			}
		}
		else if(mediatype=="HardDrive")//Enters when selected media is HardDrive.
		{
			//GEts the amount of the hardrive according to video resolution selected.
			if(document.getElementById("radio_expert").checked==true)
			var mediacost=document.getElementById("hdn_expertHardDriveamount").value;
			else
			var mediacost=document.getElementById("hdn_NormalHardDriveamount").value;
			
			//Enteres when video harddrive is selected.
			if(document.getElementById("video_hardrive").checked==true)
			{
				document.getElementById("imgVideoHD").src="../images/smugmug/check_box_selected.jpg";

				//Displays the pc/mac option when hardrive is selected.
				document.getElementById("tr_pcmac").style.display="";
				//document.getElementById("tr_myownhardrive").style.display="";
				
				//Displays the VideoHardrive options.
				if(document.getElementById("video_HDdigiformat").style.display=="none")
				{
					document.getElementById("video_HDdigiformat").style.display="";
					document.getElementById("drpdwn_HDvideo").value=1;
				}

				//GEts the number of hardrive selected.
				harddrivecount=document.getElementById("drpdwn_HDvideo").value;

				if(harddrivecount>0)
				{
					//Calculates the hardrive amount according to the selected number of copies.
					var hardriveCalculatedcost=(parseFloat(harddrivecount)*parseFloat(mediacost)).toFixed(2);
					document.getElementById("videohdcost").innerHTML="<b>$"+hardriveCalculatedcost+"</b>";
					document.getElementById("hdn_videoHDcost").value=hardriveCalculatedcost;
				}
				else
				{
					document.getElementById("hdn_videoHDcost").value="0";
				}
			}
			else
			{
				//If vedio harddrive is unselected and photo hardrive is also unselected
				//then hides the Pc/Mac option.
				if(document.getElementById("photo_hardrive").checked==false)
				{
					document.getElementById("tr_pcmac").style.display="none";
					//document.getElementById("tr_myownhardrive").style.display="none";
				}

				//Makes the amount to zero.
				document.getElementById("video_HDdigiformat").style.display="none";
				document.getElementById("hdn_videoHDcost").value="0";
			}
		}
		else if(mediatype=="both" && document.getElementById("check_videomovie").checked==true)
		{
			//will be called when use the same media option is opted.

			//Checks the vidio resolution type selected and sets the amount according to that.
			if(document.getElementById("radio_expert").checked==true)
			{
				//Sets the high resolution amount.
				var singledvdcost=document.getElementById("hdn_expertdvdamount").value;
				var mediacost=document.getElementById("hdn_expertHardDriveamount").value;
			}
			else
			{
				//Sets the low resolution amount.
				var singledvdcost=document.getElementById("hdn_Normaldvdamount").value;
				var mediacost=document.getElementById("hdn_NormalHardDriveamount").value;
			}
			
			//alert(document.getElementById("video_dvd").checked);
			//If video DVD is Selected enters
			var dvdcount = 0;
			if(document.getElementById("video_dvd").checked==true)
			{
				//Gets the number of dvd count selected.
				dvdcount=document.getElementById("drpdwn_video").value;
				if(dvdcount==1)
				{
					document.getElementById("videodvdcost").innerHTML="<b>Free!</b>";
					document.getElementById("hdn_videoDVDcost").value="0";
				}
				else if(dvdcount>1)
				{
					//Calculates dvd cost and sets the amount.
					dvdcount-=1;
					var DvdCost=(parseInt(dvdcount)*singledvdcost).toFixed(2);
					document.getElementById("videodvdcost").innerHTML="<b>$"+DvdCost+"</b>";
					document.getElementById("hdn_videoDVDcost").value=DvdCost;
				}
			}
			else
			{
				document.getElementById("hdn_videoDVDcost").value="0";
			}
			
			//Enters when video hardrive is selected.
			if(document.getElementById("video_hardrive").checked==true)
			{
				//Gets the hardrive count.
				harddrivecount=document.getElementById("drpdwn_HDvideo").value;

				if(harddrivecount>0)
				{
					//Calculates and sets the amount according to the hardrive selected.
					var hardriveCalculatedcost=(parseFloat(harddrivecount)*parseFloat(mediacost)).toFixed(2);
					document.getElementById("videohdcost").innerHTML="<b>$"+hardriveCalculatedcost+"</b>";
					document.getElementById("hdn_videoHDcost").value=hardriveCalculatedcost;
				}
				else
				{
					document.getElementById("hdn_videoHDcost").value="0";
				}
			}
			else if(document.getElementById("hardrive_both").checked==false)
			{
				//Entes when use same media is selected.
				//Sets the imaga and checks the appropriate cntrl selected.
				document.getElementById("video_hardrive").checked=true;
				document.getElementById("imgVideoHD").src="../images/smugmug/check_box_selected.jpg";
				
				//Displays the pc/mac option
				document.getElementById("tr_pcmac").style.display="";
				//document.getElementById("tr_myownhardrive").style.display="";
				document.getElementById("drpdwn_HDvideo").value=1;
				document.getElementById("video_HDdigiformat").style.display="";
				document.getElementById("videohdcost").innerHTML="<b>$"+mediacost+"</b>";
				document.getElementById("hdn_videoHDcost").value=mediacost;
			}
		}
		funShowAdditionalAmount(formname);
	}
}

//function called when use same media is selected.
function funSelectHardDrive(formname,hardrivecost)
{
	with(document.forms[formname])
	{
		var objPhotoOption=document.getElementById("tr_photoOptions");
		var objVideoOption=document.getElementById("tr_videoOptions");
		var Exprtmediacost=document.getElementById("hdn_expertHardDriveamount").value;

		if(objPhotoOption.style.display=="" && objVideoOption.style.display=="")
		{
			if(document.getElementById("hardrive_both").checked==true)
			{
				//Displays HardDrive Pc or Mac Option.
				document.getElementById("tr_pcmac").style.display="";
				//document.getElementById("tr_myownhardrive").style.display="";
				
				//Gets the cost when high resolution is selected.
				if(document.getElementById("radio_expert").checked==true)
				hardrivecost=Exprtmediacost;
				
				//unchecks the video hardrive and disable the control.
				document.getElementById("video_hardrive").checked=false;
				document.getElementById("video_hardrive").disabled=true;
				document.getElementById("imgVideoHD").src="../images/smugmug/check_box.jpg";
				document.getElementById("hdn_videoHDcost").value="0";

				if(document.getElementById("photo_hardrive").checked==false)
				{
					//selects the video hardrive and sets that image.
					document.getElementById("photo_hardrive").checked=true;
					document.getElementById("imgPhotoHD").src="../images/smugmug/check_box_selected.jpg";
					document.getElementById("photo_HDdigiformat").style.display="";
					document.getElementById("drpdwn_HDphotograph").value=1;
					document.getElementById("photohdcost").innerHTML="<b>$"+hardrivecost+"</b>";
					document.getElementById("hdn_photoHDcost").value=hardrivecost;
				}
				else 
				{
					harddrivecount=document.getElementById("drpdwn_HDphotograph").value;
					var hardriveCalculatedcost=(parseInt(harddrivecount)*parseFloat(hardrivecost)).toFixed(2);
					document.getElementById("photohdcost").innerHTML="<b>$"+hardriveCalculatedcost+"</b>";
					document.getElementById("hdn_photoHDcost").value=hardriveCalculatedcost;
				}
				document.getElementById("photo_hardrive").disabled=true;
				document.getElementById("video_HDdigiformat").style.display="none";
			}
			else if(document.getElementById("hardrive_both").checked==false)
			{
				document.getElementById("video_hardrive").disabled=false;
				document.getElementById("photo_hardrive").disabled=false;
				hardrivecost=document.getElementById("hdn_NormalHardDriveamount").value;
				
				if(document.getElementById("photo_hardrive").checked==true)
				{
					harddrivecount=document.getElementById("drpdwn_HDphotograph").value;
					var hardriveCalculatedcost=(parseFloat(harddrivecount)*parseFloat(hardrivecost)).toFixed(2);
					document.getElementById("photohdcost").innerHTML="<b>$"+hardriveCalculatedcost+"</b>";
					document.getElementById("hdn_photoHDcost").value=hardriveCalculatedcost;
				}
			}
			funShowAdditionalAmount(formname);
		}
		else
		{
			document.getElementById("hardrive_both").checked=false;
			document.getElementById("img_hardriveforboth").src="../images/smugmug/check_box.jpg";
		}
	}

}//function funSelectHardDrive ends

//Function used to calculates the additional amount.
function funShowAdditionalAmount(formname)
{
	var PhotoDvdCost=funCheckNumeric(document.getElementById("hdn_photoDVDcost").value);
	var VideoDvdCost=funCheckNumeric(document.getElementById("hdn_videoDVDcost").value);
	var PhotoHardDriveCost=funCheckNumeric(document.getElementById("hdn_photoHDcost").value);
	var VedioHardDriveCost=funCheckNumeric(document.getElementById("hdn_videoHDcost").value);
		
	var TotalDigiAmt=0;

	//gets the mediaformats amount and sums it.
	if(document.getElementById("check_photography").checked==true)
	TotalDigiAmt+=parseFloat(PhotoDvdCost)+parseFloat(PhotoHardDriveCost);

	if(document.getElementById("check_videomovie").checked==true)
	TotalDigiAmt+=parseFloat(VideoDvdCost)+parseFloat(VedioHardDriveCost);

	if(TotalDigiAmt>0)
	{	
		//Displays the additional format amount.
		document.getElementById("id_digiformat").style.display="";
		document.getElementById("digiformatamount").innerHTML="<b>$"+TotalDigiAmt.toFixed(2)+"<b>";
		document.getElementById("hdn_additionalamount").value=TotalDigiAmt;
	}
	else if(TotalDigiAmt==0)
	{
		//Hides the additional format amount.
		document.getElementById("id_digiformat").style.display="none";
		document.getElementById("hdn_additionalamount").value=TotalDigiAmt;
	}

	funupdateTotal(formname);

}//funShowAdditionalAmount ends here.


//function called photograpy resolution is selected.
function funchangeBckgnd(formname,type,mediatype)
{
	with(document.forms[formname])
	{
		if(mediatype=='photo')
		{
			//When mediatype is photography.
			if(type=="normal")
			{
				//When resolution is noramla sets the appropriate style and image checkbox.
				document.getElementById("radio_normalqlty").checked=true;
				document.getElementById("td_normalcls").className="tdselected";
				document.getElementById("td_highestcls").className="tdunselected";
				document.getElementById("img_normalqlty").src="../images/smugmug/radio_button4.jpg";
				document.getElementById("img_highqlty").src="../images/smugmug/radio_button1.jpg";
			}
			else
			{
				//When resolution is noramla sets the appropriate style and image checkbox.
				document.getElementById("radio_highqlty").checked=true;
				document.getElementById("td_normalcls").className="tdunselected";
				document.getElementById("td_highestcls").className="tdselected";
				document.getElementById("img_normalqlty").src="../images/smugmug/radio_button1.jpg";
				document.getElementById("img_highqlty").src="../images/smugmug/radio_button4.jpg";
			}
			
			//Array contains the package types.
			var arrPackageTypes=Array("PHOTO","NEGATIVE","SLIDES","ALBUM");

			//When pricing plan is Package.Sets the package amount according 
			//to the package type selected.
			if(document.getElementById("radio_package").checked==true)
			{
				for(i=0;i<arrPackageTypes.length;i++)
				{
					var ctrlname="radio_"+arrPackageTypes[i];
					if(document.getElementById(ctrlname).checked==true)
					{
						var ctrlname=document.getElementById(ctrlname).value;
						SmgFunPackageOrder(formname,arrPackageTypes[i]);
						break;
					}
				}	
			}
		}
		else
		{
			//When mediatype is Vedio.
			if(type=="premium")
			{
				document.getElementById("radio_premium").checked=true;
				document.getElementById("td_premiumcls").className="tdselected";
				document.getElementById("td_expertcls").className="tdunselected";
			}
			else
			{
				document.getElementById("radio_expert").checked=true;
				document.getElementById("td_premiumcls").className="tdunselected";
				document.getElementById("td_expertcls").className="tdselected";
			}
		}
	}
}


/* Function Used to verify the CreditCard Details*/
function funverificationnotes(event,formname)
{
	with(document.forms[formname])
	{
		x = event.clientX + document.body.scrollLeft+25;
		y = event.clientY + document.body.scrollTop - 190;

		document.getElementById("Popup1").style.display="block";
		document.getElementById("Popup1").style.left = x;
		document.getElementById("Popup1").style.top = y;
		document.getElementById("Popup1").style.display="";

		if(radio_cardType[3].checked==true)
		{
			document.getElementById("Img_amExp").style.display="";
			document.getElementById("Img_OtherCard").style.display="none";
		}
		else
		{			
			document.getElementById("Img_amExp").style.display="none";
			document.getElementById("Img_OtherCard").style.display="";	 
		}
	}
}
/* Function Used to verify the CreditCard Details---- Ends */

/* Function Used to Show the CreditCard Information Image  */
function funverificationnotes_hid(formname)
{
  document.getElementById("Popup1").style.display="none";
}

function funCheckCard(formname,ids)
{
	with(document.forms[formname])
	{
		document.getElementById(ids).checked=true;
	}
}
//function used to check and call the ajax to get the coupon details
function funCheckCoupon(formname)
{
	with(document.forms[formname])
	{
		//unset coupon values
		strGblCpntype="";
		strGblCpnValue=0;
		document.getElementById('lbl_couponmsg').innerHTML= "";		
       
		if(trimAll(txt_coupon.value)=="")
		{
			document.getElementById("hdn_coupondetails").value="";
			//function used to calculate the total amount
			funupdateTotal(formname);
			alert("Please enter your coupon code");
			txt_coupon.focus();

		}
		else
		{
			funAjaxForCouponCode(formname);
		}
	}
}

//function used to check and get the coupon details via ajax
function funAjaxForCouponCode(formname)
{
	with(document.forms[formname])
	{
		//unset coupon values
		strGblCpntype="";
		strGblCpnValue=0;
		document.getElementById('lbl_couponmsg').innerHTML= "";
		document.getElementById("hdn_couponamount").value="0";
		CouponCode=trimAll(txt_coupon.value);
		if(CouponCode!="")
		{
			url="../validatecoupon.php?cpncode="+CouponCode;

			//Does URL begin with http?
			if(url.substring(0, 4) != 'http') 
			{
			  url = base_url + url;
			}

			http_req = null;
			if(window.XMLHttpRequest)http_req = new XMLHttpRequest();
			else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

			if(http_req)
			{
				http_req.onreadystatechange = function()
				{
					if(http_req.readyState == 4)
					{
						strGblCpntype="";
						strGblCpnValue=0;

						var strCpnResponseTxt,scan_count;
						var strCpnMsg="",CpnsMinItmCntMsg="";

						//"$cpnvalid\n$CouponType\n$couponDiscountAmont\n$ScanCount";
						strCpnResponseTxt=trimAll(http_req.responseText);

						var arrCpnDetails=strCpnResponseTxt.split("\n");
						arrCpnDetails[0] = trimAll(arrCpnDetails[0]);

						if(arrCpnDetails[0]=="valid")
						{
							strGblCpntype=arrCpnDetails[1];
							strGblCpnValue = arrCpnDetails[2];
							scan_count = arrCpnDetails[3];
							strCpnMsg= arrCpnDetails[4];

							document.getElementById("hdn_coupondetails").value=arrCpnDetails;
							document.getElementById("hdn_couponamount").value="";

							if(!isNaN(scan_count) && parseInt(scan_count)>0)
							CpnsMinItmCntMsg = ", if the item counts exceeds "+scan_count;

							//for gift card	
							if(strGblCpntype=="gift")
							{
								strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>Available balance for this gift card is $'+strGblCpnValue+'</b>';
								document.getElementById("hdn_couponamount").value=strGblCpnValue;
							}
							else if(strCpnMsg=="" || strCpnMsg=="0")
							{
								if(strGblCpntype=="percentage")
								{
									strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>' + strGblCpnValue + "% Discount applicable on total amount "+CpnsMinItmCntMsg+"</b>";	
								}
								else if(strGblCpntype=="item")
								{
									strCpnMsg="<img src='../images/smugmug/tick_mark.jpg'><b>Coupon code is valid and will apply to the items send with this order</b>";
								}
								else if(strGblCpntype=="usd")
								{
									strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>$' +(strGblCpnValue) + " Discount applicable on total amount "+CpnsMinItmCntMsg+"</b>";	
								}
							}
							else if(strCpnMsg!="0")
							{
								strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>'+strCpnMsg +'</b>';
							}

							document.getElementById("lbl_couponmsg").className = "success_messagewhite";
						}
						else
						{
							document.getElementById("lbl_couponmsg").className = "error_message";
							strCpnMsg= "<font color=\"white\"><b>Invalid coupon code.</b></font>";
							document.getElementById("hdn_coupondetails").value="";
							document.getElementById("hdn_couponamount").value="0";
						}

						 if(strCpnMsg!="0")
						document.getElementById("lbl_couponmsg").innerHTML =strCpnMsg;

						//function used to calculate the total amount
						funupdateTotal("frmsmugmugorder");
				   }//http_req.readyState == 4 check ends
				}
				http_req.open("GET",url,true);
				http_req.send("");
			}

		}//CouponCode!="" check ends
		else
		{
			//function used to calculate the total amount
			funupdateTotal(formname);
		}
	}
}

function SmgCouponValidation(formname)
{
	with(document.forms[formname])
	{
		//unset coupon values
		strGblCpntype="";
		strGblCpnValue=0;
		document.getElementById('lbl_couponmsg').innerHTML= "";
		document.getElementById("hdn_couponamount").value="0";

		CouponCode=trimAll(txt_coupon.value);
		if(CouponCode!="")
		{
			url="../validatecoupon.php?cpncode="+CouponCode;

			//Does URL begin with http?
			if(url.substring(0, 4) != 'http') 
			{
			  url = base_url + url;
			}
			
			http_req = null;
			if(window.XMLHttpRequest)http_req = new XMLHttpRequest();
			else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

			if(http_req)
			{
				http_req.onreadystatechange = function()
				{
					if(http_req.readyState == 4)
					{
					  strGblCpntype="";
					  strGblCpnValue=0;

					  var strCpnResponseTxt,scan_count;
					  var strCpnMsg="",CpnsMinItmCntMsg="";

					  //"$cpnvalid\n$CouponType\n$couponDiscountAmont\n$ScanCount";
					  strCpnResponseTxt=trimAll(http_req.responseText);

					  var arrCpnDetails=strCpnResponseTxt.split("\n");	  
					  arrCpnDetails[0] = trimAll(arrCpnDetails[0]);
					  if(arrCpnDetails[0]=="valid")
					  {	
							strGblCpntype=arrCpnDetails[1];
							strGblCpnValue = arrCpnDetails[2];
							scan_count = arrCpnDetails[3];
							strCpnMsg= arrCpnDetails[4];

							document.getElementById("hdn_coupondetails").value=arrCpnDetails;
							document.getElementById("hdn_couponamount").value="";

							if(!isNaN(scan_count) && parseInt(scan_count)>0)
							  CpnsMinItmCntMsg = ", if the item counts exceeds "+scan_count;

							//for gift card	
							if(strGblCpntype=="gift")
							{
								strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>Available balance for this gift card is $'+strGblCpnValue+'</b>';
								document.getElementById("hdn_couponamount").value=strGblCpnValue;
							}
							else if(strCpnMsg=="" || strCpnMsg=="0")
							{
								if(strGblCpntype=="percentage")
								{
									strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>' + strGblCpnValue + "% Discount applicable on total amount "+CpnsMinItmCntMsg+"</b>";	
								}
								else if(strGblCpntype=="item")
								{
									strCpnMsg="<img src='../images/smugmug/tick_mark.jpg'><b>Coupon code is valid and will apply to the items send with this order</b>";
								}
								else if(strGblCpntype=="usd")
								{
									 strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>$' +(strGblCpnValue) + " Discount applicable on total amount "+CpnsMinItmCntMsg+"</b>";	
								}
							}
							else if(strCpnMsg!="0")
							{
								strCpnMsg='<img src="../images/smugmug/tick_mark.jpg"><b>'+strCpnMsg +'</b>';
							}

							funupdateTotal(formname);
							funsubmitdetails(formname);
							document.getElementById("lbl_couponmsg").className = "success_messagewhite";
					}
					else
					{
						document.getElementById("lbl_couponmsg").className = "error_message";			
						strCpnMsg= "<font color=\"white\"><b>Invalid coupon code.</b></font>";
						document.getElementById("hdn_coupondetails").value="";
						document.getElementById("hdn_couponamount").value="0";
						funupdateTotal("frmsmugmugorder");
						alert("Please enter valid coupon code");
						return false;
					}

					if(strCpnMsg!="0")
					document.getElementById("lbl_couponmsg").innerHTML =strCpnMsg;   

						//function used to calculate the total amount
						funupdateTotal("frmsmugmugorder");
					}//http_req.readyState == 4 check ends
				}
				http_req.open("GET",url,true);
				http_req.send("");
			}

		}//CouponCode!="" check ends
		else
		{
			//function used to calculate the total amount
 			funupdateTotal(formname);
			funsubmitdetails(formname);	
		}

	}
}

function funSetOrdrFormCreditCardNumber()
{
	document.getElementById("lbl_cardnum").style.display="none";
	document.getElementById("lbl_cardnumEditLnk").style.display="none";	
	document.getElementById("lbl_cardnumTxtBx").style.display="";
}

function funsubmitdetails(formname)
{
	with(document.forms[formname])
	{
		var objPhotoDvd=document.getElementById("photo_dvd");
		var objPhotoHardDrive=document.getElementById("photo_hardrive");
		var objVideoDvd=document.getElementById("video_dvd");
		var objHardDriveBoth=document.getElementById("hardrive_both");
		var objVideoHardDrive=document.getElementById("video_hardrive");
		var objPhotoOption=document.getElementById("check_photography");
		var objVideoOption=document.getElementById("check_videomovie");
		var objVideoExpertTransfer=document.getElementById("radio_expert");
		
		var ShipPhoneVal=txt_shippingphone.value;
		ShipPhoneVal=ShipPhoneVal.replace(/-/g,"");
		ShipPhoneVal=ShipPhoneVal.replace(/\(/g,"");
		ShipPhoneVal=ShipPhoneVal.replace(/\)/g,"");

		var BillgPhoneVal=txt_billingphone.value;
		BillgPhoneVal=BillgPhoneVal.replace(/-/g,"");
		BillgPhoneVal=BillgPhoneVal.replace(/\(/g,"");
		BillgPhoneVal=BillgPhoneVal.replace(/\)/g,"");

		if(objPhotoOption.checked==false && objVideoOption.checked==false)
		{
			alert("Please select the type of material");
			document.getElementById("firstfocus").focus();
			return false;
		}
		else if(objPhotoOption.checked==true && (objPhotoDvd.checked==false && objPhotoHardDrive.checked==false))
		{
			alert("Please select your photo digital format");
			document.getElementById("id_foci").focus();
			return false;
		}
		else if(objPhotoOption.checked==true && (document.getElementById("media_custom").checked==true && trimAll(txt_custom.value)==""))
		{
			alert("Please enter the title for media");
			txt_custom.focus();
			return false;
		}
		else if(objVideoOption.checked==true && ((objVideoDvd.checked==false && objVideoHardDrive.checked==false && objHardDriveBoth.checked==false)))
		{
			alert("Please select your video digital format");
			document.getElementById("id_foci").focus();
			return false;
		}
		else if((objVideoOption.checked==true && objVideoExpertTransfer.checked==true) && (objHardDriveBoth.checked==false && objVideoHardDrive.checked==false))
		{
			alert("Please select Video Hard Drive media or select use same media for Expert Transfer");
			document.getElementById("id_foci").focus();
			return false;
		}
		else if(trimAll(txt_shippingfname.value)=="")
		{
			alert("Please enter the shipping first name");
			txt_shippingfname.focus();
			return false;
		}
		else if(trimAll(txt_shippingfname.value)!="" && !validateString(trimAll(txt_shippingfname.value.replace(/ /g,""))))
		{
			alert("Please enter the shipping first name in alphabets");
			txt_shippingfname.focus();
			return false;
		}
		else if(trimAll(txt_shippinglname.value)=="")
		{
			alert("Please enter the shipping last name");
			txt_shippinglname.focus();
			return false;
		}
		else if(trimAll(txt_shippinglname.value)!="" && !validateString(trimAll(txt_shippinglname.value.replace(/ /g,""))))
		{
			alert("Please enter the shipping last name in alphabets");
			txt_shippinglname.focus();
			return false;
		}
		else if(trimAll(txt_shippingadd1.value)=="")
		{
			alert("Please enter the shipping addrress");
			txt_shippingadd1.focus();
			return false;
		}
		else if(trimAll(txt_shippingcity.value)=="")
		{
			alert("Please enter the shipping city");
			txt_shippingcity.focus();
			return false;
		}
		else if(trimAll(drpdwn_shippingCountry.value)=="")
		{
			alert("Please select the shipping country");
			drpdwn_shippingCountry.focus();
			return false;
		}
		else if(trimAll(drpdwn_shippingCountry.value)=="US" && trimAll(drpdwn_shippingState.value)=="")
		{
			alert("Please select the shipping state");
			drpdwn_shippingState.focus();
			return false;
		}
		else if(trimAll(drpdwn_shippingCountry.value)!="US" && trimAll(txt_Shipstate.value)=="")
		{
			alert("Please enter the shipping state");
			txt_Shipstate.focus();
			return false;
		}
		else if(trimAll(txt_shippingzip.value)=="")
		{
			alert("Please enter the shipping zipcode");
			txt_shippingzip.focus();
			return false;
		}
		else if(trimAll(txt_shippingzip.value)!="" && validUsCanadaZip(trimAll(txt_shippingzip.value.replace(/-/g,"")),drpdwn_shippingCountry.value)==false)
		{
			alert("Please enter valid Shipping zipcode");
			txt_shippingzip.focus();
			return false;
		}
		else if(trimAll(txt_shippingphone.value)=="")
		{
			alert("Please enter the shipping phone number.");
			txt_shippingphone.focus();
			return false;
		}
		else if(trimAll(txt_shippingphone.value)!="" && validateInteger(ShipPhoneVal)==false)
		{
			alert("Please enter valid Shipping phone number");
			txt_shippingphone.focus();
			return false;
		}
		else if(trimAll(txt_billingfname.value)=="")
		{
			alert("Please enter the billing first name");
			txt_billingfname.focus();
			return false;
		}
		else if(trimAll(txt_billingfname.value)!="" && !validateString(trimAll(txt_billingfname.value.replace(/ /g,""))))
		{
			alert("Please enter the billing first name in alphabets");
			txt_billingfname.focus();
			return false;
		}
		else if(trimAll(txt_billinglname.value)=="")
		{
			alert("Please enter the billing last name");
			txt_billinglname.focus();
			return false;
		}
		else if(trimAll(txt_billinglname.value)!="" && !validateString(trimAll(txt_billinglname.value.replace(/ /g,""))))
		{
			alert("Please enter the billing last name in alphabets");
			txt_billinglname.focus();
			return false;
		}
		else if(trimAll(txt_billingadd1.value)=="")
		{
			alert("Please enter the billing addrress");
			txt_billingadd1.focus();
			return false;
		}
		else if(trimAll(txt_billingcity.value)=="")
		{
			alert("Please enter the billing city");
			txt_billingcity.focus();
			return false;
		}
		else if(trimAll(drpdwn_billingCountry.value)=="")
		{
			alert("Please select the billing country");
			drpdwn_billingCountry.focus();
			return false;
		}
		else if(trimAll(drpdwn_billingCountry.value)=="US" && trimAll(drpdwn_billingState.value)=="")
		{
			alert("Please select the billing state");
			drpdwn_billingState.focus();
			return false;
		}
		else if(trimAll(drpdwn_billingCountry.value)!="US" && trimAll(txt_Blngstate.value)=="")
		{
			alert("Please enter the billing state");
			txt_Blngstate.focus();
			return false;
		}
		else if(trimAll(txt_billingzip.value)=="")
		{
			alert("Please enter the billing zipcode");
			txt_billingzip.focus();
			return false;
		}
		else if(trimAll(txt_billingzip.value)!="" && validUsCanadaZip(trimAll(txt_billingzip.value.replace(/-/g,"")),drpdwn_billingCountry.value)==false)
		{
			alert("Please enter valid Billing zipcode");
			txt_billingzip.focus();
			return false;
		}
		else if(trimAll(txt_billingphone.value)=="")
		{
			alert("Please enter the billing phonenumber");
			txt_billingphone.focus();
			return false;
		}
		else if(trimAll(txt_billingphone.value)!="" && validateInteger(BillgPhoneVal)==false)
		{
			alert("Please enter valid Billing phone number");
			txt_billingphone.focus();
			return false;
		}
		else if(!paymentValidation(formname))
		{
			return false;
		}
		else if(trimAll(hdn_userid.value)=="" && !funCheckLoginInfo(formname))
		{
			return false;
		}
		else if(document.getElementById("check_terms").checked==false)
		{
			alert("Please accept the terms and conditions");
			check_terms.focus();
			return false;
		}
		else
		{
			hdn_mode.value="submit";
			submit();
		}
	}
}

function funShowVideoDetails(formname)
{
	with(document.forms[formname])
	{
		if(document.getElementById("td_VideoMovie").style.display=="")
		{
			document.getElementById("imgvideochkbx").src="../images/smugmug/check_box.jpg";
			document.getElementById("check_videomovie").checked=false;
			document.getElementById("td_VideoMovie").style.display="none";
			document.getElementById("tr_videoOptions").style.display="none";
			document.getElementById("td_videobckgnd").className="tdunselected";
			document.getElementById("hardrive_both").checked=false;
			document.getElementById("img_hardriveforboth").src="../images/smugmug/check_box.jpg";
			document.getElementById("video_hardrive").disabled=false;
			document.getElementById("hdn_videoHDcost").value="0";
			document.getElementById("hdn_videoDVDcost").value="0";
			document.getElementById("video_dvd").checked=false;
			document.getElementById("video_hardrive").checked=false;
			document.getElementById("video_HDdigiformat").style.display="none";
			document.getElementById("video_digiformat").style.display="none";
			document.getElementById("photo_hardrive").disabled=false;
			document.getElementById("radio_expert").checked=false;
			document.getElementById("img_expert").src="../images/smugmug/radio_button1.jpg";

			if(document.getElementById("photo_hardrive").checked==false)
			{
				document.getElementById("tr_pcmac").style.display="none";
				//document.getElementById("tr_myownhardrive").style.display="none";
			}

//			if(document.getElementById("check_photography").checked==false)
//			{
//				document.getElementById("check_photography").checked=true;
//				document.getElementById("imgphotochkbx").src="../images/smugmug/check_box_selected.jpg";
//				document.getElementById("td_photobckgnd").className="tdselected";
//				document.getElementById("tr_photoOptions").style.display="";
//				document.getElementById("td_photobckgnd").style.display="";
//			}

			smgphotodvdcalculation(formname,'HardDrive',0);
			funShowAdditionalAmount(formname);
		}
		else 
		{
			document.getElementById("imgvideochkbx").src="../images/smugmug/check_box_selected.jpg";
			document.getElementById("imgVideoDVD").src="../images/smugmug/check_box.jpg";
			document.getElementById("imgVideoHD").src="../images/smugmug/check_box.jpg";
			document.getElementById("check_videomovie").checked=true;
			document.getElementById("radio_premium").checked=true;
			document.getElementById("img_premium").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("td_premiumcls").className="tdselected";
			document.getElementById("td_expertcls").className="tdunselected";
			document.getElementById("td_VideoMovie").style.display="";
			document.getElementById("tr_videoOptions").style.display="";
			document.getElementById("td_videobckgnd").className="tdselected";
		}
		SameMediaOption(formname);
	}
}

function funShowPhotoDetails(formname)
{
	with(document.forms[formname])
	{
		if(document.getElementById("check_photography").checked==true && document.getElementById("radio_package").checked==false)
		{
			document.getElementById("check_photography").checked=false;
			document.getElementById("imgphotochkbx").src="../images/smugmug/check_box.jpg";
			document.getElementById("tr_photoOptions").style.display="none";
			document.getElementById("td_photobckgnd").style.display="none";
			document.getElementById("td_photobckgnd").className="tdunselected";
			document.getElementById("photo_dvd").checked=false;
			document.getElementById("imgPhotoDVD").src="../images/smugmug/check_box.jpg";
			document.getElementById("photo_hardrive").checked=false;
			document.getElementById("imgPhotoHD").src="../images/smugmug/check_box.jpg";
			document.getElementById("hdn_photoDVDcost").value="0";
			document.getElementById("hdn_photoHDcost").value="0";
			document.getElementById("photo_digiformat").style.display="none";
			document.getElementById("photo_HDdigiformat").style.display="none";
			document.getElementById("hardrive_both").checked=false;
			document.getElementById("video_hardrive").disabled=false;
			document.getElementById("photo_hardrive").disabled=false;
			document.getElementById("img_hardriveforboth").src="../images/smugmug/check_box.jpg";
			document.getElementById("radio_highqlty").checked=false;
			document.getElementById("img_highqlty").src="../images/smugmug/radio_button1.jpg";

			

			if(document.getElementById("video_hardrive").checked==false)
			{
				document.getElementById("tr_pcmac").style.display="none";
				//document.getElementById("tr_myownhardrive").style.display="none";
			}

			funShowAdditionalAmount(formname);
		}
		else if(document.getElementById("radio_package").checked==false)
		{
			//CheckBox Images
			document.getElementById("imgphotochkbx").src="../images/smugmug/check_box_selected.jpg";
			
			/*
			if(document.getElementById("radio_package").checked==true)
			{
				document.getElementById("imgPhotoDVD").src="../images/smugmug/check_box_selected.jpg";
				document.getElementById("imgPhotoHD").src="../images/smugmug/check_box_selected.jpg";
			}*/
			
			document.getElementById("check_photography").checked=true;
			document.getElementById("imgphotochkbx").src="../images/smugmug/check_box_selected.jpg";
			document.getElementById("radio_normalqlty").checked=true;
			document.getElementById("img_normalqlty").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("td_normalcls").className="tdselected";
			document.getElementById("td_highestcls").className="tdunselected";
			document.getElementById("td_photobckgnd").style.display="";
			document.getElementById("tr_photoOptions").style.display="";
			document.getElementById("td_photobckgnd").className="tdselected";
		}
		SameMediaOption(formname);
	}
}

function SameMediaOption(formname)
{
	with(document.forms[formname])
	{
		if(document.getElementById("check_photography").checked==true && document.getElementById("check_videomovie").checked==false)
		{
			document.getElementById("samemedia").style.display="none";
		}
		else if(document.getElementById("check_photography").checked==true && document.getElementById("check_videomovie").checked==true)
		{
			document.getElementById("samemedia").style.display="";
		}
		else if(document.getElementById("check_photography").checked==false && document.getElementById("check_videomovie").checked==true)
		{
			document.getElementById("samemedia").style.display="none";
		}
		else if(document.getElementById("check_photography").checked==false && document.getElementById("check_videomovie").checked==false)
		{
			document.getElementById("samemedia").style.display="none";
		}

	}	
}



/* function used to fill the  billing info same as shipping info */
function funFillBillAddress(formname,CtrlIndx)
{
	with(document.forms[formname])
	{
		var arrSrcCtrlNames =new Array("txt_shippingfname","txt_shippinglname","txt_shippingadd1","txt_shippingadd2","txt_shippingcity","drpdwn_shippingState","drpdwn_shippingCountry","txt_shippingzip","txt_shippingphone","txt_Shipstate");
		var arrDesCtrlNames = new Array("txt_billingfname","txt_billinglname","txt_billingadd1","txt_billingadd2","txt_billingcity","drpdwn_billingState","drpdwn_billingCountry","txt_billingzip","txt_billingphone","txt_Blngstate");
		
		if(chkbx_same.checked ==true)
		{ 
			document.getElementById(arrDesCtrlNames[CtrlIndx]).value =trimAll(document.getElementById(arrSrcCtrlNames[CtrlIndx]).value);
		}

		if(document.getElementById("drpdwn_shippingCountry").value!="US")
		{
			document.getElementById("drpdwn_shippingState").style.display="none";
			document.getElementById("txt_Shipstate").style.display="";
			document.getElementById("ShpngStateLable").innerHTML="<b>State / Province:</b>";
			document.getElementById("SpngzipLbl").innerHTML="<b>Zip / Postal Code:</b>";
			document.getElementById("id_self").onclick();
			OrderFormShpngRateChanges(formname);
		}
		else
		{
			document.getElementById("drpdwn_shippingState").style.display="";
			document.getElementById("txt_Shipstate").style.display="none";
			document.getElementById("ShpngStateLable").innerHTML="<b>State:</b>";
			document.getElementById("SpngzipLbl").innerHTML="<b>Zip Code:</b>";
			OrderFormShpngRateChanges(formname);
		}

		if(document.getElementById("drpdwn_billingCountry").value!="US")
		{
			document.getElementById("drpdwn_billingState").style.display="none";
			document.getElementById("txt_Blngstate").style.display="";
			document.getElementById("blngStateLbl").innerHTML="<b>State / Province:</b>";
			document.getElementById("blngzipLbl").innerHTML="<b>Zip / Postal Code:</b>";
		}
		else
		{
			document.getElementById("drpdwn_billingState").style.display="";
			document.getElementById("txt_Blngstate").style.display="none";
			document.getElementById("blngStateLbl").innerHTML="<b>State:</b>";
			document.getElementById("blngzipLbl").innerHTML="<b>Zip Code:</b>";
		}

		if(trimAll(txt_shippingzip.value)!="" && drpdwn_shippingCountry.value=="US")
		{
			document.getElementById("img_GRND").onclick();
			var ShippingZip=txt_shippingzip.value;
			var zipVal=funCheckZipCode(ShippingZip,formname);
		}
	}
}

function funCheckZipCode(shipingzip,formname)
{
	with(document.forms[formname])
	{
		try
		{
			if(shipingzip!="")
			{
				//Form the string to post
				var strPostRegData="zipcode="+shipingzip;
				url="../checkzip.php";

				//Does URL begin with http?
				if(url.substring(0, 4)!='http')
				{
					url=base_url + url;
				}
				http_req = null;

				if (window.XMLHttpRequest) http_req = new XMLHttpRequest();
				else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");
				if(http_req)
				{
					http_req.onreadystatechange = function()
					{
						if(http_req.readyState==4)
						{
							//Response text is=> yes / no
							var strResponseTxt=http_req.responseText;
							if(strResponseTxt=="yes")
							{
								//document.getElementById("td_drop").style.display="";
								document.getElementById("td_2nd Day Air").style.display="none";
							}
							else
							{
								//document.getElementById("td_drop").style.display="none";
								document.getElementById("td_2nd Day Air").style.display="";
							}
						}
					};
					http_req.open("POST", url, true);
					http_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					http_req.send(strPostRegData);
				}
			}//shipingzip!="" check ends
		}
		catch(err)
		{
			txt="There was an error on this page.\n\n";
			txt+="Error description: " + err.description + "\n\n";
			txt+="Click OK to continue.\n\n";
			//alert(txt);
		}
	}
}


function funFillBilllingAdd(formname)
{
	with(document.forms[formname])
	{
		if(chkbx_same.checked==true)
		{
			txt_billingfname.value = trimAll(txt_shippingfname.value);
			txt_billinglname.value = trimAll(txt_shippinglname.value);
			txt_billingadd1.value  = trimAll(txt_shippingadd1.value);
			txt_billingadd2.value  = trimAll(txt_shippingadd2.value);
			txt_billingcity.value   = trimAll(txt_shippingcity.value);
			drpdwn_billingCountry.value	= trimAll(drpdwn_shippingCountry.value);
			if(drpdwn_shippingCountry.value=="US")
			drpdwn_billingState.value = trimAll(drpdwn_shippingState.value);
			else
			txt_Blngstate.value = trimAll(txt_Shipstate.value);
			txt_billingzip.value	= trimAll(txt_shippingzip.value);
			txt_billingphone.value	= trimAll(txt_shippingphone.value);
		}
		else if(chkbx_same.checked==false)
		{
			txt_billingfname.value="";
			txt_billinglname.value="";
			txt_billingadd1.value="";	
			txt_billingadd2.value="";	
			txt_billingcity.value="";		
			drpdwn_billingState.value="";
			txt_Blngstate.value="";
			drpdwn_billingCountry.value="";
			txt_billingzip.value="";
			txt_billingphone.value="";	
		}
		funChangeBlngCtrl(formname);
	}
}

function funChangeBlngCtrl(formname)
{
	with(document.forms[formname])
	{
		if(document.getElementById("drpdwn_billingCountry").value!="US")
		{
			document.getElementById("drpdwn_billingState").style.display="none";
			document.getElementById("txt_Blngstate").style.display="";
			document.getElementById("blngStateLbl").innerHTML="<b>State / Province:</b>";
			document.getElementById("blngzipLbl").innerHTML="<b>Zip / Postal Code:</b>";
		}
		else
		{
			document.getElementById("drpdwn_billingState").style.display="";
			document.getElementById("txt_Blngstate").style.display="none";
			document.getElementById("blngStateLbl").innerHTML="<b>State:</b>";
			document.getElementById("blngzipLbl").innerHTML="<b>Zip Code:</b>";
		}
	}
}


/* Function used to verify the Details given in the payment is correct */
function paymentValidation(formname)
{
	with(document.forms[formname])
	{
		var hdn_current_date = hdn_currentdate.value;
		var d=new Date(hdn_current_date);
		var current_month = d.getMonth()+1;
		var current_year = d.getFullYear();
		if(funFindRadioBtnSelctn(formname,"radio_cardType",4)==false)
		{
			alert("Please select your card type");
			radio_cardType[0].focus();
			return false;
		}//document.getElementById("lbl_cardnumTxtBx").style.display=="" && 
		else if((trimAll(txt_CreditCardNum.value)=="" || isNaN(txt_CreditCardNum.value)) && document.getElementById("lbl_cardnum").style.display=="none")
		{
			alert("Credit card number must be numeric (no extra spaces)");
			txt_CreditCardNum.focus();
			return false;
		}
		else if(trimAll(txt_CreditCardNum.value)!="")
		{
			validCardNumber = funcValidateCreditCardNum(txt_CreditCardNum.value);
			if(validCardNumber==false)
			{
				alert("Please enter valid credit card number");	
				txt_CreditCardNum.focus();
				return false;
			}
		}
		if(trimAll(drpdwn_CardExprdMonth.value)=="")
		{
			alert("Please select month");
			drpdwn_CardExprdMonth.focus();
			return false;
		}
		else if(trimAll(drpdwn_CardExprdYr.value)=="")
		{
			alert("Please select year");
			drpdwn_CardExprdYr.focus();
			return false;
		}
		else if(current_year > trimAll(drpdwn_CardExprdYr.value))
		{
			alert("Invalid expiration date");
			drpdwn_CardExprdYr.focus();
			return false;
		}
		else if((current_year == trimAll(drpdwn_CardExprdYr.value)) && current_month > trimAll(drpdwn_CardExprdMonth.value))
		{
			alert("Invalid expiration date");
			drpdwn_CardExprdMonth.focus();
			return false;
		}
		else if(trimAll(txt_CVCNum.value)=="")
		{
			alert("Please enter your card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else if(trimAll(txt_CVCNum.value)!="" && !funCheckNumeric(trimAll(txt_CVCNum.value)))
		{
			alert("Please enter valid card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else if(radio_cardType[3].checked==true && parseInt(trimAll(txt_CVCNum.value).length) != 4)
		{
			alert("Please enter correct card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else if (radio_cardType[3].checked !=true && parseInt(trimAll(txt_CVCNum.value).length) != 3)
		{
			alert("Please enter correct card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function funCheckLoginInfo(formname)
{
	with(document.forms[formname])
	{
		if(trimAll(txt_emailaddress.value)=="")
		{
			alert("Please enter the email address");
			txt_emailaddress.focus();
			return false;
		}
		else if(trimAll(txt_emailaddress.value)!="" && !validateEmail(trimAll(txt_emailaddress.value)))
		{
			alert("Please enter valid email address");
			txt_emailaddress.focus();
			return false;
		}
		else if(txt_password.value=="")
		{
			alert("Please enter the password");
			txt_password.focus();
			return false;
		}
		else if(txt_confirmpassword.value=="")
		{
			alert("Please confirm your password");
			txt_confirmpassword.focus();
			return false;
		}
		else if(trimAll(txt_confirmpassword.value)!=trimAll(txt_password.value))
		{
			alert("Your password doesnot matches with the confirm password");
			txt_password.focus();
			return false;
		}
		else
		{
			var email=trimAll(txt_emailaddress.value);
			//Form the string to post
			var strPostRegData="useremail="+email;
			url="ajax_useremail_check.php";

			//Does URL begin with http?
			if(url.substring(0, 4)!='http')
			{
				url=base_url + url;
			}
			http_req = null;
			document.getElementById("loadslide").style.display="";

			if (window.XMLHttpRequest) http_req = new XMLHttpRequest();
			else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");
			if(http_req)
			{
				http_req.onreadystatechange = function()
				{
					if(http_req.readyState==4)
					{
						//Response text is=> yes / no
						var strResponseTxt=http_req.responseText;
						document.getElementById("loadslide").style.display="none";
						if(strResponseTxt == "yes")
						{
							alert("Email address already exists! Please try with some other email.");
							txt_emailaddress.focus();
							return false;
						}
						else
						{
							if(!paymentValidation(formname))
							{
								return false;
							}
							else if(document.getElementById("check_terms").checked==false)
							{
								alert("Please accept the terms and conditions");
								check_terms.focus();
								return false;
							}
							else
							{
								hdn_mode.value="submit";
								submit();
							}
						}
					}
				};				
				http_req.open("POST", url, true);
				http_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http_req.send(strPostRegData);

			}
		}
	}
}

function funCreateAccount(formname)
{
	with(document.forms[formname])
	{
		/*
		if(trimAll(txt_emailaddress.value)=="")
		{
			alert("Please enter the email address");
			txt_emailaddress.focus();
			return false;
		}
		else if(trimAll(txt_password.value)=="")
		{
			alert("Please enter the password");
			txt_password.focus();
			return false;
		}
		else if(trimAll(txt_confirmpassword.value)=="")
		{
			alert("Please confirm your passoword");
			txt_confirmpassword.focus();
			return false;
		}
		else if(trimAll(txt_confirmpassword.value)!=trimAll(txt_password.value))
		{
			alert("Your password doesnot matches with the confirm password");
			txt_password.focus();
			return false;
		}
		else
		{
			var email=trimAll(txt_emailaddress.value);
			//Form the string to post
			var strPostRegData="useremail="+email;
			url="ajax_useremail_check.php";

			//Does URL begin with http?
			if(url.substring(0, 4)!='http')
			{
				url=base_url + url;
			}
			http_req = null;
			document.getElementById("loadslide").style.display="";

			if (window.XMLHttpRequest) http_req = new XMLHttpRequest();
			else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");
			if(http_req)
			{
				http_req.onreadystatechange = function()
				{
					if(http_req.readyState==4)
					{
						//Response text is=> yes / no
						var strResponseTxt=http_req.responseText;
						document.getElementById("loadslide").style.display="none";
						if(strResponseTxt == "yes")
						{
							alert("Email address already exists! Please try with some other email.");
							txt_emailaddress.focus();
							return false;
						}
						else
						{
							windowName="login";
							target=windowName;
							action="create_account.php";
							window.open('create_account.php',windowName,'top=100,left=100,width=400,height=200,resizable=yes,scrollbars=no');
							submit();
						}
					}
				};				
				http_req.open("POST", url, true);
				http_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http_req.send(strPostRegData);

			}
		}
		*/
		windowName="login";
		target=windowName;
		action="create_account.php";
		window.open('create_account.php',windowName,'top=100,left=100,width=500,height=100,resizable=yes,scrollbars=no');
		submit();
		
	}
}


//function used to show the help text when the user clicking on the help image
function funShowHideHelpPopup(strCurHelpId,strImageId,strStepFor,strToDis)
{
	with(document.frmsmugmugorder)
	{
		var strDevelopmentMode="no";
        if(strDevelopmentMode=="no")
		{
			var strDivId="HelpDiv";
			if(strToDis=="")
			{
				//Get the step title image name and find the step number from the image file name
				var strStepSrcFile=document.getElementById(strImageId).src;
				var arrFolders=strStepSrcFile.split("/");
				//var strStepNum=arrFolders[arrFolders.length-1].replace('step_','');
				//strStepNum=strStepNum.replace('.jpg','');
				 
				var strReqHelpTxt="",strTblwidth="350px";
								
				//Get the help text for the given step
				switch(strStepFor)
				{
					case "login":
								strReqHelpTxt="<b>Step1: Account Creation</b><br>This step will create your login information to track the progress of your order while it is being processed and access your free and unlimited gallery.";
								strTblwidth="260px";  
								break;

					case "pricing_plan":
								strReqHelpTxt="<b>Pricing Options</b><br>ScanDigital offers two easy pricing options: 1) Pay per image or 2) Pre-paid All inclusive Pricing.";
								strTblwidth="270px";  
								break;

					case "pricing_package":
								strReqHelpTxt="<b>Please Select Your Package</b>. Packages include all shipping materials, the cost of shipping, all scanning and digital optimization work, an unlimited online gallery and digital archiving on our servers to preserve your images.";
								strTblwidth="220px";  
								break;
					 
					case "box":
								strReqHelpTxt="<b> What Size Box Are You Sending Us?</b><br>We have removed the need for you to count or pre-sort your images, simply estimate the size of box you will be shipping us.";
								strTblwidth="300px";  
								break;
					 
					case "ship":
								if(radio_standard.checked) //standard pricing
								{
									strReqHelpTxt="<b> Select Your Shipping Method</b><br>Please select your preferred shipping method.  By selecting a UPS shipping option, the Dynamic Order Form will generate a pre-paid shipping label for you and you will be able to track your package through our site.";
								}
								else
								{
									strReqHelpTxt="<b>Select Your Shipping Method</b><br>Shipping Materials and labels will be shipped to you by ScanDigital as part of the all-inclusive package you have selected.  Should you wish to self-ship the order, the Dynamic Order Form will automatically deduct $20 from your package price.";
								}
								strTblwidth="300px";
								break;

					case "digipac":
								strReqHelpTxt="<b>DigiPac</b><br>By selecting the DigiPac, ScanDigital will provide you a secure box and all shipping materials needed to safely transport your images from your location to our central facility in Los Angeles.  In addition, with the DigiPac you will receive a pre-paid shipping label to return the package to us.  The DigiPac is ScanDigital's most secure shipping option.";
								strTblwidth="230px";  
								break;

					case "resolution":
								strReqHelpTxt="<b>Select Your Resolution</b><br>Normal Quality is more than sufficient for most customers; however, for those customers wishing to scan their images at a higher resolution we offer our \"Highest\" resolution option.  This option is ideal for our professional clients, as well as individuals wishing to create enlarged reprints from their digital images.";
								strTblwidth="300px";  
								break;

					case "media":
								strReqHelpTxt="<b>My Media</b><br>Select the format you'd like for us to return your materials digitally.";
								strTblwidth="300px";  
								break;

					case "coupon":
								strReqHelpTxt="<b>Coupon/Gift Code</b><br>If you have a coupon code or Gift Card code to redeem, please enter it here and press the apply button.";
								strTblwidth="300px";  
								break;

					case "specialinstructions":
								strReqHelpTxt="<b>Special Instructions</b><br>If you have any instructions or message for your order, please enter into the box provided.";
								strTblwidth="300px";  
								break;

					case "billingprofile":
								strReqHelpTxt="<b>Shipping and  Payment Information</b><br>Please provide your billing and shipping information. Your billing address should match the address on record with your credit card company.";
								strTblwidth="300px";  
								break;

					case "MediaType":
								strReqHelpTxt="<b> What Are You Sending Us?</b><br>Please select the media type that you are going to send us.";
								strTblwidth="300px";  
								break;

					case "payment":
								strReqHelpTxt="<b> Enter your payment information</b><br>";
								if(radio_PricingPlan[0].checked) //standard pricing
								{
									var strSelctedShpng=funGetSelectedBoxShippingValue("ship");
									if(funPlcOrdr_UPSShippingCode_Search(strSelctedShpng)==true)//for ups shippings
									{
										 strReqHelpTxt+="Please provide your credit card information. You will be billed now for UPS shipping. At the end of the process we will charge your card for the scanning and editing work prior to shipping your images back to you.";
									}
									else
									{
										 strReqHelpTxt+="Please provide your credit card information.  You will be billed now for pick-up and our representatives will be in touch shortly to schedule this pick up with you. At the end of the process we will charge your card for the scanning and editing work prior to shipping your images back to you.";
									}
								}
								else
								{
										strReqHelpTxt+="Please provide your credit card information.  As part of our all-inclusive package pricing you will now be billed for all costs associated with your order.  In the case that your image count exceeds the number of images pre-paid with the package, we will simply bill your credit card for the images over the pre-paid count at per image pricing.";
								}
								strTblwidth="300px";
								break;



				}//switch ends

				if(strReqHelpTxt!="")
				{
					strReqHelpTxt="<p class=\"Smugmugnormaltxt\">"+strReqHelpTxt+"</p>";

					var x=findPosX(document.getElementById(strCurHelpId))+20;
					var y=findPosY(document.getElementById(strCurHelpId))+20;
					document.getElementById("HelpDiv").style.width="400";

					//Set table width
					if(strStepFor=="slideshow_timing" || strStepFor=="pricing_package" )
					{
					  x=x-50;
					  strTblwidth="200px";
					}
					else if(strStepFor=="specialinstructions")
					{
						 strTblwidth="200px";
					}
					else if(strStepFor=="payment")
					{
						if(radio_PricingPlan[0].checked)
						{
							strTblwidth="370px";
							x=x+32;
						}
						else
						{
							document.getElementById("HelpDiv").style.width="425";
							strTblwidth="410px";
							y=y-10;
							x=x+40;
						}
					}
					else if(strStepFor=="digipac")
					{
						 strTblwidth="255px";
					}
					else
					{
						 strTblwidth="300px";
					}

					document.getElementById("tbl_helptext").style.width=strTblwidth;
					
					//display <div>
					document.getElementById(strDivId).style.display="";

					//find help image position
					document.getElementById("td_help_text").innerHTML=strReqHelpTxt;

					//assign the possition for help popup
					document.getElementById(strDivId).style.left = x;
					document.getElementById(strDivId).style.top = y;
				}
				else
                   document.getElementById(strDivId).style.display="none";
			}
			else
			{			
			   //document.getElementById(strDivId).innerHTML="&nbsp;";
			   document.getElementById(strDivId).style.display="none";
			}
	   }

   }//with ends
}

//Function called when package type is selected.
function SmgFunPackageOrder(formname,PackageType)
{
	with(document.forms[formname])
	{
		var imgtagid="img"+PackageType;

		//Array contains the package types.
		var arrPackageTypes =new Array("PHOTO#photopackagenormal#photopackageexpert","NEGATIVE#negativepackagenormal#negativepackageexpert","SLIDES#slidespackagenormal#slidespackageexpert","ALBUM#albumpackagenormal#albumpackageexpert");
		
		for(i=0;i<arrPackageTypes.length;i++)//for loop runs to find the selected package.
		{
			var arrPkgDetails=arrPackageTypes[i].split("#");
			var tagname="img"+arrPkgDetails[0];
			var ctrlname="radio_"+arrPkgDetails[0];

			if(imgtagid==tagname)
			{
				//Changes the cntrltype image of the selected package.
				document.getElementById(imgtagid).src="../images/smugmug/radio_button_pricing2.jpg";

				//gets the corresponding package normal and expert resolution amount.
				NormalPackageAmount=document.getElementById("hdn_"+arrPkgDetails[1]).value;
				ExpertPackageAmount=document.getElementById("hdn_"+arrPkgDetails[2]).value;
		
				//Checks the corresponding control.
				document.getElementById(ctrlname).checked=true;

				//Applies the style.
				document.getElementById("pckgid_"+arrPkgDetails[0]).className="tdselected";
			}
			else
			{
				document.getElementById(tagname).src="../images/smugmug/radio_package_unselected.jpg";
				document.getElementById(ctrlname).checked=false;
				document.getElementById("pckgid_"+arrPkgDetails[0]).className="tdunselected";
			}

		}//for loop ends here

		//Checks the Photography resolution quality and sets that corresponding package amount.
		if(document.getElementById("radio_highqlty").checked==true)
		document.getElementById("hdn_packageamount").value=funCheckNumeric(ExpertPackageAmount);
		else
		document.getElementById("hdn_packageamount").value=funCheckNumeric(NormalPackageAmount);

		document.getElementById("id_packagetype").style.display="";
		document.getElementById("packageamount").innerHTML="<b>$"+document.getElementById("hdn_packageamount").value+"</b>";

		funupdateTotal(formname);
	}

}//SmgFunPackageOrder ends here

function SmgfunchangeChkBxImg(formname,imgid,ctrlid)
{
	with(document.forms[formname])
	{
		if((document.getElementById("hardrive_both").checked==true && document.getElementById("photo_hardrive").checked==false)  && (ctrlid=="photo_hardrive" || ctrlid=="video_hardrive"))
		{
			// 
		}
		else if(document.getElementById("hardrive_both").checked==true && document.getElementById("photo_hardrive").checked==true && document.getElementById("video_hardrive").checked==false && ctrlid=="video_hardrive")
		{
			//
		}
		else
		{
			if(document.getElementById(ctrlid).checked==false)
			{
				document.getElementById(ctrlid).checked=true;

				if(imgid=="img_accept")
				document.getElementById(imgid).src="../images/smugmug/checkbox_accept.jpg";
				else
				document.getElementById(imgid).src="../images/smugmug/check_box_selected.jpg";
			}
			else
			{
				document.getElementById(ctrlid).checked=false;
				document.getElementById(imgid).src="../images/smugmug/check_box.jpg";
			}

			if(ctrlid!="check_terms")
			document.getElementById(ctrlid).onclick();
		}
	}
}

function smgChangeRadioButton(formname,type)
{
	with(document.forms[formname])
	{
		if(type=="default")
		{
			document.getElementById("media_default").checked=true;
			document.getElementById("img_mediadefault").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("img_mediacustom").src="../images/smugmug/radio_button_media.jpg";
			document.getElementById("txt_custom").disabled=true;
		}
		else if(type=="custom")
		{
			document.getElementById("media_custom").checked=true;
			document.getElementById("txt_custom").disabled=false;
			document.getElementById("img_mediacustom").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("img_mediadefault").src="../images/smugmug/radio_button_media.jpg";
		}
		else if(type=="pc")
		{
			document.getElementById("id_pc").checked=true;
			document.getElementById("img_pc").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("img_mac").src="../images/smugmug/radio_button_media.jpg";
		}
		else if(type=="mac")
		{
			document.getElementById("id_mac").checked=true;
			document.getElementById("img_mac").src="../images/smugmug/radio_button4.jpg";
			document.getElementById("img_pc").src="../images/smugmug/radio_button_media.jpg";
		}
	}
}

//Opens the price calculator popup
function funopencalculatior()
{
	with(document.frmsmugmugorder)
	{
		if(document.getElementById("radio_standard").checked==true)
			var ordertype="standard";
		else
			var ordertype="package";

		window.open('price_calc.php?ordertype='+ordertype,'prccalwin','top=20,left=150,width=700,height=500,resizable=yes,scrollbars=yes');
	}
}

//Below javascript changes used for "smg_bkuporders.php","smg_bkuporderdet.php"
function funSaveAdminComments(formname,orderid)
{
	try
	{
		with(document.forms[formname])
		{
			var AdminComments=txtarea_OrderComments.value;
			var status=SelStatus.value;
			if(AdminComments!="" || status!="")
			{
				var strPostRegData="orderid="+orderid+"&adcmnts="+AdminComments+"&status="+status;
				url="Ajx_save_admin_comments.php";

				//Does URL begin with http?
				if(url.substring(0, 4)!='http')
				{
					url=base_url + url;
				}
				http_req = null;

				if (window.XMLHttpRequest) http_req = new XMLHttpRequest();
				else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");
				if(http_req)
				{
					http_req.onreadystatechange = function()
					{
						if(http_req.readyState==4)
						{
							//Response text is=> yes / no
							var strResponseTxt=http_req.responseText;
							//alert(strResponseTxt);
							if(strResponseTxt == "yes")
							{
								document.getElementById("update_success").style.display="";
								//alert("Admin Comments have been updated successfully.");
								txtarea_OrderComments.focus();
								return false;
							}
							else
							{
								alert("Here is some problem to update.");
								txtarea_OrderComments.focus();
								return false;
							}
						}
					};				
					http_req.open("POST", url, true);
					http_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					http_req.send(strPostRegData);

				}
			}
//			else
//			{
//				alert("Please enter Admin Comments to update");
//				txtarea_OrderComments.focus();
//				return false;
//			}
		}
	}
	catch(e)
	{
		alert(e);
	}
}

function funDisableTextBox(formname)
{
	try
	{
		with(document.forms[formname])
		{
			if(rd_default.checked)
				txt_custom.disabled=true;
			else if(rd_custom.checked)
				txt_custom.disabled=false;
		}
	}
	catch(e)
	{
		alert(e);
	}
}

function funCalculateAdminAmt(formname,copiesid)
{
	try
	{
		with(document.forms[formname])
		{
			//Initial Values we get it from txt_bx and hidden
			var FltcopiesCnt = parseFloat(document.getElementById(copiesid).value);
			var ActDvdCount = parseFloat(hdn_ActDvdCnt.value);
			var TotDvdCount = parseFloat(hdn_TotDvdCnt.value);
			var NumOfCopies = parseFloat(hdn_NumCopies.value);
			var UserDvdReq = parseFloat(txt_dvdreq.value);
			var SingleDVDCost = parseFloat(hdn_SingleDvdCost.value);
			var AmtChargedFrmUser = parseFloat(hdn_AmtChargedFrmUsr.value);
			var AmtChargedFrmAdmin = parseFloat(hdn_AmtChargedFrmAdmn.value);
			var InitialChargedTotalAmount = parseFloat(hdn_TotalAmount.value);
			var orderstatus = hdn_orderstatus.value;
			//alert(FltcopiesCnt+"<==>"+ActDvdCount+"<==>"+TotDvdCount+"<==>"+NumOfCopies+"<==>"+UserDvdReq+"<==>"+SingleDVDCost+"<==>"+AmtChargedFrmUser+"<==>"+AmtChargedFrmAdmin+"<==>"+InitialChargedTotalAmount);
			//===================================//
			if(FltcopiesCnt<NumOfCopies)
			{
				alert("Please select copies greater than Actual copies");
				//Change the txt_bx values into old one
				document.getElementById(copiesid).value=NumOfCopies;
				//txt_dvdreq.value=TotDvdCount;
				//txt_TotAmnt_ChargedFromCreditcard_Admin.value=AmtChargedFrmAdmin.toFixed(2);
				txt_CreditcardAmnt_Charged_Now.value=AmtChargedFrmAdmin.toFixed(2);
				txt_TotalAmount.value=InitialChargedTotalAmount.toFixed(2);
				//===================================//
				document.getElementById(copiesid).focus();
				return false;
			}
			else
			{
				var DiffAdmnCopies=parseFloat(FltcopiesCnt-NumOfCopies);
				var IncAdmnDvdCount=parseFloat(DiffAdmnCopies*ActDvdCount);
				//txt_dvdreq.value=parseFloat(TotDvdCount+IncAdmnDvdCount);
				var AmtChargedFromAdminEnd=parseFloat(DiffAdmnCopies*SingleDVDCost*UserDvdReq);
				//txt_TotAmnt_ChargedFromCreditcard_Admin.value=AmtChargedFromAdminEnd.toFixed(2);
				txt_CreditcardAmnt_Charged_Now.value=AmtChargedFromAdminEnd.toFixed(2);
				var TotalAmount=InitialChargedTotalAmount+AmtChargedFromAdminEnd;
				txt_TotalAmount.value=TotalAmount.toFixed(2);
			}
		}
	}
	catch(e)
	{
		alert(e);
	}
}

//function used to fill the  billing info same as shipping info
function funFillBillingAddressSmugMug(CtrlIndx)
{		
	var arrSrcCtrlNames=new Array("txt_Shpngfname","txt_Shpnglname","txt_ShpngEmail","txt_Shpngaddress1","txt_Shpngaddress2","txt_Shpngcity","drpdwn_Shpngstate","drpdwn_ShpngCountry","txt_Shpngpostalcode","txt_ShpngPhone");
	var arrDesCtrlNames= new Array("txt_Blngfname","txt_Blnglname","txt_BlngEmail","txt_Blngaddress1","txt_Blngaddress2","txt_Blngcity","drpdwn_Blngstate","drpdwn_BlngCountry","txt_Blngpostalcode","txt_BlngPhone");
	with(document.frmManageSmugMugOrders)
	{
		if(chkbx_UseSameAddress.checked ==true)
		{
			document.getElementById(arrDesCtrlNames[CtrlIndx]).value =trimAll(document.getElementById(arrSrcCtrlNames[CtrlIndx]).value);
		}
	}
}

//billing informations
function funUseBillingAddressSmugMug(formname)
{
	try
	{
		with(document.forms[formname])
		{
			if(chkbx_UseSameAddress.checked ==true)
			{
				txt_Blngfname.value = trimAll(txt_Shpngfname.value);
				txt_Blnglname.value = trimAll(txt_Shpnglname.value);
				txt_BlngEmail.value = trimAll(txt_ShpngEmail.value);
				txt_Blngaddress1.value = trimAll(txt_Shpngaddress1.value);
				txt_Blngaddress2.value = trimAll(txt_Shpngaddress2.value);
				txt_Blngcity.value = trimAll(txt_Shpngcity.value);
				drpdwn_Blngstate.value = trimAll(drpdwn_Shpngstate.value);
				drpdwn_BlngCountry.value = trimAll(drpdwn_ShpngCountry.value);
				txt_Blngpostalcode.value = trimAll(txt_Shpngpostalcode.value);
				txt_BlngPhone.value = trimAll(txt_ShpngPhone.value);
			}
			else  if(chkbx_UseSameAddress.checked ==false)
			{
				txt_Blngfname.value =  "";
				txt_Blnglname.value =  "";
				txt_BlngEmail.value = "";
				txt_Blngaddress1.value = "";
				txt_Blngaddress2.value = "";
				txt_Blngcity.value = "";
				drpdwn_Blngstate.value = "";
				drpdwn_BlngCountry.value ="";
				txt_Blngpostalcode.value = "";
				txt_BlngPhone.value = "";
			}
		}
	}
	catch(e)
	{
		alert(e);
	}
}

//function used to validates the place order form
function funValidateSmgMugOrderDetails(formname,forWhat)
{
	try
	{
		with(document.forms[formname])
		{
			var ShipPhoneVal=txt_ShpngPhone.value;
			ShipPhoneVal=ShipPhoneVal.replace(/-/g,"");
			ShipPhoneVal=ShipPhoneVal.replace(/\(/g,"");
			ShipPhoneVal=ShipPhoneVal.replace(/\)/g,"");

			var BillgPhoneVal=txt_BlngPhone.value;
			BillgPhoneVal=BillgPhoneVal.replace(/-/g,"");
			BillgPhoneVal=BillgPhoneVal.replace(/\(/g,"");
			BillgPhoneVal=BillgPhoneVal.replace(/\)/g,"");
			if(document.getElementById("rd_custom").checked && trimAll(txt_custom.value)=="")
			{
				alert("Please enter media title");
				txt_custom.focus();
				return false;
			}
			else if(trimAll(txt_CreditcardAmnt_Charged_Now.value)=="" || isNaN(trimAll(txt_CreditcardAmnt_Charged_Now.value)))
			{
				alert("Total amount should be numeric");
				//funShow_OrderDetailBox(9);
				txt_CreditcardAmnt_Charged_Now.focus();
				return false;
			}
			else if(trimAll(txt_Shpngfname.value)=="")
			{
				alert("Please enter first name for shipping");
				//funShow_OrderDetailBox(6);
				txt_Shpngfname.focus();
				return false;
			}
			else if(trimAll(txt_Shpngfname.value)!="" && !validateString(trimAll(txt_Shpngfname.value.replace(/ /g,""))))
			{
				alert("Please enter the shipping first name in alphabets");
				txt_Shpngfname.focus();
				return false;
			}
			else if(trimAll(txt_Shpnglname.value)=="")
			{
				alert("Please enter last name for shipping");
				//funShow_OrderDetailBox(6);
				txt_Shpnglname.focus();		 
				return false;
			}
			else if(trimAll(txt_Shpnglname.value)!="" && !validateString(trimAll(txt_Shpnglname.value.replace(/ /g,""))))
			{
				alert("Please enter the shipping last name in alphabets");
				txt_Shpnglname.focus();
				return false;
			}
			else if(trimAll(txt_ShpngEmail.value)=="")
			{
				alert("Please enter email address");
				//funShow_OrderDetailBox(6);
				txt_ShpngEmail.focus();		 
				return false;
			}
			else if(trimAll(txt_ShpngEmail.value)!="" && !validateEmail(txt_ShpngEmail.value))
			{
				alert("Please enter valid email address");
				//funShow_OrderDetailBox(6);
				txt_ShpngEmail.focus();		 
				return false;
			}
			else if(trimAll(txt_Shpngaddress1.value)=="")
			{
				alert("Please enter shipping address");
				//funShow_OrderDetailBox(6);
				txt_Shpngaddress1.focus();
				return false;
			}
			else if(trimAll(txt_Shpngcity.value)=="")
			{
				alert("Please enter shipping city");
				//funShow_OrderDetailBox(6);
				txt_Shpngcity.focus();
				return false;
			}
			else if(trimAll(drpdwn_ShpngCountry.value)=="US" && trimAll(drpdwn_Shpngstate.value)=="")
			{
				alert("Please select shipping state");
				//funShow_OrderDetailBox(6);
				drpdwn_Shpngstate.focus();
				return false;
			}
			else if(trimAll(drpdwn_ShpngCountry.value)=="")
			{
				alert("Please select shipping country");
				//funShow_OrderDetailBox(6);
				drpdwn_ShpngCountry.focus();
				return false;
			}
			else if(trimAll(txt_Shpngpostalcode.value)=="")
			{
				alert("Please enter shipping postal code");
				//funShow_OrderDetailBox(6);
				txt_Shpngpostalcode.focus();
				return false;
			}
			else if(trimAll(txt_Shpngpostalcode.value)!="" && !validateInteger(trimAll(txt_Shpngpostalcode.value)))
			{
				alert("Please enter valid shipping zip code");
				txt_Shpngpostalcode.focus();
				return false;
			}
			else if(trimAll(txt_ShpngPhone.value)=="")
			{
				alert("Please enter shipping phone");
				//funShow_OrderDetailBox(6);
				txt_ShpngPhone.focus();
				return false;
			}
			else if(trimAll(txt_ShpngPhone.value)!="" && !validateInteger(ShipPhoneVal))
			{
				alert("Please enter valid shipping phone number");
				txt_ShpngPhone.focus();
				return false;
			}
			else if(trimAll(txt_Blngfname.value)=="")
			{
				alert("Please enter first name for billing");
				//funShow_OrderDetailBox(6);
				txt_Blngfname.focus();
				return false;
			}
			else if(trimAll(txt_Blngfname.value)!="" && !validateString(trimAll(txt_Blngfname.value.replace(/ /g,""))))
			{
				alert("Please enter the billing first name in alphabets");
				txt_Blngfname.focus();
				return false;
			}
			else if(trimAll(txt_Blnglname.value)=="")
			{
				alert("Please enter last name for billing");
				//funShow_OrderDetailBox(6);
				txt_Blnglname.focus();		 
				return false;
			}
			else if(trimAll(txt_Blnglname.value)!="" && !validateString(trimAll(txt_Blnglname.value.replace(/ /g,""))))
			{
				alert("Please enter the billing last name in alphabets");
				txt_Blnglname.focus();
				return false;
			}
			else if(trimAll(txt_BlngEmail.value)=="")
			{
				alert("Please enter email address");
				//funShow_OrderDetailBox(6);
				txt_BlngEmail.focus();
				return false;
			}
			else if(trimAll(txt_BlngEmail.value)!="" && !validateEmail(txt_BlngEmail.value))
			{
				alert("Please enter valid email address");
				//funShow_OrderDetailBox(6);
				txt_BlngEmail.focus();
				return false;
			}
			else if(trimAll(txt_Blngaddress1.value)=="")
			{
				alert("Please enter billing address");
				//funShow_OrderDetailBox(6);
				txt_Blngaddress1.focus();
				return false;
			}
			else if(trimAll(txt_Blngcity.value)=="")
			{
				alert("Please enter billing city");
				//funShow_OrderDetailBox(6);
				txt_Blngcity.focus();
				return false;
			}
			else if(trimAll(drpdwn_BlngCountry.value)=="US" &&  trimAll(drpdwn_Blngstate.value)=="")
			{
				alert("Please select billing state");
				//funShow_OrderDetailBox(6);
				drpdwn_Blngstate.focus();
				return false;
			}
			else if(trimAll(drpdwn_BlngCountry.value)=="")
			{
				alert("Please select billing country");		
				//funShow_OrderDetailBox(6);
				drpdwn_BlngCountry.focus();
				return false;
			}
			else if(trimAll(txt_Blngpostalcode.value)=="")
			{
				alert("Please enter billing postal code");
				//funShow_OrderDetailBox(6);
				txt_Blngpostalcode.focus();
				return false;
			}
			else if(trimAll(txt_Blngpostalcode.value)!="" && !validateInteger(trimAll(txt_Blngpostalcode.value)))
			{
				alert("Please enter valid billing zip code");
				txt_Blngpostalcode.focus();
				return false;
			}
			else if(trimAll(txt_BlngPhone.value)=="")
			{
				alert("Please enter billing phone");
				//funShow_OrderDetailBox(6);
				txt_BlngPhone.focus();
				return false;
			}
			else if(trimAll(txt_BlngPhone.value)!="" && !validateInteger(BillgPhoneVal))
			{
				alert("Please enter valid billing phone number");
				txt_BlngPhone.focus();
				return false;
			}
			if(forWhat=="completeorder")
			{
				//for credit card
				var CrdtCardTypeSelected =0;
				for (var card=0; card < 4; card++)
				{
					if(radio_cardType[card].checked==true)
					{				
						CrdtCardTypeSelected++;
						break;
					}
				}//for loop ends

				if(CrdtCardTypeSelected == 0)
				{
					alert("Please select your card type");
					//funShow_OrderDetailBox(7);
					radio_cardType[0].focus();
					return false;
				} 
				else if(trimAll(txt_CreditCardNum.value)=="")
				{
					alert("Please enter your credit card number");
					//funShow_OrderDetailBox(7);
					txt_CreditCardNum.focus();
					return false;
				} 			
				else if(trimAll(drpdwn_CardExprdMonth.value)=="")
				{
					alert("Please select month");
					//funShow_OrderDetailBox(7);
					drpdwn_CardExprdMonth.focus();
					return false;
				} 
				else if(trimAll(drpdwn_CardExprdYr.value)=="")
				{
					alert("Please select year");
					//funShow_OrderDetailBox(7);
					drpdwn_CardExprdYr.focus();
					return false;
				} 
				else if(trimAll(txt_CVCNum.value)=="")
				{
					alert("Please enter your card verification number");
					//funShow_OrderDetailBox(7);
					txt_CVCNum.focus();
					return false;
				}
				else if(!paymentValidation(formname))
				{
					return false;
				}
				else
				{
					hdn_mode.value = "completeorder";
					submit();
					return true;
				}
			}
			else
			{
				var ContactName = trimAll(txt_Shpngfname.value)+" "+trimAll(txt_Shpnglname.value);
				var ZipCode  = trimAll(txt_Shpngpostalcode.value);
				var City     = trimAll(txt_Shpngcity.value);
				var State    = trimAll(drpdwn_Shpngstate.value);
				var Country = trimAll(drpdwn_ShpngCountry.value);
				var Address1 = trimAll(txt_Shpngaddress1.value);
				var Address2 = trimAll(txt_Shpngaddress2.value);
				var Phone = trimAll(txt_ShpngPhone.value);
				var CompanyName = trimAll(hdn_UsrcompanyName.value);	
				var OrdrId = trimAll(HidOrderId.value);

				if(CompanyName=="")
				{
					CompanyName=ContactName;
					ContactName = "";
				}
				return false;
			}
		}
	}
	catch(e)
	{
		alert(e);
	}
}

//function used to show the order boxes
function funShow_OrderDetailBox(intBoxIndx)
{
	try
	{
		/*0=>userdetails  ----	1=>ordercomments
		2=>Resolution ----	3=>DigitalFormat
		4=>ShippingMethod ---- 5=>AffiliateInfo
		6=>ShippingAndBilling ---- 7=>PaymentDetails
		8=>PackageDetails ---- 9=>CouponDetails
		*/
		var arrBoxIds=new Array("userdetails","ordercomments","Resolution","DigitalFormat","ShippingMethod","AffiliateInfo","ShippingAndBilling","PaymentDetails","PackageDetails","CouponDetails");
		funShowHideOrderDetails("show",arrBoxIds[intBoxIndx]);
	}
	catch(e)
	{
		alert(e);
	}
}

//function used to show and hide the order form controls
function funShowHideOrderDetails(strProcess,strCtrl)
{
	try
	{
		with(document.frmManageSmugMugOrders)
		{
			if(strProcess=="show")
			{
				//display details
				document.getElementById("box_"+strCtrl).style.display="";

				//hide show button
				document.getElementById("btn_"+strCtrl+"_show").style.display="none";

				//display hide button
				document.getElementById("btn_"+strCtrl+"_hide").style.display="";
			}
			else
			{
				//hide details
				document.getElementById("box_"+strCtrl).style.display="none";

				//display show button
				document.getElementById("btn_"+strCtrl+"_show").style.display="";

				//hide hide button
				document.getElementById("btn_"+strCtrl+"_hide").style.display="none";
			}
		}
	}
	catch(e)
	{
		alert(e);
	}
}

function SmgpaymentValidation(formname)
{
	with(document.forms[formname])
	{
		var hdn_current_date = hdn_currentdate.value;
		var d=new Date(hdn_current_date);
		var current_month = d.getMonth()+1;
		var current_year = d.getFullYear();
		if(funFindRadioBtnSelctn(formname,"radio_cardType",4)==false)
		{
			alert("Please select your card type");
			radio_cardType[0].focus();
			return false;
		}//else if(document.getElementById("lbl_cardnumTxtBx").style.display=="" && (trimAll(txt_CreditCardNum.value)=="" || isNaN(txt_CreditCardNum.value)))
		else if((trimAll(txt_CreditCardNum.value)=="" || isNaN(txt_CreditCardNum.value)))
		{
			alert("Credit card number must be numeric (no extra spaces)");
			txt_CreditCardNum.focus();
			return false;
		}
		else if(trimAll(txt_CreditCardNum.value)!="")
		{
			validCardNumber = funcValidateCreditCardNum(txt_CreditCardNum.value);
			if(validCardNumber==false)
			{
				alert("Please enter valid credit card number");	
				txt_CreditCardNum.focus();
				return false;
			}
		}
		if(trimAll(drpdwn_CardExprdMonth.value)=="")
		{
			alert("Please select month");
			drpdwn_CardExprdMonth.focus();
			return false;
		}
		else if(trimAll(drpdwn_CardExprdYr.value)=="")
		{
			alert("Please select year");
			drpdwn_CardExprdYr.focus();
			return false;
		}
		else if(current_year > trimAll(drpdwn_CardExprdYr.value))
		{
			alert("Invalid expiration date");
			drpdwn_CardExprdYr.focus();
			return false;
		}
		else if((current_year == trimAll(drpdwn_CardExprdYr.value)) && current_month > trimAll(drpdwn_CardExprdMonth.value))
		{
			alert("Invalid expiration date");
			drpdwn_CardExprdMonth.focus();
			return false;
		}
		else if(trimAll(txt_CVCNum.value)=="")
		{
			alert("Please enter your card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else if(trimAll(txt_CVCNum.value)!="" && !funCheckNumeric(trimAll(txt_CVCNum.value)))
		{
			alert("Please enter valid card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else if(radio_cardType[3].checked==true && parseInt(trimAll(txt_CVCNum.value).length) != 4)
		{
			alert("Please enter correct card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else if (radio_cardType[3].checked !=true && parseInt(trimAll(txt_CVCNum.value).length) != 3)
		{
			alert("Please enter correct card verification number");
			txt_CVCNum.focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function funOpenPopup(formname,orderid)
{
	with(document.forms[formname])
	{
		document.getElementById("id_openpopup").href="smg_bkup_print_shipping_form.php?mode=front"+"&orderid="+orderid;
		initLytebox();
		document.getElementById("id_openpopup").onclick();
	}
}


function OrderFormShpngRateChanges(formname)
{
	with(document.forms[formname])
	{
		var arrBoxType=new Array('flatbox','smallbox','mediumbox','largebox');
		var arrindx=0;
		for (i=0;i<arrBoxType.length;i++)//for loop runs to find the selected box type
		{
			var cntrlname="radio_"+arrBoxType[i];	
			if(document.getElementById(cntrlname).checked==true)
			{
				arrindx=i;
			}
		}
		
		//alert(document.getElementById("drpdwn_shippingstate").value);
		//Array contains the Shipping Cost.
		if((document.getElementById("drpdwn_shippingState").value=="HI" || document.getElementById("drpdwn_shippingState").value=="AK") && document.getElementById("drpdwn_shippingState").style.display!="none")
		{
			var ArrShpngPrcs  =new Array([25,55,35,5],
									[25,55,35,5],
									[30,72,42,5],
									[42,100,65,5]);
			//document.getElementById("AK_HI_note").style.display="";
			//document.getElementById("lower48_note").style.display="none";
		}
		else
		{
			var ArrShpngPrcs =new Array([10,45,22,5],
										[10,50,25,5],
										[10,72,42,5],
										[10,95,68,5]);

			//document.getElementById("AK_HI_note").style.display="none";
			//document.getElementById("lower48_note").style.display="";
		}

		document.getElementById("lbl_NextDay").innerHTML="($"+ArrShpngPrcs[arrindx][1]+")";
		document.getElementById("lbl_ground").innerHTML="($"+ArrShpngPrcs[arrindx][0]+")";

		if(document.getElementById("lbl_2ndDay"))
		document.getElementById("lbl_2ndDay").innerHTML="($"+ArrShpngPrcs[arrindx][2]+")";

		//Sets the amount in the hidden.
		document.getElementById("hdn_ground").value=ArrShpngPrcs[arrindx][0];
		document.getElementById("hdn_nextdayair").value=ArrShpngPrcs[arrindx][1];
		document.getElementById("hdn_upssecondday").value=ArrShpngPrcs[arrindx][2];
		document.getElementById("hdn_selfshipping").value=ArrShpngPrcs[arrindx][3];

		funupdateTotal(formname);
	}
}
