// JavaScript Document

function getXmlHttpRequestObject()
{
	var xmlReqObject;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlReqObject= new XMLHttpRequest();
	}else {
		// code for IE6, IE5
		xmlReqObject= new ActiveXObject("Microsoft.XMLHTTP");
  }
	return xmlReqObject;
}

function addLoadEvent(func) {
	if ((func != 'undefined') && (func != '') && (func != null)) {
		var oldonload= window.onload;
		if (typeof window.onload != 'function') {
			window.onload= func;
		}else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}
}

function setFocus(id) {
	if ((id != 'undefined') && (id != '') && (id != null)) {
		var ctl= document.getElementById(id);
		if ((ctl != 'undefined') && (ctl != '') && (ctl != null)) {
			ctl.focus();
		}
	}
}


function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}


function valButton(btn) {var cnt = -1;for (var i=btn.length-1; i > -1; i-- ) {if (btn[i].checked) {cnt = i; i = -1;}}if (cnt > -1) {return btn[cnt].value;} else {return null;}}

function Trim(str) {
	while(str.charAt(0) == (" ")) {
		str = str.substring(1);
	}
	while(str.charAt(str.length-1) == " " ) {
		str = str.substring(0,str.length-1);
	}
	return str;
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99999;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);
    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;
    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY-10;
    element.style.left = setX + "px";
    element.style.top  = setY + "px";
    element.style.display  = 'block';
}


function checkRequiredFieldsFeedback() {
	if (document.feedbackForm.comments.value == "") {
		document.getElementById('commentdiv').innerHTML="<span style='color:red;font-size:14px;'>REQUIRED</span>";
		return false;
	} else {
		document.feedbackForm.submit();
	}
}

function showBoxfeedback(){
    $('overlay').show();
    center('box');
}

function hideBoxfeedback(){
    $('box').hide();
    $('overlay').hide();
}


function toggleLayer(whichLayer)
	{
	if (document.getElementById)
	{
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.display = style2.display? "":"block";
	}
	}
	 function pop_window(url) {
			 var popit = window.open(url,'console','width=760,height=900,status=no,resizable=yes,top=80,left=50');
			 }
	 function pop_window_4(url) {
	 var popit = window.open(url,'console','scrollbars=no,resizable=no,width=580,height=480');
	 }
// -->

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function checkRequiredFields() {
	var btn = valButton(pollForm.answer);
	if (btn == null){
		alert("Please select one answer!");
		return false
	}
	else {
	return true;
	}
}

// this is live code and is used for HP regular story large video popups
function pop_largevideo(url) {
			 var popit = window.open(url,'console','scrollbars=yes,resizable,width=1024,height=700');
			 }
			 
			 
 function pop_windowCartoon(url,wd,ht) {
			 var popit = window.open(url,'console','scrollbars=no,resizable,width='+wd+',height='+ht);
			 }
function pop_windowCartoonNoResize(url,wd,ht) {
			 var popit = window.open(url,'console','scrollbars=no,resizable=no,width='+wd+',height='+ht);
			 }
function pop_windowKoteki(url) {
			 var popit = window.open(url,'console','scrollbars=no,resizable=no,width=1024,height=650');
			 }			 
function pop_windowCartoonScroll(url,wd,ht) {
			 var popit = window.open(url,'console','scrollbars=yes,resizable=no,width='+wd+',height='+ht);
			 }			 
			 
function pop_window3(url) {
			 var popit = window.open(url,'console','scrollbars=yes,resizable,width=1024,height=768');
			 }
			 
function pop_window77(url) {
			 var popit = window.open(url,'console','scrollbars=no,resizable,width=1024,height=550');
			 }
			 
			 function pop_windowstream(url) {
			 var popit = window.open(url,'console','scrollbars=no,resizable,width=750,height=490');
			 }	
			 
 function pop_window2(url) {
			 var popit = window.open(url,'console','scrollbars=no,resizable,width=635,height=515');
			 }
			 
			 function pop_windowstream(url) {
			 var popit = window.open(url,'console','scrollbars=no,resizable,width=750,height=490');
			 }	
myPopup = '';

function openPopup(url) {
    myPopup = window.open(url,'popupWindow','left=80,top=80,width=550,height=700,toolbar=0,resizable=1');
    if (!myPopup.opener)
         myPopup.opener = self; 
}

/***********************************************
* IFrame SSI script II-  Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/
var iframeids=["calloutboxIFrame","mtvuiframe","politico44IFrame"]
//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 0 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
	if (document.getElementById){
		document.getElementById(iframeid).src=url;
	}
}

if (window.location.hostname == 'www.politico.com'){
	if (window.addEventListener){
		window.addEventListener("load", resizeCaller, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", resizeCaller);
	} else {
		window.onload=resizeCaller;
	}
}

var agt = navigator.userAgent.toLowerCase();
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.") == -1));
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.") != -1) );
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
var is_ie6  = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.") != -1));
var is_ie7  = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.") != -1)); 
var is_opera   = (agt.indexOf("opera") != -1);// New Code

function pmtogglefeed(id) {
	var obj=document.getElementById(id);
	if (is_ie5up || is_ie6 || is_ie7){
		obj.style.display=!(obj.style.display=="inline-block")? "inline-block" : "none"; 
	} else {
		obj.style.display=!(obj.style.display=="table-row")? "table-row" : "none";
	}
}			

// EMAIL VALIDATION
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ 
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true					
}
