$(function() {
	$("#accordion").accordion({
	header: "h5",
	active: false, 
	autoHeight: false,
	alwaysOpen: false
	});
});
/* ********************************************************************************************** */
function submitlink(linktype, url) {
var linkurl = window.location;
var title = document.title;
var wintitle = title.substr(title.indexOf(": ") + 2);
switch (linktype)
{
case "delicious":
  window.location = "http://del.icio.us/login/?url=" + linkurl + "&title=" + wintitle;
  break;
case "stumbleupon":
 window.location = "http://www.stumbleupon.com/submit?url=" + linkurl + "&title=" + wintitle;
   break;
case "sendtofriend":
 <!--   break; -->
case "forum":
	var gd = gdomain(linkurl);
  document.location.href = gd + url;
  break;
case "newsfeed":
  document.location.href = url;
  break;
case "twitter incontext":
  document.location.href = "http://twitter.com/home/?status=Reading this on InContext " + linkurl;
  break;
case "twitter perceptivesw":
  document.location.href = "http://twitter.com/home/?status=Reading this on Perceptive Software " + linkurl;
  break;
default:
  window.location = url;
}
}
/* ********************************************************************************************** */
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
/* ********************************************************************************************** */
function queryStRef(name, id) {
var getstring = unescape(document.referrer);
var splitval = getstring.split("?");
var getval = name;
jQuery.each(splitval, function(index, item) {
if(index > 0) {
	var endvalue = item.split("&"); 
	jQuery.each(endvalue, function() {
		var varname = this.split("=");
		if(varname[0] == getval) {
		$(id).val(varname[1]);
		}
	});
	}
});
}
/* ********************************************************************************************** */
function commonTemplate(item) {
			return "<option value='" + item.Value + "'>" + item.Text + "</option>"; 
			};
/* ********************************************************************************************** */
function commoncheck(item) {
			return "<li><a href='" + item.Value + "'>" + item.Text + "</a></li>"; 
			};
			
/* ********************************************************************************************** */
function commonMatch(selectedValue) {
			return this.When == selectedValue; 
			};
/* 
Used to get the collection of CaseStudies for the inital 
launch of the page. Also used as the reset for the page
if All is reselected as the Industry
*/
/* ********************************************************************************************** */
function loaddept() {
	$(document).ready(function(){
	
  	var industry = encodeURIComponent($('#industry').val());
  
  	if($('#industry').val() == "All") {
    	$("#caselist").load("/includes/xsl/case-study-list.jsp?Include=Beginning li");
    	$("#caselist1").load("/includes/xsl/case-study-list.jsp?Include=End li");
    	$(".departmentselect").css({"display":"none"});
  	} else {
    	$("#department").load("/includes/xsl/department-list.jsp?Industry=" + industry + " option");
    	$("#caselist").load("/includes/xsl/case-study-list.jsp?Include=Beginning&Industry=" + industry + " li");
    	$("#caselist1").load("/includes/xsl/case-study-list.jsp?Include=End&Industry=" + industry + " li");
    	$(".departmentselect").css({"display":"block"});
  	}
	});
}
/* ********************************************************************************************** */
function loaddept_contactus() {
	$(document).ready(function(){
	
  	var industry = encodeURIComponent($('#Industry').val());
  
    	$("#Department").load("/includes/xsl/contactus-department-list.jsp?Industry=" + industry + " option");
    	$("#OrganizationalArea").load("/includes/xsl/contactus-department-list.jsp?Industry=" + industry + " option");
				});
}
/* ********************************************************************************************** */
/* 
Used to get the collection of CaseStudies based on Industry
and Department
*/
function loadlist() {
  $(document).ready(function(){
  	var industry = encodeURIComponent($('#industry').val());
  	var dept = encodeURIComponent($('#department').val());
  	industry.replace(/ /g, "%20");
  	dept.replace(/ /g, "%20");	
    $(".departmentselect").css({"display":"block"});	

if (dept != null && dept != "All") {
    	$("#caselist").load("/includes/xsl/case-study-list.jsp?Include=Beginning&Industry=" + industry + "&Department=" + dept + " li");
    	$("#caselist1").load("/includes/xsl/case-study-list.jsp?Include=End&Industry=" + industry + "&Department=" + dept + " li");
  	} else {
		
    	industry.replace(/ /g, "%20");
    	dept.replace(/ /g, "%20");
    	
     	$("#caselist").load("/includes/xsl/case-study-list.jsp?Include=Beginning&Industry=" + industry + " li");
    	$("#caselist1").load("/includes/xsl/case-study-list.jsp?Include=End&Industry=" + industry + " li");
  	}
	});
}
/* ********************************************************************************************** */
function set_state() {
$('#State_Province').val($('#states').val());
}

