function focusAll()
{
var j=0; var flag=true;
var buttonSubmit=true;
while((j<document.forms.length))
	{
	var i=0;
	while ((i<document.forms[j].length))
		{		
		obj=document.forms[j].elements[i];
		if (obj.getAttribute('noFocus')!='yes')
			{
			if(obj.tagName!='SELECT') obj.onfocus=showTooltip;
			else obj.onmousedown=showTooltip;
			obj.onblur=hideTooltip;
			
			if (obj.type!='hidden')
				if (obj.id!='ignore')
					if(flag)
						if(obj.tagName=='INPUT')
							if(obj.type!='submit')
								if(obj.type!='button')
									if (obj.disabled==false)
										if (obj.style.visibility!='hidden')
											if (obj.style.display!='none')
												{
												obj.select();
												obj.focus();
												flag=false;
												}
			if (obj.type=='file')
				obj.onchange=onChangeCheckAllowed;
			}
		i++;
		}
	//document.forms[j].onsubmit=processSubmit;
	j++;	
	}
}

function processSubmit()
	{
	if (checkFields(this)===false)
		return false;
	}

function deactivateSubmit(element)
	{
	if (element.parentNode!=undefined)
		{
		var working=document.createElement('div');
//		working.setAttribute('style','font-weight:bold;');
		working.innerHTML="<blink><font size='1'>submitting...</font></blink>";
		element.parentNode.insertBefore(working,element);
		element.style.display='none';
		}
	}

function onChangeCheckAllowed()
	{
	var notAllowed=checkAllowed(this)
	if (notAllowed)
		alert(notAllowed);
	}

function checkAllowed(element)
	{
	var allowed=element.getAttribute('allow');
	if (allowed)
		{	
		if (element.value!='')
			{
			file=element.value;
			if (file.indexOf('.')!=-1)
				{
				var extension=file.substr(file.lastIndexOf('.')+1);
				var is_array=false;
				if (allowed.indexOf(',')!=-1)
					{
					is_array=true;
					allowed_array=allowed.split(',');
					}
				if (!is_array)
					{
					if (allowed.toUpperCase()!=extension.toUpperCase())
						return "You have uploaded a "+extension.toUpperCase()+" file but you are only allowed to upload "+allowed.toUpperCase()+" files!";
					}
				else
					{
					var is_valid=false;
					for (var i in allowed_array)
						if (allowed_array[i].toUpperCase()==extension.toUpperCase())
							is_valid=true;
					if (!is_valid)
						return "You have uploaded a "+extension.toUpperCase()+" file but you are only allowed to upload "+allowed.toUpperCase()+" files!";
					}
				}
			else
				return "We could not determine the type of your file. Please choose another one!";
			}
		}
	return false;
	}
	
function checkFields(element)
{
var flag=true;
var i=0;
var submiters=Array();
while ((i<element.length))
	{	
	obj=element.elements[i];
	if (obj.getAttribute('isRequired')=='yes')
		if(obj.value=='')
			{
			requiredName=obj.getAttribute('requiredName').toLowerCase();
			requiredName=requiredName.charAt(0).toUpperCase()+requiredName.substr(1);
			alert(requiredName+' is missing !');
			return false;
			}
	if (obj.type=='file')
		{
		var notAllowed=checkAllowed(obj);
		if (notAllowed)
			{
			alert(notAllowed);
			return false;
			}
		}
	if (obj.type=='submit')
		if (obj.getAttribute('noFocus')!='yes') submiters[i]=obj;
			
	i++;
	}
for (var j in submiters)
	deactivateSubmit(submiters[j]);
}

