var xmlHttp
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}
function GetLength()
{
	var oEditor = d3editorAPI.GetInstance('post') ;
	var oDOM = oEditor.EditorDocument ;

	var iLength ;
	if ( document.all )	
	{
		iLength = oDOM.body.innerText.length ;
	}
	else	
	{
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}

	
	return iLength ;
}

function isemail(strString) {

var blnResult = false;

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strString)){
blnResult = true;
}
return blnResult;
}


function Confirdel(id,$page,cat,table) 
{ 
answer = confirm( js_con_delete  )
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=delete&id='+id
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('qid_'+id).style.display = "none"
document.getElementById('mid_'+id).style.display = ""
document.getElementById('nid_'+id).className = "red "
}}

function Confirmres(id,$page,table) 
{ 
answer = confirm( js_con_resuser)
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=restore&id='+id
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('qid_'+id).style.display = ""
document.getElementById('mid_'+id).style.display = "none"
document.getElementById('nid_'+id).className = "black"
}}




function Confirmdeleten(id,$page,cat,table) 
{ 
answer = confirm( js_con_deleten )
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=delete&table='+table+'&cat='+cat+'&id='+id
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('nid_'+id).style.display = "none"
}}

function Confirmrestore(id,$page,table) 
{ 
answer = confirm( js_con_restoren )
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=restore&cat='+table+'&id='+id
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('nid_'+id).style.display = "none"
}}


function Confirmdelete(id,$page) 
{ 
answer = confirm( js_con_delete )
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=delete&id='+id
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('nid_'+id).style.display = "none"
}}


function Confirmshow(id,$page) 
{ 
answer = confirm( js_con_show )
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=show&id='+id+'&rand='+Math.random()
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('did_'+id).style.display = "none"
document.getElementById('sid_'+id).style.display = ""
}}



function Confirmshows(id,$page,cat) 
{ 
answer = confirm( js_con_show )
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=show&id='+id+'&cat='+cat+'&rand='+Math.random()
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('did_'+id).style.display = "none"
document.getElementById('sid_'+id).style.display = ""
}}

function setadmin(id,$page) 
{ 
answer = confirm( js_con_admin )
if (answer !=0) 
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=admin&id='+id+'&rand='+Math.random()
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('did_'+id).style.display = "none"
document.getElementById('sid_'+id).style.display = ""
}}



function setuser(id,$page) 
{ 
answer = confirm( js_con_user )
if (answer !=0) 
{ 


xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=user&id='+id+'&rand='+Math.random()
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('did_'+id).style.display = ""
document.getElementById('sid_'+id).style.display = "none"
}}



function Confirmhides(id,$page,cat) 
{ 
answer = confirm( js_con_hide )
if (answer !=0) 
{ 


xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=hide&id='+id+'&cat='+cat
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('did_'+id).style.display = ""
document.getElementById('sid_'+id).style.display = "none"
}}



function Confirmhide(id,$page) 
{ 
answer = confirm( js_con_hide )
if (answer !=0) 
{ 


xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= $page + '.php?do=hide&id='+id
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById('did_'+id).style.display = ""
document.getElementById('sid_'+id).style.display = "none"
}}


function postform(){

if ((document.senform.title.value.length==0) || (document.senform.title.value==null)) {
	alert(js_enter_title);
   return false ;
} else if(GetLength() == ''){
	alert(js_ent_post);
	return false ;
	}else {
	return true ;
}}


function login(){

if ((document.logfrm.username.value.length==0) || (document.logfrm.username.value==null)) {
	alert(js_enter_user);
   return false ;
} else if ((document.logfrm.password.value.length==0) || (document.logfrm.password.value==null)) {
	alert(js_enter_pass);
   return false ;
} else {
	return true ;
}}


function msgend(id){
	fade('msg');
	Set_Cookie('msg',id, '7', '', '', '' );

}


function TestFileType( fileName ) {

fileTypes = ['gif', 'jpg', 'png']

dots = fileName.split(".")
fileType = "." + dots[dots.length-1];

return (fileTypes.join(".").indexOf(fileType) != -1) ?
msgh = true : 
msgh =  false

return msgh
}

function isUrl(s) {
	if( /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ . test(s)){
	msgh=true;
	}else{
	msgh=false;
	}
	return msgh	
}

function IsNumeric(strString)	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
function eeform(){
if ((document.senform.suject.value.length==0) || (document.senform.suject.value ==null)) {
	alert(js_enter_title);
	return false ;
	} else if(GetLength() == ''){
	alert(js_ent_post);
	return false ;
	}else if(isemail(document.senform.email.value) == false ){
	alert(js_emil_sub);
	return false ;
	}else{
	return true ;
	}
}


function postmem(){
if ((document.senform.username.value.length==0) || (document.senform.username.value ==null)) {
	alert(js_enter_user);
	return false ;
	}else if(isemail(document.senform.email.value) == false ){
	alert(js_emil_sub);
	return false ;
	}else{
	return true ;
	}
}



