
/*
Object.prototype.isEmpty = function() {
    for (var prop in this) {
        if (this.hasOwnProperty(prop)) return false;
    }
    return true;
}

Object.prototype.notEmpty = function() {
    for (var prop in this) {
        if (this.hasOwnProperty(prop)) return true;
    }
    return false;
}
// when used this the there was a problem in j query
*/

//if(window.location.href.indexOf(host)!=0)alert("Change in HOST");

function notEmpty(o){
    for (var prop in o) {
        if (o.hasOwnProperty(prop)) return true;
    }
    return false;
}

function isEmpty(o){
    for (var prop in o) {
        if (o.hasOwnProperty(prop)) return false;
    }
    return true;
}

function isEmail(address) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(address)
}

function nEmail(ref) 
{
	val = document.getElementById(ref).value
	var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;
	return !reg.test(val)
}
 
function nPhone(ref)
{
	val = document.getElementById(ref).value	
	var reg = /[0-9-()]$/
	return !reg.test(val)
}
function trimtext(itag)
{
	var tag = document.getElementsByTagName(itag);
	for(var i=0;i<tag.length;i++)
	{
		if(tag[i].type!='file')
			tag[i].trimText()
	}
}

function usernameValidity(src,len) 
{
	var noalpha = /^[A-Za-z_]*$/;
	
	if(!noalpha.test(src.value))
	{
		displayRed(1,src,'This field should be of alphabets mixed with underscore') 
		return;
	}
	else
		displayRed(0,src,'');
//	alert(!src.value.length>len)
	if(len && src.value.length<len)
		displayRed(!src.value.length<len,src,"This field should be more than "+len+" characters") 	
}

function isAlpha(src)
{
   var noalpha = /^[A-Za-z]*$/;
	return noalpha.test(src)
}

