// JavaScript Document



var timerID = 0;
var tStart  = 180;

function UpdateTimer() 
{
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }

  document.getElementById('theTime').innerHTML = tStart;

  tStart = tStart - 1; 

   
   
   timerID = setTimeout("UpdateTimer()", 1000);
}

function Start() {
  
   document.getElementById('theTime').innerHTML = tStart;

   timerID  = setTimeout("UpdateTimer()", 1000);
}




//functions for not-logged in popup warning
function unpopp(){poppDiv=document.getElementById('poppDiv');if(poppDiv){poppDiv.parentNode.removeChild(poppDiv);poppDiv=false;}}
function popp(id,text){unpopp();document.getElementById(id).innerHTML+='<div id="poppDiv" class="inline-warning"><div><p><strong>'+ text + '</strong>, <a href="/login">login</a> or <a href="/register">join Buzzscribe</a> for free.</p><a href="javascript:unpopp()"><img src="/images/close.gif" class="close" width="22" height="22" alt="Close" border=0 /></a></div></div>';return(false);}
function poppd(id){return(popp('content'+id,'Make your vote count!'));}
function poppd_page(id){return(popp('main_keyword','Make your vote count!'));}
function poppe(id){return(popp('content'+id,'Bookmark many interesting links!'));}
function poppe_page(id){return(popp('main_keyword','Save many pages!'));}

//to make a list for
function make_list(id)
{
	var list = document.getElementById("id_order_list_" + id);
	DragDrop.makeListContainer( list, "name_order_list_" + id );
	list.onDragOver = function() { this.style["background"] = "#EEF"; };
	list.onDragOut = function() {this.style["background"] = "none"; };
}


//--------------------------------------------------------------------------

sfHover = function() { 
    var sfEls = document.getElementById("dropdownnav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
	sfEls[i].onmouseover=function() {
             this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
probHover = function() { 
    var probEls = new Array()
    for (j = 0; j<100; j++) {
        probEls[j] = new Array();
	var item = document.getElementById('probdrop'+j);
	if (item) {
	    probEls[j] = item.getElementsByTagName("LI");
	    for (var i=0; i <probEls[j].length; i++) {
	        probEls[j][i].onmouseover=function() {
	            this.className +=" probhover";
		}
		probEls[j][i].onmouseout=function() {
		    this.className=this.className.replace(new RegExp(" probhover\\b"), "");
                }
	    }
	}
    }
}
function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}


function checkMouseLeave (element, evt) {

  evt = (evt) ? evt : ((window.event) ? window.event : "");
  window.status = evt;
  if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  } else {
        if (element.contains(evt.toElement)) {
                return(false);
        } else {
                return(true);
        }
  }
}
function HideandUNhideObj(i){
        nav=document.getElementById('div'+i).style;
        con=document.getElementById('ul'+i);
        if(nav.display=="none"){
                // set mouseout function here
                nav.display = 'block';
                con.onmouseout = function(evt) {
                    if (checkMouseLeave(this, evt)) {
                        i = parseInt(this.id.substr(2));
                        nav=document.getElementById('div'+i).style;
                        nav.display = 'none';
                    }
                }
        } else {
                nav.display='none';
                con.onmouseout = function (evt) {
                    if (checkMouseLeave(this, evt)) {
                        i = parseInt(this.id.substr(2));
                        nav=document.getElementById('div'+i).style;
                        nav.display= 'none';
                    }
                }
        }
}

if (window.attachEvent) {
//    window.attachEvent("onload", sfHover);
    window.attachEvent("onload", probHover);
}

//------------------------------------------------------------------------------




function spantitle(id)
{
				
	var folder = document.getElementById(id).style
	if (folder.display=="none")
	{	
		folder.display=""
	}
	else
	{	
		folder.display="none"
	}		
}

function openDiv(id)
{
				
	var folder = document.getElementById(id).style
		
	folder.display=""
	
	
}//end of function

function closeDiv(id)
{
				
	var folder = document.getElementById(id).style
	
	folder.display="none"
}//end of function



function spantitleEx(video_id)
{
				
	var folder = document.getElementById("dot_" + video_id).style 
	var rest = document.getElementById('rest_' + video_id).style 
	var span_title = document.getElementById('span_title_' + video_id)
	
	if (folder.display=="none")
	{	
		folder.display=""
		rest.display="none"
		span_title.innerHTML="more"
	}
	else
	{	
		folder.display="none"
		rest.display=""
		span_title.innerHTML="less"
	}		
}//end of function
			

function change(status, id)
{
var x=document.getElementById(id)

if(status == 0)
	x.bgColor = "white"
else
	x.bgColor = "#FFFFCC"

}

/* AJAX function begins  */


function createXMLHttpRequest() {
    try {return new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {}
    try {return new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}
    try {return new XMLHttpRequest();} catch(e) {}
    return null;
}//end of function 

function postAndFetchXml(url, content, handler) 
{
   
	
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

   xmlhttp.onreadystatechange = function() 
   {
        
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            handler(xmlhttp.responseXML);
        }
    };
	//alert(url);
	//alert(content);

    xmlhttp.open('POST', url);	
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(content);
	
}//end of function 


function postAndFetch(url, content, handler, area_id) 
{
	
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

   
   var indicator = document.getElementById(area_id);
	   //indicator.innerHTML="<div><img src='images/indicator.gif'></div>";
   
   xmlhttp.onreadystatechange = function() 
   {
        
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
            handler(xmlhttp.responseText, area_id);
        }
    };

    xmlhttp.open('POST', url, true);	
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(content);
	
}//end of function 