function showTooltip()
{
//this.style.backgroundColor = '#fff7ca';
//this.style.color='#000';

if(this.name) if(typeof(tooltips)!='undefined')
	{
	var flag=true, i=0;
	while((i<tooltips.length)&&(flag))
		if(this.name==tooltips[i]) flag=false;
		else i+=2;
		
	if(!flag)
		{
		var coors = findPos(this);
		var x = document.getElementById('Tooltip');
		var elemWidth=parseInt(this.offsetWidth);
		var additional=parseInt(this.getAttribute('additional'));
		if (!isNaN(additional)) elemWidth=elemWidth+additional;
		
		var text = tooltips[i+1];
		var	cclass='Tooltip_container';
		var	tooltip_text='<span class="Tooltip_span">'+text+'</span>';
		if(text.indexOf('<br>')!=-1){cclass+='_ml';tooltip_text=text;}
			
		x.className=cclass;
		x.style.top = (coors[1]-5)+'px';
		x.style.left = coors[0] +elemWidth+10+'px';
		x.innerHTML=tooltip_text;
		x.style.visibility='visible';
		}
	}

}

function showTips(Obj,text)
{
if(typeof Obj!='object') Obj=document.getElementById(Obj);

var coors = findPos(Obj);
var x = document.getElementById('Tooltip');
var elemWidth=parseInt(Obj.offsetWidth);
var additional=parseInt(Obj.getAttribute('additional'));
if (!isNaN(additional))	elemWidth=elemWidth+additional;

var	cclass='Tooltip_container';
var	tooltip_text='<span class="Tooltip_span">'+text+'</span>';
if(text.indexOf('<br>')!=-1){cclass+='_ml';tooltip_text=text;}

x.className=cclass;
x.style.top = (coors[1]-10)+'px';
x.style.left = coors[0] +elemWidth+10+'px';
x.innerHTML=tooltip_text;
x.style.visibility='visible';
}

function hideTips() 
	{
	var x = document.getElementById('Tooltip');
	x.style.visibility='hidden';
	}

function hideTooltip() 
	{
	document.getElementById('Tooltip').style.visibility='hidden';;
	this.style.backgroundColor = '';	
	this.style.color='';
	}

function findPos(InputTag)
	{
	var curleft = curtop = 0;
		curleft = InputTag.offsetLeft
		curtop = InputTag.offsetTop
		while (InputTag = InputTag.offsetParent) {
			curleft += InputTag.offsetLeft
			curtop += InputTag.offsetTop
		}
	return [curleft,curtop];
	}


	
function doBlink()
{
var blink = document.getElementsByTagName('BLINK');
for (var i=0; i < blink.length; i++)
  blink[i].style.visibility = blink[i].style.visibility == '' ? 'hidden' : '' 
}
setInterval('doBlink()',1000);


function q(name){return confirm('Are you sure you want to delete ' + name + ' ?');}

function p(name){return confirm('Are you sure you want to ' + name + ' ?');}


function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function capsDetect(Obj,e) 
{
 if(!e) e = window.event;
 if(!e) return; 
 var theKey = 0;
 if( e.which ) { theKey = e.which; } 
 else if( e.keyCode ) { theKey = e.keyCode; } 
 else if( e.charCode ) { theKey = e.charCode } 
 var theShift = false;
 if( e.shiftKey ) theShift = e.shiftKey;
 else if( e.modifiers ) 
 	{ 
    if( e.modifiers & 4 ) theShift = true;
	}
 
 if( theKey > 64 && theKey < 91 && !theShift ) showTips(Obj,'Caps Lock is ON');
 else if( theKey > 96 && theKey < 123 && theShift ) showTips(Obj,'Caps Lock is ON');
 else hideTips();
}

function echo(string)
{
document.getElementById('Tooltip').innerHTML=string;
document.getElementById('Tooltip').style.visibility="visible";
}

function formSubmit(ObjID){document.getElementById(ObjID).submit();} 

function http_build_query(newData)
{
var query = window.location.search.substring(1);

QueryObj={};		
var vars = query.split('&');
for (var i=0;i<vars.length;i++)
	{
	var pair = vars[i].split('=');
	if(pair[0]!='') QueryObj[pair[0]]=pair[1];
	}
for(vars in newData)QueryObj[vars]=newData[vars];
	
var tmpStr='';var flag=false;
for(vars in QueryObj) {if(flag)tmpStr+='&';tmpStr+=vars+'='+QueryObj[vars];flag=true;}
return tmpStr;
}

