//start: confirm function
function confirmThis(message) {
 if(confirm(message)) return true;
 return false;
}

function confirmdelete(url,message) {
 if(confirmThis(message)) {
  window.location.href = url;
 }
}
//end: confirm function

//Start auto drop down function
function GotoUrl(s)
{
	var d = s.options[s.selectedIndex].value;
	if ( d != "#" ) {
		window.location.href = d;
		s.selectedIndex=0;
	}
}
//end auto drop down function

//start: popup functions
function popUpWin(url,windowName, windowOptions) {
	windowName = window.open(url,windowName,windowOptions);
	windowName.focus();
}

function popMore(id) {
	mypage = 'hp_more' + id + '.cfm';
	myname = 'more';
	w=450;
	h=300;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no";
	more = window.open(mypage, myname, winprops);
	more.focus();
}
//end: popup functions

//start: snapshot function
function popUpWin(url,windowName, windowOptions) {
	windowName = window.open(url,windowName,windowOptions);
	windowName.focus();
}

function SnapShot(id,s) {
	mypage = 'snapshot.cfm?id=' + id + "&s=" + s;
	myname = 'more';
	w=450;
	h=465;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no";
	more = window.open(mypage, myname, winprops);
	more.focus();
}
//end: snapshot functions

//start: ReviewDetail function
function popUpWin(url,windowName, windowOptions) {
	windowName = window.open(url,windowName,windowOptions);
	windowName.focus();
}

function ReviewDetail(id,rid) {
	mypage = 'reviewdetail.cfm?rid=' + rid  + "&id=" + id;
	myname = 'review';
	w=400;
	h=450;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes";
	more = window.open(mypage, myname, winprops);
	more.focus();
}
function YouWon(pts) {
	mypage = 'youwon.cfm?pts=' + pts;
	myname = 'youwon';
	w=200;
	h=200;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no";
	youwon = window.open(mypage, myname, winprops);
	youwon.focus();
}

function goToURL(form)
  {
    var myindex=form.GenreID.selectedIndex
    if(!myindex=="")
      {
        window.location.href=form.GenreID.options[myindex].value;
      }
}

function VideoPop(url) {
	mypage = url;
	myname = 'VPop';
	w=640;
	h=550;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes";
	VPop = window.open(mypage, myname, winprops);
	VPop.focus();
}

function HelpPop(section,bookmark) {
	mypage = 'helpsystem.cfm?s=' + section  + "&bm=" + bookmark;
	myname = 'help';
	w=400;
	h=450;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes";
	more = window.open(mypage, myname, winprops);
	more.focus();
}

function AddCredits(tablename,id) {
	mypage = 'movie_add_credits.cfm?sctypeid=' + tablename + "&id=" + id;
	myname = 'profile';
	w=400;
	h=450;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,resizable=yes";
	more = window.open(mypage, myname, winprops);
	more.focus();
}

function AddCreditsUpd(tablename,id) {
	mypage = 'movie_add_credits_upd.cfm?sctypeid=' + tablename + "&id=" + id;
	myname = 'profile';
	w=400;
	h=450;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,resizable=yes";
	more = window.open(mypage, myname, winprops);
	more.focus();
}

function UploadHeadshot(token,id) {
	mypage = 'http://secure.showbizdata.com/insider/image_uplhead.cfm?token=' + token + "&id=" + id;
	myname = 'images';
	w=500;
	h=550;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,resizable=yes";
	more = window.open(mypage, myname, winprops);
	more.focus();
}

function UploadHeadshotP(token,id) {
	mypage = 'http://secure.showbizdata.com/profile/image_uplhead.cfm?token=' + token + "&id=" + id;
	myname = 'images';
	w=500;
	h=550;
	winprops = "HEIGHT="+h+",WIDTH="+w+",toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,resizable=yes";
	more = window.open(mypage, myname, winprops);
	more.focus();
}