function isBox(src)
{
	var nobox = /^((?:[A-Za-z-'.,@:?!()$#/\\]+|&[^#])*&?)$/
	return nobox.test(nobox)	
}

function isAlphaSpace(src,len)
{
//	var cit=/^[a-z ]+$/i/;

//	displayRed(,src,'Value should be only of Alphabets and Space')
	var nov = !src.value.match(/^[a-z ]+$/i)
//	alert(nov)
	if(nov)
	{

		displayRed(1,src,'This field should be of alphabets and space') 
		return;
	}
	else
		displayRed(0,src,'');
//	alert(!src.value.length>len)
	if(len && src.value.length<len)
		displayRed(!src.value.length<len,src,"This field should be more than "+len+" characters") 	
}	
function emailValidity(src)
{				
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	displayRed(!reg.test(src.value),src,'Email should be in correct form') 
}

function phoneValidity(src)
{
	var pho=/^[0-9+]*$/;
	displayRed(!pho.test(src.value),src,'Phone number should be in correct form')
}

function mobileValidity(src)
{
	var mob=/^[0-9+]*$/;
	displayRed(!mob.test(src.value),src,'Mobile number should be in correct form')
}
function zipcodeValidity(src)
{
	var zipc=/^[0-9]*$/;
	displayRed(!zipc.test(src.value),src,'zip code should be in correct form')
}
function displayRed(flag,src,txt)
{
	if(flag)
	{
		eflag ++;
		document.getElementById(src.id+'err').innerHTML = txt;		
	}
	else
	{
		document.getElementById(src.id+'err').innerHTML = "";
		eflag-- 
	}
}	

function createAjax()
{
	var xt;
	xt = window.XMLHttpRequest ? new XMLHttpRequest() : ( window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : null)

	return xt;
}

var gjax = createAjax()? false : true;

function show(jax)
{
	var wini; wini = window.open('','');wini.document.write("<pre>"+jax.responseText); wini.document.close()
}

function trim(str, chars) {

    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
	
function checkphonevalidity(str)
{	
	var phon=/^[0-9]*$/;
	if(!phon.test(str))
	return str;
}

function checkemailvalidity(str)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(!reg.test(str))
	return str;
}

function checkzipcodevalid(str)
{	
	var zip=/^[0-9a-zA-Z]*$/;
	if(!zip.test(str))
	return str;
}

function strip_tags(str)
{
	var re= /<\S[^><]*>/g
	str = str.replace(re, "")
	return str;
}	

function doSelect(oid,ids)
{
	var obj = document.getElementById(oid)
	for(var i=0;i<obj.options.length;i++)
		if(obj.options[i].value==ids)
			obj.selectedIndex = i;
}

function selectAllx(obj,ref)
{	
	var ch = document.getElementsByName(ref)	
	for(var i=0;i<ch.length;i++)
		ch[i].checked = obj.checked;
}

function selectAll(ref,mode)
{	
	var ch = document.getElementsByName(ref)	
	for(var i=0;i<ch.length;i++)
		ch[i].checked = mode;
}

function setSelection(nami,idx)
{
	var al = document.getElementById(nami)
	for(var i=0;i<al.length;i++)
		if(al[i].value==idx)
			al[i].selected = true
}

function setRadio(nami,idx)
{
	var al = document.getElementsByName(nami)
	for(var i=0;i<al.length;i++)
		if(al[i].value==idx)
			al[i].checked = true
}


function unSetRadio(nami)
{
	var al = document.getElementsByName(nami)
	for(var i=0;i<al.length;i++)
			al[i].checked = false
}

function getRadio(nami)
{
	var al = document.getElementsByName(nami)
	for(var i=0;i<al.length;i++)
			if(al[i].checked)return al[i].value
	return false;
}

function isSelected(ref)
{
	var ch = document.getElementsByName(ref)	
	for(var i=0;i<ch.length;i++)
		if(ch[i].checked)return true;
	return false;		
}

function getSelected(nami)
{
	var al = document.getElementsByName(nami)
	var str='';
	for(var i=0;i<al.length;i++)
		if(al[i].checked)
			str += al[i].value +','
			
	return str
}

function isAlphaSpace(src)
{
	var noalpha = /^[A-Za-z ]*$/;
	
	if(!noalpha.test(src))
		return false;
	else 
		return true;

}

function hideNote()
{
	if(document.getElementById('shownote'))
		document.getElementById('shownote').style.display='none'
}

function doAjax(query)
{
	var jax = createAjax();if(!jax)return;
	jax.open("GET",query)
	jax.onreadystatechange = function(){if(jax.readyState==4)xResponse(jax)}
	jax.send(null)
}
function xResponse(x)
{
	busy(0)
	if(x.responseText.indexOf('DONiZ') + 1)
		window.location.reload()
	else
		alert(x.responseText)
}

function doAjaxSync(query)
{
	var jax = createAjax();if(!jax)return;
	jax.open("GET",query,false)
	jax.send(null)

	busy(0)

	try{
	var obj = eval( "(" + jax.responseText + ")" )
	}catch(e){alert(trim(strip_tags(jax.responseText)));throw new Error("Stopa");}	

	if(obj.err)
	{
		alert(obj.err);
		throw new Error("Stopa");
	}
	return obj.avail
}


function deleteSelectedChecks(ref,box)
{
	
	if(!isSelected(ref))
	{
		alert("Please select item(s) to delete");
		return;
	}

	if(!confirm("Are you sure you want to delete?"))return
	
	var str = getSelected(ref)
	jRequest(baseurl+"admin/ajax","command=commonclear&box="+box+"&eye="+str,true)
}

function deleteSingle(ref,box)
{
	if(!confirm("Are you sure you want to delete?"))return
	jRequest(baseurl+"admin/ajax","command=commonclear&box="+box+"&eye="+ref,true)
}

function deleteSelectedChecksDi(ref,box,box2,id1,id2)
{
	
	if(!isSelected(ref))
	{
		alert("Please select item(s) to delete");
		return;
	}

	if(!confirm("Are you sure you want to delete?"))return
	
var str = getSelected(ref)
jRequest(baseurl+"admin/ajax","command=commoncleardi&box="+box+"&eye="+str+"&box2="+box2+"&id1="+id1+"&id2="+id2,false)

}


function deleteSingleDi(id,box,box2,id1,id2)
{
	if(!confirm("Are you sure you want to delete?"))return		
	jRequest(baseurl+"admin/ajax","command=commoncleardi&box="+box+"&eye="+id+"&box2="+box2+"&id1="+id1+"&id2="+id2,false)
}


function deleteSelectedDi(ref,box1,box2,id1,id2)
{
	
	if(!isSelected(ref))
	{
		alert("Please select item(s) to delete");
		return;
	}

	if(!confirm("Are you sure you want to delete?"))return
	
var str = getSelected(ref)
jRequest(baseurl+"admin/ajax","command=deletedi&box1="+box1+"&eye="+str+"&box2="+box2+"&id1="+id1+"&id2="+id2,false)

}


/*
function deleteDi(id,box,box2,id1,id2)
{
	if(!confirm("Are you sure you want to delete?"))return		
	jRequest(baseurl+"admin/ajax","command=commoncleardi&box="+box+"&eye="+id+"&box2="+box2+"&id1="+id1+"&id2="+id2,false)
}
*/
function deleteDi(id,box1,box2,id1,id2)
{
	if(!confirm("Are you sure you want to delete?"))return		
	jRequest(baseurl+"admin/ajax","command=deletedi&box1="+box1+"&eye="+id+"&box2="+box2+"&id1="+id1+"&id2="+id2,false)
}
/*
function deleteSingleTri(id,box,box2,box3,id1,id2,id3)
{
	if(!confirm("Are you sure you want to delete?"))return		
	jRequest(baseurl+"admin/ajax","command=commoncleartri&box="+box+"&eye="+id+"&box2="+box2+"&box3="+box3+"&id1="+id1+"&id2="+id2+"&id3="+id3,false)
}
*/

function deleteTri(id,box1,box2,box3,id1,id2,id3)
{
	if(!confirm("Are you sure you want to delete?"))return		
	jRequest(baseurl+"admin/ajax","command=deletetri&box1="+box1+"&eye="+id+"&box2="+box2+"&box3="+box3+"&id1="+id1+"&id2="+id2+"&id3="+id3,false)
}

function deleteSelectedTri(ref,box1,box2,box3,id1,id2,id3)
{
		
	if(!isSelected(ref))
	{
		alert("Please select item(s) to delete");
		return;
	}

	if(!confirm("Are you sure you want to delete?"))return
	
var str = getSelected(ref)
jRequest(baseurl+"admin/ajax","command=deletetri&box1="+box1+"&eye="+str+"&box2="+box2+"&box3="+box3+"&id1="+id1+"&id2="+id2+"&id3="+id3,false)

}


function busy(mode)
{

	var bus = document.getElementById('processing')
	if(bus)
		if(mode)
			bus.style.visibility='visible'
		else
			bus.style.visibility='hidden'
}

function busyx(mode,id)
{

	if(!busyx.prev)prev=null
	if(id) busyx.current = id
	
	if(prev)document.getElementById(prev).style.visibility = 'hidden'

	var bus = document.getElementById(busyx.current)

	if(bus)
		if(mode)
			bus.style.visibility='visible'
		else
			bus.style.visibility='hidden'			
}



function c2d($dt)
{
	var a = $dt.split('-')
	return a[2]+'-'+a[1]+'-'+a[0]
}

function print_r(theObj){

  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}

function getDays(fromdate,todate)
{
	fromdate = fromdate.split('-')
	todate = todate.split('-')
	var a = new Date(fromdate[0],fromdate[1]-1,fromdate[2]);			
	var d = new Date(todate[0],todate[1]-1,todate[2]);
	return  (d.getTime() - a.getTime())/86400000
}

function setLanguage(mode,lang)
{
	var loc =  window.location.href;
	if(loc.match(/\?/))
	{
		if(loc.match(/lang=[a-z][a-z]/))
			loc = loc.replace(/lang=[a-z][a-z]/,"lang="+lang)
		else loc = loc + "&lang="+lang				  
	}
	else
		loc = loc + "?lang="+lang				  

	window.location = loc
}

function jaxResponse(jax)
{
	if(jax.responseText.indexOf('bien') + 1)window.location.reload()
	else
	{
		var resl = strip_tags(jax.responseText)
		if(resl.length)alert(resl)
	}
}

function jsalert(str)
{
	alert(str)
	if(jsalert.arguments.length>1)
	{
		if(document.getElementsByName(jsalert.arguments[1])[0])
			document.getElementsByName(jsalert.arguments[1])[0].focus()
	}
	throw new Error('Stopa');
}

function getjsText(nami)
{
	var os = document.getElementsByName(nami)[0];
	if(os)
	{
		if(os.type!='file')
		if(window.trim)os.value = trim(os.value)
		return os.value
	}
	return null
}

function doProcessing(ref,mode)
{
	if(document.getElementById(ref))
	{
		if(mode)
			document.getElementById(ref).style.visibility='visible'
		else
			document.getElementById(ref).style.visibility='hidden'			
	}
}

function request(script,param)
{
	var jax = createAjax();if(!jax)return;
	jax.open("GET",script+".php?"+param,false)
	jax.send(null)
	return jax
}

function getid(ids) { return document.getElementById('ids') }

function jRequestI(args,param)
{
	var jax = createAjax();if(!jax)return;
	jax.open("POST",args,false)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	jax.send(param);
	if(jax.responseText.indexOf('bien')+1){busy(0);jsalert('Email already Exists')}
//	else jsalert(jax.responseText);
}

function jRequest(args,param,mode)
{
//	mode = true;
	var jax = createAjax();if(!jax)return;
	jax.open("POST",args,mode)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	if(mode)jax.onreadystatechange = function() { if(jax.readyState==4)jaxResponse(jax); }
	jax.send(param);
	if(!mode)jaxResponse(jax);
}

function jRequestCall(args,param,mode,callback)
{
	var jax = createAjax();if(!jax)return;
	jax.open("POST",args,mode)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	if(mode)jax.onreadystatechange = function() { if(jax.readyState==4)jRtr(jax,callback); }
	jax.send(param);
//	alert(jax.responseText)
	if(!mode)jRtr(jax,callback);
}

function jRequestBool(args,param,mode)
{
	var jax = createAjax();if(!jax)return;
	jax.open("POST",args,mode)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	if(mode)jax.onreadystatechange = function() { if(jax.readyState==4)jResponseBool(jax); }
	jax.send(param);
//	alert(jax.responseText);
	if(!mode)return isbien(jax.responseText)?false:strip_tags(jax.responseText);	
}

function jRtr(jax,callback)
{
//	alert(jax.responseText)
	if( (jax.responseText.indexOf('bien')+1) || (jax.responseText.indexOf('DONiZ')+1) )
		eval(callback+"('Registred successfully. Please check you mail to activate your account')")
	else
		eval(callback+"('Unable to process this request. Please try again later')")
}

function display(ref,mode)
{
	mode = mode ? 'inline' : 'none'
	document.getElementById(ref).style.display = mode
}

function displayd(ref,mode)
{
	mode = mode ? 'block' : 'none'
	document.getElementById(ref).style.display = mode
}


function nullThese(whose)
{
	var str = whose.split(',')
	for(i in str)
		if(document.getElementById(str[i]))
			document.getElementById(str[i]).value=''
}

function setvalue(whose,ofwhat)
{
	document.getElementById(whose).value = ofwhat
}

function setvalueh(whose,ofwhat)
{
	document.getElementById(whose).innerHTML = ofwhat
}

function getvalueh(whose)
{
	return document.getElementById(whose).innerHTML 
}

function setimage(id,src)
{
	document.getElementById(id).src = src
}

function checkset(nami,err)
{
	var os = document.getElementsByName(nami)[0]
	if(!os)jsalert("'"+nami+"'"+' is Undefined');
	
	if(os.type!='file')
		if(window.trim)os.value = trim(os.value);
	
	if(os.value=='')
	{
		alert(err);
		os.focus();
		throw new Error('Stopa')
	}
}

function checkset_tinymce(src,msg)
{
	var content = tinyMCE.get(src).getContent()	
	content = trim(content);
	
	if(content=='')
	{ 
		alert(msg);
		throw new Error('Stopa')		
		return false;		
	}
}

function setTiny(id,val)
{
	tinyMCE.getInstanceById(id).setContent(val); 
}

function getTiny(id)
{
	return tinyMCE.get(id).getContent()	
}

function _checkset(nami,err)
{
	var os = document.getElementsByName(nami)[0]
	if(window.trim)os.value = trim(os.value);
	
	if(os.value=='')
	{
		alert(err);
		os.focus();
		throw new Error('Stopa')
	}
}

function clearall(str)
{
	str = str.split(',')
	for(i in str)
		if(document.getElementById(str[i]))
			document.getElementById(str[i]).value=''
}

function isbien(str)
{
	str = str.replace(/[\x00-\x1f]/,'')
	if( (str.indexOf('bien')+1) || (str.indexOf('DONiZ')+1) ) return true;
	return false;
}

function getjsSelectedText(nami)
{
	var nami = document.getElementsByName(nami)[0];
	if(nami) return nami.options[nami.selectedIndex].value
	else return null
}

function setActivity(id,box)
{
	var args = baseurl+'admin/ajax/'
	var param = "command=setactivity&id="+id+"&box="+box
	var arglen = arguments.length
	var jax = createAjax();if(!jax)return;
	jax.open("POST",args,true)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	jax.send(param);	
	jax.onreadystatechange = function() { if(jax.readyState==4) {	

		try{ var obj = eval('('+jax.responseText+')') }
		catch(e) {
			if(arglen>2)jsalert(trim(strip_tags(jax.responseText)))
			else jsalert("Unable to process the response code");
		}
		changeStatusImage('status',obj.status,id,'as')		
	}}
}

function changeStatusImage(which,status,id,prefix)
{
	var path = baseurl + 'static/images/'
	switch(which)
	{
		case 'status':
			var imi = document.getElementById(prefix+id)		
			if(status)
			{
				imi.src = path + 'tick.png'
				imi.title = 'Active'
				imi.alt = 'Active'
				imi.className = 'action'				
				imi.style.width = '16px'				
			}
			else 
			{
				imi.src = path + 'fileclose.gif'
				imi.title = 'Disabled'
				imi.alt = 'Disabled'
				imi.className = 'action opaty'
				imi.style.width = '13px'
			}
		break;
		
		case 'featured':
			var so = document.getElementsByTagName('img')
			for(var i=0;i<so.length;i++)
			{
				if(so[i].id.indexOf('fe')+1)
				{
					so[i].src = path + 'featured_not2.png'
					so[i].title = 'No'
					so[i].alt = 'No'
					so[i].className = 'action opaty'
					so[i].style.width = '13px'
					
				}
			}
			
			var imi = document.getElementById(prefix+id)	
			if(status)
			{
				imi.src = path + 'featured2.png'
				imi.title = 'Yes'
				imi.alt = 'Yes'
				imi.className = 'action'				
				imi.style.width = '16px'				
			}
/*			else 
			{
				imi.src = path + 'featured_not2.png'
				imi.title = 'No'
				imi.alt = 'No'
				imi.className = 'action opaty'
				imi.style.width = '13px'
			}
*/			
		break;
		
		
	}	
}

/*
function setActivity(id,box)
{
	jRequest(baseurl+'admin/ajax/',"command=setactivity&id="+id+"&box="+box,true)
}
*/

function toggleStatus(id,box,field)
{
//	jRequest(baseurl+'admin/ajax/',"command=togglestatus&id="+id+"&box="+box+'&field='+field,true)	

	var args = baseurl+'admin/ajax/'
	var param = "command=togglestatus&id="+id+"&box="+box+'&field='+field
	var arglen = arguments.length
	var jax = createAjax();if(!jax)return;
	jax.open("POST",args,true)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	jax.send(param);	
	jax.onreadystatechange = function() { if(jax.readyState==4) {	

		try{ var obj = eval('('+jax.responseText+')') }
		catch(e) {
			if(arglen>3)jsalert(trim(strip_tags(jax.responseText)))
			else jsalert("Unable to process the response code");
		}
		changeStatusImage('featured',obj.status,id,'fe')		
	}}

}

function setjsSelectedText(id,ref)
{
	var os = document.getElementById(ref)
	for(var i=0;i<os.options.length;i++)
		if(os.options[i].value==id)os.options.selectedIndex = i; 
}

function findAbsolutePosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
//returns an array
}

function makeParam(param)
{
	var str = param.split(',')
	var val='';
	val += str[0] + '=' + str[1];
	for(var i=2;i<str.length;i+=2)
		val += "&" + str[i] + '=' + encodeURIComponent(document.getElementById(str[i+1]).value)
	return val;	
}

function recaptcha(ref,url)
{
	document.getElementById(ref).src = url +  Math.floor(Math.random()*9000)+'/'	
}

function setjsDisable(flag,param)
{
	var str = param.split(',')
	for(var i=0;i<str.length;i++)
			document.getElementById(str[i]).disabled = flag
}

function helpThis()
{
//	alert('This will display the options and its usage in this page.\nThis has not yet been implemented.')	
	if(document.getElementById('helpdiv').style.display=='block')
		$('#helpdiv').hide(500);
	else $('#helpdiv').show(500);	
}

 $(document).ready(function() {
   // put all your jQuery goodness in here.
   $('#helpdiv').click( function () {
								  	$(this).hide(500); 
									});
 });


function isnFile(filename)
{
	filename = document.getElementsByName(filename)[0].value
	if(filename=='')return true;
	
	if (!/(\.(jpg|jpeg|gif|png))$/i.test(filename))return true
	else return false;
}

function savePosition(box)
{
	var sel
	if(arguments.length==2)sel = arguments[arguments.length-1]
	else sel='checks[]'	
	var sa = document.getElementsByName(sel)
	if(!sa.length) { alert('No items Found'); return; }
	var str
	if(arguments.length==3)
		str = "command=setposition&yesphotos=true&box="+box+"&pos=";
	else
		str = "command=setposition&box="+box+"&pos=";
	var s=''
	for(var i=0;i<sa.length;i++)
		s+=sa[i].value+','
	s = rtrim(s,',')
	
	jRequest(baseurl+'admin/ajax/',str+s,false);
}

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.toGMTString()) + "; path=/";
}

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 null;
}


