//JQuery
$(document).ready(function() {	
	MM_preloadImages('images/btn-outside-over.jpg','images/btn-outside-sel.jpg','images/btn-inside-over.jpg','images/btn-inside-sel.jpg','images/btn-order-over.jpg','images/btn-order-sel.jpg');
	MM_preloadImages('images/btn-order-now-over.jpg');
	
	if (document.getElementById('ShoppingCartWidget') != undefined) {
		//Display Cart Widget
		displayCartItems();
	}
	
	$("[rel=ProductImage]").fancybox({
		'showNavArrows'		: false
	});
	$("a#ccv").fancybox();
	$("[rel=Video]").click(function() {
		$.fancybox({
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'title'				: this.title,
				'width'				: 640,
				'height'			: 385,
				'href'				: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'				: 'swf',
				'swf'				: {
				'wmode'				: 'transparent',
				'allowfullscreen'	: 'true'
				}
			});
	
		return false;
	});
	
	$("a#ccv").fancybox();
	$("[rel=ModalWindow]").fancybox({
		'width'				: 480,
		'height'			: 380,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'scrolling'			: 'no',
		'showNavArrows'		: false,
		'type'				: 'iframe'
	});
	$("[rel=ModalWindowLarger]").fancybox({
		'width'				: 600,
		'height'			: 350,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'scrolling'			: 'no',
		'showNavArrows'		: false,
		'type'				: 'iframe'
	});
	$("[rel=ModalWindowPAPTerms]").fancybox({
		'width'				: 800,
		'height'			: 650,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'scrolling'			: 'no',
		'showNavArrows'		: false,
		'type'				: 'iframe'
	});
	$("[rel=ModalTranscript]").fancybox({
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'scrolling'			: 'no',
		'showNavArrows'		: false
	});
});
function goToURL(which, target) {
	if (target == "") {
		location.href = which;
	}
	if (target == "_blank") {
		window.open(which);
	}
}
function showDropDown(param1, param2, param3) {
	if (document.getElementById(param2).className != 'background_global_navigation_bar_inside_selected') {
		document.getElementById(param1).style.display = 'inline';
		document.getElementById(param2).className = param3;
	} else {
		document.getElementById(param1).style.display = 'inline';
	}
}
function hideDropDown(param1, param2, param3) {
	if (document.getElementById(param2).className != 'background_global_navigation_bar_inside_selected') {
		document.getElementById(param1).style.display = 'none';
		document.getElementById(param2).className = param3;
	} else {
		document.getElementById(param1).style.display = 'none';
	}
}
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}
function highlightMenuItem(param1, param2, param3) {
	if (param3 == 'outside') {
		if (document.getElementById(param1).className != 'background_global_navigation_bar_outside_selected') {
			document.getElementById(param1).className = param2;
		}
	}
	if (param3 == 'inside') {
		if (document.getElementById(param1).className != 'background_global_navigation_bar_inside_selected') {
			document.getElementById(param1).className = param2;
		}
	}
	if (param3 == 'order') {
		if (document.getElementById(param1).className != 'background_global_navigation_bar_order_now_selected') {
			document.getElementById(param1).className = param2;
		}
	}
	if (param3 == 'view_cart') {
		if (document.getElementById(param1).className != 'background_global_navigation_bar_view_cart_selected') {
			document.getElementById(param1).className = param2;
		}
	}
}
function setPaymentType(which) {
	if (which == 'Credit-Card') {
		document.getElementById('E-Check').style.display = 'none';
		document.getElementById(which).style.display = 'inline';
	}
	if (which == 'E-Check') {
		document.getElementById('Credit-Card').style.display = 'none';
		document.getElementById(which).style.display = 'inline';
	}
}	
function initializePaymentBox(paymenttype) {
	if (paymenttype == 1) { //Display Credit Card Information
		document.getElementById('Credit-Card').style.display = 'inline';
	}
	if (paymenttype == 2) { //Display E-Check Information
		document.getElementById('E-Check').style.display = 'inline';
	}
}
function updatePrice(quantity) {
	var price = quantity * 179.80;
	document.getElementById('Price').innerHTML = formatCurrency((price).toFixed(2));
}
function roundNumber(number,decimal_points) {
	if (!decimal_points) return Math.round(number);
	if (number == 0) {
		var decimals = "";
		for (var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}
	
	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}
function formatCurrency(num) 
{	
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' +  num + '.' + cents);
}
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 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 eraseCookie(name) {
	createCookie(name,"",-1);
}
function getRadioCheckedValue(radio_name) {
	var oRadio = document.frmOrder.elements[radio_name];
	
	for (var i = 0; i < oRadio.length; i++) { 		
		if (oRadio[i].checked) {
			return oRadio[i].value;
		}		
	}		
	return '';
}
function order() {
	var utm_campaign = readCookie("MI_ReferrerUTMCampaign");
	
	if (utm_campaign != "") {
		var url = "http://www.thecontour.com/cart.aspx?cd=css2000&promo=HOLIDAY2010&campaign=" + utm_campaign;
	} else {
		var url = "cart95b6.html?cd=css2000&amp;promo=HOLIDAY2010";
	}
	document.location.href = url;
}
function numbersonly(e, decimal) {
	var key;
	var keychar;
	
	if (window.event) {
	   key = window.event.keyCode;
	}
	else if (e) {
	   key = e.which;
	}
	else {
	   return true;
	}
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
	   return true;
	}
	else if ((("0123456789.").indexOf(keychar) > -1)) {
	   return true;
	}
	else if (decimal && (keychar == ".")) { 
	  return true;
	}
	else
	   return false;
}
//Shopping Cart