function checkcountry()
{
  	var country = $('#Country').val();
  	country.replace(/ /g, "%20");

		if (country != null) {
			$.get("/includes/xsl/country-list.jsp?Country=" + country, function(data){
			var list = $.trim(data);

				if(list) {
					$('#statesblock').show('fast');
					$("#State_Province").html(list);
					return;
 				} else {
				$('#statesblock').hide('fast');
				}
			 });
		}
}
/* ********************************************************************************************** */
function checkcountrynew()
{
  	var country = encodeURIComponent($('#Country').val());
  	country.replace(/ /g, "%20");

		if (country != null) {
			$.get("/includes/xsl/country-list.jsp?Country=" + country, function(data){
				if(jQuery.trim(data)) {
				    // $('#State_Province').hide('fast');
					$('#statesblock').show('fast');
					$('#states').show('fast');
					$("#states").load("/includes/xsl/country-list.jsp?Country=" + country);
					return;
 				} else {
				// $('#State_Province').show('fast');
				$('#statesblock').hide('fast');
				}
			 });
		}
}
/* ********************************************************************************************** */
function hearus() {
$(document).ready(function() {
if ($('#LeadSourceMostRecent').val() != "Word of Mouth") {
$('#wordquestion').hide('fast');
} else {
$('#wordquestion').show('fast');
}

});
}
/* ********************************************************************************************** */
function hideother() {
$(document).ready(function() {
if ($('#othercheck:checked').val() != undefined) {
$('.otherdata').show('fast');
} else {
$('.otherdata').hide('fast');
$('#othertexterror').hide('fast');
}
});
}
/* ********************************************************************************************** */
function FormReferrer(){
if($('#C_WebSource1') != null){
	$('<input type="hidden" name="C_WebSource1" id="C_WebSource1" value="">').prependTo("form");
}
$('#C_WebSource1').attr("value",document.referrer);
	return;
}
/* ********************************************************************************************** */
$(document).ready(function() {
                FormReferrer();
	// --- language dropdown --- //

	// turn select into dl
	createDropDown();
	
	var $dropTrigger = $(".dropdown dt a");
	var $languageList = $(".dropdown dd ul");
	
	// open and close list when button is clicked
	$dropTrigger.toggle(function() {
		$languageList.slideDown(200);
		$dropTrigger.addClass("active");
	}, function() {
		$languageList.slideUp(200);
		$(this).removeAttr("class");
	});

	// close list when anywhere else on the screen is clicked
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
			$languageList.slideUp(200);
			$dropTrigger.removeAttr("class");
	});

	// when a language is clicked, make the selection and then hide the list
	$(".dropdown dd ul li a").click(function() {
		var clickedValue = $(this).parent().attr("class");
		var clickedTitle = $(this).find("em").html();
		$("#target dt").removeClass().addClass(clickedValue);
		$("#target dt em").html(clickedTitle);
		$languageList.hide();
		$dropTrigger.removeAttr("class");
	});
});
/* ********************************************************************************************** */
	// actual function to transform select to definition list
	function createDropDown(){
		var $form = $("div#country-select form");
		$form.hide();
		var source = $("#country-options");
		source.removeAttr("autocomplete");
		var selected = source.find("option:selected");
		var options = $("option", source);
		$("#country-select").append('<dl id="target" class="dropdown"></dl>')
		$("#target").append('<dt class="' + selected.val() + '"><a href="#"><span class="flag"></span><em>' + selected.text() + '</em></a></dt>')
		$("#target").append('<dd><ul></ul></dd>')
		options.each(function(){
			$("#target dd ul").append('<li class="' + $(this).val() + '"><a href="' + $(this).attr("title") + '"><span class="flag"></span><em>' + $(this).text() + '</em></a></li>');
			});
	}
