﻿$(window).bind('beforeunload', $.noop);

$(document).ready(function() {		
	
	AddNewsItems();
		
	//$('.sqt-tabs').tabs();

	$('.sqt-tabbed-zone').wpTabify();

	// site specific functions
	var path = window.location.pathname;
	// blogs	
	if(path.indexOf('/blog') >= 0) {	
		HideBlogAuthor(path);
		ShowBlogHeader(path);
		ShowBlogSidebar(path);
		HideBlogAlerts();
	}	
	// products	
	if(path.indexOf('/products/') >= 0) {	
		StyleProductPages();
	}	
	
	// events
	StyleEvents();
	
});

function StyleEvents() {

	$('.sqt-training-audience').parent().parent().addClass('sqt-training-audience-rollup');
	$(".sqt-training-audience-rollup div[id*='audience-id-']").each(function(e) {
		var id = $(this).attr('id').replace('audience-id-','');
		var links = "";
		$('.groupheader').each(function(e) {
			//console.log('"'+$(this).text().trim()+'"="'+id+'"');
			if($(this).text().trim() == id) {
				links = $(this).parent().find('ul').html();
			}
		});
		$(this).html(links);
	});
	
	// tabs
	$('.sqt-grey-tabs').tabs();
	if($('.course-detail').size() > 0) {
		$('.sqt-page-title').text($('.course-detail h2').text());
		$('.course-detail h2').hide();
	}
	
	var courseid = $('.event-page .course-id').text().trim();	
	$('.training-course a').attr('href',"/training/courses/pages/course-detail.aspx?courseid="+courseid);
	
	$('.event-page .course-information').each(function(e) {
		$.ajax({
		  url: "/training/courses/pages/course-detail.aspx?courseid="+courseid,
		  async: false,
		  context: document.body,
		  success: function(data){
		    $('.event-page .course-information').html($(data).find('.course-detail .sqt-grey-tabs'));
		    $('.sqt-grey-tabs').tabs();
		  }
		});
	});

	var instructorid = $('.event-page .instructor-id').text();		
	if(instructorid != null && instructorid != "") {
		GetInstructorInfo(instructorid);
	}	
	
	var locationid = $('.event-page .location-id').text();		
	if(locationid != null && locationid != "") {
		GetLocationInfo(locationid);
	}	

	var audience = $('.event-page .training-audience').text();		
	if(audience != null && audience != "") {
		GetRelatedCourses(courseid, audience);
	}	
	
	if($('.item.sqt-event').size() > 0) {
		// class the event items parent container, for styling
		$('.item.sqt-event').first().parents('.cbq-layout-main > ul.dfwp-list').addClass('sqt-event-wrapper');
		$('.sqt-event-wrapper .groupheader').each(function(e) {
			var markup = $(this).text();			
			markup = markup.substring(markup.indexOf("(")+1, markup.indexOf(")")); 
			$(this).html(markup);
		});
	}
	
	$('.event-icon').click(function(e) {

		var show = true;
		
		if($(this).hasClass('off')) {
			$(this).removeClass('off');
		}
		else {
			$(this).addClass('off');
			show = false;			
		}
		var filter = "";
		if($(this).hasClass('training-event')) {
			filter = "SusQtechTrainingClass";
		}	
		else if($(this).hasClass('webinar-event')) {
			filter = "SusQtechWebinar";		
		}	
		else if($(this).hasClass('community-event')) {
			filter = "SusQtechCommunityEvent";		
		}	
		else if($(this).hasClass('conference-event')) {
			filter = "SusQtechConference";		
		}	
		
		if(show) {
			$('.'+filter).show();
		}
		else {
			$('.'+filter).hide();		
		}

	});
	
	
	// fix event dates, if not in edit mode	
	if($('.sqt-event-date').size() > 0 && $('.sqt-event-date input').size() == 0) {	
					
			$('.sqt-event-date').each(function(i){						
				var sd = new Date($(this).find('.start-date').text());
				var ed = new Date($(this).find('.end-date').text());

				var dateString = "";

				var ampm;
				var h = parseInt(sd.getHours());
				if(h > 12) {
					ampm = "PM";
					h = h - 12;
				}
				else {
					ampm = "AM";
				}
				
				var min = sd.getMinutes();
				if(min.toString().length == 1) {
					min = "0" + min.toString();
				}				
				/*
				if($('.ms-welcomeMenu a.ms-menu-a').size() <= 0) {
					if(h+4 > 12) {
						ampm = "PM";
						h = h - 12;
					}
					else {
						ampm = "AM";
					}
				
					dateString = (sd.getMonth()+1)+"/"+sd.getDate()+"/"+sd.getFullYear()+" "+(h+4)+":"+min+" "+ampm+ " to "; 				
				}
				else {
				*/
					dateString = (sd.getMonth()+1)+"/"+sd.getDate()+"/"+sd.getFullYear()+" "+h+":"+min+":"+ampm + " to ";
				/*}*/
				
				var h = parseInt(ed.getHours());
				var ampm;
				if(h > 12) {
					ampm = "PM";
					h = h - 12;
				}
				else {
					ampm = "AM";
				}
				
				var min = ed.getMinutes();
				if(min.toString().length == 1) {
					min = "0" + min.toString();
				}
				

				/*if($('.ms-welcomeMenu a.ms-menu-a').size() <= 0) {
					if(h+4 > 12) {
						ampm = "PM";
						h = h - 12;
					}
					else {
						ampm = "AM";
					}

					if(sd.getFullYear() == ed.getFullYear() && sd.getMonth() == ed.getMonth() &&
						sd.getDay() == ed.getDay()) {
						dateString += (h+4)+":"+min+" "+ampm; 							
					}
					else {
						dateString += (ed.getMonth()+1)+"/"+ed.getDate()+"/"+ed.getFullYear()+" "+(h+4)+":"+min+" "+ampm; 
					}										
				}
				else {
				*/
					if(sd.getFullYear() == ed.getFullYear() && sd.getMonth() == ed.getMonth() &&
						sd.getDay() == ed.getDay()) {
						dateString += h+":"+min+" "+ampm; 							
					}
					else {					
						dateString += (ed.getMonth()+1)+"/"+ed.getDate()+"/"+ed.getFullYear()+" "+h+":"+min+":"+ampm;
					}				
				/*}*/
																
				$(this).text(dateString); 
			});			
		}

}