function eaform(){
if ((document.senform.suject.value.length==0) || (document.senform.suject.value ==null)) {
	alert(js_enter_title);
	return false ;
	} else if(GetLength() == ''){
	alert(js_ent_post);
	return false ;
	}else{
	return true ;
	}
}


function postpass(){
if ((document.pass.oldpass.value.length==0) || (document.pass.oldpass.value ==null)) {
	alert(js_enter_oldpass);
	return false ;
	}if ((document.pass.newpass.value.length==0) || (document.pass.newpass.value ==null)) {
	alert(js_enter_newpass);
	return false ;
	}else if ((document.pass.cpass.value.length==0) || (document.pass.cpass.value ==null)) {
	alert(js_enter_cpass);
	return false ;
	}else if ( document.pass.cpass.value != document.pass.newpass.value ) {
	alert(js_enter_goodpass);
	return false ;
	}else{
	return true ;
	}
}


function weform(){
if ((document.senform.title.value.length==0) || (document.senform.title.value ==null)) {
	alert(js_enter_title);
	return false ;
	} else if(GetLength() == ''){
	alert(js_ent_post);
	return false ;
	} else if(isUrl(document.senform.link.value) == false ){
	alert(js_link_sub);
	return false ;
	}else{
	return true ;
	}
}




function upform(){
if ((document.senform.title.value.length==0) || (document.senform.title.value ==null)) {
	alert(js_enter_title);
	return false ;
	}else if ((document.senform.userfile2.value.length==0)&& (document.senform.state.value == 'new') || (document.senform.userfile2.value ==null   )&& (document.senform.state.value == 'new')){
	alert(js_file_sel);
	return false ;
	}else if ((document.senform.userfile1.value.length==0)&& (document.senform.state.value == 'new') || (document.senform.userfile1.value ==null)&& (document.senform.state.value == 'new')){
	alert(js_img_sel);
	return false ;
	} else if(GetLength() == ''){
	alert(js_ent_post);
	return false ;
	} else if(TestFileType(document.senform.userfile1.value) == false){
	alert(js_file_sub);
	return false ;
	}else{
	return true ;
	}
}

function upiform(){

	if ((document.senform.userfile2.value.length==0)&& (document.senform.state.value == 'new') || (document.senform.userfile2.value ==null   )&& (document.senform.state.value == 'new')){
	alert(js_file_sel);
	return false ;
	}else if(TestFileType(document.senform.userfile2.value) == false){
	alert(js_file_sub);
	return false ;
	}else if ((document.senform.Height.value.length==0) || (document.senform.Height.value ==null)) {
	alert( js_img_height);
	return false ;
	}else  if ((document.senform.Width.value.length==0) || (document.senform.Width.value ==null)) {
	alert( js_img_width);
	return false ;
	}else  if ((IsNumeric(document.senform.Width.value) == false) || (IsNumeric(document.senform.Height.value) == false)) {
	alert( js_num_all);
	return false ;
	}else{
	return true ;
	}
}



function editform(id){
if ((document.getElementById('title_'+id ).value.length==0) || (document.getElementById('title_'+id).value ==null)) {
	alert(js_enter_title);
	return false ;
	}else{
	return true ;
	}
}

function searchform(id){
if ((document.getElementById('title_'+id ).value.length==0) || (document.getElementById('title_'+id).value ==null)) {
	alert(js_enter_name);
	return false ;
	}else{
	return true ;
	}
}

function editmail(id){
if (isemail(document.getElementById( 'title_'+id ).value) == false ){
	alert(js_emil_sub);
	return false ;
	}else{
	return true ;
	}
}



function display(id){
if (document.getElementById( id ).style.display == "none"){
document.getElementById( id ).style.display = ""
}else{
document.getElementById( id ).style.display = "none"
}}

function hideshow(show,hide){
if (document.getElementById(show).style.display == "none"){
document.getElementById(hide).style.display = "none"
document.getElementById(show).style.display = ""
}else{
document.getElementById(hide).style.display = ""
document.getElementById(show).style.display = "none"
}}


function reddel(cat,table)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
     
var url="bin.php"
url=url+"?cat="+cat
url=url+"&table="+table
url=url+"&rand="+Math.random()
xmlHttp.onreadystatechange=stateChangedc

xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function unimg(cat,table)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
     
var url="unimg.php"
url=url+"?rand="+Math.random()
xmlHttp.onreadystatechange=stateChangedi

xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChangedi() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("uimg").innerHTML=xmlHttp.responseText 
   document.getElementById('load').style.display = "none" 
   document.getElementById('uimg').style.display = ""
  } 
} 

function restorig(id,file) 
{ 
answer = confirm( js_con_restorig )
if (answer !=0) 
{ 


xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}        
var url= 'unimg.php?do=update&id='+file
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById(id).style.display = "none"
}}


function stateChangedc() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   { 
   document.getElementById("load").innerHTML=xmlHttp.responseText 
   document.getElementById('load').style.display = "" 
   document.getElementById('uimg').style.display = "none"
   } 
} 
function nop(){
alert(js_error_alert);
}




