/*********************************************************************************
*	Page object
*	created: 01/10/07
*	modified:
*********************************************************************************/
Page = {};
page = Page;
function element(id){
	return document.getElementById(id);
}
Page.show = function(){
	for(var i = 0; i < arguments.length; i++){
		try{
			document.getElementById(arguments[i]).style.visibility = 'visible';
		}
		catch(e){
			try{
				System.out.println('ERROR Page.show('+arguments[i]+');');
			}
			catch(e){
				System.out.println('ERROR Page.show');
			}
		}
	}
}
Page.hide = function(){
	for(var i = 0; i < arguments.length; i++){
		try{
			document.getElementById(arguments[i]).style.visibility = 'hidden';
		}
		catch(e){
			try{
				System.out.println('ERROR Page.hide('+arguments[i]+');');
			}
			catch(e){
				System.out.println('ERROR Page.hide');
			}
		}
	}
}
Page.href = function(href){
	// display change action graphic
	document.location.href = href;	
}
Page.fadeout = function(layer,rate){
}
Page.fadein = function(layer,rate){
}
Page.onload = function(func){
	if(window.attachEvent){
		window.attachEvent('onload',eval(func));
	}
	else if(document.addEventListener){
		// safari
		if(/WebKit/i.test(navigator.userAgent)){
			var safari_timer = setInterval(function(){
				if (/loaded|complete/.test(document.readyState)){
					clearInterval(safari_timer);
					eval(func+'()');
				}
			}, 10);
		}
		else // not safari
			document.addEventListener('DOMContentLoaded',eval(func),null);
	}
}
Page.e = function(name){
	return document.getElementById(name);
}
Page.linkcall = function(obj,area,pntype){
	return true;
}
Page.writeTo = function(layer,str){
	try{
		document.getElementById(layer).innerHTML = str;
	}
	catch(e){
		System.out.println('ERROR Page.writeTo()');
	}
}
Page.removeChar = function(str,charToRemove){
	regExp = new RegExp("["+charToRemove+"]","g");
	return str.replace(regExp,"");
}
Page.replaceChar = function(str,charToReplace,charToReplaceWith){
	regExp = new RegExp("["+charToReplace+"]","g");
	return str.replace(regExp,charToReplaceWith);
}
Page.txtImg = function(layer,img, alt){
	document.getElementById(layer).innerHTML = '<img src="'+img+'" border="0" alt="'+alt+'" />';
}
Page.txtSwf = function(layer,swf,name,w,h,flashVars){
	return;
}
Page.imgErr = function(imgObj, defaultImg){
	// Used in the img onerror event
	// will return a default image if specified
	// if the default errors, or is not specified - a transparent gif is returned
	if(!defaultImg){
		imgObj.src = '/img/spc.gif';
	}
	else{
		var replacementImage = new Image();
		replacementImage.src = defaultImg;
		replacementImage.onload = function(){
			imgObj.src = replacementImage.src;
		}
		replacementImage.onerror = function(){
			imgObj.src = '/img/spc.gif';
		}
	}
}
Page.sendToMobile = function(tSource, tStoryID){
	var url="http://www.vh1.com/mobile/sendtomobile/SendToMobile.jhtml?source=" + tSource + "&storyID=" + tStoryID; 
	STMPopup = window.open(url,"sendtomobile","width=250, height=180, top=300, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}
Page.setInput = function(elementId,defaultText){
	var theInput = document.getElementById(elementId);
	if (theInput.value == '') {
		theInput.value = defaultText;
	}
}
Page.clearInput = function(elementId,defaultText){
	var theInput = document.getElementById(elementId);
	if (theInput.value == defaultText) {
		theInput.value = '';
	}
}
Page.validateSearchOnSubmit = function(elementId, blankFieldWarning){
	var fieldValue = document.getElementById(elementId).value;
	if(fieldValue==""){
		Page.setInput(elementId, blankFieldWarning);
		return false;
	}else if(fieldValue==blankFieldWarning){
		return false;
	}
}
Page.thumbOver = function(elementObj){
	elementObj.style.borderColor="#fe4db7";
}
Page.thumbOut = function(elementObj){
	elementObj.style.borderColor="#aeaeae";
}
var adCount = 0;
Page.ad_area_promo = {
	adtest : function(){
		var ad_width = Page.getElementWidth('opa_and_ad_holder');
		if(ad_width){
			if(ad_width < 800){
				try{
					var iev = Page.getIEVersion();
					if(iev == -1 || iev > 6){
					document.getElementById('ad_promo').style.display = 'block';
						$('#ad_promo img').filter(':[longdesc]').each(function(i){
						var tmpLongDesc = $(this).attr("longdesc");
						$(this).attr("src",tmpLongDesc)[0].removeAttribute("longdesc",0);
							});
						}
						//temporary flashclock delivery for Brett Micheals
						//document.getElementById('ad_promo').innerHTML = '';
						//document.getElementById('ad_promo').style.backgroundColor = '#000000';
						//document.getElementById('ad_promo').style.backgroundImage = 'none';
						//document.getElementById('ad_promo').style.height = '105px';
						///setTimeout('Page.drawFlashPromo()',50);
						// end brett micheals stuff
				}
				catch(e){
				}
			}
			else{
				//these items are defaulted
			}
		}
		else{
			if(adCount < 10){
				adCount++;
			}
		}
	}
}
Page.drawFlashPromo = function(){
	document.getElementById('ad_promo').innerHTML = '<div style="padding-top:8px;padding-bottom:5px;"><embed src="http://www.vh1.com/content/widget/container/container.3.swf" flashVars="config=/content/widget/bret_michaels_countdown/config/240x90.xml" width="240" height="90" name="container" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></div>';
}
Page.getIEVersion = function()
{
	var rv = -1; // Return value assumes failure.
	if(navigator.appName == 'Microsoft Internet Explorer'){
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if(re.exec(ua) != null)
			rv = parseFloat( RegExp.$1 );
	}
	return rv;
}
Page.getElementWidth = function(Elem){
	var elem = {};
	if(document.all){
		elem = document.all[Elem];
	}
	else if(document.getElementById) {
		elem = document.getElementById(Elem);
	}
	if(elem != null && elem != 'undefined'){
		var xPos = elem.offsetWidth;
		return xPos;
	}
	else
		return false;
}
Page.ajaxInto = function(layer,url){
	var req
	if(window.XMLHttpRequest){
		try{
			req = new XMLHttpRequest();
		}
		catch(e){
			req = false;
		}
		if(!req)
			alert('PAGE.ajax:req not made');
		req.onreadystatechange = callback;
		req.open("GET", url);
		req.send(null);
	}else if(window.ActiveXObject){
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if(req){
			req.onreadystatechange = callback;
			req.open("GET", url, true);
			req.send();
		}
	}
	function callback(){
		if (req.readyState == 4){
			if (req.status == 200){
				document.getElementById(layer).innerHTML = req.responseText;
			}
		}
	}
}


