var pagePath = window.location.pathname;
var pathPage = pagePath.substring(pagePath.lastIndexOf('/') + 1);
var pageName = pathPage.substring(0,pathPage.indexOf("."));
var scrollpos=0, scrollspeed=30; 

var support = new Boolean(false);
try {
	var thisPage = new ArgumentURL();
	var packageType = thisPage.getArgument('package');
	var subscription = packageType;
	var packageCost = 59.95;
} catch(err) {
	var packageType = "bronze";
	var subscription = packageType;
	var packageCost = 59.95;
}

function setCookie(name, value, expires) {
	if (!expires) expires = new Date(); 
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

try {
	var affid = thisPage.getArgument('affid');
	var expdate = new Date(); // pre-set to the current time and date
	expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 60); // add 60 days to it 
	setCookie("affid",affid,expdate);
} catch(err) {
	var affid = getCookie("affid");
	if (!affid) { affid = 'none'; }
}
   
try {
	var awc = thisPage.getArgument('awc');
	var awcdate = new Date(); // pre-set to the current time and date
	awcdate.setTime(awcdate.getTime() + 1000 * 60 * 60 * 24 * 7); // add 7 days to it 
	setCookie("awc",awc,awcdate);
} catch(err) {
	var awc = getCookie("awc");
	if (!awc) { awc = 'none'; }
}

if (pageName == "thankyou") {
	var oldProt = window.location.protocol;
	if (oldProt != "https:") {
		var newURL = "https://" + window.location.hostname + window.location.pathname;
		window.location = newURL;
	}
	var orderType = getCookie("order");
	if (!orderType) {
		alert("Complete the Paypal subscription to access this page.  Your IP address has been logged for security purposes.");
		window.location = "http://www.ezdownloadsolutions.com/packages.html";
	} else {
		packageType = orderType;
	}
}

if (pageName == "partners") {
	try {
		var ptype = thisPage.getArgument('ptype');
	} catch(err) {
		var ptype = 'affiliate';
	}
}

function Leftstr(str, n){
 if (n <= 0)
  return "";
 else if (n > String(str).length)
  return str;
 else
  return String(str).substring(0,n);
}

function Rightstr(str, n){
 if (n <= 0)
  return "";
 else if (n > String(str).length)
  return str;
 else {
  var iLen = String(str).length;
  return String(str).substring(iLen, iLen - n);
 }
}

function setSupport(package) {
 x = eval("document.orderForm.chooseSupport");
 switch(package) {
 case "titanium":
  packageType = "titanium";
  subscription = packageType;
  x.checked = true;
  x.disabled = true;
  document.getElementById('supportText').innerHTML = "Support Package (included)";
  packageCost = 159.95;
  document.getElementById('orderprice').innerHTML = "$" + parseFloat(packageCost).toFixed(2);
  document.orderForm.encrypted.value = "896339";
  break;
 case "platinum":
  packageType = "platinum";
  subscription = packageType;
  x.checked = true;
  x.disabled = true;
  packageCost = 139.95;
  document.getElementById('supportText').innerHTML = "Support Package (included)";
  document.getElementById('orderprice').innerHTML = "$" + parseFloat(packageCost).toFixed(2);
  subscription = packageType;
  document.orderForm.encrypted.value = "896306";
  break;
 case "gold":
  packageType = "gold";
  subscription = packageType;
  x.disabled = false;
  packageCost = 89.95;
  document.orderForm.encrypted.value = "896235";
  if (x.checked) {
   packageCost = packageCost + 19.95;
   subscription = packageType + "cs";
   document.orderForm.encrypted.value = "896263";
  }
  document.getElementById('supportText').innerHTML = "Support Package ($19.95/mth)";
  document.getElementById('orderprice').innerHTML = "$" + parseFloat(packageCost).toFixed(2);
  break;
 case "silver":
  packageType = "silver";
  subscription = packageType;
  x.disabled = false;
  packageCost = 69.95;
  document.orderForm.encrypted.value = "896133";
  if (x.checked) {
   packageCost = packageCost + 19.95;
   subscription = packageType + "cs";
   document.orderForm.encrypted.value = "896210";
  }
  document.getElementById('supportText').innerHTML = "Support Package ($19.95/mth)";
  document.getElementById('orderprice').innerHTML = "$" + parseFloat(packageCost).toFixed(2);
  break;
 default:
  packageType = "bronze";
  subscription = packageType;
  x.disabled = false;
  packageCost = 59.95;
  document.orderForm.encrypted.value = "896029";
  if (x.checked) {
   packageCost = packageCost + 19.95;
   subscription = packageType + "cs";
   document.orderForm.encrypted.value = "896176";
  }
  document.getElementById('supportText').innerHTML = "Support Package ($19.95/mth)";
  document.getElementById('orderprice').innerHTML = "$" + parseFloat(packageCost).toFixed(2);
 }
}
   
