<!--

//        Copyright (c) 2009 magicdew.com. All rights are reserved.
//        The content of this page is protected by copyright laws.
//        Copying, mirroring and / or "scraping" any part of this content including but not limited to
//        the javascript code is strictly prohibited. Any violation will be prosecuted to the maximum extent allowed by the law. 
//      	All protocols, packets, IPs, timestamps, etc. are sent to the owners of this page.

//-->

function change_page()
{
  var x = document.getElementById("store_select");

  window.name = 'new';

  document.new_link_location.action = x.options[x.selectedIndex].value;
  document.new_link_location.method = "post";
  document.new_link_location.submit();

}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


function check_date()
{
	var pos = document.URL.indexOf("#");
	if (pos == -1) return false;
	
	var str = document.URL.substring(pos+2);
	str = htoa_str( str );
	pos = str.indexOf("_");
	if (pos == -1) return false;
	
	var id = str.substring(0,pos);
	var time = str.substring(pos+1);
	var date = new Date();
	
	if (!check_id(id) || (Math.abs(date.getTime() - time) > 90000)) return false;
	
	return true;
}

function get_link_id()
{
	var pos = document.URL.indexOf("#");
	if (pos == -1) return '';
	
	var str = document.URL.substring(pos+2);
	str = htoa_str( str );
	pos = str.indexOf("_");
	if (pos == -1) return '';
	
	var id = str.substring(0,pos);
	return id;
}

function check_id(id)
{
	if (id.substr(0, 6) == 'cpShow') return true;
	for (var index = 0; index < ct_count; index++)
	{
		if (ct[index][1] == id) return true;
	}
	
	return false;
}


var ah_string = '1a2b3d4s5f0e7g8k';

function atoh_str( str )
{
	var str_len = str.length;
	var res = ''; var mod; var rem;
	for (var index = 0; index < str_len; index++)
	{
		mod = Math.floor(str.charCodeAt(index) / 16);
		rem = str.charCodeAt(index) % 16;
		res += ah_string.substring(mod,mod+1)+ah_string.substring(rem,rem+1);
//		res += ah_string[mod]+ah_string[rem];
	}
	return res;
}

function htoa_str( str )
{
	var str_len = str.length;
	var res = '';
	var index = 0; var mod; var rem; var ch; var pos1; var pos2;
	while (index < str_len)
	{
		pos1 = index++; pos2 = index++;
		mod = ah_string.indexOf(str.substring(pos1,pos1+1));
		rem = ah_string.indexOf(str.substring(pos2,pos2+1));
//		mod = ah_string.indexOf(str[index++]);
//		rem = ah_string.indexOf(str[index++]);
		ch = mod * 16 + rem;
		res += String.fromCharCode(ch);
	}
	return res;
}


var site = 'magicdew.com';

var wtarget = check_date() ? get_link_id() : '';
var ourparentall = (wtarget != '');