function generalHandler_email_form(Text)
{
	//alert(Text);
	var str= Text;
	var holder = str.substr(0, str.indexOf("<"));
    var content = str.substr(str.indexOf("<"));
	//alert(holder);
	//var indicator = document.getElementById('indicator');
	  // indicator.innerHTML="";
	var updateform = document.getElementById(holder);
	   updateform.innerHTML=content;
	   
	RoundedTop("div#email_form","#FFFFFF","#e3e3e3", "small");	
}


function generalHandler(Text, area_id)
{
	
	//alert(Text);
	var str= Text;
	
	var content = Text
	//alert(holder);
	
	if(area_id != "")
	{
		var updateform = document.getElementById(area_id);
		   updateform.innerHTML=content;
	}
	

		
}//end of function

function generalHandler_rounded(Text, area_id)
{
	
	//alert(Text);
	var str= Text;
	
	var content = Text
	//alert(holder);
	
	if(area_id != "")
	{
		var updateform = document.getElementById(area_id);
		   updateform.innerHTML=content;
	}
	
	openDiv("browse_quote");
	Rounded("div.main_content_next","#FFFFFF","#FFEB9A", "small");
		
}//end of function


//global variables for timer
var timerID = 0;
var tStart  = 180;

//For timer 
function UpdateTimer(id) 
{
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }

  document.getElementById().innerHTML = tStart;

  tStart = tStart - 1; 

   
   
   timerID = setTimeout("UpdateTimer()", 1000);
}

function Start() {
  
   document.getElementById('theTime').innerHTML = tStart;

   timerID  = setTimeout("UpdateTimer()", 1000);
}


function generalHandler_timer(Text)
{
	alert(Text);
	var str= Text;
	var holder = str.substr(0, str.indexOf("<"));
    var content = str.substr(str.indexOf("<"));
	//alert(holder);
	//var indicator = document.getElementById('indicator');
	  // indicator.innerHTML="";
	var updateform = document.getElementById(holder);
	   updateform.innerHTML=content;
	
	//UpdateTimer();
	
}


