



function sortTable(x, y) {
	document.TableSelect.action.value = 0;
	document.TableSelect.actionkey.value = 0;
	document.TableSelect.actiondata1.value = 0;
	document.TableSelect.sortcol.value = x;
	document.TableSelect.sortord.value = y;

	document.TableSelect.submit();
}

function goToPage(x) {
	document.TableSelect.action.value = 0;
	document.TableSelect.actionkey.value = 0;
	document.TableSelect.actiondata1.value = 0;
	document.TableSelect.sortpage.value = x;

	document.TableSelect.submit();
}





function openPopupTextTitle(e,title,text)
{
  var left = 0;
  var top = 0;
  if(e)
  {
    var pos = getMousePos(e);
    left = pos[0]+30;
    top = pos[1]-40;
  }
  else
  {
    var pos = getPageSize();
    left = pos[0]/2-320/2;
    top = pos[1]/2 - 200/2;
  }
  showLayerPopupSized(title,text,320,250);


}

function openPopupText(e,x) {

  var attrib = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=141,height=186";
  var text = "";
  switch (x) {
   case 1:
     text = "Web page address where text links will reside";
     break;
   case 2:
     text = "Number of text link spaces being sold by Web site";
     break;
   case 3:
     text = "Indicates whether the link space you purchase will live on the homepage or subpage of the Web site";
     break;
   case 4:
     text = "PageRank is an index used by Google to value Websites on a scale of 0 to 10, based largely on link popularity.<BR> Learn more <a href=\"http://pr.blogflux.com\" target=\"_blank\">click here</a>";
     break;
   case 5:
     text = "Indicates whether the link space you purchase will live on a single page or on all pages of the Web site";
     break;
   case 6:
     text = "Cost per month to rent text link space on the Web site";
     break;
	case 7:
	 text = "Web page description where text links will reside";
	 break;
    case 8:
     text = "Indicates the positioning of the text link space being sold on the Web site<BR><div align=center><img src='images/position.gif'></div>";
	 break;
    case 9:
     text = "Number of Web pages that are currently linking to the Web site";
	 break;
	case 10:
     text = "Number of incoming .edu links for the Web site";
	 break;
   case 11:
     text = "Alexa ranking is a general indicator for the amount of traffic a Web site receives (similar to Nielsen ratings for the Web).<BR> The lower the Alexa number, the more traffic the Web site receives, i.e. Yahoo.com is #1, Google.com is #2. <BR>To find out more about Alexa, <a href=\"http://www.alexa.com/\" target=\"_blank\">click here</a>";
     break;
   case 12:
     text = "The date when the site was go live";
     break;
   case 13:
     text = "";
     break;
   case 14:
     text = "Number of Web pages that are currently linking to the Web site";
	 break;
   case 15:
     text = "This is the date when all of the statistics (i.e. incoming links, edu links, PageRank etc.) were gathered for this Web site";
	 break;
  }

  var pos = getMousePos(e);
  var left = pos[0]+30;
  var top = pos[1]-40;
  var h = (text.length/40+1) * 18;
  showLayerPopupSized('Instructions',text,300,h);
  var div = document.getElementById('zsPopupDivZS');
  if(div)
  {
     var winSize = getPageSize();
	 var winWidth = winSize[0];
	 if(winWidth<left+300)
	  left =  winWidth - 300 - 50;
     div.style.left = left + 'px';
 	 div.style.top = top + 'px';
  }

}

var globalLastPositionElement;
function showPositionsImage(positionElement)
{
  globalLastPositionElement = positionElement;

  showLayerPopup('Position','<img src="images/position.gif" width="121" height="151" border="0" usemap="#Map"  align="center"/>'+
	              '<map name="Map" id="Map">'+
				  '<area shape="rect" coords="0,0,127,23" href="javascript:setPosition(2);" />'+
				  '<area shape="rect" coords="99,21,119,94" href="javascript:setPosition(2);" />'+
				  '<area shape="rect" coords="1,22,20,94" href="javascript:setPosition(1);" />'+
				  '<area shape="rect" coords="22,22,100,94" href="javascript:setPosition(1);" />'+
				  '<area shape="rect" coords="2,95,121,149" href="javascript:setPosition(3);" />'+
				'</map>');
}


