<!--//
// ns 4.x resize bug fix

function reloadPage(init) {  
  if (init==true) with (navigator) {
  	if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
  	    document.pgW=innerWidth; 
  	    document.pgH=innerHeight; 
  	    onresize=reloadPage; }
    	} else if 
    	    (innerWidth!=document.pgW || innerHeight!=document.pgH) 
    
    location.reload();
}

reloadPage(true);

// drop-down script

function menuOver(id) {
	
	ie4 = (document.all)? true:false
	nn4 = (document.layers)? true:false
	stDom = false;
    if (id) {	
	if(document.getElementById && document.createElement) {
		stDom = true;
		ie4 = false; }
	else { stDom = false; }

	if(ie4){
		if (document.all[id].style.visibility == 'hidden') {
			document.all[id].style.visibility = "visible";
			 }
		else { 
			document.all[id].style.visibility = "hidden"; }
	}
if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4)) {
	 stDom = false; }
	 	
	if(stDom){
		if (document.getElementById(id).style.visibility == 'hidden') {
			document.getElementById(id).style.visibility = "visible"; }
		else { 
			document.getElementById(id).style.visibility = "hidden"; }
	}
      }
}


// drop-down redirect
function jumpMenu(targ,path,selObj,restore){ 
eval(targ+".location='"+path+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0; }

function softEx(nonEx,framePage) {
	
	getTagCheck = (document.getElementsByTagName)? true:false;
				
	// redirect to iframed order page
	if ((getTagCheck) && (framePage)) {
		if (document.getElementsByTagName('iframe')) {
			nonEx = framePage;						
		} 					
	}
	
	document.write(nonEx);

}

function setCookie(name,value) {
	var today = new Date();
	var expiry = new Date(today.getTime() + 60 * 24 * 60 * 60 * 1000); // plus 60 days
	document.cookie = name + '=' + value + ';expires=' + expiry.toGMTString() + ';path=/'; 
	//alert(document.cookie);
}

function checkDrop(sel,cookieName,force) {
	getCookie(cookieName);
	var formName = document.CHECKOUTFORM;
	if (value == 1) {
		formName[sel].options[formName[sel].selectedIndex].value = force;
		//alert(force);		
	}
	
	function getCookie(name) {	 	
	 	var cookie = document.cookie;
	 	cookie = unescape(cookie);
	 	var beg = cookie.indexOf(name);
	 	if(beg != -1)  {
			beg += name.length + 1;
			value = cookie.substring(beg, (beg+1));
		} else {
			//alert('fail cookie value check');
		}
	}
}

function url(link,action) {
	if (action == 'over') {
		window.status = 'http://www.standalone.com'+link;
	} 
	
	if (action == 'out') {
		window.status = '';
	} 
	
	if (action == 'redirect') {
		window.location = link;
	}						
}

function redirectMe(selObj) {
	var link;
	var app = selObj.options[selObj.selectedIndex].value;
	if (app == 'newtonos') {
		link = 'http://www.standalone.com/'+app;
	} else if (app == 'pocketpc') {
		link = 'http://www.standalone.com/'+app;
	} else if (app == 'ebooks') {
		link = 'http://www.standalone.com/'+app;
	} else if (app == 'smartphone') {
		link = 'http://www.standalone.com/'+app;
	} else if (app.substr(0, 2) == 'C-') { 
		app = app.substr(2,app.length);
		link = 'http://www.standalone.com/pocketpc/'+app;
	} else if (app.substr(0, 2) == 'S-') { 
		app = app.substr(2,app.length);
		link = 'http://www.standalone.com/smartphone/'+app;
	} else if (app.substr(0, 2) == 'E-') { 
		app = app.substr(2,app.length);
		link = 'http://www.standalone.com/ebooks/'+app;
	}  else if (app.substr(0, 2) == 'P-') { 
		app = app.substr(2,app.length);
		link = 'http://www.standalone.com/palmos/'+app;
	} else if (app) {
		if (app == 'palmos') { app = ''; }
		link = 'http://www.standalone.com/palmos/'+app;
	}

	if (link) { window.location = link; }
}

// optimized PSI junk
function GetTurboBackCookie() {
	if (location.search != '?s=load' && location.search != '?s=loadNB' && location.search != '?s=noPI' && location.search != '?s=oldPI') {
		var allcookies = document.cookie;
		var pos = allcookies.indexOf("turboback=");
		if (pos != -1) {
			var start = pos+10;
			var end = allcookies.indexOf(";",start);
			if (end == -1) end = allcookies.length;
			var value = allcookies.substring(start,end);
			return value;
		}
	}
	return '';
}

function GetBasePath() {
	var pathname = location.pathname;
	var len = pathname.length;
	var ext = pathname.substring(pathname.length-4);
 	var i1, i2;
	if (ext == '.htm' || ext == 'html') {
		i1 = pathname.lastIndexOf('/');
		i2 = pathname.lastIndexOf('\\');
		if (i2>i1)
			i1=i2;
		pathname = pathname.substring(0,i1);
	}
	return location.protocol + "//" + location.host+pathname;
}

function GetPalmCallURL(path,app) {	
	return "PalmCall:psix.appl?p=a:en,de,es,b:1414,2828&n=SAIAPP&u=" + path + '/ota_'+app+'.prc';
}

function IsPalmOS() {
	return navigator.userAgent.indexOf("PalmOS") != -1 || navigator.userAgent.indexOf("PalmSource") != -1 || navigator.userAgent.indexOf("Blazer") != -1;
}

function IsWindows() {
	return navigator.userAgent.indexOf("Windows") != -1;
}

function SetupTimer() {
	if (GetTurboBackCookie() != 'Y' && IsPalmOS()) {
		if (location.search == "?s=load" || location.search == "?s=loadNB") {
			if (location.search == "?s=load")
				document.cookie = 'turboback=Y';
			else
				document.cookie = 'turboback=N';
			document.location = GetPalmCallURL();
		} else if (location.search == "?s=oldPI") {
			document.cookie = 'turboback=Y';
			document.location = "PalmCall:psix.appl?v=1.5.0.4(" + location.protocol+"//"+location.host+location.pathname+"?s=load)";
		} else {
			document.location = "PalmCall:psix.appl?v=1.5.0.4(" + location.protocol+"//"+location.host+location.pathname+"?s=load)("+location.protocol+"//"+location.host+location.pathname+"?s=oldPI)";
			if (location.search == "?s=noPI")
				document.cookie = 'turboback=Y';
			else
				setTimeout("GetPackageInstaller()",10000);
		}
	}
}
 
 function GetPackageInstaller() {
	document.location = location.protocol+"//"+location.host+location.pathname+"?s=noPI";
 }
// end PSI junk

// new shop iframe sniffer
// if agent reads iframes, append embed var to a.shop elements
function appendEmbed() {
	var links =document.getElementsByTagName('a');
	for (var i=0;i<links.length;i++) {
		if (links[i].className != 'shop') { continue; }

		var tagChk 			= document.getElementsByTagName ? true : false;		
		var iframeChk		= document.getElementsByTagName('iframe') ? true : false;
		if (tagChk && iframeChk) { links[i].href = links[i].href+'&embed=on'; }
	}
}

function dlRedirect(selObj) {
	if (selObj.value) {
		document.forms[selObj.form.name].submit();
	} else {
		return false;
	}
}

// http://perishablepress.com/press/2007/11/20/open-external-links-as-blank-targets-via-unobtrusive-javascript/
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}

