document.domain = 'kapanlagi.com';
var cbrowser = $.browser.msie && $.browser.version < 7;

function top_framing() {
    var offset = 0;
    var element = document.getElementById('topframe');
    element.style.top = (document.documentElement.scrollTop + offset) + 'px';
}

function bottom_framing() {
    var offset = 50;
    var element = document.getElementById('bottomframe');
	if (cbrowser){
	    //var offset = 100;
	    //element.style.position = "absolute";
	    element.style.top = (document.documentElement.clientHeight) + (document.documentElement.scrollTop - offset) + 'px';
	}
	else {
	element.style.top = (document.documentElement.clientHeight - offset) + 'px';
	}
	
}

function winHeight() {
    var myHeight = 0;
    if( typeof( window.innerHeight ) == 'number' ) {
	//Non-IE
	myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientHeight ) ) {
	//IE 4 compatible
	myHeight = document.body.clientHeight;
    }
    return myHeight;
}

// ********** this function gets cookies
function getCookieValue(cookieName) {
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
	if (cookieStartsAt == -1) {
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");
	}
	if (cookieStartsAt == -1) {
		cookieValue = null;
	} else {
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if (cookieEndsAt == -1) {
			cookieEndsAt = cookieValue.length;
		}
		cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));
	}
	return cookieValue;
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// ********** this function makes cookies
function setCookie(cookieName, cookieValue, cookiePath, cookieExpires) {
	cookieValue = escape(cookieValue);
	if (cookieExpires == "") {
		var nowDate = new Date();
		nowDate.setHours(nowDate.getHours() + 1);
		cookieExpires = nowDate.toGMTString();
	}
	if (cookiePath != "") {
		cookiePath = ";Path=" + cookiePath;
	}
	document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath + ";Domain=kapanlagi.com";
}

function setIframeHeight(iframe_id) {
	var the_height = document.getElementById(iframe_id).contentWindow.document.body.scrollHeight;
	document.getElementById(iframe_id).height = the_height;
}



function str_pad(input, pad_length, pad_string, pad_type) {
    var half = '', pad_to_go;
    var str_pad_repeater = function(s, len) {
        var collect = '', i;
        while(collect.length < len) collect += s;
        collect = collect.substr(0,len);
        return collect;
    };
    
    if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') { pad_type = 'STR_PAD_RIGHT'; }
    if ((pad_to_go = pad_length - input.length) > 0) {
        if (pad_type == 'STR_PAD_LEFT') { input = str_pad_repeater(pad_string, pad_to_go) + input; }
        else if (pad_type == 'STR_PAD_RIGHT') { input = input + str_pad_repeater(pad_string, pad_to_go); }
        else if (pad_type == 'STR_PAD_BOTH') {
            half = str_pad_repeater(pad_string, Math.ceil(pad_to_go/2));
            input = half + input + half;
            input = input.substr(0, pad_length);
        }
    }
 
    return input;
}

function ord(string) {
    return str_pad(string.charCodeAt(0), 3, '0', 'STR_PAD_LEFT');
}

function m_showRequest(formData, jqForm, options) {
	$('#m_message').html('<img src="http://www.kapanlagi.com/v4/i/ajaxloading.gif" alt="" width="16" height="16" /> Silahkan tunggu...');
	return true;
}

function m_showResponse(responseText, statusText) {
	return true;
}
function loadalias(url){
    window.location.replace(url);
    return false;
}


setCookie("cookieEnabled","enabled","/","");
var areCookiesEnabled = getCookieValue("cookieEnabled");
var doesSawAdExist = getCookieValue("sawAd");
var doesAdDisplay = getCookieValue("AdDisplay");
var requestedPage = window.location.href;
if (areCookiesEnabled != null && doesSawAdExist != null && doesAdDisplay == null && requestedPage.substring(0,32) != 'http://musicstore.kapanlagi.com/' && requestedPage.substring(0,28) != 'http://search.kapanlagi.com/' && requestedPage.substring(0,44) != 'http://www.kapanlagi.com/accounts/signup.php' && requestedPage.substring(0,52) != 'http://www.kapanlagi.com/accounts/signup.php?ref=ftd' && requestedPage.substring(0,51) != 'http://www.kapanlagi.com/accounts/index.php?ref=ftd' && requestedPage.substring(0,39) != 'http://woman.kapanlagi.com/v4/generated' && requestedPage.substring(0,27) != 'http://mobil.kapanlagi.com/' && requestedPage.substring(0,48) != 'http://www.kapanlagi.com/v4/generated/right.html' && requestedPage.substring(0,50) != 'http://media.kapanlagi.com/v4/generated/right.html' && requestedPage.substring(0,58) != 'http://media.kapanlagi.com/v4/generated/left-20090301.html' && requestedPage.substring(0,54) != 'http://selebriti.kapanlagi.com/v4/generated/right.html' && requestedPage.indexOf('/kredit.php') < 0 && requestedPage.substring(0,57) != 'http://www.kapanlagi.com/v4/generated/rightecard_new.html' && requestedPage.substring(0,56) != 'http://www.kapanlagi.com/v4/generated/leftecard_new.html' && requestedPage.substring(0,50) != 'http://media.kapanlagi.com/v4/generated/right.html')  {
    window.document.location="http://www.kapanlagi.com/takeover.html?"+ requestedPage ;
} else {
    setCookie("sawAd","true","/","");
}