var product;

function StyleProductPages() {
	try {
		if($('.ms-formfieldvaluecontainer').size() == 0 && $('#product').size() > 0) {		
			
			// top tabs
			$('#product-top-tabs').tabs();					
			
			// bottom tabs
			$('#product-bottom-tabs').tabs();
			
			product = $('#product-title').text().trim();
			
			// contact form
			/*$('.product-contact-form-input').focusin(function(e) {
				if($(this).val().toLowerCase() == $(this).attr('title')) {
					$(this).val('');
					$(this).css('color','#666666');
				}
			});
			$('.product-contact-form-input').focusout(function(e) {
				if($(this).val().toLowerCase() == '') {
					$(this).val($(this).attr('title'));
				}
			});
			$('#btnProductContactSubmit').click(function(e) {
				var name = $('#tbxProductContactName').val();
				var phone = $('#tbxProductContactPhone').val();
				var email = $('#tbxProductContactEmail').val();
				var valid = true;
				if(name.toLowerCase() == "" || name.toLowerCase() == "name") {
					$('#tbxProductContactName').css('color','#EC6C0E');
					valid = false;
				}
				if(phone.toLowerCase() == "" || phone.toLowerCase() == "phone") {
					$('#tbxProductContactPhone').css('color','#EC6C0E');
					valid = false;
				}
				if(email .toLowerCase() == "" || email.toLowerCase() == "email") {
					$('#tbxProductContactEmail').css('color','#EC6C0E');
					valid = false;
				}
				if(valid) {
					// submit form
				   $().SPServices({
				        operation: "UpdateListItems",
				        async: false,
				        batchCmd: "New",
				        listName: "Sales Contact Form",
				        valuepairs: [["Title", name], ["Phone", phone], ["Email", email]],
				        completefunc: function(xData, Status) {
				         	$('#product-contact-form-inner').text('Thank you for submitting the contact form. A SusQtech SharePoint Product Expert will contact your shortly.');
				        }
				    });				
				}
			});*/						

			ProcessProductScreenshots();
			ProcessProductVideos();
			ProcessProductReviews();
					
		}
		else {
			// edit mode style accordingly		
			$('div[id*=product]').addClass('edit-mode');
		}
	}
	catch(e) {}

}