function hideError()
{
	if(window.location.href.indexOf('admin')+1)
		$('#errdiv').fadeOut(500);
}

function changeurl(id)
{
	var str;	

	switch(id)
	{
		case 1: str='';break;		
		case 2: str='aboutus/';break;
		case 3: str='titles/';break;
		case 4: str='gallery/';break;
		case 5: str='news/';break;
		case 6: str='onlinecomics/';break;
		case 9: str='community/';break;
		case 8: str='contact/';break;
		case 7: str='store/';break;		
		default: return;
	}
	
//	if(window.location.href.match(/\/store\//))baseurl = baseurl.replace(/https:\/\//,'http://')
	baseurl = baseurl.replace(/www\.www\./,'www.')
	window.location = baseurl+str;

/*	
	var hre = document.createElement('a')
	hre.href = baseurl+str
	hre.id = 'aiyohy'
	hre.style.display = 'block'
	hre.innerHTML = 'aiyoo'
	document.body.appendChild(hre);
	$('#aiyohy').trigger('click');
//	alert(document.getElementById('aiyohy').href)
*/						
}

function bookmarkthis()
{
//	return;
var title = 'Penny-Farthing Press';
var url = baseurl

if(window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
else alert('Please use CTRL + D to bookmark this site')

} 


function jsonRequest(args,param,mode)
{
	var jax = jPreset(args,param,mode)
	jax.send(param)
	try{ return eval('('+jax.responseText+')') }
	catch(e) {
		if(arguments.length>3)jsalert(trim(strip_tags(jax.responseText)))
		else jsalert("Unable to process the response code");
	}
}

function jaxPreset_no()
{
	var jax = createAjax();if(!jax)return false;
	if(arguments.length)ajaxpath = arguments[0]	
	jax.open("POST",ajaxpath,false)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	return jax;
}

function urlencode (str) {

    str = (str+'').toString();
    
  return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function showScrolly(id,ref1,ref2)
{

//	alert($('#'+id)[0].scrollHeight + ' - ' + $('#'+id).height())

	if($('#'+id).height()) {
					
	if($('#'+id)[0].scrollHeight > $('#'+id).height() )
	{
//			alert('er')
			document.getElementById(ref1).style.display = 'block'
			document.getElementById(ref2).style.display = 'block'			
	} }
}

function prefixHttp(ref)
{
	if(!(ref = document.getElementById(ref)))return;
	if( (ref.value.indexOf('http://')+1 !=1) && (ref.value.indexOf('https://')+1 !=1) )
	{
//		if(confirm('No http:// prefix in url\n\nClick OK to add or Cancel to continue'))
		ref.value = 'https://'+ref.value
	}
}

var sc, maxscroll, minscroll=0;
var uptime, downtime
var pixelsteps=2;
var delay = 10
function inscroll(src)
{
	if(arguments.length>1)pixelsteps = arguments[1]	
	if(arguments.length>2)delay = arguments[2]		
	
	sc = document.getElementById(src);
	maxscroll = sc.scrollHeight - sc.offsetHeight
	minscroll = 0		
}

function scrollup()
{
	uptime = window.setInterval('scrollUp()',delay)
}
function scrolldown()
{
	downtime = window.setInterval('scrollDown()',delay)
}

function scrollUp()
{
	if(sc.scrollTop>0)
		sc.scrollTop = sc.scrollTop - pixelsteps
}
function scrollDown()
{
	if(sc.scrollTop<maxscroll)
		sc.scrollTop = sc.scrollTop +  pixelsteps
}

function clearscroll()
{
	if(uptime)window.clearInterval(uptime)
	if(downtime)window.clearInterval(downtime)	
}


function base64_encode (data) {
        
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];

    if (!data) {
        return data;
    }

    data = this.utf8_encode(data+'');
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);

        bits = o1<<16 | o2<<8 | o3;

        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch (data.length % 3) {
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}

function utf8_encode ( argString ) {

    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

function html_entity_decode (string, quote_style) {
 
    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }

    // fix &amp; problem
    // http://phpjs.org/functions/get_html_translation_table:416#comment_97660
    delete(hash_map['&']);
    hash_map['&'] = '&amp;';

    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    tmp_str = tmp_str.split('&#039;').join("'");
    
    return tmp_str;
}

function get_html_translation_table (table, quote_style) {
    
    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';

    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }

    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }

    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';


    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }
    
    return hash_map;
}