function setPosition(index)
{
  globalLastPositionElement.selectedIndex = index-1;
  hidePopup();
}


function addToCart(action, id, title, price)
{
	addRowToShoppingCartTable(id, title, price);
	var url = CAMPUS_AJAX_URL;
	var pars = 'action=' + action + '&id=' + id+'&title='+escape(title)+'&price='+escape(price);
	var myAjax = new Ajax.Request(
					url,
					{method: 'get', parameters: pars}
					);
}


function addRowToShoppingCartTable(id, title, price)
{
    var tbody = $('shoppingCartTable').getElementsByTagName("TBODY")[0];
	if(tbody)
	 {
		if($('shoppingCartRow'+id))
		{
			//highliht exisiting row in shopping cart
		    highlightTableRow('shoppingCartRow'+id,'#FCE185');
		}
		else
		 {
			var row = document.createElement("TR");
			row.id = 'shoppingCartRow'+id;
			var td1 = document.createElement("TD");
			td1.style.paddingLeft = 0;
			td1.appendChild(document.createTextNode(title));

			var td2 = document.createElement("TD");
			td2.style.paddingLeft = 5;
			td2.appendChild (document.createTextNode("$"+(formatPrice(price)) ));

			var link = document.createElement('A');
			link.innerHTML = 'remove';
			link.onclick = new Function('',"deleteFromCart(501," + id + ","+price+");");
			var td3 = document.createElement("TD");
			td3.appendChild (link);

			row.appendChild(td1);
			row.appendChild(td2);
			row.appendChild(td3);
			tbody.appendChild(row);
			var totalPrice = $('shoppingCartTotalSpan').innerHTML.replace(',','');
			var total = parseFloat(totalPrice) + parseFloat(price);

			$('shoppingCartTotalSpan').innerHTML = formatPrice(total);


	        if($('shoppingCartEmptyMessage'))
        		$('shoppingCartEmptyMessage').style.display = total?'none':'';
            if($('shoppingCartTable'))
    	    	$('shoppingCartTable').style.display = total?'':'none';
			if($('shoppingCartProceedButton'))
				$('shoppingCartProceedButton').style.display = total?'':'none';

			//highliht new row in shopping cart
		    highlightTableRow('shoppingCartRow'+id,'#CAE8B5');
		 }
	 }
}

function deleteFromCart(action,id,price)
{
	 deleteRowFromShoppingCartTable(id,price);
	 var url = CAMPUS_AJAX_URL;
	 var pars = 'action=' + action + '&id=' + id;
	 var myAjax = new Ajax.Request(
					url,
					{method: 'get', parameters: pars}
					);
}

function deleteRowFromShoppingCartTable(id,price)
{
	if($('shoppingCartTable'))
    {
		var tbody = $('shoppingCartTable').getElementsByTagName("TBODY")[0];
		var row = $('shoppingCartRow'+id);
		tbody.removeChild(row);
		var totalPrice = $('shoppingCartTotalSpan').innerHTML.replace(',','');
		var total = parseFloat(totalPrice) - parseFloat(price);
		if(total<0)
			total = 0;

		$('shoppingCartTotalSpan').innerHTML = formatPrice(total);

        if($('shoppingCartEmptyMessage'))
    		$('shoppingCartEmptyMessage').style.display = total?'none':'';
        if($('shoppingCartTable'))
    		$('shoppingCartTable').style.display = total?'':'none';
		if($('shoppingCartProceedButton'))
				$('shoppingCartProceedButton').style.display = total?'':'none';

	}
	else if($('mainShoppingCartTable'))
	{
      var prevID = getPreviousFillCheckBoxID(id);
      var nextID = getNextFillCheckBoxID(id);
	  var tbody = $('mainShoppingCartTable').getElementsByTagName("TBODY")[0];
	  var row = $('shoppingCartSmallRow'+id);
	  if(row)
	    tbody.removeChild(row);
       var row2 = $('shoppingCartLargeRow'+id);
       if(row2)
	     tbody.removeChild(row2);
       var row3 = $('shoppingCartDetailRow'+id);
       if(row3)
	     tbody.removeChild(row3);



       if(nextID && !prevID)
	   {
		   var span = $('autoFillSpan'+nextID);
		   if(span)
		   {
             span.checked = false;
		     span.style.display = 'none';
		   }
	   }

	   updateGrandTotal();

	}
}