function parse_str(query_string)
{
QueryObj=new Object();
var vars = query_string.split('&');
for (var i=0;i<vars.length;i++)
	{
	var pair = vars[i].split('=');
	if(pair[0]!='') QueryObj[pair[0]]=pair[1];
	}
return QueryObj; 
}

function toggleElement(ObjId)
{
var x=document.getElementById(ObjId);
if(x) x.style.display=(x.style.display=='none'?'block':'none');
}

function toggleElementLine(ObjId)
{
var x=document.getElementById(ObjId);
x.style.display=(x.style.display=='none'?'inline':'none');
}

	
function toggleSignIn(clickedObj,ObjId)
{
var x=document.getElementById(ObjId);
if(x.style.display=='none')
	{
	x.style.display='block';
	document.getElementById("slide_user_box").focus();
	clickedObj.className='signin menu-open'
	}
else{
	x.style.display='none';
	document.getElementById("slide_user_box").blur();
	clickedObj.className='signin';
	}	
}
	
	
function toggleElementOpacity(ObjId,opacity)
{
var x=document.getElementById(ObjId);
x.style.opacity=opacity;
ie_opactity=opacity*100;
x.style.filter='alpha(opacity='+ie_opactity+')';
}
	
function isDefined(property) {return typeof property !== 'undefined';}

function urlencode(s)
{
return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
}
   
function urldecode(s)
{
return decodeURIComponent( s.replace( /\+/g, '%20' ).replace( /\%21/g, '!' ).replace( /\%27/g, "'" ).replace( /\%28/g, '(' ).replace( /\%29/g, ')' ).replace( /\%2A/g, '*' ).replace( /\%7E/g, '~' ) );
}

function active_search2(query_string)
{
if(isDefined(query_string))document.getElementById('search_box').value=query_string;
if(document.getElementById('search_box').value.length>0)
	{
	var x=document.getElementById('search_form');
	x.action='http://blogcopy.com/#search?q='+urlencode(query_string);
	x.submit();
	}
}
	
function active_search()
{
var x=document.getElementById('search_box');
if(x.value.length==0) return false;
else{
	document.getElementById('search_form').action='http://blogcopy.com/#search?q='+urlencode(x.value);
	return true;
	} 
}
	
function buildLine(actionData)
{
if(actionData.ct!=null)
	{
	var maxLength=250;
	if(isDefined(actionData.timeago)) var timeago=actionData.timeago;
	else var timeago=jQuery.timeago(actionData.ts);
	
	var text=text_truncate(actionData.ct,250);
	var url=actionData.profile_link;
	
	var html='';
	html+='<li class="excerpts_text">';
	html+='<div  class="excerpts_thumb_container">';
	html+='<a href="'+url+'" target="_blank" title="'+actionData.bh+'"><img src="'+actionData.thumb_src+'" class="thumb_image" width="48" height="48"></a>';
	html+='</div>';
	html+='<div class="excerpts_text_container">';
	html+='<span class="excerpts_inner_text">'+text+'</span>';
	html+='<br> on <a href="'+url+'" target="_blank" title="'+actionData.bh+'" class="excerpts_link">'+actionData.bh+'</a>&nbsp;&nbsp;';
	html+='<span align="left" class="excerpts_time" ts="'+actionData.ts+'">'+timeago+'</span><br>';
	html+='</div>';
	html+='</li>';
	
	return html;
	}
}
	
function buildSearchLine(actionData)
{
var html='';	
for(k in actionData)
	{
	var timeago=jQuery.timeago(actionData[k].ts);
	var text=actionData[k].ct;
	var url=actionData.profile_link;

	html+='<li class="excerpts_text">';
	html+='<div  class="excerpts_thumb_container">';
	html+='<a href="'+url+'" target="_blank" title="'+actionData[k].bh+'"><img src="'+actionData[k].thumb_src+'" class="thumb_image" width="48" height="48"></a>';
	html+='</div>';
	html+='<div class="excerpts_text_container">';
	html+='<span class="excerpts_inner_text">'+text+'</span>';
	html+='<br> on <a href="'+url+'" target="_blank" title="'+actionData[k].bh+'" class="excerpts_link">'+actionData[k].bh+'</a>&nbsp;&nbsp;';
	html+='<span align="left" class="excerpts_time">'+timeago+'</span><br>';
	html+='</li>';	
	html+='</div>';
	html+='</li>';
	} 
return html;	
}

