// JavaScript Document

function check(id){
	var answer = confirm(' Are you sure to delete this image?');
	if(answer){
		location.href = 'gallery.php?action=Delete&gallery_id='+id;

	}
	else
		alert('s');
}



function Ajax() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};
function subscribe(thread,comment) {
		
	 var req = Ajax();
	 req.onreadystatechange = function () { 
		  if (req.readyState==4) {
			   if (req.status==200) {
								
			   } 
		  }
	 };
	
	
	
	 req.open("GET", "subscribe.php?thread="+thread+"&comment="+comment); 
	 
	 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); 
	 req.send(null); 
		var loc = window.parent.location;
	 window.parent.location = loc;
}

function unsubscribe(thread,comment) {
	
	 var req = Ajax();
	 req.onreadystatechange = function () { 
		  if (req.readyState==4) {
			   if (req.status==200) {
								
			   } 
		  }
	 };
	
	
	
	 req.open("GET", "subscribe.php?thread="+thread+"&comment="+comment+"&mode=unsubscribe"); 
	 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); 
	 req.send(null); 
	var loc = window.parent.location;
				window.parent.location = loc;
}

function checkAll(field)
{

	for (var i=0;i<field.length;i++){
		var e = field[i];
		
		if (e.name != 'allbox' || e.name != 'ff')
			e.checked = field.allbox.checked;
	}
}

function uncheckAll(field){
	//var check = document.back.allbox.checked;
	//alert(document.back.allbox.checked)
	if(document.back.allbox.checked == true)
		document.back.allbox.checked = false
//	field.all	
}
function coursepage(ele){
	var loc = window.parent.location.href;
	var keyword = '';
	var myRegExp = /coursekey/;
	var matchPos1 = loc.search(myRegExp);
	var type = '';
	
	if(matchPos1 != -1){
		keyword = getparam('keyword');
		coursekey = getparam('coursekey');
		
		
		newloc = 'cresult.php?mode=course&keyword='+keyword+'&coursekey='+coursekey+'&pageno='+ele;
	}
	else{
		lvl = getparam('lvl');
		coursekey = getparam('coursenow');
		key = getparam('key');
		type = getparam('type[]');

		
		
		var add1 = '';
		var add2 = '';
		var add3 = '';
		if(lvl.length > 0)
			add1 = 'lvl='+lvl+'&';
		if(key.length > 0)
			add2 = 'key='+key+'&';
		if(type.length > 0)
			add3 = 'type='+type+'&';
		
		
		
		var myRegExp = /&pageno/;
		var result = loc.search(myRegExp);
		
		if(result == -1){
			var newloc = loc.substring(0,result);
			
			newloc = loc + '&pageno='+ele;		
		}
		else{
			var newlink = loc.split("&");
			
			for(var i=0;i<newlink.length;i++){
				
				var lastget  = newlink[(newlink.length-1)].split('=');
				
				if(lastget[0] != 'pageno'){
					newloc = loc+'&pageno='+ele;
				}
				else{
					var myRegExp = /&pageno/;
					var result = loc.search(myRegExp);
					
					var newloc = loc.substring(0,result);
					newloc = newloc + '&pageno='+ele;
					
					
				}
			}
		}
		
		
		//newloc = 'cresult.php?'+add1+add3+add2+'mode=course&coursenow='+coursekey+'&pageno='+ele;
	
	}
	
	window.parent.location = newloc;
}
function changepage(ele){
	var loc = window.parent.location.href;
	var keyword = '';
	var myRegExp = /keysearch/;
	var matchPos1 = loc.search(myRegExp);
	
	if(matchPos1 != -1){
		keyword = getparam('keyword');
		keysearch = getparam('keysearch');
		
		newloc = 'result.php?keyword='+keyword+'&keysearch='+keysearch+'&pageno='+ele;
	}
	else{
		var myRegExp = /arrowsearch/;
		var matchPos1 = loc.search(myRegExp);
		var newloc;
		if(matchPos1 != -1){
			keyword = getparam('keyword');
			keysearch = getparam('arrowsearch');
			
			newloc = 'result.php?keyword='+keyword+'&arrowsearch='+keysearch+'&pageno='+ele;
		}
		else{ 
			
	 		/*var lol=(""+location.search).substring(1).split("&");
			window.location.GET=new Array();
			var keyword = "";
			for (var i in lol) {
			  var stringarr = lol[i];
			  var temp = stringarr.split("=");
			  window.location.GET[temp[0]]=temp.splice(1,temp.length-1).join("=");
				if(window.location.GET[temp[0]] != "+"){
						keyword = keyword + "key[]="+ window.location.GET[temp[0]]+"&"; 				
				}	
				var jon = keyword;
			}
			*/
			var newlink = loc.split("&");
			
			for(var i=0;i<newlink.length;i++){
				
				var lastget  = newlink[(newlink.length-1)].split('=');
				
				if(lastget[0] != 'pageno'){
					newloc = loc+'&pageno='+ele;
				}
				else{
					var myRegExp = /&pageno/;
					var result = loc.search(myRegExp);
					//alert(result)
					var newloc = loc.substring(0,result);
					newloc = newloc + '&pageno='+ele;
					
					
				}
			}
				keysearch = getparam('searchnow');
			//newloc = 'result.php?'+keyword+'searchnow='+keysearch+'&pageno='+ele;	
		}
		
	}
	
	
	window.parent.location = newloc;
}

function setGET() {
   var get=(""+location.search).substring(1).split("&");
   window.location.GET=new Array();
   for (var i in get) {
      var temp=get[i].split("=");
      window.location.GET[temp[0]]=temp.splice(1,temp.length-1).join("=");
   }
}



function getparam( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}


function clickme(id) {
		
	 var req = Ajax();
	 req.onreadystatechange = function () { 
		  if (req.readyState==4) {
			   if (req.status==200) {
								
			   } 
		  }
	 };
	
	
	
	 req.open("GET", "click.php?id="+id); 
	 
	 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); 
	 req.send(null); 
		var loc = window.parent.location;
	 window.parent.location = loc;
}