$(document).ready(function() {
    var options = {minWidth: 160, arrowSrc: 'http://www.kapanlagi.com/v4/i/arrow_right.gif'};
    var cookiesMember = getCookieValue("mbralname");
    
    if(cookiesMember == null) {
	cookiesMember = 'Tamu';
	var items = [
	    {src: 'Login Member', url:'http://www.kapanlagi.com/accounts/#login'},
	    {src: ''},
	    {src: 'Mengapa Jadi Member?', url:'http://www.kapanlagi.com/accounts/'}
	];
    } else {
	var items = [
	    {src: 'Account Home', url:'http://www.kapanlagi.com/accounts/home.php'},
			{src: ''},
			{src: 'KL Face', url:'http://face.kapanlagi.com/'},
	    {src: ''},
	    {src: 'Logout', url:'http://www.kapanlagi.com/accounts/logout.php'}
	];
    }
    
    $('#menumember').html('Halo ' + cookiesMember + ' <small>&#9660;</small>');
    $('#menumember').menu(options, items);
    
    $('#webclipbar').serialScroll({
	target:'#webclip',
	items:'li',
	prev:'#webclipprev',
	next:'#webclipnext',
	axis:'x',
	duration:300,
	force:true,
	cycle:false,
	onBefore:function( e, elem, $pane, $items, pos ){
	    e.preventDefault();
	    if( this.blur )
		this.blur();
	},
	onAfter:function( elem ){
	}
    });
    $('#webclipbar2').serialScroll({
	target:'#webclip2',
	items:'li',
	prev:'#webclipprev2',
	next:'#webclipnext2',
	axis:'x',
	duration:300,
	force:true,
	cycle:false,
	onBefore:function( e, elem, $pane, $items, pos ){
	    e.preventDefault();
	    if( this.blur )
		this.blur();
	},
	onAfter:function( elem ){
	}
    });
    
    var m_options = {
	target:			'#m_message',
	beforeSubmit:	m_showRequest,
	success:		m_showResponse
    };
    $('#m_form').submit(function() {
	$(this).ajaxSubmit(m_options);
	return false;
    });
	
      
});


if (requestedPage.substring(0,25) != 'http://face.kapanlagi.com') {
    
    //accordion menu
    $(document).ready(function () {
      // hide all ULs inside LI.drawer except the first one
      $('LI.drawer UL:not(:first)').hide(); 
      
      // apply the open class
      $('LI.drawer UL:first').addClass('open');
      
      $('DIV.handle-drawer').click(function () {
	// hide the currently visible drawer contents
	$('LI.drawer UL:visible').hide();
	
	// remove the open class from the currently open drawer
	$('DIV.open').removeClass('open');
	
	// show the associated drawer content to 'this' (this is the current H2 element)
	// since the drawer content is the next element after the clicked H2, we find
	// it and show it using this:
	$(this).next().show();
	
	// set a class indicating on the H2 that the drawer is open
	$(this).addClass('open');
      });
    });
    
    $(function () { // same as $(document).ready(function () { })
      // assuming we have the open class set on the H2 when the HTML is delivered
      $('LI.drawer DIV:not(.open)').next().hide();
    
      $('DIV.handle-drawer').click(function () {
	// find the open drawer, remove the class, move to the UL following it and hide it
	$('DIV.open').removeClass('open').next().hide();
	
	// add the open class to this H2, move to the next element (the UL) and show it
	$(this).addClass('open').next().show();
      });
    });
    
    $(function () {
      $('UL.drawers').accordion({
	// the drawer handle
	header: 'DIV.handle-drawer',
	
	// our selected class
	selectedClass: 'open',
	
	// match the Apple slide out effect
	event: 'mouseover'
      });
    });
}