function highlightTableRow(id,color)
{
 var hColor = color || '#cecece';
 var row  = $(id);
 if(row)
 {
   row.style.backgroundColor = hColor;
   setTimeout("$('"+id+"').style.backgroundColor = '#FFFFFF';",800);
 }
}



function toggleFilterRow(row,id)
{
  if(document.getElementById(id).style.display=='none')
	{
	  row.style.backgroundPosition = '0px -17px';
      document.getElementById(id).style.display = '';
	}
  else
	{
	  row.style.backgroundPosition = '0px 0px';
      document.getElementById(id).style.display = 'none';
	}

}


function addToHotList(row,action,id)
{
 var uaIE = typeof document.all!="undefined" && !window.opera;
 if(!HotListPagesArray[id])
	{
	  row.style.backgroundPosition = uaIE?'0px -33px':'0px -40px';
      HotListPagesArray[id] = id;
	  ajaxAddToHotList(action,id);
 	}
  else
	{

	  row.style.backgroundPosition = uaIE?'0px 6px':'0px -1px';
	  HotListPagesArray[id] = '';
	  ajaxAddToHotList(action,id);
	  if($('hotPagesRow'+id))
	     $('hotPagesRow'+id).parentNode.removeChild($('hotPagesRow'+id));
	}
    if($('noHotPagesMessage'))
	  $('noHotPagesMessage').style.display = getHotListPagesArrayLength()>0?'none':'';
	if($('hotPagesTop'))
	  $('hotPagesTop').style.display = getHotListPagesArrayLength()>0?'':'none';
	if($('hotPagesTable'))
	  $('hotPagesTable').style.display = getHotListPagesArrayLength()>0?'':'none';
}

function getHotListPagesArrayLength()
{
 var count = 0;
 for(var i=0;i<HotListPagesArray.length;i++)
 {
  if(HotListPagesArray[i])
   count++;
 }
 return count;
}


function ajaxAddToHotList(action,id)
{
 		var url = CAMPUS_AJAX_URL;
		var pars = 'action=' + action + '&id=' + id;


		var myAjax = new Ajax.Request(
					url,
					{method: 'get', parameters: pars, onComplete: ajaxAddToHotListResponse}
					);

}

function ajaxAddToHotListResponse(originalRequest)
{
		//put returned XML in the textarea
		if($('hotpages_count_span'))
         $('hotpages_count_span').innerHTML = originalRequest.responseText;

}


 function updateLinkPreview(id)
 {
   $('textLinkPreview'+id).innerHTML = $('linkText'+id).value;
   $('textLinkPreview'+id).href =  $('linkDestination'+id).value;
   autoFillAll($('autoFill'+id));
 }

 function updateTotal(id,price)
 {
   var index =  $('linkDuration'+id).options[$('linkDuration'+id).selectedIndex].value;
   $('textLinkTotal'+id).innerHTML = formatPrice(index*price);

   $('linkTotal'+id).value = index*price;
   updateGrandTotal();
 }