function getRandom(max,min) {
	min = min || 0;
	return Math.random()*(max-min)+min;
}

// allow fader toggling
function generateFaderNav() {
	var carouselEle = '.carousel';
	var carouselButtonsEle = '.carouselButtons';
	var buttonEle = carouselButtonsEle+' button';
	var activeClass = 'active';
	var screenshotEle = carouselEle+' .screenshot img';
	if ($(carouselEle).length == 0) return;
	
	// insert carousel buttons
	$('<div class="carouselButtons"><button type="button" name="deviceType" value="iphone">iPhone</button><button type="button" name="deviceType" value="ipad" class="active">iPad</button></div>').appendTo(carouselEle);
	
	$(buttonEle).click(function () {
		var button = this.value.toLowerCase();
		$(buttonEle).removeClass('active');
		$(this).addClass('active');
		$(buttonEle).each(function () {
			$(carouselEle).removeClass(this.value.toLowerCase()+'Screens');
		});
		
		$(carouselEle).addClass(button+'Screens');
		// replace screenshots
		$(screenshotEle).each(function () {
			this.src = this.src.replace(/\-\w{1,}(\.\w{3,4}$)/, '-'+button.toLowerCase()+'$1');
		});
	}); 
	
}


window.onload = function() {
	externalLinks();
}
//-->	