function ShowDiv(id,keywords,type) {
		document.getElementById(id).style.display ='block';			
		var eid = id.replace('sidebar','m');
		document.getElementById(eid).style.background ='#990000';			
		document.getElementById(eid).style.color ='#fff';			
		if(id != 'sidebar-content'){HideDiv('sidebar-content');}
		if(id != 'sidebar-stats'){HideDiv('sidebar-stats');}
		if(id != 'sidebar-video'){HideDiv('sidebar-video');}
		if(id == 'sidebar-video'){SearchTruVeo(keywords);}
}

function HideDiv(id) {
		document.getElementById(id).style.display ='none';
		var eid = id.replace('sidebar','m');
		document.getElementById(eid).style.background ='#fff';			
		document.getElementById(eid).style.color ='#000';			
}

function SearchTruVeoTool(){
	var keywords = document.getElementById('keywords').value;	
	AOLVS.getVideos(keywords);
}

function SearchTruVeo(keywords){
	AOLVS.getVideos(keywords);
}
function ShowTruVeo(){
	
		
		var theHTML = '<table width=100% border=0 cellspacing=0 cellpadding=0>';
 		var views = 0;
 		var runtime = '';
		var hd = '';
		var vtype = document.getElementById('vtype').innerHTML;			
		

 		if(AOLVS.VideoSet.totalResultsAvailable >= 1){
			for (var i=0; i < AOLVS.VideoSet.totalResultsReturned; i++) {
				
				if(AOLVS.VideoSet.Video[i].viewCount > 0){views =AOLVS.VideoSet.Video[i].viewCount;}
				if(AOLVS.VideoSet.Video[i].hiDefVideoUrl){hd = 'HD';};
				var runtime = AOLVS.VideoSet.Video[i].runtime/60;

				if(vtype == 'm'){
					theHTML += "<tr><td style='padding:5px 0 5px 0;'><a href='javascript:VideoPop(&quot;"+AOLVS.VideoSet.Video[i].videoUrl+"&quot;);' class=text ><img width=70 height=54 src='"+AOLVS.VideoSet.Video[i].thumbnailUrl+"' /></a></td><td class=video><a href='javascript:VideoPop(&quot;"+AOLVS.VideoSet.Video[i].videoUrl+"&quot;);' class=text><b>"+AOLVS.VideoSet.Video[i].title+"</b></a> <span class=smalltext>("+AOLVS.VideoSet.Video[i].channel+" / <span class=redtext>"+views+"</span> views) runtime: "+AOLVS.VideoSet.Video[i].runtime+" secs "+hd+"</span></td></tr>";
				} else if(vtype == 'p') {
					theHTML += "<tr><td style='padding:5px 0 5px 0;'><a href='javascript:VideoPop(&quot;"+AOLVS.VideoSet.Video[i].videoUrl+"&quot;);' class=text ><img width=90 src='"+AOLVS.VideoSet.Video[i].thumbnailUrl+"' /></a></td><td width=100% class=video><a href='javascript:VideoPop(&quot;"+AOLVS.VideoSet.Video[i].videoUrl+"&quot;);' class=normaltext><b>"+AOLVS.VideoSet.Video[i].title+"</b></a><br /> <span class=smalltext>("+AOLVS.VideoSet.Video[i].channel+" / <span class=redtext>"+views+"</span> views) runtime: "+AOLVS.VideoSet.Video[i].runtime+" secs "+hd+"</span></td></tr>";
				} else if(vtype == 'n') {
					theHTML += "<tr><td style='padding:5px 0 5px 0;'><a href='javascript:VideoPop(&quot;"+AOLVS.VideoSet.Video[i].videoUrl+"&quot;);' class=text ><img width=70 height=54 src='"+AOLVS.VideoSet.Video[i].thumbnailUrl+"' /></a></td><td width=100% class=video><a href='javascript:VideoPop(&quot;"+AOLVS.VideoSet.Video[i].videoUrl+"&quot;);' class=text>"+AOLVS.VideoSet.Video[i].title+" ("+AOLVS.VideoSet.Video[i].channel+")</a><br />"+AOLVS.VideoSet.Video[i].description+"</span></td><td><input type=checkbox name=vid value="+AOLVS.VideoSet.Video[i].id+"><input type=hidden name=vtitle value='"+escape(AOLVS.VideoSet.Video[i].title)+"'><input type=hidden name=vlink value='"+escape(AOLVS.VideoSet.Video[i].videoUrl)+"'><input type=hidden name=vimage value='"+AOLVS.VideoSet.Video[i].thumbnailUrl+"'><input type=hidden name=tid value='"+AOLVS.VideoSet.Video[i].id+"'></td></tr>";
				}
				
			//theHTML += "<div><a href='javascript:VideoPop(&quot;"+AOLVS.VideoSet.Video[i].videoUrl+"&quot;);'>"+AOLVS.VideoSet.Video[i].title+"</a></div>";
			}

		theHTML = theHTML + '<tr><td colspan=2>';
			
		//if(AOLVS.hasPreviousPage){theHTML = theHTML + '<a href="javascript:previousPage();" class="text">Previous</a> | ';}
		if(AOLVS.VideoSet.totalResultsAvailable >10){theHTML = theHTML + '<a href="javascript:nextPage();" class="text">Next</a>';}

		theHTML = theHTML + '</td></tr></table>';

		document.getElementById('results').innerHTML = theHTML;

		}else{
			theHTML = "<span class=normaltext>Sorry no clips were found. Check back soon!</span>";
			document.getElementById('results').innerHTML = theHTML;
		}
}