function buildResultsResponse(actionData)
{
var html='';	
for(k in actionData)if(actionData[k].ct!=null)
	{
	var text=actionData[k].ct;
	var timeago=actionData[k].timeago;
	var url = 'http://'+actionData[k].ph+actionData[k].pp;

	html+='<li>';
	html+='<div  class="excerpts_text">';
	html+='<span class="expandable_text">'+text+'</span><br>';
	html+='on <a href=\"'+url+'\" target=\"_blank\" title=\"'+actionData[k].ph+'\">'+actionData[k].ph+'</a>&nbsp;&nbsp;';
	html+='<span align="left" class="excerpts_time">'+timeago+'</span><br>';
	html+='</div>';
	html+='</li>';
	}
return html;	
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function isEmpty(obj)
{
for(var prop in obj) if(obj.hasOwnProperty(prop)) return false;
return true;
}


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function viewNextOption(option,containerID)
	{
	var a=containerID+option.toString();
	var b=containerID+(option-1).toString();
	var c=document.getElementById('nextBtn_'+containerID);
	var d=document.getElementById('prevBtn_'+containerID);
	var x=document.getElementById(a).style.display='block';
	var y=document.getElementById(b).style.display='none';

	d.onclick=function(){viewPrevOption((option-1),containerID)};
	d.style.cursor='pointer';
	d.className='button_arrow_left_active';

	if(option<total_options[containerID]) c.onclick=function(){viewNextOption((option+1),containerID)};
	else{
		c.onclick=function(){return false;};
		c.style.cursor='default';
		c.className='button_arrow_right_inactive';
		}		
	}


function viewPrevOption(option,containerID)
	{
	var a=containerID+option.toString();
	var b=containerID+(option+1).toString();
	var c=document.getElementById('nextBtn_'+containerID);
	var d=document.getElementById('prevBtn_'+containerID);
	var x=document.getElementById(a).style.display='block';
	var y=document.getElementById(b).style.display='none';
	
	c.onclick=function(){viewNextOption((option+1),containerID)};
	c.style.cursor='pointer';
	c.className='button_arrow_right_active';

	if(option>1) d.onclick=function(){viewPrevOption((option-1),containerID)};
	else{
		d.onclick=function(){return false;};
		d.style.cursor='default';
		d.className='button_arrow_left_inactive';	
		}		
	}


function text_truncate(text,length)
	{
	if (text.length > length)
		{
		text = text.substr(0,length);
		text+=" ...";
		}
	return text;
	}
	
function sortObject(o)
	{
    var sorted = {},
    key, a = [];

    for (key in o) if (o.hasOwnProperty(key)) a.push(key); 
    a.sort();

    for (key = 0; key < a.length; key++) sorted[a[key]] = o[a[key]];
    return sorted;
	}
	
function block_spaces(o)
	{
	if(typeof o.value == 'undefined') return false;
	o.value=o.value.replace(/\s/g,'');
	o.value=o.value.replace(/_/g,'');
	}
	
function array_keys(input, search_value, argStrict)
{
var tmp_arr = [], strict = !!argStrict, include = true, cnt = 0,key = '';
for (key in input)
	{
    include = true;
    if (search_value != undefined)
    	{
        if (strict && input[key] !== search_value) include = false;
        else if (input[key] != search_value) include = false;
        }
    if (include) {tmp_arr[cnt] = key;cnt++;}
    }
    
tmp_arr.sort();
tmp_arr.reverse();    
return tmp_arr;
}

function get_cookies_array()
{
var cookies = { };
if (document.cookie && document.cookie != '')
	{
    var split = document.cookie.split(';');
    for (var i = 0; i < split.length; i++)
    	{
        var name_value = split[i].split("=");
        name_value[0] = name_value[0].replace(/^ /, '');
        cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
    	}
	}
return cookies;
}



var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16615336-3']);