var fc_name;
function arrange()
{
var opnr_target = '';
var trgt_name = '';
var fnc_name = 'magicwindow';
var an;
var mc_params = '';
var smc_id = '';
var smc_code = '';
var index = 0;
var ans = null;

var ohsafari = false;

var browser_support = !check_browser();

if ( browser_support && ourparentall )
{ opnr_target = ' target="parent_'+wtarget+'"'; fnc_name = (typeof(is_page_static) != 'undefined') ? 'showcoupon_static' : 'showcoupon'; };

fc_name = fnc_name;
while (index < ct_count)
{
	ans = document.getElementById(ct[index][1]);
    an = document.getElementById( 'para_' + ct[index][1] );
	mc_params = "'" + ct[index][1] + "','" + check_index( ct[index][2] ) + "'";
	if (wtarget==ct[index][1]) { smc_id = ct[index][1]; smc_code = check_index( ct[index][2] ); }
	an_relhref = typeof(ct[index][3]) != 'undefined' ? ct[index][3] : relhref;
	if ((!ourparentall || browser_support))
	{
		var ancl = document.getElementById(ct[index][1]),
			scName = ans.getAttribute('scName');
		scName = scName == null ? '' : ' scName="'+scName+'"';
		if (typeof ancl.href != 'undefined') an_relhref = ancl.href;
		an.innerHTML = '<a id="'+ans.id+'" lw="'+ans.getAttribute('lw')+'"'+scName+' href="'+ an_relhref +'"'+opnr_target+' rel="nofollow" onclick="'+fnc_name+'('+ mc_params +');return true;">'+code_text+'</a>'; }
	else
	{ if (typeof(is_page_static) != 'undefined') showcoupon_static(ct[index][1],check_index(ct[index][2])); else showcoupon(ct[index][1],check_index(ct[index][2])); }
	index++;
};

var sc_show = document.getElementById('cpShow');
if (sc_show) {
if (!ourparentall || browser_support) {
	var cpSI = document.getElementById('cpShow_image');
	if (wtarget=='cpShow') { smc_id = 'cpShow'; smc_code = check_index(eval(sc_show.getAttribute('hs'))); }
	sc_show.onclick = function() {
		eval(fc_name+'("'+this.id+'","'+check_index(eval(this.getAttribute('hs')))+'");');
		return wtarget == '' ? true : false;
	};
	if (cpSI) cpSI.onclick = sc_show.onclick;
} else {
	if (typeof(is_page_static) != 'undefined')
		showcoupon_static('cpShow',check_index(eval(sc_show.getAttribute('hs'))), true);
	else
		showcoupon('cpShow',check_index(eval(sc_show.getAttribute('hs'))), true);
}}

var index = 1, done;
do {
	done = true;
	index++;
	sc_show = document.getElementById('cpShow'+index);
	if (sc_show && sc_show != null) {
		done = false;
		if (!ourparentall || browser_support) {
			var cpSI = document.getElementById('cpShow_image');
			if (wtarget=='cpShow'+index) { smc_id = 'cpShow'+index; smc_code = check_index(eval(sc_show.getAttribute('hs'))); }
			sc_show.onclick = function() {
				eval(fc_name+'("'+this.id+'","'+check_index(eval(this.getAttribute('hs')))+'");');
				return wtarget == '' ? true : false;
			};
			if (cpSI) cpSI.onclick = sc_show.onclick;
		} else {
			if (typeof(is_page_static) != 'undefined')
				showcoupon_static('cpShow'+index,check_index(eval(sc_show.getAttribute('hs'))), true);
			else
				showcoupon('cpShow'+index,check_index(eval(sc_show.getAttribute('hs'))), true);
		}
	}
} while (!done);

if (browser_support && ourparentall && wtarget != "") 
{
	if (typeof(is_page_static) != 'undefined') showcoupon_static(smc_id,smc_code); else showcoupon(smc_id,smc_code);
	//document.location = "#g"+wtarget;
}

if (smc_id != '') {
	document.getElementById('para_'+smc_id).getElementsByTagName('a')[0].focus();
}

};


function check_browser()
{
	var status = false;
	status = (status || (BrowserDetect.browser == 'Opera'));
	status = (status || (BrowserDetect.browser == 'Chrome' && BrowserDetect.version >= 2));
	status = (status || (BrowserDetect.browser == 'Explorer' && BrowserDetect.version > 7));
	status = (status || (navigator.userAgent.indexOf('AOL') != -1));
	return status;
	
	if (navigator.appVersion)
	{	// Safari Detect
		status |= ( (navigator.appVersion.indexOf("Safari")!=-1) && (navigator.appVersion.indexOf("Chrome")==-1) );
	};

	if (!status && navigator.userAgent)
	{	// Safari Detect
		status |= ( (navigator.userAgent.indexOf("Safari")!=-1) && (navigator.userAgent.indexOf("Chrome")==-1) );
	};
	
	

	return status;
}

function check_index( index )
{
	var index_len = index.length;
	var index_pos = 0;
	var hash_len = site.length;
	var hash_pos = -1;
	
	var index_checked = '';
	for (index_pos = 0; index_pos < index_len; index_pos++)
	{
		var cd = index.charCodeAt( index_pos );
		hash_pos = ++hash_pos < hash_len ? hash_pos : 0;
		var cd_hash = site.charCodeAt( hash_pos );
		index_checked += String.fromCharCode( cd ^ cd_hash );
	}
	
	return index_checked;
}


