var previous = "discimg0";
var cc = 0;
var imgOwner = "";
var imgCat = "";
var imgCatNum = 0;

function getXmlhttpObject(){
   var Xobject = null;
	  if (window.XMLHttpRequest){
		 Xobject = new XMLHttpRequest();
	  }else if (window.ActiveXObject){
		 Xobject = new ActiveXObject("Microsoft.XMLHTTP");
	  }
   return Xobject;
}

function setwkuser(id){
		 document.getElementById("setmsg").innerHTML = "a moment pls..";
   xmlHttp = getXmlhttpObject();
	  if (xmlHttp == null){
		 alert("Browser doesn't support HTTP Resquest try a newer version");
		 return;
	  }

  

  var q = "id="+id+"&sid="+Math.random();
  xmlHttp.open("GET","setweekuser.asp?"+q);
  
  xmlHttp.send(0);
   
  xmlHttp.onreadystatechange = function stateChanged(){
	  if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		 
		 data = xmlHttp.responseText;
		 document.getElementById("setmsg").innerHTML = ""+data;

		 return "nothing"; 
	  }
   };

}

function downld1(){
	if(document.getElementById("ss").value != ""){
	  alert("this stage has expired  click on gallery to start over");
	  exit(0);
  }
document.getElementById("loadmsg").innerHTML = "one moment please...";
   xmlHttp = getXmlhttpObject();
	  if (xmlHttp == null){
		 alert("Browser doesn't support HTTP Resquest try a newer version");
		 return;
	  }

  
  var fname = document.getElementById("filename").value;
  
  var q = "address="+fname;
  xmlHttp.open("GET","test1.aspx?"+q);
  
  xmlHttp.send(0);
  
  xmlHttp.onreadystatechange = function stateChanged(){
	  if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
	 
		 data = xmlHttp.responseText;
		 document.getElementById("loadmsg").innerHTML = "file: "+data;
		 document.getElementById("filename").value = data;
		 document.getElementById("ss").value = "1";
		 document.getElementById("loadmsg").innerHTML = "done!";
		 document.getElementById("pictemp").submit();
		 return "nothing";
	  }
   };
}

function downld(){
	if(document.getElementById("ss").value != ""){
	  alert("this stage has expired click on gallery to start over");
	  exit(0);
  }
document.getElementById("loadmsg").innerHTML = "one moment please...";
   xmlHttp = getXmlhttpObject();
	  if (xmlHttp == null){
		 alert("Browser doesn't support HTTP Resquest try a newer version");
		 return;
	  }

  
  var fname = document.getElementById("filename").value;
  
  var q = "address="+fname;
  xmlHttp.open("GET","test1.aspx?"+q);
  
  xmlHttp.send(0);
  
  xmlHttp.onreadystatechange = function stateChanged(){
	  if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
	 
		 data = xmlHttp.responseText;
		 document.getElementById("loadmsg").innerHTML = "file: "+data;
		 document.getElementById("filename").value = data;
		 document.getElementById("ss").value = "1";
		 document.getElementById("loadmsg").innerHTML = "done!";
		 document.getElementById("pictemp").submit();
		 return "nothing";
	  }
   };
}

function changeimg(img_src) {

	document.getElementById('filename').value = img_src;
	document.getElementById('filename').innerHTML = img_src;
	document.mainimg.src = img_src;
}

function check() {

	if(document.mainimg.src == "nothing.jpg"){
		alert("You must select a file");
		document.exit(0);
	}else{
		return true;
	}
}


function setlocation(href,count,cat) {

	location.href = href+count+"&order="+cat;
}

function checklen(text) {
	
	if (text.value.length > 200){
		alert("description too long");
	}
}

function showeditor(type){

	if (type == "pass"){
		document.getElementById("p1").disabled  = false;
		document.getElementById("p2").disabled  = false;
		document.getElementById("edittype").value  = "editp";
	}else if (type == "desc"){
		document.getElementById("desc").disabled  = false;
		document.getElementById("edittype").value  = "editd";
	}else if (type == "url"){
		document.getElementById("url").disabled  = false;
		document.getElementById("edittype").value  = "editu";
	}
}

function setprevious(prev){
		
		previous = prev;					
}

function eraseback() {

		if (previous != "") {
			document.getElementById(previous).style.backgroundColor = '#666666';
		}

}

function showImgforOwner() {
	
	location.href = "account.asp?id="+imgOwner;
}

function showImgforCat() {
	
	location.href = "gallery.asp?cat="+imgCatNum;
}


function getImgOwner(id, type) {
		
	  xmlHttp = getXmlhttpObject();
	  
	  if (xmlHttp == null) {
		 alert("Browser doesn't support HTTP Resquest try a newer version");
		 return;
	  }

	  if(type == "") {

		  var q = "id="+id+"&sid="+Math.random();
	  } else {

		  id = id.replace("http://mymymedia.com/","");
		  id = id.replace("uploads/","");
		  //id = id.replace(" ","%20");
		  //alert(id);
		  //var q = "fname="+id.replace("http://mymymedia.com/uploads/","")+"&type=filename&sid="+Math.random();
		  var q = "fname="+id+"&type=filename&sid="+Math.random();
	  }

	  

	  //if (window.XMLHttpRequest) {
	  
	  if(navigator.appName != "Microsoft Internet Explorer") {

		  xmlHttp.open("GET","detailsq.asp?"+q);
		  xmlHttp.send(0);
		  //alert(id+"fdg");
	  } else if (window.ActiveXObject) {		  

		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlHttp) {
	                //xmlHttp.onreadystatechange = handleHttpResponse;
			xmlHttp.open("GET", ("detailsq.asp?"+q));
			xmlHttp.send();
	        } else {
			alert("Your browser does not support ajax");
		}
		  
		  
		  //xmlHttp.send();		 
	  }
	  	  

	  xmlHttp.onreadystatechange = function stateChanged() {
		  
		  if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

			 data = xmlHttp.responseText+"";
			 
			 data = data.split("|");			 
			 document.getElementById("by").innerHTML = ""+data[0];
			 document.getElementById("cata").innerHTML = ""+data[1];			 

			imgOwner = data[0];
			imgCat = data[1];
			imgCatNum = data[2]; 
			 //return "nothing";       
		  }
	   };
	   //return false;
}

//function getURL(url) {
//  if(isWorking == true) { setTimeout("getURL(\""+url+"\")", "100"); return false; }
//
//  isWorking = true;
//
//  if (window.XMLHttpRequest) {
//	req = new XMLHttpRequest();
//        req.onreadystatechange = handleHttpResponse;
//	req.open("GET", url, true);
//	req.send(null);
//  } else if (window.ActiveXObject) { // IE
//	try {
//		req = new ActiveXObject("Msxml2.XMLHTTP");
//	} catch (e) {
//		req = new ActiveXObject("Microsoft.XMLHTTP");
//	}
//	if (req) {
//                req.onreadystatechange = handleHttpResponse;
//		req.open("GET", url, true);
//		req.send();
//        } else {
//		alert("Your browser does not support ajax");
//	}
//  } else {
//	alert("Your browser does not support ajax");
//  }
//
//  return false;
//}


function getImgCat(){
	
	
}

function checkEnter(e){ 
	var characterCode; 
	
	if(e && e.which){ 
		e = e;
		characterCode = e.which; 
	}else{
		e = event;
		characterCode = e.keyCode; 
	}
	if(characterCode == 13){ 
		document.getElementById("login").submit(); 
		return false;
	}else{
		return true;
	}

}



