// Set our variables
var url = "http://www.geekycreative.com/services";
var ua = navigator.userAgent.toLowerCase();	
var ipod = detect_Phone(/ipod/i); // Will return true OR false
var iphone = detect_Phone(/iphone/i);
var android = detect_Phone(/android/i);
var blackberry = detect_Phone(/blackberry/i);
var windows = detect_Phone(/windows ce/i);
	
$(document).ready(function(){	
	// Call our function
	throwPopUp(iphone, "iphone", url);
	throwPopUp(android, "android", url);
	throwPopUp(blackberry, "blackberry", url);
	throwPopUp(windows, "windows", url);
});

function throwPopUp(bool, phone, url) {		
	if(bool == true){
		var cookie = vetCookie(phone); // Check the cookie out
		var mssg = "Dear " + phone + " user,\nHere at GeekyCreative we build Apps for " + phone + ".\nClick OK to find out more.\nYou will not be shown this alert again in the next 60 days.";
		if(cookie == false){
			if(confirm(mssg)){
				window.location.href = url;
			}
		}
	}
}
	
function detect_Phone(phone) {
	if (ua.search(phone) > -1) {
		return true;
	} else {
		return false;
	}
}
	
function setCookie(name,value,numb) {
	var xDate = new Date();
	xDate.setDate(xDate.getDate() + numb);
	var cval = escape(value) + ((numb == null) ? "" : "; expires=" + xDate.toUTCString());
	document.cookie = name + "=" + cval;
}

function getCookie(name) {
	var i,x,y,ARRcookies = document.cookie.split(";");
	for(i=0;i<ARRcookies.length;i++){
		x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		x = x.replace(/^\s+|\s+$/g,"");
		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		if(x == name) {
			return unescape(y);
		}
	}
}

function vetCookie(phone) {
	var sg = getCookie("GeekyCreative.com.PhoneCheck");
	if(sg != null && sg != "" && sg == phone)
	{
		return true;
	}
	else
	{
		setCookie("GeekyCreative.com.PhoneCheck",phone,60);
		return false;
	}
}
