//POPUP PLUGIN STARTS HERE//
var checkgdid;
var checksenddocgdid;
(function($){ 		  
	$.fn.popupWindow = function(instanceSettings){
		
		return this.each(function(){
		
		$(this).click(function(){
		
		$.fn.popupWindow.defaultSettings = {
			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
			height:500, // sets the height in pixels of the window.
			left:0, // left position when the window appears.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			width:500, // sets the width in pixels of the window.
			windowName:null, // name of window set from the name attribute of the element that invokes the click
			windowURL:null, // url used for the popup
			top:0, // top position when the window appears.
			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
		};
		
		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
		
		var windowFeatures =    'height=' + settings.height +
								',width=' + settings.width +
								',toolbar=' + settings.toolbar +
								',scrollbars=' + settings.scrollbars +
								',status=' + settings.status + 
								',resizable=' + settings.resizable +
								',location=' + settings.location +
								',menuBar=' + settings.menubar;

				settings.windowName = this.name || settings.windowName;
				settings.windowURL = this.href || settings.windowURL;
				var centeredY,centeredX;
			
				if(settings.centerBrowser){
						
					if ($.browser.msie) {//hacked together for IE browsers
						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
					}else{
						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
					}
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else if(settings.centerScreen){
					centeredY = (screen.height - settings.height)/2;
					centeredX = (screen.width - settings.width)/2;
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else{
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
				}
				return false;
			});
			
		});	
	};
})(jQuery);
//POPUP FUNCTION ENDS HERE//
try{
	var old_switch_country = switchCountry;
}catch(err){
}
switchCountry = function(country){
	switch(country){
		case 'EN' : location.href= "http://test-en.oboulo.com/?lang=en";
					break;
		case 'PT' : location.href= "http://test-pt.oboulo.com/?lang=pt";
					break;
		default: location.href= "http://test-fr.oboulo.com/?lang=fr";
	}
}
try{
	var old_swapy = swapy;
}catch(err){
}
swapy = function(_id,_doc, page, start, subject, type, lang, order, sort, ratio ){
	old_swapy(_id, _doc, page, start, subject, type, lang, order, sort, ratio);
	var zone = $('#zone'+_id);
	var result = zone.parent();
	if(zone.html()){
		$('.links .ssd-link', result).addClass('tab-link');
		zone.removeClass('mtop');
	}else{
		$('.links .ssd-link', result).removeClass('tab-link');
		zone.addClass('mtop');
	}
}

function scrollIntoView(node) {
  var parent = node.parentNode;
  var parentCHeight = parent.clientHeight;
  var parentSHeight = parent.scrollHeight;
  if (parentSHeight > parentCHeight) {
    var nodeHeight = node.clientHeight;
    var nodeOffset = node.offsetTop;
    var scrollOffset = nodeOffset + (nodeHeight / 2) - (parentCHeight / 2);
    parent.scrollTop = scrollOffset;
  }
  if (parent.parent) {
    scrollIntoView(parent);
  }
}

function reset_cart_scroll(){
	//console.log("scroll_cart=>"+window.scroll_cart+", rscroll=>"+$("#rscroll").css('position'));
	//if (window.scroll_cart == false && $('#rscroll').css('position')!='fixed') return;
	var cart_height = $("#rightbox .cart").height() || 0;
	if (cart_height == 0) return;
	var rbox_height = $('#rscroll').height();
	var content_height = $("#content").height();
	var top_padding = 0;
	var margin_top = 0;
	try{
		top_padding = Number($('#content').css('padding-top').match(/\d+/)[0]);
	}catch(err){
	}
	var viewport_top = $(window).scrollTop();
	
	var use_margin_top = false;

	if (window.scroll_cart == false)
		use_margin_top = 1;

	if(viewport_top > top_padding)
		margin_top = viewport_top - top_padding;
	else
		use_margin_top = 1;

	if(margin_top + rbox_height  > content_height){
		margin_top = content_height - rbox_height;
		if (margin_top < 0) margin_top = 0;
		use_margin_top = 1;
	}

	if ($("#rscroll").css('position') != 'fixed' && window.scroll_cart == false){
		var current_margin_top = Number($("#rscroll").css('margin-top').match(/\d+/)[0]);
		if (current_margin_top > margin_top)
			use_margin_top = 1;
		else
			return;
	}

	if($.browser.msie && $.browser.version=="6.0")
		use_margin_top = 1;

	if(use_margin_top == 0){	
	    $("#rightbox").css('position', 'static');
		$("#rscroll").css('margin-top', '0px').css('position', 'fixed').css('top', '0px');
	}else{
		$("#rscroll").stop();
		$("#rscroll").css('position', 'static').css('margin-top', margin_top+"px"); 
	}
}
if ($.onAvailable){
	$.onAvailable("footer", function(){
		function get_doc_id(url){
			var match = url.match(/.*?(\d+)\.html/);
			if (!match){
				match = url.match(/.*?=(\d+).*/);
			}
			if (match){
				return match[1];
			}
			return null;
		}

		function do_ajax(url, callback){
			if (window.XMLHttpRequest) 
			{ 
				xmlhttp = new XMLHttpRequest();
				xmlhttp.open('GET',url,false);
				xmlhttp.send(null);
				html_rep = xmlhttp.responseText;
				var end_time = new Date().getTime();
				callback(html_rep);
			}
			else if (window.ActiveXObject)
			{ 	
				xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
				if (xmlhttp)
				{ 
					xmlhttp.open('GET',url,false);
					xmlhttp.send(null);
					html_rep = xmlhttp.responseText;
					call_back(html-rep);
				}
			}

		}
		function modifyHeaderCurrency(cur){
			var cur = cur.replace(cur.match(/[\d+\.,]+/)[0], '0' );
			$("#navigation .totalprice").html(cur);
		}
		function applyPrices(doc_ids){
			var url = "/eprices.php?lang="+window.lang+"&ip="+window.ip+"&ids="+doc_ids.join(',');
			do_ajax(url, function(data){
				var arr = data.split('|');
				var length = arr.length;
				var pricesData = {};
				for (var i=0;i<length;i++){
					var item = arr[i].split(":");
					var doc_id = item[0];
					var price = item[1];
					pricesData[Number(doc_id)] = price;
				}
				var prices = $("span.price");
				if (prices.length > 0){
					prices.each(function(i, price_element){
						var container = $(price_element).parents().filter('div.result');
						if (container.length > 0){ //for search pages
							var doc_id = get_doc_id($("h2.title a",container).attr('href'));
							doc_id = Number(doc_id);
							$(price_element).html(pricesData[doc_id]);
						}else{//for summary pages
							var doc_id = get_doc_id(window.location.href);
							doc_id = Number(doc_id);
							$(price_element).html(pricesData[doc_id]);
						}
			
					});
				}
				modifyHeaderCurrency(pricesData[doc_id]);
				$('body').show();
			});
		}

		if (typeof window.loadbalance != "undefined" && window.loadbalance == 1){
			window.loadbalance = 0;
			var prices = $("span.price");
			if (prices.length > 0){
				var doc_ids = [];
				prices.each(function(i, price_element){
					var container = $(price_element).parents().filter('div.result');
					if (container.length > 0){
						doc_ids.push(get_doc_id($("h2.title a", container).attr('href')));
					}else{
						doc_ids.push(get_doc_id(window.location.href));
					}
				});
				var prices = applyPrices(doc_ids);
			}
		}

	
	});
}
$(document).ready(function (){
	
	function reset_cradio_buttons(){
		$(".cradio-button input").each(function(i, element){
			if ($(this).attr('checked')){
				$(this).parent().addClass($(this).attr('id')+'-on');
			}else{
				$(this).parent().removeClass($(this).attr('id')+'-on');
			}
		});
	}

	reset_cradio_buttons();

	function init_cradio_buttons(){
		$(".cradio-button").click(function(){
			if (!$('input', this).attr('checked'))
				$('input', this).attr('checked', true);
			reset_cradio_buttons();
		});

	}
	init_cradio_buttons();

	if (typeof window.modify_header_currency != "undefined" && window.modify_header_currency == 1){
		$.ajax({
			type: "GET",
			url: "/eprices.php",
			data: "lang="+window.lang+"&ip="+window.ip+"&ids=",
			success: function(data){
				var arr = data.split(":")
				var cur = arr[1];
				cur.replace(cur.match(/[\d+\.,]+/)[0], '0' );
				$("#navigation .totalprice").html(cur);
				$('body').show();
			}
		});
	}

	$.ajax({type:"GET", url:"/index/currencybox", success:function(data){
		//console.log(data.legnth);
		if(data.length == 0){
			$("#currencybox").hide();
		}else{
			$("#currencybox").show();
		}
	}});

	var overlay = $("#cart-overlay");
	overlay.click(function(e){
		e.stopPropagation();
	});
	$('#navigation .my-cart').click(function (e){
		if (overlay.is(':hidden')){
			overlay.fadeIn()
			$(this).addClass('lineunder');
		}else{
			overlay.fadeOut();
			$(this).removeClass('lineunder');
		}
		e.stopPropagation();
		return false;
	});
	var filters = ['category', 'type', 'language', 'extension', 'pages', 'date'];
	$(filters).each(function (ind, obj){
		$('#'+obj+'-overlay').click(function(e){
			e.stopPropagation();
		});
		$('.'+obj+"-button").click(function(e){
			var objoverlay = "#"+obj+"-overlay";
			var offset = $(this).offset();
			if($(objoverlay).is(':hidden')){
				$(filters).each(function(ind2, obj2){
					if (!$(obj2).is(':hidden') && obj != obj2){
						$("#"+obj2+"-overlay").fadeOut();
					}
				});
				$(objoverlay).css({top:"80px", left:"0px"});
				$(objoverlay).fadeIn();
			}else{
				$(objoverlay).fadeOut();
			}
			e.stopPropagation();
		});
		$('.'+obj+'-button a').click(function(e){
			e.stopPropagation();
		});
	});
	//showing cart overlay in header.
	$(document).click(function (){
		overlay.fadeOut();
		$(filters).each(function(ind, obj){
			$("#"+obj+"-overlay").fadeOut();
		});
		$('#navigation .my-cart').removeClass('lineunder');
	});
	
	//cart scrolling
	var cart_height = $('#rightbox .cart').height() || 0;
	if (cart_height > 0){
		reset_cart_scroll();
		$(window).scroll(function(){
			//if (typeof window.scroll_cart != "undefined" && window.scroll_cart != true) return;
			reset_cart_scroll();
		});
	}

	function setupgbox(){
		//gurantee box expand animation.
		$("#guranteebox .links a.toggle-link").click(function(e){
			var content = $(this).next();
			var link = $(this);
			var current_id = link.attr('id');
			//hide all other content.
			$("#guranteebox .links a.toggle-link").each(function(i){
				if (current_id != $(this).attr('id') && !$(this).next().is(":hidden")){
					var loop_link = $(this);
					$(this).next().animate({opacity:'toggle', height:'toggle'}, 300, 'linear', function(){
						loop_link.removeClass('expanded');
						//reset_cart_scroll();
					});
				}
			});
			if (content.is(':hidden')){
				$(this).addClass('expanded');
				content.animate({opacity:'toggle', height:'toggle'}, 300, 'linear', function(){
					window.scroll_cart = false;
					reset_cart_scroll();
				});
			}else{
				content.animate({opacity:'toggle', height:'toggle'}, 300, 'linear', function(){
					link.removeClass('expanded');
					window.scroll_cart = true;
					reset_cart_scroll();
				});
			}
			return false;
		});
	}
	setupgbox();
	
	if(typeof window.gbox != "undefined" && window.gbox){
		$.ajax({type:"GET", url:"/search/getguaranteebox", success:function(gdata){
			$('#linklistbox').html(gdata);
			setupgbox();
		}});
	}
	var select_boxes = ['#studies_box', '#sources_box', '#countries_box', '#studylevels_box', '#states_box', '#activity_box'];
	$(select_boxes).each(function(i, ele){
		if ($(ele).length > 0){
			$(ele).selectbox();
		}
	});


	function reset_reg_radio_buttons(){
		$(".radio-button input").each(function(i, element){
			if ($(this).attr('checked')){
				$(this).parent().addClass('radio-button-selected');
			}else{
				$(this).parent().removeClass('radio-button-selected');
			}
		});
		if ($("#paypal-button").length > 0){
			if (!$("#paypal-button").attr('checked')){
				$("#paypal-fields input").removeClass('required');
				$("#paypal-fields").addClass('hidden');
			}else{
				$("#paypal-fields input").addClass('required');
				$("#paypal-fields").removeClass('hidden');
			}
		}
	}
	reset_reg_radio_buttons();
	$(".payment-method .radio-button").click(function(){
		if (!$('input', this).attr('checked'))
			$('input', this).attr('checked', true);
		reset_reg_radio_buttons();
	});


/*
	function reset_pay_buttons(){
		$(".pay-button input").each(function(i, element){
			if ($(this).attr('checked')){
				$(this).parent().addClass('pay-button-selected');
			}else{
				$(this).parent().removeClass('pay-button-selected');
			}
		});
	}
	reset_pay_buttons();
	$(".pay-button").click(function(){
		if (!$('input', this).attr('checked'))
			$('input', this).attr('checked', true);
		reset_pay_buttons();
	});
*/

	function reset_pay_buttons(){
		$(".pay-button input").each(function(i, element){
			if ($(this).attr('checked')){
				$(this).parent().addClass('pay-button-selected');
			}else{
				$(this).parent().removeClass('pay-button-selected');
			}
		});
		}
	
	reset_pay_buttons();
	
	function init_pay_buttons(){
		$(".pay-button").click(function(){
			if (!$('input', this).attr('checked'))
				$('input', this).attr('checked', true);
			reset_pay_buttons();
		});
	
	}
	init_pay_buttons();
	
	
	function reset_radio_buttons(){
		$(".radio-button input").each(function(i, element){
			if ($(this).attr('checked')){
				$(this).parent().addClass('radio-button-selected');
			}else{
				$(this).parent().removeClass('radio-button-selected');
			}
		});
		}
	
	reset_radio_buttons();
	
	function init_radio_buttons(){
		$(".radio-button").click(function(){
			if (!$('input', this).attr('checked'))
				$('input', this).attr('checked', true);
			reset_radio_buttons();
		});
	
	}
	init_radio_buttons();
	
	function checkgdid(type){
		$.ajax({
			 type: "POST",
			 url: "/registration/renderprivateoptions",
			 data: "type="+type+"&godfatherId="+$("#godfatherId").val(),
			 success: function(msg){
			 var strmsg=jQuery.trim(msg);
			 var check=strmsg.split('|||');
			  			if(check[0]!='notvalid'){
			  				$("#ambblock").html('<span id="ambvalue">'+$("#godfatherId").val()+'</span>');
							$("#optbuttons").html(msg);
						}else{
								$("#successmsg").show();
								$("#successmsg").html(_VALID_AMBCODE);
								$("#optbuttons").html(check[1]);
								setTimeout(function(){$("#successmsg").fadeOut("slow");}, 8000);
							}
					init_pay_buttons();
					reset_pay_buttons();
					  }
		});
	}

	function checksenddocgdid(type){
		$.ajax({
				 type: "POST",
				 url: "/registration/renderoptions",
				 data: "type="+type+"&godfatherId="+$("#godfatherId").val(),
				 success: function(msg){
				 var strmsg=jQuery.trim(msg);
				 var check=strmsg.split('|||');
				  			if(check[0]!='notvalid'){
								$("#ambcodebox").html('<span id="ambvalue">'+$("#godfatherId").val()+'</span>');
								$("#optbuttons").html(msg);
							}else{
								$("#successmsg").show();
								$("#successmsg").html(_VALID_AMBCODE);
								$("#optbuttons").html(check[1]);
								setTimeout(function(){$("#successmsg").fadeOut("slow");}, 8000);
							}
						init_radio_buttons();
						reset_radio_buttons();
						  }
			});
			
	}
	window.checkgdid=checkgdid;
	window.checksenddocgdid=checksenddocgdid;
	
	function reset_states(){
		var country = $("#countries_box option:selected").text();
		if (/india/i.test(country) || /united states/i.test(country) || window.lang == "pt"){
			var state_html = "";
			var states = null;
			if ( typeof states_en != "undefined")
				states = states_en;
			if (/india/i.test(country) && typeof states_in != "undefined")
				states = states_in;
			if (window.lang == "pt" && typeof states_pt != "undefined")
				states = states_pt;
			if (states == null) return;
			state_html +="<select name='state' id='states_box' class='required'>";
			state_html += "<option value=''> </option>";
			for (var i = 0; i < states.length; i++){
				var option = "<option value='"+states[i]+"'";
				if (states[i] == current_state)
					option+=" SELECTED ";
				option += ">"+states[i]+"</option>";
				state_html += option;
				
			}
			state_html+= "</select>";
			$("#state-field").html(state_html);
			$("#states_box").selectbox();
			$("#state-row").removeClass('hidden');
		}else{
			$("#state-field").html("");
			$("#state-row").addClass('hidden');
		}
	}
	reset_states();
	$("#countries_box").change(function(){reset_states();})

	//$("#countries-box").change(reset_states);
	/*
	function reset_cat_pages(){
		var page_num = 1;
		if (window.location.hash){
			page_num = window.location.hash.substring(1);	
		}
		$('.catpage').each(function(i, ele){
			if ($(this).attr('id') != 'catpage_'+page_num){
				$(this).addClass('hidden');
			}else{
				$(this).removeClass('hidden');
			}
		});
	}
	reset_cat_pages();
	*/
	if ($.validator){
		$.validator.addMethod('textonly', function(value, ele){
			return !/\d+/.test(value);
		}, "Please enter only valid text");
		$.validator.addMethod('monthfilter', function(value, ele){
			var month = Number(value);
			return value >= 1 && value <= 12;
		}, "Enter valid month range");
		$.validator.addMethod('dayfilter', function(value, ele){
			var day = Number(value);
			return value >= 1 && value <= 31;
		}, "Enter valid day range");
		$.validator.addMethod('yearfilter', function(value, ele){
			var year = Number(value);
			var current_year = new Date().getFullYear();
			return year <= current_year - 13 ;   //submitter must be atleast 14 years old.
		}, "Enter valid year");
		$.validator.addMethod('confirmemailfilter', function(value, ele){
			return $("#email-field-1").attr('value') == $("#email-field-2").attr('value');
		}, "Email mismatch");
		$.validator.addMethod('hrequired', function(value, ele){
			if ($(ele).is(":hidden")) return true;
			return $(ele).attr('value') && $(ele).attr('value').length > 0;
		}, "Required field");


	}
	function validate_reg_form(form_id){
		if ($("#"+form_id).length > 0) {
			$("#"+form_id).validate({
				rules:{
					firstName:{
						required:true,
						minlength:2
					},
					lastName:{
						required:true,
						minlength:2
					},
					phoneNumber:{
						required:true,
						number:true
					},
					year:{
						required:true,
						number:true
					},
					day:{
						required:true,
						dayfilter:true
					},
					city:{
						required:true,
						textonly:true
					},
					month:{
						required:true,
						monthfilter:true
					},
					year:{
						required:true,
						yearfilter:true
						
					},
					paypalEmail:{
						hrequired:true
                    },
					paypalEmailBis:{
						hrequired:true,
						confirmemailfilter:true
					},
					new_password2:{
						required:true,
						equalTo:"#new_password"

					}



					
				},
				messages:{
					firstName:{
						required:_VALID_FIRSTNAME,
						minlength:_VALID_FIRSTNAME
					},
					lastName:{
						required:_VALID_LASTNAME,
						minlength:_VALID_LASTNAME
					},
					email:_VALID_EMAIL,
					study:_VALID_FIELDSTUDY,
					school:_VALID_SCHOOL,
					level:_VALID_LEVEL,
					profession:_VALID_PROFESSION,
					address:_VALID_ADDRESS,
					zipCode:_VALID_POSTALCODE,
					city:_VALID_CITY,
					country:_VALID_COUNTRY,
					phoneNumber:_VALID_PHONENUMBER,
					year:_VALID_ENTER_YEAR,
					month:_VALID_ENTER_MONTH,
					day:_VALID_ENTER_DAY,
					new_password2:{
						equalTo: _VALID_PASSWORD_CONFIRM
					}
				}
			});
		}
	}

	validate_reg_form("registrationform");
	validate_reg_form("registrationform-sending");
	validate_reg_form("reg-form");
	var loginbox = $('.row2 .login-box');
	var username = $('.row2 .login-box p:first-child');
	//if (username.width()> 90){
	//	$('.row2 .login-box').width($('.row2 .login-box p:first-child').width()+20);
	//}else{
	//	loginbox.css('width', '108px');
	//}
	var payment_forms = ["paypal-form", "whapayment-form","ebs_form","cc_pt_form"];
	$(payment_forms).each(function(i,v){
		if($("#"+v).length > 0)
			$("#"+v).submit();
	});
	$('#cc_form input').click();
	function get_doc_id(url){
		var match = url.match(/.*?(\d+)\.html/);
		if (!match){
			match = url.match(/.*?=(\d+).*/);
		}
		if (match){
			return match[1];
		}
		return null;
	}
	function apply_price(doc_id){
		var price_element = this;
		$.ajax({
			type:'GET',
			url:'/index/eprice',
			data:'doc_id='+doc_id,
			success:function(msg){
				$(price_element).html(msg);
			}
		});
	}
	function do_ajax(url, callback){
		if (window.XMLHttpRequest) 
		{ 
			xmlhttp = new XMLHttpRequest();
			xmlhttp.open('GET',url,false);
			xmlhttp.send(null);
			html_rep = xmlhttp.responseText;
			var end_time = new Date().getTime();
			callback(html_rep);
		}
		else if (window.ActiveXObject)
		{ 	
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
			if (xmlhttp)
			{ 
				xmlhttp.open('GET',url,false);
				xmlhttp.send(null);
				html_rep = xmlhttp.responseText;
				call_back(html-rep);
			}
		}

	}
	
	function applyPrices(doc_ids){
		var url = "/eprices.php?lang="+window.lang+"&ip="+window.ip+"&ids="+doc_ids.join(',');
		do_ajax(url, function(data){
			var arr = data.split('|');
			var length = arr.length;
			var pricesData = {};
			for (var i=0;i<length;i++){
				var item = arr[i].split(":");
				var doc_id = item[0];
				var price = item[1];
				pricesData[Number(doc_id)] = price;
			}
			var prices = $("span.price");
			if (prices.length > 0){
				prices.each(function(i, price_element){
					var container = $(price_element).parents().filter('div.result');
					if (container.length > 0){ //for search pages
						var doc_id = get_doc_id($("h2.title a",container).attr('href'));
						doc_id = Number(doc_id);
						$(price_element).html(pricesData[doc_id]);
					}else{//for summary pages
						var doc_id = get_doc_id(window.location.href);
						doc_id = Number(doc_id);
						$(price_element).html(pricesData[doc_id]);
					}
		
				});
			}

		});
		/*
		$.getJSON("/eprices.php?lang="+window.lang+"&ip="+window.ip+"&ids="+doc_ids.join(','), function(data){
			var end_time = new Date().getTime();
			console.log(end_time - start_time);
			var pricesData = data;
			var prices = $("span.price");
			if (prices.length > 0){
				prices.each(function(i, price_element){
					var container = $(price_element).parents().filter('div.result');
					if (container.length > 0){ //for search pages
						var doc_id = get_doc_id($("h2.title a",container).attr('href'));
						doc_id = Number(doc_id);
						$(price_element).html(pricesData[doc_id]);
					}else{//for summary pages
						var doc_id = get_doc_id(window.location.href);
						doc_id = Number(doc_id);
						$(price_element).html(pricesData[doc_id]);
					}
		
				});
			}

		});
		*/
	}
	/*
	if (typeof window.loadbalance != "undefined" && window.loadbalance == 1){
		var prices = $("span.price");
		if (prices.length > 0){
			var doc_ids = [];
			prices.each(function(i, price_element){
				var container = $(price_element).parents().filter('div.result');
				if (container.length > 0){
					doc_ids.push(get_doc_id($("h2.title a", container).attr('href')));
				}else{
					doc_ids.push(get_doc_id(window.location.href));
				}
			});
			var prices = applyPrices(doc_ids);
		}
	}
	*/

	$("#suggestions a").click(function(){
		try{
		window.pageTracker._trackEvent(window.location.href, 'click', $(this).text());
		}catch(err){
		}
	});

	if (typeof window.in_showcart != "undefined" && window.in_showcart){
		window.scrollTo(0, 5000);
	}
	
	function do_search(){
		var form = $(this).parents().filter('#searchbar');
		var url = $("input[name='action']", form).val();
		var url = url +"?q="+$('.querybox').val()+"&S=&T=&L=&E=&N=&fullSearch=1";
		window.location.href = url;
		return false;

	}
	$(".searchbar-js .search-button").click(function(){
		do_search.apply(this);
	});
	$(".searchbar-js .querybox").keyup(function(e){
		if (e.keyCode == 13){
			do_search.apply(this);
		}
	});

$('.newsletter').popupWindow({ 
	height:200, 
	width:630, 
	top:50, 
	left:50 
});

});

 
function hopen(a)
{
	var x=window.open(a,'cvpanel','top=0,left=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=1030,height=630');
	x.focus();
}

function matrixopen(a)
{
	var x=window.open(a,'cvopen','top=50,left=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=520,height=500');
	x.focus();
}

function matrixenopen(a)
{
	var x=window.open(a,'cvopen','top=50,left=50,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=525,height=400');
	x.focus();
}

function copen(a)
{
	var x=window.open(a,'cvopen','top=50,left=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=485,height=365');
	x.focus();
}

function openPopup(url, options){
	var options_string = 'top=50,left=50,toolbar=0,location=0,directories=0,status=0,resizable=0,copyhistory=0,menuBar=0';
	options = options || {};
	options['scroll'] = options['scroll'] || 0;
	options['width'] = options['width'] || 485;
	options['height'] = options['height'] || 365;
	options_string += ",scrollbars="+options['scroll'];
	options_string += ",width="+options['width'];
	options_string += ",height="+options['height'];
	var win = window.open(url, 'cvopen', options_string);
	win.focus();
	return false;
}

$(document).ready(function(){
	//Hide (Collapse) the toggle containers on load
	
	//Switch the "Open" and "Close" state per click
	$("a.trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});

	//Slide up and down on click
	$("a.trigger").click(function(){
		$(".toggle_container").slideToggle("slow");
	});

});

function cvopen(a)
{
	var x=window.open(a,'cvpanel','top=0,left=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=550,height=630');
	x.focus();
}

function cgu(a)
{
	var x=window.open(a,'cgupage','top=0,left=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=1025,height=630');
	x.focus();
}
function goTo(url)
{
	window.location.href = url;
}
function checkAddendum(error,cess)
{
	if(!isChecked("add1")&&!isChecked("add2"))
	{
		alert(error);
		return false;
	}
	else
	{
		
		return true;
	}
	
}

function openWindow(a)
{
	var x=window.open(a,'popup','top=0,left=0,toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1,copyhistory=1,menuBar=1');
	x.focus();
}

function popen(a)
{
	var x=window.open(a,'profit','top=0,left=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=700,height=500');
	x.focus();
}

function checkCheckBox(x,error)
{
	var test = isChecked(x);
	if(!test)
	{
		alert(error);
		return false;
	}
	return test;
}

function isChecked(x)
{
	return document.getElementById(x).checked;

}

function nopen(a)
{
	var x=window.open(a,'newsletter','top=0,left=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=650,height=200');
	x.focus();
}