function getNextFillCheckBoxID(id)
 {
  var autoFills = document.getElementsByClassName('autoFillCheckbox');
  for(var i = 0; i<autoFills.length-1; i++)
  {
	  if(autoFills[i].value == id)
          return autoFills[i+1].value;
  }
  return 0;
 }


 function getPreviousFillCheckBoxID(id)
 {
  var autoFills = document.getElementsByClassName('autoFillCheckbox');
  for(var i = autoFills.length-1; i>0; i--)
  {
	  if(autoFills[i].value == id)
          return autoFills[i-1].value;
  }
  return 0;
 }

 function fillFromPrevious(id)
 {
  var oldID = getPreviousFillCheckBoxID(id);
  if(oldID)
  {
    if($('linkText'+oldID) && $('linkText'+id))
       $('linkText'+id).value = $('linkText'+oldID).value;
    if($('linkDestination'+oldID) && $('linkDestination'+id))
       $('linkDestination'+id).value = $('linkDestination'+oldID).value;
  }
 }


 function autoFillAll(except)
 {
  var autoFills = document.getElementsByClassName('autoFillCheckbox');
  for(var i=0;i<autoFills.length;i++)
   {

     if(except != autoFills[i] && autoFills[i].checked)
	 {
       var id = parseInt(autoFills[i].value);
       fillFromPrevious(id);
	 }
   }
 }

 function updateGrandTotal()
 {
  var grandTotal = 0;
  var totals = document.getElementsByClassName('linkTotalValue');
  for(var i=0;i<totals.length;i++)
  {
    grandTotal+=parseFloat(totals[i].value);
  }
  $('textLinkGrandTotal').innerHTML = formatPrice(grandTotal);
  //$('linkGrandTotal').value = grandTotal;
  if($('mainCheckoutButton'))
	  $('mainCheckoutButton').style.visibility = grandTotal>0?'visible':'hidden';
 }

 function numberMask(e, val, y) {
  var y = y || 0;
  var keynum;
  var keychar;
  var numcheck;


  if (window.event) {
    keynum = e.keyCode;
  }
  else if (e.which && e.which!=8 && e.which!=9) {
    keynum = e.which;
  }
  else
    return true;


  if(navigator.userAgent.toLowerCase().indexOf('safari') >= 0 && (keynum == 8 || keynum ==9))
	{
	  return true;
	}
  keychar = String.fromCharCode(keynum);
  numcheck = /\d/;
  return ((val.length<y||!y) && numcheck.test(keychar));
}


function openPrintPreview(html)
{
 var win =  window.open('','print_payment','');
 if(win)
 {
  	 win.document.title = 'Print Preview';
	 win.document.open();
  	 win.document.write(html);
 	 win.document.close();
  	 win.print();
 }
 else
	 alert('Popup window can not be opened! Probably it was blocked.');
}


function showRenewWindow(link)
{
  var html = '<div align="left" style="padding:5px">Note: When you click \'Continue\' below you will be taken to your shopping cart page with your link text and destination URL pre-populated. If you change either the link text or destination URL, your text link will be treated as a new text link.<BR><BR>';
  html += 'If you leave the link text and destination URL as they appear in your shopping cart, then the duration and end date of your existing text link will just be extended.<BR><BR>';
  html +=  '<INPUT TYPE="button"  value="Continue" class="button_select" onclick="location.href = \''+link.href+'\';"><BR></div>';
  showLayerPopupSized('Renew Text Link',html,420,200);
}


function showEditWindow(e, id, text, href, locationURL) {

  var pos = getMousePos(e);
  var left = pos[0]-400;
  var top = pos[1]-100;
  if( href!=null && href.indexOf('http://')<0 )
	  href  = 'http://'+href;

  var link = "<a href=\""  + href + "\">" + text + "</a>";
  document.getElementById("actionkey").value = id;
  document.getElementById("locationSpan").innerHTML = locationURL;
  document.getElementById("copyDiv").style.left = left+'px';
  document.getElementById("copyDiv").style.top = top+'px';
  document.getElementById("copyDiv").style.visibility = 'visible';
  document.getElementById("copytext").value = text;
  document.getElementById("copytext2").value = href;
  document.getElementById("linkPreview").href = href;
  ltxt = text.length>37?(text.substring(0,35)+'...'):text;

  document.getElementById("linkPreview").innerHTML = ltxt;
}