function ProcessProductReviews() {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/products",
		async: false,
		CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Review' /></ViewFields>",
		listName: "SusQtechProductReviews",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+product+"</Value></Eq></Where></Query>",    
		CAMLRowLimit: "20",
		completefunc: function(xData,Status) {
		
			var review = "";
			
			$("#product-reviews .tab-content-inner").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function(i) {
		
		    	review = $(this).attr("ows_Review");		    	
		    					    	
		        if(review != null) {
					$("#product-reviews .tab-content-inner").append(''+
						'<div>'+review+'</div>');						
				}
														
		    });				    								         
   		}
	}); 
		
	
	// hide empty review tabs
	if($("#product-reviews .tab-content-inner").html().trim() == '') {
		$("#product-reviews").hide();
		$("a[href='#product-reviews']").parent().hide();
	}
	
}


function ProcessProductVideos() {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/products",
		async: true,
		listName: "SusQtechProductVideos",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+product+"</Value></Eq></Where></Query>",    
		CAMLRowLimit: "20",
		completefunc: function(xData,Status) {
		
			var image = "";
			var thumb = "";
			var ext = "";					
			var file = "";
			var title = "";
			var description = "";
			
			$("#product-videos .tab-content-inner").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function(i) {
		
		    	file = $(this).attr("ows_VideoUrl").split(',')[0];	
		    	thumb = $(this).attr("ows_VideoThumbnail");
		    	title = $(this).attr("ows_Title");        	
		    	description = $(this).attr("ows_VideoDescription");		    	
		    					    	
		        if(image != null) {
					$("#product-videos .tab-content-inner").append(''+
						'<a class="product-video" title="'+description+'" href="#video-'+i+'">'+thumb+'<img src="/Style Library/susqtech-2010/i/product-video-overlay.png" class="video-overlay" /></a>'+
						'<div style="display:none;"><div id="video-'+i+'">'+												
						'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
							'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#4,0,0,0" '+
							'width="640" height="480" id="player-'+i+'" name="player-'+i+'">'+
							   '<param name="SRC" value="/Style Library/susqtech-2010/player.swf" />'+
							   '<param name="allowfullscreen" value="true" />'+
							   '<param name="allowscriptaccess" value="always" />'+
							   '<param name="flashvars" value="file='+file+'" />'+						
							'<embed '+
								'src="/Style Library/susqtech-2010/player.swf" '+
								'data="/Style Library/susqtech-2010/player.swf" '+
								'width="640" '+
								'height="480" '+
								'wmode="transparent" '+
								'allowfullscreen="true" '+
								'allowscriptaccess="always" '+								
								'flashvars="file='+file+'&autostart=false" /></object>'+
						'</div></div>');						
				}
														
		    });				    		
		    
			$('a.product-video').fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'cyclic'		: 	false,
				'showNavArrows'	:	true,
				'overlayShow'	:	false				    
	    	});
	    	
			// hide empty video tabs			
			if($("#product-videos .tab-content-inner").html().trim() == '') {
				$("#product-videos").hide();
				$("a[href='#product-videos']").parent().hide();
			}	    							         
   		}
	}); 	
	
	
}

function GetRelatedCourses(courseID, trainingAudience) {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/",
		async: true,
		listName: "Training Courses",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='Training_x0020_Audience' /><Value Type='Lookup'>"+trainingAudience+"</Value></Eq></Where>"+
						"<OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>"+
					"</Query>",
		completefunc: function(xData,Status) {
		
			var title = "";
			var benefits = "";
			var id = "";
			var markup = "";				
			
			$(".event-page .related-course-information").html('<h3>Related Courses</h3>');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
						
		    	title = $(this).attr("ows_Title");		    	
		    	id = $(this).attr("ows_ID");		    			    							
		    	benefits = $(this).attr("ows_Benefits");		    			    									    	
		    	
		    	if(id != courseID) {
		    	
				    markup += '<div class="related-course-title field"><a href="/training/courses/Pages/Course-Detail.aspx?courseid='+id+'">'+title+'</a></div>';
   				    markup += '<div class="related-course-benefits field">'+benefits+'</div>';
				    $(".event-page .related-course-information").append(markup);
				    markup = "";
			    }
		    });				 		    		    
		}
	}); 			
}


