﻿// JScript File
//1-Ticket(Download) 2-UploadSuccess 0-Others
var Splash = true;
var sDomain = "http://www.fileflyer.com/";
//var sDomain = "http://test.fileflyer.com/";
//var sDomain = "http://localhost/fileflyer/";
//var sMaxDomain = "http://localhost/fileflyermax/";
var sMaxDomain = "http://max.fileflyer.com/";

var browserName
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(!is_chrome)
	browserName=navigator.appName;
else
	browserName="Chrome";

var is_Vista = navigator.userAgent.indexOf('Windows NT 6.0') > -1;



//sending ToolbarID to server side
function OnPageLoadDesign()
{	
  var ToolbarID = GetToolbarID();
  if (ToolbarID!="0" && ToolbarID!=null) {
	if(document.getElementById("maxlogo")) document.getElementById("maxlogo").innerHTML = "<img src=\"" + sDomain + "img/max_header.gif\" width=\"63\" height=\"58\" alt=\"Max\" />";
	if(document.getElementById("maxlogo_eg")) document.getElementById("maxlogo_eg").innerHTML = "<img src=\"" + sDomain + "img/max_header.gif\" width=\"63\" height=\"58\" alt=\"Max\" />";
	if(document.getElementById("maxlogogadget")) document.getElementById("maxlogogadget").innerHTML = "<img src=\"" + sDomain + "img/gadget_header2.gif\" width=\"49\" height=\"44\" alt=\"Max\" />";
  }
}

function showMaxBanner() {
//	if((browserName == "Netscape") || (browserName == "Microsoft Internet Explorer")) {
	if(browserName == "Microsoft Internet Explorer") {
		ToolbarID = GetToolbarID();
		if (ToolbarID == "0") {
			//if((PageName == "2") || ((PageName == "1") && (browserName == "Netscape"))) {
//			if(PageName == "2") {
//				cValue=location.href;
//				setCookie('FFMaxpreURL',cValue,2);
//				if(document.getElementById("showBanner")) document.getElementById("showBanner").innerHTML = "<a href=\"" + sDomain +"max/\"><img src=\"" + sDomain + "img/max_banner.gif\" alt=\"FileFlyerMax\" \/></a>";
//			} else if (browserName=="Microsoft Internet Explorer" && PageName == "1") {
			if (!is_Vista) {
				if(document.getElementById("showBanner")) document.getElementById("showBanner").innerHTML = "<a href=\"javascript:\" onclick=\"setCookie('FFMax','');setCookie('FFVisit','',1);dwlFileFlyerMax();\"><img src=\"" + sDomain + "img/max_banner.gif\" alt=\"FileFlyerMax\" \/></a>";
			} else if (is_Vista) {
				if(document.getElementById("showBanner")) document.getElementById("showBanner").innerHTML = "<a href=\"" + sDomain +"max/\" target=\"_blank\"><img src=\"" + sDomain + "img/max_banner.gif\" alt=\"FileFlyerMax\" \/></a>";
			}
//			}
		} 
	}
}

function showSplash() {
	if (Splash == true) {
		FFMax = getCookie('FFMax');
		FFVisit = getCookie('FFVisit');
		if(FFVisit == null || FFVisit == "") {
			FFVisit = setCookie('FFVisit','1',24);
			dwlFileFlyerMax();
		} else if (FFVisit == "1" && (FFMax == "1" || FFMax == "2")) {
			dwlFileFlyerMax();
		}
	} else {
		
		FFMax = getCookie('FFMax');
		if(FFMax == "1") {
			dwlFileFlyerMax();
		}
	}

}