//Declare Globals
var quantity_array = new Array();
quantity_array[0] = 1;
quantity_array[1] = 2;
quantity_array[2] = 3;
quantity_array[3] = 4;
quantity_array[4] = 5;
quantity_array[5] = 6;
quantity_array[6] = 7;
quantity_array[7] = 8;
quantity_array[8] = 9;
quantity_array[9] = 10;

function displayCartItems() {
	//Check for existing cookie
	var shopping_cart_cookie = readCookie("CSSShoppingCart");
	
	if (shopping_cart_cookie == null) {
		document.getElementById('ShoppingCartWidget').innerHTML = "";
	} else {
		var cart_total = 0;
		var cart_total_items = 0;
		
		var cookie_exploded = shopping_cart_cookie.split('~');
		
		//Declare cookie array
		var cookie_array = new Array();
		
		//Create array from cookie
		for (i = 0; i < cookie_exploded.length - 1; i++) {
			cookie_array[i] = cookie_exploded[i] + "~";
			var cartitem = cookie_array[i];
			var cartitem = cartitem.split("|");
			var qty = cartitem[4];
			var price = cartitem[5];
			var price = qty * price;
			var price = roundNumber(price, 2);
			cart_total = roundNumber(parseFloat(cart_total) + parseFloat(price), 2);
			cart_total_items = roundNumber(parseFloat(cart_total_items) + parseFloat(qty));
			if (document.getElementById('ShoppingCartWidget') != undefined) {
				document.getElementById('ShoppingCartWidget').innerHTML = formatCurrency(cart_total) + " " + "(" + cart_total_items + " " + "items" + ")";
			}
		}
	}
}
function getSubTotal() {
	var sub_total = 0;
	for (i = 0; i <= document.forms[0].elements.length - 1; i++) {
		if (document.forms[0].elements[i].type == "select-one") {
			var curName = document.forms[0].elements[i].name;
			
			var aPosition = curName.indexOf("qty_");
			
			if (aPosition != -1) {
				var price_split = document.getElementById(curName).value;
				var price_split = price_split.split("|");
				var qty = price_split[0];
				var price = price_split[1];
				var price = qty * price;
				var price = roundNumber(price, 2);
				sub_total = roundNumber(parseFloat(sub_total) + parseFloat(price), 2);
				document.getElementById('SubTotal').innerHTML = formatCurrency(sub_total);
			}
		}
	}
}
function returnSubTotal() {
	var sub_total = 0;
	for (i = 0; i <= document.forms[0].elements.length - 1; i++) {
		if (document.forms[0].elements[i].type == "select-one") {
			var curName = document.forms[0].elements[i].name;
			
			var aPosition = curName.indexOf("qty_");
			
			if (aPosition != -1) {
				var price_split = document.getElementById(curName).value;
				var price_split = price_split.split("|");
				var qty = price_split[0];
				var price = price_split[1];
				var price = qty * price;
				var price = roundNumber(price, 2);
				return roundNumber(parseFloat(sub_total) + parseFloat(price), 2);
			}
		}
	}
}
function getDiscountTotal() {
	var data = readCookie('ContourProductOrderData_Step_1');
	if (data != null) {
		var data = data.split('|');
		var promocode = data[3];
		var shippingcode = data[4];
		var shippingcode = shippingcode.split('~');
		var shippingindex = shippingcode[0];
		var shippingcode = shippingcode[2];
		if (promocode == "CSS2000M") {
			var sub_total = document.getElementById("SubTotal").innerHTML;
			var sub_total = +sub_total.replace(/[^\d\.-]/g,'');
			var discount = sub_total * .1;
			if (document.getElementById("PromoCode")) {
				document.getElementById("PromoCode").innerHTML = "10%*";
			}
		}
		document.getElementById("ShippingCode").innerHTML = formatCurrency(shippingcode);
		document.forms[0].intShippingCode[shippingindex].checked = true;
	}
}
function getShippingCode() {
	var data = readCookie('ContourProductOrderData_Step_1');
	var data = data.split('|');
	var shippingcode = data[4];
	document.forms[0].intShippingCode[shippingcode[0]].checked = true;
	document.getElementById("ShippingCode").innerHTML = formatCurrency(shippingcode);
}
function updateShippingAmount(which) {
	var shippingcode = which.split("~");
	var shippingamount = shippingcode[2];
	var sub_total = document.getElementById('SubTotal').innerHTML;
	var sub_total = +sub_total.replace(/[^\d\.-]/g,'');
	var taxable_amount = parseFloat(sub_total) + parseFloat(shippingamount);
	var taxable_amount = roundNumber(taxable_amount, 2);
	document.getElementById("ShippingCode").innerHTML = formatCurrency(shippingamount);
	document.getElementById("TaxableAmount").innerHTML = formatCurrency(taxable_amount);
}
function updateShippingCode(which) {
	var shippingcode = which.split("~");
	var shippingcode = shippingcode[2];
	var sub_total = document.getElementById('SubTotal').innerHTML;
	var sub_total = +sub_total.replace(/[^\d\.-]/g,'');
	var shipping_and_handling = shippingcode;
	var taxable_amount = parseFloat(sub_total) + parseFloat(shipping_and_handling);
	var taxable_amount = roundNumber(taxable_amount, 2);
	document.getElementById("ShippingCode").innerHTML = formatCurrency(shippingcode);
	document.getElementById("TaxableAmount").innerHTML = formatCurrency(taxable_amount);
	
	var data = readCookie('ContourProductOrderData_Step_1');
	var data = data.split('|');
	
	var firstname = data[0];
	var lastname = data[1];
	var emailaddress = data[2];
	var promocode = data[3];
	var shippingcode = which;
	
	//Update Product Order in Database
	$.ajax({
		type: "POST",
		url: "/mysql/update_lead_product_orders.php",
		data: "firstname="+ firstname +"& lastname="+ lastname +"& emailaddress="+ emailaddress +"& promocode="+ promocode +"& shippingcode="+ shippingcode,
		success: function(msg){
		var data = firstname + "|" + lastname + "|" + emailaddress + "|" + promocode + "|" + shippingcode;
		createCookie('ContourProductOrderData_Step_1',data,1);
		}
	});
}
function getTaxableAmount() {
	var sub_total = document.getElementById('SubTotal').innerHTML;
	var sub_total = +sub_total.replace(/[^\d\.-]/g,'');
	var shipping_and_handling = document.getElementById('ShippingCode').innerHTML;
	var shipping_and_handling = +shipping_and_handling.replace(/[^\d\.-]/g,'');
	var taxable_amount = parseFloat(sub_total) + parseFloat(shipping_and_handling);
	var taxable_amount = roundNumber(taxable_amount, 2);
	document.getElementById("TaxableAmount").innerHTML = formatCurrency(taxable_amount);
}
function updateShoppingCartDisplay(which) {
	location.reload();
}
function updateItemPrice(field, qty, price) {
	//alert(field + " : " + qty + " : " + price);
	var price = qty.split('|');
	var qty = price[0];
	var price = price[1];
	var price = qty * price;
	document.getElementById(field).innerHTML = formatCurrency((price).toFixed(2));
}
function addItemToCart(id, name, description, url, qty, price, quantity) {
	//Split qty because I am passing both the qty and price in the value field of the drop down list
	var qty_split = qty.indexOf('|');
	if (qty_split != -1) {
		var qty = qty[0];
	}
	
	//Check for existing cookie
	var shopping_cart_cookie = readCookie("CSSShoppingCart");
	
	//Create cookie data string to save into new or existing cookie
	if (quantity == undefined) {
		var cookie_data = id + '|' + name + '|' + description + '|' + url + '|' + qty + '|' + price + '|' + '~';
	} else {
		var cookie_data = id + '|' + name + '|' + description + '|' + url + '|' + qty + '|' + price + '|' + quantity + '|' + '~';
	}
	
	if (shopping_cart_cookie == null) { //Create new cookie
		createCookie("CSSShoppingCart", cookie_data, 1);
	} else { //Add New Product or Update quantity of existing product into cookie
		var cookie_exploded = shopping_cart_cookie.split('~');
		
		//Declare cookie array
		var cookie_array = new Array();
		
		//Create array from cookie
		for (i = 0; i < cookie_exploded.length - 1; i++) {
			cookie_array[i] = cookie_exploded[i] + "~";
			//alert(cookie_array[i]);
		}
		//Check each index in the cookie array for match on ID for existing product
		for (i = 0; i <= cookie_array.length - 1; i++) {
			for (x = 0; x <= cookie_array.length - 1; x++) {
				if (cookie_array[i].indexOf(id) != -1) { //Match Found
					var array_position = i;
					break;
				}
			}
		}
		if (array_position == undefined) {
			var array_position = cookie_array.length;
		} 
		cookie_array[array_position] = cookie_data;
		
		//Update cookie
		var updated_cookie_data = "";
		for (i = 0; i <= cookie_array.length - 1; i++) {
			updated_cookie_data = updated_cookie_data + cookie_array[i];
			//alert(updated_cookie_data);
		}
		//alert(updated_cookie_data);
		createCookie("CSSShoppingCart", updated_cookie_data, 1);
	}
	location.href = "Contour-Belt-Shopping-Cart/46564/index.html";
}
function addItemToCartAndCheckout(id, name, description, url, qty, price, quantity) {
	//Split qty because I am passing both the qty and price in the value field of the drop down list
	var qty_split = qty.indexOf('|');
	if (qty_split != -1) {
		var qty = qty[0];
	}
	
	//Check for existing cookie
	var shopping_cart_cookie = readCookie("CSSShoppingCart");
	
	//Create cookie data string to save into new or existing cookie
	if (quantity == undefined) {
		var cookie_data = id + '|' + name + '|' + description + '|' + url + '|' + qty + '|' + price + '|' + '~';
	} else {
		var cookie_data = id + '|' + name + '|' + description + '|' + url + '|' + qty + '|' + price + '|' + quantity + '|' + '~';
	}
	
	if (shopping_cart_cookie == null) { //Create new cookie
		createCookie("CSSShoppingCart", cookie_data, 1);
	} else { //Add New Product or Update quantity of existing product into cookie
		var cookie_exploded = shopping_cart_cookie.split('~');
		
		//Declare cookie array
		var cookie_array = new Array();
		
		//Create array from cookie
		for (i = 0; i < cookie_exploded.length - 1; i++) {
			cookie_array[i] = cookie_exploded[i] + "~";
			//alert(cookie_array[i]);
		}
		//Check each index in the cookie array for match on ID for existing product
		for (i = 0; i <= cookie_array.length - 1; i++) {
			for (x = 0; x <= cookie_array.length - 1; x++) {
				if (cookie_array[i].indexOf(id) != -1) { //Match Found
					var array_position = i;
					break;
				}
			}
		}
		if (array_position == undefined) {
			var array_position = cookie_array.length;
		} 
		cookie_array[array_position] = cookie_data;
		
		//Update cookie
		var updated_cookie_data = "";
		for (i = 0; i <= cookie_array.length - 1; i++) {
			updated_cookie_data = updated_cookie_data + cookie_array[i];
			//alert(updated_cookie_data);
		}
		//alert(updated_cookie_data);
		createCookie("CSSShoppingCart", updated_cookie_data, 1);
	}
}
function getShoppingCart() {
	var shopping_cart_cookie = readCookie("CSSShoppingCart");
	if (shopping_cart_cookie == null) {
		alert("cookie is empty");
	} else {
		alert(shopping_cart_cookie);
	}
}
function removeItemFromCart(id) {
	var shopping_cart_cookie = readCookie("CSSShoppingCart");
	var cookie_exploded = shopping_cart_cookie.split('~');
	
	//Declare cookie array
	var cookie_array = new Array();
	
	//Create array from cookie
	for (i = 0; i < cookie_exploded.length - 1; i++) {
		cookie_array[i] = cookie_exploded[i] + "~";
		//alert(cookie_array[i]);
	}
	
	//Check each index in the cookie array for match on ID for existing product
	for (i = 0; i <= cookie_array.length - 1; i++) {
		for (x = 0; x <= cookie_array.length - 1; x++) {
			if (cookie_array[i].indexOf(id) != -1) { //Match Found
				var array_position = i;
				break;
			}
		}
	}
	//alert(array_position);
	cookie_array[array_position] = "";
	
	//Create revised array from original array
	for (i = 0; i < cookie_array.length; i++) {
		if (cookie_array[i] != "") {
			cookie_array[i] = cookie_array[i];
			//alert(cookie_array[i]);
		}
	}
	//Update cookie
	var updated_cookie_data = "";
	for (i = 0; i <= cookie_array.length - 1; i++) {
		updated_cookie_data = updated_cookie_data + cookie_array[i];
		//alert(updated_cookie_data);
	}
	//alert(updated_cookie_data);
	if (cookie_array != "") {
		createCookie("CSSShoppingCart", updated_cookie_data, 1);
	} else {
		removeShoppingCart();
	}
	//Special Rules
	if (id == 'CSS2000AS') {
		//Check each index in the cookie array for match on ID for existing product
		for (i = 0; i <= cookie_array.length - 1; i++) {
			for (x = 0; x <= cookie_array.length - 1; x++) {
				if (cookie_array[i].indexOf('BPK2000KTBONUS') != -1) { //Match Found
					var array_position = i;
					break;
				}
			}
		}
		//alert(array_position);
		if (array_position != 0) {
			removeItemFromCart('BPK2000KTBONUS');
		}
	}
	if (id == 'CSS2000') {
		//Check each index in the cookie array for match on ID for existing product
		for (i = 0; i <= cookie_array.length - 1; i++) {
			for (x = 0; x <= cookie_array.length - 1; x++) {
				if (cookie_array[i].indexOf('IS1000FBBONUS') != -1) { //Match Found
					var array_position = i;
					break;
				}
			}
		}
		//alert(array_position);
		if (array_position != 0) {
			removeItemFromCart('IS1000FBBONUS');
		}
		for (i = 0; i <= cookie_array.length - 1; i++) {
			for (x = 0; x <= cookie_array.length - 1; x++) {
				if (cookie_array[i].indexOf('DVD1000WOBONUS') != -1) { //Match Found
					var array_position = i;
					break;
				}
			}
		}
		//alert(array_position);
		if (array_position != 0) {
			removeItemFromCart('DVD1000WOBONUS');
		}
	}
	//End
}
function removeShoppingCart() {
	eraseCookie("CSSShoppingCart");
}
function displayPromoCode() {
	var step1_data = readCookie('ContourProductOrderData_Step_1');
	var step1_data = step1_data.split('|');
	var promo_code = step1_data[3];
	if (promo_code != "") {
		document.getElementById("PromoCodeTable").style.display = "inline";
	}
}
function toggle(param1, param2) {
	if (param1 == 'flavor') {
		var flavor_array = new Array();
		flavor_array[0] = 'LP1000DC';
		flavor_array[1] = 'LP1000FV';	
		for (i = 0; i < flavor_array.length; i++) {
			document.getElementById(flavor_array[i]).style.display = 'none';
		}
		document.getElementById(param2.value).style.display = 'inline';
	}
	
	if (param1 == 'flavor2') {
		var flavor_array = new Array();
		flavor_array[0] = 'LP1000DCPAP';
		flavor_array[1] = 'LP1000FVPAP';	
		for (i = 0; i < flavor_array.length; i++) {
			document.getElementById(flavor_array[i]).style.display = 'none';
		}
		document.getElementById(param2.value).style.display = 'inline';
	}
	
		if (param1 == 'amount') {
		var flavor_array = new Array();
		flavor_array[0] = '1000GIFT';
		flavor_array[1] = '2500GIFT';	
		flavor_array[2] = '5000GIFT';	
		for (i = 0; i < flavor_array.length; i++) {
			document.getElementById(flavor_array[i]).style.display = 'none';
		}
		document.getElementById(param2.value).style.display = 'inline';
	}

}
// track an event with GA
function trackEvent(elementRef, param1, param2, param3) {
	// get the href from the link
	virtualLink = $(elementRef).attr('href');
	// push an event to track external links
	_gaq.push(['_trackEvent', param1, param2, param3]);
}
// track a page view with GA
function trackPageview(elementRef) {
	// get the href from the link
	virtualLink = $(elementRef).attr('href');
	// push a page view to GA
	_gaq.push(['_trackPageview', virtualLink]);
}
// track an external link with GA
function trackExternalLink(elementRef, param1, param2) {
	// get the href from the link
	redirectLink = $(elementRef).attr('href');
	// get the target from the link
	linkTarget = $(elementRef).attr('target');
	// push an event to track external links
	if (param1 == undefined && param2 == undefined) {
		_gaq.push(['_trackEvent', 'Outgoing links', 'Click', redirectLink]);
	} else if (param2 == undefined) {
		_gaq.push(['_trackEvent', param1, 'Click - Outgoing links', redirectLink]);
	} else {
		_gaq.push(['_trackEvent', param1, param2, redirectLink]);
	}
	// if the link is not opening in a new window delay the link
	if (linkTarget != '_blank') {
		setTimeout('document.location = "' + redirectLink + '"', 100);
	}
}
function popup(url, width, height) 
{
 var width  = width;
 var height = height;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=no';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
// return false;
}
function sendSiteTunerConversion(stConversionType, stCconversionValue, callbackURL) {
	var url_post = "apis/sitetuners/postConversion.html";
	
	$.ajax({
		type: "POST",
		url: url_post,
		data: "stConversionType="+ stConversionType +"& stCconversionValue="+ stCconversionValue,
		success: function(msg){
			if (callbackURL != undefined) {
				var target = callbackURL.target;
				if (target == '_blank') {
					window.open(callbackURL);
				} else {
					location.href = callbackURL;
				}
			}
		}
	});
}
//Macromedia Functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
  var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
  for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
      if (r&&v.length==0){err=true}
      if (v.length>0)
      if (t==1){ //fromto
        ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
      } else if (t==2){
        rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
      } else if (t==3){ // date
        ma=a[i+1].split("#");at=v.match(ma[0]);
        if(at){
          cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
          dte=new Date(cy,cm,cd);
          if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
        }else{err=true}
      } else if (t==4){ // time
        ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
      } else if (t==5){ // check this 2
            if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!o1.checked){err=true}
      } else if (t==6){ // the same
            if(v!=MM_findObj(a[i+1]).value){err=true}
      }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
          at = a[i].match(/(.*)\[(\d+)\].*/i);
          o2=(o.length>1)?o[at[2]]:o;
      if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
      if (t==2){
        oo=false;
        for(j=0;j<o.length;j++){oo=oo||o[j].checked}
        if(!oo){s+='* '+a[i+3]+'\n'}
      }
    } else if (o.type=='checkbox'){
      if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
      if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
      if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
  }
  if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
  document.MM_returnValue = (s=='');
}
function parseStrForParam(param1, param2) {
	var str = param2;
	if ((str == null) || (str == "")) {
		return "";
	} else {
		if (str.indexOf(param1) == -1) {
			return "";
		}
		var startString = str.substr(str.indexOf(param1) + (param1.length + 1));
		var end = (startString.indexOf("&") != -1) ? (startString.indexOf("&")) : startString.length;
		var answer = startString.substr(0,end);
		return answer;
	}
}

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
}
else if(document.all)// ie
window.external.AddFavorite(url, title);
} 