function nextPage(){
		AOLVS.nextPage();
		ShowTruVeo();
}
function previousPage(){
		AOLVS.previousPage();
		ShowTruVeo();
}

function AOLPageLoad() { 
		AOLVS = new AOLVideoSearch('1d09024b18d3c8d8b'); 
        //AOLVS.attachEvent('onload', 'SearchTruVeo();');
        AOLVS.attachEvent('onupdate', 'ShowTruVeo();');
		AOLVS.initialize();

		// highlight default sidebar tab
		document.getElementById('m-content').style.background ='#990000';			
		document.getElementById('m-content').style.color ='#fff';			

} 

function ShowPanel(id,menu) {
		document.getElementById(id).style.display ='block';			
		var mchoices = document.getElementById(menu).innerHTML;
		var eid = id.replace('p','l');
		document.getElementById(eid).style.background ='#990000';			
		document.getElementById(eid).style.color ='#fff';
		if(id != 'p-1' && mchoices.indexOf('p-1,') >=0){HidePanel('p-1');}
		if(id != 'p-2' && mchoices.indexOf('p-2,') >=0){HidePanel('p-2');}
		if(id != 'p-3' && mchoices.indexOf('p-3,') >=0){HidePanel('p-3');}
		if(id != 'p-4' && mchoices.indexOf('p-4,') >=0){HidePanel('p-4');}
		if(id != 'p-5' && mchoices.indexOf('p-5,') >=0){HidePanel('p-5');}
		if(id != 'p-6' && mchoices.indexOf('p-6,') >=0){HidePanel('p-6');}
		if(id != 'p-7' && mchoices.indexOf('p-7,') >=0){HidePanel('p-7');}
		if(id != 'p-8' && mchoices.indexOf('p-8,') >=0){HidePanel('p-8');}
		if(id != 'p-9' && mchoices.indexOf('p-9,') >=0){HidePanel('p-9');}
		if(id != 'p-10' && mchoices.indexOf('p-10,') >=0){HidePanel('p-10');}
		if(id != 'p-11' && mchoices.indexOf('p-11,') >=0){HidePanel('p-11');}
		if(id != 'p-12' && mchoices.indexOf('p-12,') >=0){HidePanel('p-12');}
}

function HidePanel(id) {
		document.getElementById(id).style.display ='none';
		var eid = id.replace('p','l');
		document.getElementById(eid).style.background ='#fff';			
		document.getElementById(eid).style.color ='#000';			
}


function utt(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {uttDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function uttDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function loadp(name, div) {
	utt(name,div);
	return false;
}


// call code with the name of the external file and the id of the div you want to put the content into
//<a href="file1.html" onclick="load('file1.html','content');return false;">File 1</a>