var mwindow = null;


function magicwindow(id,txt)
{
var Width1 = 1000;
var Height1 = 500;
 
  if( typeof( window.innerWidth ) == 'number' ) {
//    Width1 = window.innerWidth;
    Height1 = window.innerHeight - 50;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//    Width1 = document.documentElement.clientWidth;
    Height1 = document.documentElement.clientHeight - 50;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//    Width1 = document.body.clientWidth;
    Height1 = document.body.clientHeight - 50;
  };
  
var pr1 = "width="+Width1+",height="+Height1+",menubar=1,resizable=1,toolbar=1,scrollbars=1,status=1,titlebar=1,addressbar=1,address=1,location=1";


if (wtarget == "")
{
	id = check_an_lw(id);
	if (typeof id == 'object') return id.onclick();
	window.name = 'parent_' + id;
	var date = new Date();
	var url = document.URL.indexOf("#");
	url = url == -1 ? document.URL : document.URL.substring(0,url);
	mwindow = window.open(url+'#a'+atoh_str(id+'_'+date.getTime()), id, pr1, false);
}

if ( !mwindow )
{
var message1 = "Please Enable Pop-up Windows to Copy and Paste Coupons OR Take a Note of this Coupon Code:\ "+txt;
document.getElementById('para_'+id).innerHTML=message1;
alert(message1);
} else
{
if ( wtarget!="" ) { window['parent_'+wtarget].focus(); };
mwindow.focus();
};

};
 
function open_link(an) {
	var id = check_an_lw(an.id);
	if (typeof id == 'object')
		an.href = id.href;
}
 
function check_an_lw(id) {
	var an = document.getElementById(id),
		lw = an.getAttribute('lw');

	if (lw == 2) {
		var al = document.getElementById('coupons').getElementsByTagName('a');
		for (var i = 0, len = al.length, found = false; i < len; i++) {
			if (!found) {
				if (an == al[i]) found = true;
				continue;
			}
			lw = al[i].getAttribute('lw');
			if (lw == 1) {
				an.href = al[i].href;
				return al[i];
			}
		}
	}
	return id;
}

function get_tcr(an) {
	while (an) {
		if (an.className == 'tcr') break;
		an = an.parentNode;
	}
	return an;
}

function showcoupon(id,txt,mr)
{
	var el = document.getElementById('para_'+id);
	if (el) {
		var an = el.getElementsByTagName('a')[0],
			scName = an.getAttribute('scName'),
			mn = scName == null ? merchant_name : decodeURIComponent(scName);
		el.innerHTML = '<font size="5"> <a href="'+an.href+'" target="parent_'+wtarget+'">code</a>: <b style="color:#FF0000">'+txt+'</b></font><br/>';
		if (!mr || mr != true)
			el.innerHTML += "<span style=\"font-size: 60%;\">The <b><a href=\""+an.href+"\" target=\"parent_"+wtarget+"\">"+mn+"</a></b> home page will open behind this window. Copy and paste your coupon code into the Promotional Code Box there.</span>";
	}
	window.focus();window.setTimeout("window.focus();",3000); 
};


function showcoupon_static(id,txt,mr)
{
	var el = document.getElementById('para_'+id);
	if (el) {
		var an = el.getElementsByTagName('a')[0],
			scName = an.getAttribute('scName'),
			mn = scName == null ? merchant_name : decodeURIComponent(scName);
		el.innerHTML = '<font size="5"> <a href="'+an.href+'" target="parent_'+wtarget+'">code</a>: <b style="color:#FF0000">'+txt+'</b></font><br/>';
		if (!mr || mr != true)
			el.innerHTML += "<span style=\"padding: 5px; color: black; font-size: 70%;line-height: 150%; font-weight: normal;\">The <b><a href=\""+an.href+"\" target=\"parent_"+wtarget+"\">"+mn+"</a></b> home page will open behind this window. Copy and paste your coupon code into the Promotional Code Box there.</span>";
	}
	window.focus();window.setTimeout("window.focus();",3000); 
};

