
function selectAll() {
	$.each($('.ticket_check'), function(index, item) {
		$(item).attr('checked', true);
	});
}
function unselectAll() {
	$.each($('.ticket_check'), function(index, item) {
		$(item).attr('checked', false);
	});
}
function invertAll() {
	$.each($('.ticket_check'), function(index, item) {
		if ($(item).is(':checked')) {
			$(item).removeAttr('checked');
		}else {
			$(item).attr('checked', true);
		}
	});
}


function getExtraHtml(){

		$.get("Extra.html", {}, function(data) {
					$('#extra').html(data);
				});
}

function emailOffer(name,email,phone,comment){
				
			        var header='<html><table>\n';
					header+="<tr><td align='left'>Marneen,</td></tr>";
					header+="<tr><td align='left'></br></td></tr>";
					header+="<tr><td align='left'>I want to check if you can accept my offer for the following events.</td></tr>";
					header+="<tr><td align='left'></br></td></tr>";
					header+='</table>\n';

					var body='<table border="1">\n';
					
					body+= '<tr bordercolor:"black"> <td bordercolor:"black"> EventName </td> <td bordercolor:"black"> EventDate </td> <td bordercolor:"black"> EventTime </td> <td bordercolor:"black"> City </td> <td bordercolor:"black"> State </td> <td bordercolor:"black"> Section </td> <td bordercolor:"black"> Quantity </td> <td bordercolor:"black"> FacePrice </td> <td bordercolor:"black"> YourPrice </td> <td bordercolor:"black"> Offer Price </td></tr>';
			        
			        
			        $('INPUT[type=checkbox]:checked').each(function(i, checkbox) {
			        	body+='<tr bordercolor:"black">\n'
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[1]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[2]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[3]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[4]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[5]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[6]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[7]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[8]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> ' + $($(checkbox).parent().parent().children()[9]).text() + '</td>\n';
			        	body +='<td bordercolor:"black"> $' + parseFloat($($($(checkbox).parent().parent().children()[10]).children()[0]).val()).toFixed(2) + '</td>\n';
			        	body+='</tr>\n'
			        });
					body+='</table>\n';
					var phoneDetails='';
					if(phone.trim()!=''){
						phoneDetails='<div align="left"> My Contact info is: ' + phone + '</div>';
					}	
					var commentDetails='';
					if(comment.trim()!=''){
						commentDetails='<div align="left"> Additional Comment: ' + comment + '</div>';
					}
					var footer="<table><tr><td align='left'></br></td></tr>";
					footer+="<tr ><td align='left'>Regards</td></tr>";
					footer+="<tr><td align='left'></br></td></tr>";
			 		footer+="<tr ><td align='left' >" + name + ".</td></tr>";
					footer+='</table></html>\n';
					
					var subject="Email Offer From " + name + " <" + email + ">";
					body=header+body+phoneDetails+commentDetails+footer;
					$.ajax({url:'email.php',type:'POST',data:{bodypart:body,name:"Marneen",email:"marneen@aol.com",subject:subject}});

					body='<html><table>\n';
					body+="<tr ><td align='left' >" + name + ",</td></tr>";
					body+="<tr><td align='left'></br></td></tr>";
					body+="<tr ><td>Thanks for making an offer, although I cannot promise that it will be accepted, I will get back to you as soon as possible with an answer. If you need the answer immediately, feel free to call me at 561-400-1808.</td></tr>";
			 		body+="<tr><td align='left'></br></td></tr>";
					body+="<tr ><td align='left'>Regards</td></tr>";
			 		body+="<tr><td align='left'>Marneen.</td></tr>";
					body+='</table></html>\n'
					$.ajax({url:'email.php',type:'POST',data:{bodypart:body,name:name,email:email,subject:"Email Offer - Admitone "}});
			}
			$.strPad = function(i,l,s) {
				var o = i.toString();
				if (!s) { s = '0'; }
				while (o.length < l) {
					o =  o + s;
				}
			return o;
			};
			
			

	function createForm(){
		
		
		var emailDialog = 	$.DIV({id:"emailDialog", title:"Info"}, 
								$.FORM({id:"dialogbox", name:"dialogbox"},
									$.TABLE({},
											$.TR({},
												$.TD({}, 
														"Name"),
												$.TD({}, 
														$.INPUT({type:"text", id:"txtname", name:"txtname" })
												)
											),
											$.TR({},
												$.TD({},
														"Email"),
												$.TD({},
														$.INPUT({type:"text", id:"txtemail", name:"txtemail"})
													)
											),
											$.TR({},
												$.TD({},
														"Phone"),
												$.TD({},
														$.INPUT({type:"text", id:"txtPhone", name:"txtPhone"})
													)
											),
											$.TR({},
												$.TD({},
														"Comment"),
												$.TD({},
														$.TEXTAREA({id:"txtComment", name:"txtComment"})
													)
											)
									)
								)
							);

		$('BODY').append(emailDialog);

		$("#emailDialog").dialog({
	            bgiframe: true,
	            resizable: false,
	            draggable: false,
	            width: 600,
	            height: 300,
	            minHeight: 370,
	            modal: true,
	            autoOpen: false,
	            position: 'center',
	            overlay: {
	                    backgroundColor: '#000',
	                    opacity: 0.5
	            },
	            buttons: {
	                    'Submit': function() {
							$('#dialogbox').submit();						
						},
						
						'Cancel': function() {
							$('#txtname').val('');
							$('#txtemail').val('');
							$('#txtPhone').val('');
							$('#txtComment').val('');
							$(this).dialog('close');
						}
	            },
	            close: function() {
					$("#feedbackDialog").remove();	            	
	            }
	    });

	$("#emailDialog").dialog("open");
	
	// dirty trick
	//$(".ui-dialog").positionCenter();
	$('#dialogbox').validate({
				rules:{
					txtemail:{
						required: true,
						email: true
					},
					txtname:{
						required: true,
						minlength: 3
					},
					txtPhone:{
						minlength: 10,
						number :true
					}
					
				},
				messages: {
					txtemail:{
						required: "Email address is must field.",
						email: "Email address is not valid."
					},
					txtname: {
						required: "Name is must field.",
						minlength: "Name should be of atleast 2 Character."
					},
					txtPhone:{
						minlength : "Enter Valid Phone No.",
						number :"Enter digits only."
					}
				},

				submitHandler: function() {
					var phone=$('#txtPhone').val();
					var comment=$('#txtComment').val();
					emailOffer($('#txtname').val(), $('#txtemail').val(),phone,comment);
					$('#txtname').val('');
					$('#txtemail').val('');
					$('#txtPhone').val('');
					$('#txtComment').val('');
					$('#emailDialog').dialog('close');
				}

			});

	}