/* ********************************************************************************************** */
//Contact Us Validation
$(document).ready(function() {
if($("#newcontact").length)
 {
	$("#newcontact").validate({
		errorElement: "div"
	});
};
//Landing page validations - possibly to be used for all forms to be submitted
	if($(".form-ajax").length)
		 {
			$(".form-ajax").validate({
				errorElement: "div",
				submitHandler: function(form) {
					$(form).ajaxSubmit();
					eloquaSubmit();
				}
			});
		}
		if($(".form-normal").length)
		 {
			$(".form-normal").validate({
				errorElement: "div"
			});
		}

});
/* ********************************************************************************************** */
//PRODUCT SUBMISSION SCRIPT
$(document).ready(function() {
if($("#register").length)
 {
	$("#register").validate({
		errorElement: "div",
		submitHandler: function(form) {
			$(form).ajaxSubmit();
			eloquaSubmit();
		}
	});
	//$("form.infieldlabel label").inFieldLabels({ fadeOpacity: 0, fadeDuration: 200 }).css({ "color":"#999" });
	$("form.infieldlabel label").addClass("inline").inFieldLabels({ fadeOpacity: 0, fadeDuration: 200 });
	$("form.infieldlabel input").attr("autocomplete","off");
};
});
/* ********************************************************************************************** */
function eloquaSubmit() {
	var wrapper = "div.form-wrap";
	var thankyou = "div.thankyou";
	var formHeight = $(wrapper).height();
	if ( $('input[name="redirect"]').val() ) {
		var redirect = $('input[name="redirect"]').attr("value");
		$("div.message").addClass("redirect");
		var thankyouHeightRedirect = $(thankyou).height();
		$(wrapper).css({"height":formHeight}).children("form").fadeOut(300, function() {
			$(wrapper).animate({
				height: thankyouHeightRedirect
			}, 400, function() {
				$(thankyou).fadeIn(200).delay(3000).queue(function() {
					window.location.href = redirect;
				});
			});
		});
	} else {
		var thankyouHeight = $(thankyou).height();
		$(wrapper).css({"height":formHeight}).children("form").fadeOut(300, function() {
			$(wrapper).animate({
				height: thankyouHeight
			}, 400, function() {
				$(thankyou).fadeIn(200);
			});
		});
	}
};
/* ********************************************************************************************** */
   	function getjoblistings(dept){
	var url = "http://api.perceptivesoftware.com/hr/northamerica/" + dept + "/list/json";
	var jlisting = "";

	$.ajax({
		  dataType: 'jsonp',
		  url: url,
		  success: function(data) {
		  var careers = [];
		  
			$.each(data, function(i, vals) { 
			careers.push('<li><a class="iframe" href="'+data[i].ApplyNowUrl+'">'+data[i].Title+'</a></li>');
				jlisting = "yes";
			})
						$(".careerlist").html(careers.join(""));
						$(".careerlist").find(".iframe").colorbox({iframe:true, width:"63%", height:"75%", fastIframe:false})
		  }
		});
  };
/* ********************************************************************************************** */
$(document).ready(function () {

    $("#PartnerType").change(function() {

		var fieldset = $(this).parent().parent().attr('id');
    	    	var url="/partners/global-partner-program/partner-type.json";
		var alltype = $("#PartnerType").val();
	   $("#dquestions").html("");
	  	switch (alltype)
			{
			case "Developer Network":
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #developer");
			  break;
			case "Reseller":
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #reseller");
			  break;
			case "OEM":
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #oem");
			  break;
			  default:
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #global");
			  break;
			}
    });
	   getpartnertype("");
})
/* ********************************************************************************************** */
function getpartnertype(ptype) {
	var getparttype = decodeURI(querySt("qs"));
		if(getparttype) {
			var parttype = getparttype;
			$("#PartnerType").val(getparttype);
		} else {
			var parttype = ptype;
		}
		
	switch (parttype)
			{
			case "Developer Network":
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #developer");
			  break;
			case "Reseller":
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #reseller");
			  break;
			case "OEM":
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #oem");
			  break;
			  default:
			  $("#dquestions").load("/partners/global-partner-program/partner-type.html #global");
			  break;
			}
}