function move(pid, sort_by)
{
	sid=document.getElementById('filter_topic').options[document.getElementById('filter_topic').selectedIndex].value
	window.location="product?pid=" + pid + "&sid=" + sid + "&sort=" + sort_by;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



function validateContentStep1()
{
	if(document.getElementById("content_type0").checked)
	{	
		if(document.getElementById("url").value == "http://")
		{	
			alert("URL is required");
			return false;
		}
		else
			return true;
	}
	else
	{	
		if(document.getElementById("title").value.length < 1)
		{	
			alert("Title is required");
			return false;
		}
		else
			return true;
	}
	
	
}

function validateContentStep3()
{
	if(document.getElementById("content_type").value == 0)//url form
	{	
		if(document.getElementById("title").value.length < 2)
		{	
			alert("Title is required and must be more than 1 chracter length");
			return false;
		}
		
		if(document.getElementById("content").value.length < 2)
		{	
			alert("Description is required and must be more than 1 chracter length");
			return false;
		}
		
		topics=document.myForm.topic;
		
		for (i=0;i<topics.length;++ i)
		{
			if (topics[i].checked)
			{
				
				if(topics[i].value == -1) //new topic
				{
					
					if(document.myForm.new_topic.value.length < 2)
					{
						alert("If you want to create a new topic, a new topic must be specified and more than 1 chracter length");
						return false;
					}
					else
						return true;
				}
				else
					return true;
				
			}
		}
		
		if(document.getElementById("choice0").checked && document.myForm.new_topic.value.length >= 2)
			return true;
		
		alert("Topic is required");
		return false;	
		
		
	}
	else//text content form
	{	
		if(document.getElementById("content").value.length < 1)
		{	
			alert("The content is required and must be more than 1 chracter length");
			return false;
		}
		
		topics=document.myForm.topic;
		for (i=0;i<topics.length;++ i)
		{
			if (topics[i].checked)
			{
				
				if(topics[i].value == -1) //new topic
				{
					if(document.myForm.new_topic.value.length < 1)
					{
						alert("If you want to create a new topic, a new topic must be specified and more than 1 chracter length");
						return false;
					}
					else
						return true;
				}
				else
					return true;
				
			}
		}
		alert("Topic is required");
		return false;	
		
	}
}//end of function

function loginRedirect(url)
{

	document.write("");
			
	
		document.getElementById('redirect_form').submit();
			
			
}

function edit_content(pid)
{
	form = document.myForm
	form.action = "add_content3?edit=1&pid=" + pid;
	form.submit();
}//end of fucntion 

function edit_buzzwords()
{
	form = document.myForm
	form.action = "add_buzz1?edit=1";
	form.submit();
}//end of fucntion 

function validateQuote()
{
	if(document.getElementById("author").value.length < 2)
	{	
		alert("Author name is required and must be more than 1 character length");
		return false;
	}
		
	if(document.getElementById("quote_content").value.length < 2)
	{	
		alert("Quote content is required and must be more than 1 character length");
			return false;
	}
	
	
	if(document.getElementById("tag").value.length < 2)
	{	
		alert("At least one tag is required and must be more than 1 character length");
			return false;
	}
		
	return true;	
}//end of function


//This function highlight the chosen image by putting a border around it
function highlightBorder(highlighted_id)
{
	//get right all the border for all images except the chosen one
	for(i = 1; i <= 30 ; i++)
	{
		if(i == highlighted_id)
			document.getElementById("img" + highlighted_id).border=1;
		else
			document.getElementById("img" + i).border=0;
	}
	
	document.getElementById("preview_image").src = document.getElementById("img" + highlighted_id).src;
	document.getElementById("big_photo").src = document.getElementById("img" + highlighted_id).src;
	document.getElementById("confirm_messages").innerHTML = "Your image choice has been saved";
	
}//end of function 

//This function change the feature content box based on the choice user clicks
function select_feature(select_choice, URL)
{
	
	old_select = parseInt(document.getElementById("button_select").value)
	document.getElementById("link_button" + old_select).className="unselect";
	if(old_select == 1)
		document.getElementById("button" + old_select).style.background="url(/images/button1.gif)";
	else if(old_select == 2)
		document.getElementById("button" + old_select).style.background="url(/images/button2.gif)";
	else if(old_select == 3)
		document.getElementById("button" + old_select).style.background="url(/images/button3.gif)";
	
	
	if(select_choice == 1)
	{
		openDiv("flash_promo");
		closeDiv("share_quote");
		closeDiv("browse_quote");
		
		document.getElementById("link_button" + select_choice).className="select";
		document.getElementById("button" + select_choice).style.background="url(/images/button1_sel.gif)";
		document.getElementById("button_select").value = 1
	}
	else if(select_choice == 2)
	{
		
		
		closeDiv("flash_promo");
		openDiv("share_quote");
		closeDiv("browse_quote");
		document.getElementById("link_button" + select_choice).className="select";
		document.getElementById("button" + select_choice).style.background="url(/images/button2_sel.gif)";
		document.getElementById("button_select").value = 2
	}
	else if(select_choice == 3)
	{
		closeDiv("flash_promo");
		closeDiv("share_quote");
		//openDiv("browse_quote");
		postAndFetch('/recent_quote_CB?order=1&URL=' + URL,'',generalHandler_rounded, 'browse_quote');
		document.getElementById("link_button" + select_choice).className="select";
		document.getElementById("button" + select_choice).style.background="url(/images/button3_sel.gif)";
		document.getElementById("button_select").value = 3
	}
}//end of function


function button_over(number, status)
{
	
	//alert("yes");
	
	if(parseInt(document.getElementById("button_select").value) != number)
	{
		if(status == 1) //onmouseover
		{
			document.getElementById("link_button" + number).className="select";
			if(number == 1)
				document.getElementById("button" + number).style.background="url(/images/button1_sel.gif)";
			else if(number == 2)
				document.getElementById("button" + number).style.background="url(/images/button2_sel.gif)";
			else if(number == 3)
				document.getElementById("button" + number).style.background="url(/images/button3_sel.gif)";
			
			
		}
		else //on mouseout
		{
			document.getElementById("link_button" + number).className="unselect";
			
			if(number == 1)
				document.getElementById("button" + number).style.background="url(/images/button1.gif)";
			else if(number == 2)
				document.getElementById("button" + number).style.background="url(/images/button2.gif)";
			else if(number == 3)
				document.getElementById("button" + number).style.background="url(/images/button3.gif)";
			
		}
	
	}
}//end of function 

//To preload images
function MM_preloadImages() 
{ //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}//end of function
