/*
affiliate webstore generating javascript file
*/

/////////////////////////////////// resize iframe height script /////////////////////////////////////////////
function setIframeHeight() {
		  //var iframeWin = window.frames[iframeName];
		var iframeName = 'ppgframe';
		  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
		  if (iframeEl) {
		  iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
		  //var docHt = getDocHeight(iframeWin.document);
		  // need to add to height to be sure it will all show
		  var h = alertSize();
		  var new_h = (h-148);
		  iframeEl.style.height = new_h + "px";
		  //alertSize();
		  }
		}

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

///////////////////////////////////// end of resize iframe height script ///////////////////////////////////

///// get variable from querystring script from idealog.us/2006/06/javascript_to_p.html
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return('0');
} 
////// end of get qs variable script

var affid = getQueryVariable('afid');

// write the iframe to set affiliate cookie
document.write('<iframe id="ppgaff" scrolling="no" height="0" width="0" frameborder="0" style="display: block;" hspace="0" vspace="0" marginheight="0" marginwidth="0" src="http://www.purepointgolfshop.com/afcookie.php?afid=1000006"></iframe>');

// write the style info for the iframe
//document.write('');


//iFrameHeight();
//setInterval('iFrameHeight()',1000);

function iFrameHeight() {
	if(document.getElementById && !(document.all)) {
		h = document.getElementById('ppgframe').contentDocument.body.scrollHeight;
		document.getElementById('ppgframe').style.height = h + 100;
		//alert('document height reset to ' + document.getElementById('ppgframe').style.height);
	} else if(document.all) {
		h = document.frames('ppgframe').document.body.scrollHeight;
		document.all.ppgframe.style.height = h + 100;
		//alert('document height reset to ' + document.all.ppgframe.style.height);
	}
} // end of function definition
function checkHeight () {
	if(document.getElementById && !(document.all)) {
	h = document.getElementById('ppgframe').contentDocument.body.scrollHeight + 100;
		if ( document.getElementById('ppgframe').style.height != h ) {
			iFrameHeight();
		}
	} else if(document.all) {
		h = document.frames('ppgframe').document.body.scrollHeight + 100;
		if ( document.all.ppgframe.style.height != h ) {
			iFrameHeight();
		}
	}
}
window.onload = setInterval('checkHeight()',15000);

// write the store's iframe
document.write('<iframe id="ppgframe" name="cart" scrolling="no" onload="javascript:iFrameHeight();" onchange="javascript:iFrameHeight();" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" src="aff-files/aff-index.php"></iframe>');