function GetInstructorInfo(id) {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/",
		async: true,
		listName: "Training Instructors",
		CAMLViewFields: "<ViewFields><FieldRef Name='Bio' /><FieldRef Name='FullName' />"+
			"<FieldRef Name='EMail' /><FieldRef Name='InstructorImage' /><FieldRef Name='JobTitle' />"+
			"<FieldRef Name='WebPage' />"+
			"</ViewFields>",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>"+id+"</Value></Eq></Where></Query>",
		completefunc: function(xData,Status) {
		
			var fullname = "";
			var email = "";
			var image = "";					
			var jobtitle = "";
			var bio = "";
			var webpage = "";
			var instructorMarkup = "";
			
			$(".event-page .instructor-info").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
						
		    	fullname = $(this).attr("ows_FullName");		    	
		    	email = $(this).attr("ows_EMail");		    			    							
		    	image = $(this).attr("ows_InstructorImage");		    	
		    	jobtitle = $(this).attr("ows_JobTitle");        	
		    	bio = $(this).attr("ows_Bio");        	
		    	webpage = $(this).attr("ows_WebPage").split(',')[0];		    	
		    					    					
		    });				 
		    
			if(fullname != null && fullname != "") {
		    
			    instructorMarkup += '<div class="instructor-image">'+image+'</div>';
			    instructorMarkup += '<div class="instructor-info-right"><div class="instructor-name">'+fullname+'</div>';
			    instructorMarkup += '<div class="instructor-jobtitle">'+jobtitle+'</div>';		    		    
	   		    instructorMarkup += '<div class="instructor-email"><a href="mailto:training@susqtech.com">email</a></div>';
			    instructorMarkup += '<div class="instructor-webpage"><a href="'+webpage+'">blog</a></div></div>';
			    instructorMarkup += '<div class="instructor-bio">'+bio+'</div><div class="clear"></div>';		       		    
		    }
		    else {
		    	instructorMarkup += 'An instructor has not been assigned to this class.';
		    }
		    $(".event-page .instructor-info").html(instructorMarkup);
		}
	}); 			
}

function GetLocationInfo(id) {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/",
		async: true,
		listName: "Training Locations",
		CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Address' /><FieldRef Name='Directions' />"+
			"</ViewFields>",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>"+id+"</Value></Eq></Where></Query>",
		completefunc: function(xData,Status) {
		
			var title = "";
			var address = "";
			var locationMarkup = "";				
			var directions = "";
			
			$(".event-page .location-info").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
						
		    	title = $(this).attr("ows_Title");		    	
		    	address = $(this).attr("ows_Address");		    			    							
		    	directions = $(this).attr("ows_Directions");
		    	if(directions != null && directions != "") {
			    	directions = '<a href="'+directions.split(',')[0]+'">'+ directions.split(',')[1]+'</a>';
			    }	
		    					    					
		    });				    				         
		    
		    if(address != null && address != "") {
		    
			    locationMarkup += '<div class="location-title field">'+title+'</div>';
			    locationMarkup += '<div class="location-address field">'+address+'</div>';		    		    
			    locationMarkup += '<div class="location-address field">'+directions+'</div>';		    
			    		    			    
			    try {
			    
					var map = new GMap2(document.getElementById("map_canvas"));
					var geocoder = new GClientGeocoder();
					
					function showAddress(address) {
					  geocoder.getLatLng(
					    address,
					    function(point) {
					      if (!point) {
					        alert(address + " not found");
					      } else {
					        map.setCenter(point, 13);
					        var marker = new GMarker(point);
					        map.addOverlay(marker);
					
					        // As this is user-generated content, we display it as
					        // text rather than HTML to reduce XSS vulnerabilities.
					        //marker.openInfoWindow(document.createTextNode(address));
					      }
					    }
					  );
					}
					showAddress(address);
				}
				catch(err) {}	    
				
			}
			else {
			    locationMarkup += '<div class="location-address field">'+directions+'</div>';
		    	// hide map
		    	$('#map_canvas').hide();		   
			}
			
			$(".event-page .location-info").html(locationMarkup);
		}
	}); 		

}

