﻿// Mobile Redirect Module
// For AdultAdWorld.com
// Written by Joe 02/25/2010
// joe@adworldmedia.com
// www.adultadworld.com
<!-- Begin
var urlpage = "http://newt1.adultadworld.com/jsc/z5/ff2.html?n=607;c=";
var urlcodes_end = ";w=1;h=1"; 
var expDays = 1;
// Number of days the cookie should last
var expHours = 1;
// Number of hours the cookie should last
var expMins = 1;
// Number of minutes the cookie should last

function checkMobile(pub,channel)
{
   //var count = GetCookie('aawmob');
   //if (count == null)
   //{
      //count = 1;
      //SetCookie('aawmob', count, exp);
      
       if((pub != null) && (channel != null)) {
	       uri = urlpage +  channel + ";s=" + pub + ";p=" + pub;
	       sPub = pub;
       }
       
       if (navigator.userAgent.match(/(android)/i)) {
        location.replace(uri + ";d=28" + urlcodes_end); }
       else if (navigator.userAgent.match(/(blackberry)/i)) {
        location.replace(uri + ";d=27" + urlcodes_end); }
       else if (navigator.userAgent.match(/(ipad)/i)) {
        location.replace(uri + ";d=29" + urlcodes_end); }
       else if (navigator.userAgent.match(/(iphone)/i)) {
        location.replace(uri + ";d=26" + urlcodes_end); }
       else if (navigator.userAgent.match(/(ipod)/i)) {
        location.replace(uri + ";d=30" + urlcodes_end); }
       else if (navigator.userAgent.match(/(palm)/i)) {
        location.replace(uri + ";d=31" + urlcodes_end); }
       else if (navigator.userAgent.match(/(pie|window ce|iemobile)/i)) {
        location.replace(uri + ";d=32" + urlcodes_end); }
   //}
   //else
   //{
   //   count ++ ;
   //   SetCookie('aawmob', count, exp);
   //}   
             
   //if (navigator.userAgent.match(/(opera mini|ipod|iphone|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo|nokia|blackberry|android)/i)) {
    //location.replace("http://ad.adworldmedia.com/mobile/redirect.aspx?d=" + escape(navigator.userAgent)); 
   //}
}

function GetCookie (name)
{
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen)
   {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0)
      break;
   }
   return null;
}
function SetCookie (name, value)
{
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   var exdate = new Date();
   exdate.setDate(exdate.getDate()+1);
   document.cookie = name + "=" + escape (value) +
   ((expires == null) ? "" : ("; expires=" + exdate.toUTCString())) +
   ((path == null) ? "" : ("; path=" + path)) +
   ((domain == null) ? "" : ("; domain=" + domain)) +
   ((secure == true) ? "; secure" : "");
}
function DeleteCookie (name)
{
   var exp = new Date();
   exp.setTime (exp.getTime() - 1);
   var cval = GetCookie (name);
   document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (30000 * 60 * 6));
function amt()
{
   var count = GetCookie('aawmob')
   if(count == null)
   {
      SetCookie('aawmob', '1')
      return 1
   }
   else
   {
      var newcount = parseInt(count) + 1;
      DeleteCookie('aawmob')
      SetCookie('aawmob', newcount, exp)
      return count
   }
}
function getCookieVal(offset)
{
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == - 1)
   endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
//  End -->