function pageSetup(package){
 switch (pageName) {
  case "packages" :
   packageType = package;
   hidediv('bronzetab');
   hidediv('silvertab');
   hidediv('goldtab');
   hidediv('platinumtab');
   hidediv('titaniumtab');
   hidediv('bronzetext');
   hidediv('silvertext');
   hidediv('goldtext');
   hidediv('platinumtext');
   hidediv('titaniumtext');
   showdiv(package + 'tab');
   showdiv(package + 'text');
   setSupport(package);
   break;
  case "thankyou" :
   switch (package) {
    case "titaniumcs":
    case "platinumcs":
     packageType = Leftstr(package,package.length - 2);
     support = true;
     break;
    default:
     if (Rightstr(package,2) == "cs") {
      packageType = Leftstr(package,package.length - 2);
      support = true;
     } else {
      packageType = package;
      support = false;
     }
     switch (packageType) {
      case "gold":
      case "silver":
      case "bronze":
       break;
      default:
       window.location = "http://www.ezdownloadsolutions.com";
     }
   }
   hidediv('bronzetab');
   hidediv('silvertab');
   hidediv('goldtab');
   hidediv('platinumtab');
   hidediv('titaniumtab');
   hidediv('supportText');
   hidediv('noSupportText');
   if (support)
    showdiv('supportText');
   else
    showdiv('noSupportText');
   showdiv('namePrompt');
   showdiv(packageType + 'tab');
   switch (packageType) {
    case "titanium":
     document.getElementById('pkg').style.color = "#657274";
     break;
    case "platinum":
     document.getElementById('pkg').style.color = "#786469";
     break;
    case "gold":
     document.getElementById('pkg').style.color = "#ebb93d";
     break;
    case "silver":
     document.getElementById('pkg').style.color = "#a5a6aa";
     break;
    case "bronze":
     document.getElementById('pkg').style.color = "#ce8c6c";
     break;
   }
   document.getElementById('pkg').innerHTML = UCFirst(packageType) + " ";
   document.accountForm.contact.focus();
   break;
  default:
   break;
 }
}

function showThis(thisDiv) {
 hidediv('namePrompt');
 hidediv('emailPrompt');
 hidediv('phonePrompt');
 hidediv('companyPrompt');
 hidediv('cartemailPrompt');
 hidediv('paypalPrompt');
 hidediv('confirmPrompt');
 hidediv('passPrompt');
 showdiv(thisDiv);
}

function showPartnerText() {
 thisdiv = ptype + 'text';
 showdiv(thisdiv);
}

function submitAccountForm() {
 if(document.accountForm.onsubmit())
 {
 document.accountForm.package.value = packageType;
 document.accountForm.affid.value = affid;
 document.accountForm.submit();
 }
}

function submitContactForm() {
 if(document.contactForm.onsubmit())
 {
 document.contactForm.submit();
 }
}

function submitPartnerForm() {
 if(document.partnerForm.onsubmit())
 {
 document.partnerForm.ptype.value = ptype;
 document.partnerForm.submit();
 }
}

function submitOrderForm() {
	submitURL = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=" + document.orderForm.encrypted.value;
	x = eval("document.orderForm.chooseSupport");
	if (x.checked) {
		subscription = packageType + "cs";
	} else {
		subscription = packageType;
	}
	orderExp = new Date();
	orderExp.setTime(orderExp.getTime() + 1000 * 60 * 15); // add 15 minutes to it 
	setCookie("order",subscription,orderExp);
	window.location = submitURL;
}

function UCFirst(str) {
   // split string
   firstChar = str.substring(0,1);
   remainChar = str.substring(1);
   // convert case
   firstChar = firstChar.toUpperCase(); 
   remainChar = remainChar.toLowerCase();
   return firstChar + remainChar;
}

function showMovie(mov) {
	document.getElementById('demomovie').innerHTML = '<OBJECT id="demomov" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="500" height="390" codebase="http://www.apple.com/qtactivex/qtplugin.cab">\n<param name="src" value="/images/' + mov + '">\n<param name="autoplay" value="true">\n<param name="scale" value="tofit">\n<param name="kioskmode" value="true">\n<param name="loop" value="false">\n<EMBED name="demomov" src="/images/' + mov + '" width="500" height="390" autoplay="true" kioskmode="true" scale="tofit" loop="false" pluginspage="http://www.apple.com/quicktime/download/">\n</EMBED>\n</OBJECT>\n';
}

function doTrackers() {
	if (awc != 'none') {
	
	}
}

function scrollIt() {
	document.getElementById('scroller').style.backgroundPosition=scrollpos+'px 0px';
	scrollpos--;  // specifies left / right or top / bottom.
	setTimeout('scrollIt()',scrollspeed);
}

function animBanner() { 
	document.getElementById('scrolltext').style.right = '650px';
	$('element').hide();
	$('element2').hide();
	
	$('element').grow({direction: 'top-right', duration: 1.5, queue: 'front'});
	$('element').pulsate({ pulses: 1, from: 1.0, duration: 3.0, queue: 'end' });
	$('element').shrink({direction: 'bottom-left', duration: 1.5, queue: 'end'});
	$('element2').appear({ duration: 4.0, queue: 'end' });
	$('element2').pulsate({ pulses: 1, from: 1.0, duration: 2.0, queue: 'end' });
	$('element2').fade({ duration: 2.0, from: 1.0, to: 0.0, queue: 'end' });
	new Effect.Morph ('scrolltext', {style: {right: '0px'}, duration: 5.0, queue: 'end'});
	$('scrolltext').pulsate({ pulses: 5, duration: 2.0, queue: 'end' });
	
	setTimeout('animBanner()',25000);
}

function showTerms() {
	if (ptype == 'affiliate') {
		window.open('http://www.ezdownloadsolutions.com/terms.htm');
	} else {
		window.open('http://www.ezdownloadsolutions.com/termsresellers.htm');
	}
}