function ProcessProductScreenshots() {

	$().SPServices({
		operation: "GetListItems",
		webURL: "/products",
		async: true,
		listName: "SusQtechProductScreenshots",
		CAMLQuery:	"<Query><Where><Eq><FieldRef Name='SusQtechProducts' /><Value Type='Choice'>"+product+"</Value></Eq></Where></Query>",    
		CAMLRowLimit: "20",
		completefunc: function(xData,Status) {
		
			var image = "";
			var thumb = "";
			var ext = "";					
			var file = "";
			var title = "";
			var description = "";
			
			$("#product-screenshots .tab-content-inner").html('');
			
		    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
		
		    	image = $(this).attr("ows_RequiredField").toLowerCase();
		    	ext = $(this).attr("ows_DocIcon").toLowerCase();	
		    	file = $(this).attr("ows_NameOrTitle").toLowerCase();	
		    	thumb = image.replace(file,'_t/'+file.replace('.'+ext,'_'+ext+'.jpg'));
		    	title = $(this).attr("ows_Title")+"";        	
		    	description = $(this).attr("ows_Description");        	
		    					    	
		        if(image != null) {
					$("#product-screenshots .tab-content-inner").append('<a class="product-screenshot" title="'+description+'" href="/'+image+'"><img src="/'+thumb+'" /></a>');
				}
				
		    });				    				         
		    $("a.product-screenshot").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'cyclic'		: 	false,
				'showNavArrows'	:	true,
				'overlayShow'	:	false				    
		    });
		    
			// hide empty video tabs			
			if($("#product-screenshots .tab-content-inner").html().trim() == '') {
				$("#product-screenshots").hide();
				$("a[href='#product-screenshots']").parent().hide();
			}
		    
		}
	}); 		
		

}

function ShowBlogSidebar(path) {
	try {
		// show sidebar if on a blog page
		if(path.indexOf('http://www.susqtech.com/blogs/ui') >= 0 ||
			path.indexOf('http://www.susqtech.com/blogs/dev') >= 0) {
			$('div.sqt-main').css('background','#E9E7DB');
			$('div.sqt-main').css('width','818px');
			$('div.sqt-main-footer').css('background','url("/Style Library/susqtech-2010/i/page-sidebar-wide.png") repeat-y scroll left top transparent');
			$('.ms-blogRightZone table:first').wrap('<div class="blog-sidebar-inner">');
			$('.blog-sidebar-inner').wrap('<div class="blog-sidebar">');
		}
	}
	catch(e) {}
}
function HideBlogAlerts() {
	$('.ms-blogrss').each(function() {
	
		if($(this).attr('id') != "BlogRSSMain") {			
			$(this).hide();
		}
	});
}

function ShowBlogHeader(path) {
	try {
		// show blog header if in the blog site
		if(path.indexOf('http://www.susqtech.com/blogs') >= 0) {
			$('h1.sqt-logo a').addClass('blog-logo');
			$('h1.sqt-logo').addClass('sqt-logo-blog');
		}
	}
	catch(e) {}
}

function HideBlogAuthor() {
	try {
		$('a[href*=/_layouts/userdisp.aspx?ID=]').each(function() {
			$(this).parent().html($(this).text());
		});
		$('div.ms-CommentFooter nobr span').each(function() {
			if($(this).text() == "System Account") {
				$(this).text('Anonymous');
			}
		});
	}
	catch(e) {}
}

function AddNewsItems() {	


  $().SPServices({
    operation: "GetListItems",
    webURL: "/about/news",
    async: true,
    listName: "Pages",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='ArticleStartDate' /><FieldRef Name='ows_FileLeafRef' /></ViewFields>",
    CAMLQuery:	"<Query><Where><IsNotNull><FieldRef Name='ArticleStartDate' /></IsNotNull></Where><OrderBy><FieldRef Name='ArticleStartDate' Ascending='False' /></OrderBy></Query>",    
    CAMLRowLimit: "5",
    completefunc: function(xData,Status) {
    
    	var url = "";
    	var news = "";
		var title = "";
		var articleDate = "";
		
        $(xData.responseXML).find("z\\:row").each(function() {

        	url = 'about/news/pages/' + $(this).attr("ows_FileLeafRef").split('#')[1];
        	title = $(this).attr("ows_Title");        	
        	articleDate = $(this).attr("ows_ArticleStartDate");        	
        	
        	
	        if(articleDate != null) {
            	news += '<li><a href="/' + url + '">' + title + '</a></li>';            
			}           
			
        });
        
        $(".sqt-footer-news").append('<ul>'+news+'</ul>');     
    }
  });        
}