function dwlFileFlyerMax() {
	ToolbarID = GetToolbarID();
	//if(((browserName == "Netscape") || (browserName == "Microsoft Internet Explorer")) && (ToolbarID == "0")) {
	if((browserName == "Microsoft Internet Explorer") && (ToolbarID == "0")) {

		// set height for dark screen
		if(document.getElementById("sms_offer")) wrapheight = "1400px"
		else if(document.getElementById("plimus_offer")) wrapheight = "1450px"
		else wrapheight = "1200px"
		if(document.getElementById("overlay")) document.getElementById("overlay").style.height = wrapheight;

		// show dark screen and spash window
		document.getElementById("overlay").style.display = "block";
		document.getElementById("boxDrag").style.display = "block";

		// if no cookie - show activex explanation
		FFMax = getCookie('FFMax');
		if(FFMax==null || FFMax =="" || FFMax == "2") {
			//set cookies
			cValue=location.href;
			setCookie('FFMaxpreURL',cValue,2);

			document.getElementById("maxdwl1").style.visibility = "visible";
			document.getElementById("maxdwl1").style.display = "block";
			document.getElementById("maxdwlframe").style.visibility = "hidden";
			document.getElementById("maxdwlframe").style.display = "none";

			//if(browserName=="Netscape") document.getElementById("maxdwlhref").innerHTML = "<a href=\"" + sDomain + "max/\"><img src=\""  + sDomain + "img/click_to_proceed.gif\" alt=\"Click to proceed\" \/><\/a>";
			//if(browserName=="Microsoft Internet Explorer") document.getElementById("maxdwlhref").innerHTML = "<a href=\"javascript:\" onclick=\"ActiveXPage();\"><img src=\""  + sDomain + "img/click_to_proceed.gif\" alt=\"Click to proceed\" \/><\/a>";
			//document.getElementById("maxdwlhref").innerHTML = "<a href=\"javascript:\" onclick=\"ActiveXPage();\"><img src=\""  + sDomain + "img/click_to_proceed.gif\" alt=\"Click to proceed\" \/><\/a>";
			if (PageName==1) document.getElementById("GenFileName").innerHTML = GetShortFileName(GetDownloadFileName());
			else if(PageName == 2) document.getElementById("GenFileName").innerHTML = GetShortFileName(GetUploadFileName());
		
		// if cookie - show download progress
		} else if (FFMax == "1") {
			document.getElementById("maxdwl1").style.visibility = "hidden";
			document.getElementById("maxdwl1").style.display = "none";
			document.getElementById("maxdwlframe").style.visibility = "visible";
			document.getElementById("maxdwlframe").style.display = "block";
			FFMaxProgress();
		}
	}
}

function ActiveXPage() {
	alert
	setCookie('FFMax','1');
	document.getElementById("maxdwl1").style.visibility = "hidden";
	document.getElementById("maxdwl1").style.display = "none";
	document.getElementById("maxdwlframe").src= sMaxDomain + "download.aspx";
	document.getElementById('maxdwlframe').style.visibility = "visible";
	document.getElementById("maxdwlframe").style.display = "inline";	
	
}

function FFMaxProgress() {
	//clearCookie('FFMax');
	setCookie('FFMax','2');
	document.getElementById("maxdwl1").style.visibility = "hidden";
	document.getElementById("maxdwl1").style.display = "none";
	document.getElementById("maxdwlframe").src= sMaxDomain + "install.aspx";
	document.getElementById('maxdwlframe').style.visibility = "visible";
	document.getElementById("maxdwlframe").style.display = "inline";
	
}

function closedwlFileFlyerMax() {
	clearCookie('FFMax');
	setCookie('FFVisit','2',24);
	document.getElementById("overlay").style.display = "none";
	document.getElementById("boxDrag").style.display = "none";
}

function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if(results == null)
    return "";
  else
    return results[1];
}

function getCookie(c_name) {
if (document.cookie.length>0) {
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1) { 
		c_start=c_start + c_name.length+1 ;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length
		return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	//document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) + "; path=/" + "; domain=fileflyer.com"
}

function clearCookie (c_name) {
	setCookie(name,"",0);
//	var d = new Date ( );  // current date & time
//	d.setTime (d.getTime() - 1 );
//	document.cookie = c_name += "=; expires=" + d.toGMTString();
}


function showSendToFriend(url, iSourcePage) {
		// show dark screen and spash window
		// iSourcePage=0-downloads 1-uploads
		document.getElementById("overlay").style.display = "block";
		document.getElementById("boxDrag").style.display = "block";
		// !!!!important!!!!! - EVERY CHANGE IN SNOTE STRING REQUIRE CHANGE IN SENDTOFRIEND.ASCX
		var sNote = "Hello, ";
		if (iSourcePage==0)
		{
			sNote += "I've downloaded this file using FileFlyer.com and I thought you may like it. ";
		}
		else
		{
			sNote += "I've uploaded this file using FileFlyer.com and I thought you may like it. ";
		}
		sNote +="You can download it at: ";
		sNote += url;
		sNote += " Enjoy. ";
		sNote += "Visit FileFlyer at: http://www.fileflyer.com";
		document.getElementById('SendToFriend_Note').innerHTML = sNote;

		//document.frmDownloadsViews.Note.value = sNote;
		
}

function closeWin(winName) {
	document.getElementById("overlay").style.display = "none";
	document.getElementById(winName).style.display = "none";
}