function getSearch(x){  
  var v=document.getElementById("c");
  var b=document.getElementById("cx");
  
  if(v.value=="1"){
    b.value= '015807142566320303553:k1dkqrp_-k8';
    x.id = 'searchbox_015807142566320303553:k1dkqrp_-k8';
    x.submit();
  }
  if(v.value=="2"){
    b.value= '015807142566320303553:ih_j3p0m3ca';
    x.id='cse-search-box';    
    x.submit();
  }
  if(v.value=="3"){
    b.value= '015807142566320303553:8cp44rzz9a4';
    x.id='cse-search-box';    
    x.submit();
  }
  if(v.value=="4"){
    b.value= '015807142566320303553:la95tdl2bie';
    x.id='cse-search-box';    
    x.submit();
  }
    
}
function getSearchx(w){  
  var vv=document.getElementById("cc");
  var bb=document.getElementById("cxx");
  
  if(vv.value=="1"){
    bb.value= '015807142566320303553:k1dkqrp_-k8';
    w.id = 'searchbox_015807142566320303553:k1dkqrp_-k8';
    w.submit();
  }
  if(vv.value=="2"){
    bb.value= '015807142566320303553:ih_j3p0m3ca';
    w.id='cse-search-box';    
    w.submit();
  }
  if(vv.value=="3"){
    bb.value= '015807142566320303553:8cp44rzz9a4';
    w.id='cse-search-box';    
    w.submit();
  }
  if(vv.value=="4"){
    bb.value= '015807142566320303553:la95tdl2bie';
    w.id='cse-search-box';    
    w.submit();
  }
}

function fullpageNew(id,cGameName,oriwidth,oriheight,notes,onOpenerW,onOpenerH)
{
   nAvailW = parseInt(oriwidth)+(navigator.appName == 'Microsoft Internet Explorer' ? 254 : 240);
   nAvailH = parseInt(oriheight)+(navigator.appName == 'Microsoft Internet Explorer' ? 32 : 20);;
   notes=notes.replace('&lt;br /&gt;','~enter~');
   cVars = '?id='+id+'&title='+cGameName+'&width='+oriwidth+'&height='+oriheight+'&notes='+notes+'&oPW='+onOpenerW+'&oPH='+onOpenerH;   
   oFullW = window.open('http://www.kapanlagi.com/u/playfullpage.php'+cVars,'_blank','toolbar=0,location=0,fullscreen=1,resizable=1,menubar=0');
   oFullW.focus();
}

function fullpageGame(id,cGameName,oriwidth,oriheight,notes,onOpenerW,onOpenerH,other)
{
   nAvailW = parseInt(oriwidth)+(navigator.appName == 'Microsoft Internet Explorer' ? 254 : 240);
   nAvailH = parseInt(oriheight)+(navigator.appName == 'Microsoft Internet Explorer' ? 32 : 20);;
   notes=notes.replace('&lt;br /&gt;','~enter~');
   cVars = '?id='+id+'&title='+cGameName+'&width='+oriwidth+'&height='+oriheight+'&notes='+notes+'&oPW='+onOpenerW+'&oPH='+onOpenerH+'&other='+other;   
   oFullW = window.open('http://www.kapanlagi.com/u/playfullpage.php'+cVars,'_blank','toolbar=0,location=0,fullscreen=1,resizable=1,menubar=0');
   oFullW.focus();
}

function calcage(secs, num1, num2,d) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if(s==0)
  s='';
  
  if(s != 0){
  if(d==1){
     s=s+' Hari';  
  }
  if(d==2){
     s=s+' Jam';  
  }
  if(d==3){
     s=s+' Menit';  
  }
  }
  return s;
}

function CountBack(secs,id) {  
  if (secs < 0) {
    document.getElementById("cntdwn"+id).innerHTML = '';
    return;
  }
  DisplayStr = DisplayFormat.replace(/%%d%%/g, calcage(secs,86400,100000,1));  
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24,2));
  if(calcage(secs,86400,100000,1) == 0){
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60,3));
  }else{
  DisplayStr = DisplayStr.replace(/%%M%%/g, '');
  }
  if (document.getElementById("cntdwn"+id)!=null)
  document.getElementById("cntdwn"+id).innerHTML = DisplayStr;
  setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
  return;
}