function AddContactFormItem() {
	var fullname = $('#contact-form-name').val();
	var email = $('#contact-form-email').val();
	var message = $('#contact-form-message').val();
	
	if(fullname == "") {
		$('#contact-form-name').addClass('form-highlight');
	}
	else {
		$('#contact-form-name').removeClass('form-highlight');
	}
	if(email == "") {
		$('#contact-form-email').addClass('form-highlight');
	} 
	else { 
		$('#contact-form-email').removeClass('form-highlight'); 
	}		
	if(message == "") {
		$('#contact-form-message').addClass('form-highlight');
	}	
	else { 
		$('#contact-form-message').removeClass('form-highlight'); 
	}
	
	if(fullname != "" && email != "" && message != "") {
	    var batch =
	        "<Batch OnError=\"Continue\"> \
	            <Method ID=\"1\" Cmd=\"New\"> \
	                <Field Name=\"FullName\">" + fullname + "</Field> \
	                <Field Name=\"EMail\">" + email + "</Field> \
	                <Field Name=\"Message\">" + message + "</Field> \
	            </Method> \
	        </Batch>";
	
	    var soapEnv =
	        "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
	        <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \
	            xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \
	            xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
	          <soap:Body> \
	            <UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> \
	              <listName>ContactForm</listName> \
	              <updates> \
	                " + batch + "</updates> \
	            </UpdateListItems> \
	          </soap:Body> \
	        </soap:Envelope>";
	
	    $.ajax({
	        url: "/_vti_bin/lists.asmx",
	        beforeSend: function(xhr) {
	            xhr.setRequestHeader("SOAPAction",
	            "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
	        },
	        type: "POST",
	        dataType: "xml",
	        data: soapEnv,
	        complete: processResult,
	        contentType: "text/xml; charset=utf-8"
	    });
    }

	function processResult(xData, status) {

		$('#contact-form').hide();

	    if(status == "success") {	    
	    	$('#contact-form-success').show();
	    }
	    else {
	    	$('#contact-form-fail').show();	    
	    }
	}        
}

(function($){
	$.fn.wpTabify = function(){
		if($('.ms-WPAddButton').size() == 0){
			return this.each(function(i){
				var tabList = $('<ul class="wpt-ui-tabs-nav"/>');
				var panels = $('<div class="wpt-ui-tabs-wrapper"/>');
				$(this).find('.s4-wpTopTable,td[id^="MSOZoneCell_"] > table').each(function(j){
					$(tabList).append('<li><a href="#ui-tab-panel' + i + j + '">' + $(this).find('h3.ms-WPTitle').text() + '</a></li>');
					var thisPanel = $('<div id="ui-tab-panel' + i + j + '" class="wpt-ui-tabs-panel"/>');
					var panelContents = $(this).detach();
					$(thisPanel).append($(panelContents).find('.ms-WPBody').html());
					$(panels).append(thisPanel);
				});
				if($(tabList).find('li').size() > 0){
					$(this).prepend(panels);
					$(this).prepend(tabList);
					$(this).tabs();
				}
			});
		}
		else{
			return false;
		}
	};
})(jQuery);

function FixRibbonAndWorkspaceDimensions(){
	ULSxSy:;
	g_frl = true;
	var elmRibbon = GetCachedElement("s4-ribbonrow");
	var elmWorkspace = GetCachedElement("s4-workspace");
	var elmTitleArea = GetCachedElement("s4-titlerow");
	var elmBodyTable = GetCachedElement("s4-bodyContainer");
	if(!elmRibbon || !elmWorkspace || !elmBodyTable){
	return;
	}
	if (!g_setWidthInited){
	var setWidth = true;
	if (elmWorkspace.className.indexOf("s4-nosetwidth") > -1)
	  setWidth = false;
	g_setWidth = setWidth;
	g_setWidthInited = true;
	}
	else{
	var setWidth = g_setWidth;
	}
	var baseRibbonHeight = RibbonIsMinimized() ? 44 : 135;
	var ribbonHeight = baseRibbonHeight + g_wpadderHeight;
	if(GetCurrentEltStyle(elmRibbon, "visibility") == "hidden"){
	ribbonHeight = 0;
	}
	
	// Override default resizing behavior
	// -- adds padding to the top of the "s4-workspace" <div> if the ribbon exists and has content
	// -- allows the ribbon to be positioned using CSS instead of JavaScript (more accessible)
	// -- checks to see if the page is inside a "no-ribbon" dialog
	if(elmRibbon.children.length > 0 && document.getElementsByTagName("html")[0].className.indexOf('ms-dialog-nr') == -1){
	elmWorkspace.style.paddingTop = ribbonHeight + 'px';
	}
}	

