// Just a stub function we'll tell ajaxObject to call when it's done
// callback functions get responseText, and responseStat respectively
// in their arguments.
function fin(responseTxt,responseStat) {
  //alert(responseStat+' - '+responseTxt);
}

// create a new ajaxObject, give it a url it will be calling and
// tell it to call the function "fin" when its got data back from the server.
//var test1 = new ajaxObject('http://someurl.com/server.cgi',fin);
//    test1.update();
               
// create a new ajaxObject, give it a url and tell it to call fin when it
// gets data back from the server.  When we initiate the ajax call we'll
// be passing 'id=user4379' to the server.           
//var test2 = new ajaxObject('http://someurl.com/program.php',fin);
//    test2.update('id=user4379');
               
// create a new ajaxObject but we'll overwrite the callback function inside
// the object to more tightly bind the object with the response hanlder.


// create a new ajaxObject and pass the data to the server (in update) as
// a POST method instead of a GET method.
//var test4 = new ajaxObject('http://someurl.com/postit.cgi', fin);
//   test4.update('coolData=47&userId=user49&log=true','POST'); 


function ajaxObject(url, callbackFunction) {
	var that=this;     
  	this.updating = false;
  	this.abort = function() {
    	if (that.updating) {
      		that.updating=false;
      		that.AJAX.abort();
      		that.AJAX=null;
    	}
	}
	this.update = function(passData,postMethod) {
    	if (that.updating) { 
			return false;
		}
    	that.AJAX = null;                         
    	if (window.XMLHttpRequest) {             
      		that.AJAX=new XMLHttpRequest();             
    	} else {                                 
      		that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    	}                                             
    	if (that.AJAX==null) {                             
      		return false;                               
    	} else {
      		that.AJAX.onreadystatechange = function() { 
        		if (that.AJAX.readyState==4) {             
          			that.updating=false;               
          			that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);       
          			that.AJAX=null;                                         
        		}                                                     
      		}                                                       
      		that.updating = new Date();                             
      		if (/post/i.test(postMethod)) {
        		var uri=urlCall+'?'+that.updating.getTime();
        		that.AJAX.open("POST", uri, true);
        		that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        		that.AJAX.send(passData);
      		} else {
        		var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());
        		that.AJAX.open("GET", uri, true);                             
        		that.AJAX.send(null);                                         
      		}             
      		return true;                                             
    	}                                                                           
  	}
  	var urlCall = url;       
  	this.callback = callbackFunction || function () { };
  
}

var AjaxCategoryIdArr=new  Array();

     	
	
	/********** pages       **********/


function MenuMove(cid,orderid,parentid,task){
 // alert(parentid);
 //alert(orderid);
 //alert(cid);
 //document.page_form.hidden_name.value='';
 
 var flag = false ;
    if(flag == false){
	link='ordering.php?task='+task+'&parentid='+parentid+'&menu='+cid+'&orderid='+orderid;
	var linkComp = link.split( "?");		
		
		var result;		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
          
           //ShowBlogPage();  
			// we'll do something to process the data here.
			result = responseTxt
			//alert(result);
	location.reload(true);
			//return ; 
          flag = true ;
		}
      }
	}
		
function LinkTypeMove(cid,orderid,parentid,task){
 // alert(parentid);
 //alert(orderid);
 //alert(cid);
 //document.page_form.hidden_name.value='';
 var flag = false ;
    if(flag == false){
	link='../link_type/ordering.php?task='+task+'&parentid='+parentid+'&menu='+cid+'&orderid='+orderid;
	    var linkComp = link.split( "?");	
		var result;		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
          
			// we'll do something to process the data here.
			result = responseTxt
			//alert(result);
	location.reload(true);
			//return ; 
           flag = true ;
		}

	}		
}	
	
	
function ShowMedia(media_type,library_id){
	//alert("ok");
 //alert(library_id);
 //alert(media_type);
 //alert(cid);
 //document.page_form.hidden_name.value='';
 
	link='gallery/show_media.php?media_type='+media_type+'&library_id='+library_id;
	var linkComp = link.split( "?");		
		
		var result;		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
          
           
			// we'll do something to process the data here.
			result = responseTxt
			//alert(result);
			document.getElementById('media_display').innerHTML = result;  
	//location.reload(true);
			//return ; 

		}

	}		

function PlayVideo(video_name,video_thumb,media_type,library_id){

   link='gallery/show_media.php?media_type='+media_type+'&library_id='+library_id;
	var linkComp = link.split( "?");		
		
		var result;		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
          
           
			// we'll do something to process the data here.
			result = responseTxt
    document.getElementById('media_display').innerHTML = result;  

	//alert(video_name);
								var s1 = new SWFObject("../../player.swf","ply","440","250","9","#F5F2EF");

									s1.addParam("allowfullscreen","true");

									s1.addParam("allowscriptaccess","always");

									//echo 's1.addParam("flashvars","file='.$filename.'");';
									//$file=___SERVER_ROOT_URL."images/gallery/videos/thumb/";
									//$video_image = $Details[0]['video_thumb'];
                                        //$file ="";
									s1.addParam('flashvars','file='+video_name+'&image='+video_thumb+'&controlbar=over&');

									//echo "s1.write('preview');";

									s1.write("gallery_display");
	
	//document.getElementById('media_desc').innerHTML = title; 
	//document.getElementById('media_desc').innerHTML = desc; 
	
	
}
}

function ShowParentMenu(baseurl,id){
		//alert(menu_type);
		link= baseurl+'menulist.php?id='+id;
	  var linkComp = link.split( "?");
      var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	   obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('parent_id').innerHTML = result;  
					
	}
}
function ShowCategory(baseurl,cid,id){
	link= baseurl+'process.php?cid='+cid+'&id='+id;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('result'+cid).innerHTML = result;  
			 document.getElementById('result'+cid).style.display = "block";
            document.getElementById('showCat'+cid).style.display = "none";
            document.getElementById('HideCat'+cid).style.display = "block";
            
                 // for internet explorer
        if( document.getElementById('result'+cid).innerHTML==""){
            document.getElementById('result'+cid).style.display = "none";
        } 
         
            
		}

	}	
function HideCategory(baseurl,cid,id){
	link= baseurl+'process.php?cid='+cid+'&id='+id;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('result'+cid).innerHTML = result;  
			document.getElementById('result'+cid).style.display = "none";
            document.getElementById('showCat'+cid).style.display = "block";
            document.getElementById('HideCat'+cid).style.display = "none";
		}

	}

function ShowCategoryList(baseurl,cid,id){
//var CatOptionStatus+cid=true;
var optionCatIdStr=optionCatIdArr.toString();
	link= baseurl+'process1.php?cid='+cid+'&id='+id+'&optionCatIdArr='+optionCatIdStr;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('resultN'+cid).innerHTML = result;  
			 document.getElementById('resultN'+cid).style.display = "block";
            document.getElementById('showCatN'+cid).style.display = "none";
            document.getElementById('HideCatN'+cid).style.display = "block";
        
    	
                 // for internet explorer
        if( document.getElementById('resultN'+cid).innerHTML==""){
            document.getElementById('resultN'+cid).style.display = "none";
        } 
	}

}	
function HideCategoryList(baseurl,cid,id){
//CatOptionStatus+cid=false;
	link= baseurl+'process1.php?cid='+cid+'&id='+id;
	var linkComp = link.split( "?");
    var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");
	    obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('resultN'+cid).innerHTML = result;  
			document.getElementById('resultN'+cid).style.display = "none";
            document.getElementById('showCatN'+cid).style.display = "block";
            document.getElementById('HideCatN'+cid).style.display = "none";
		}

	}
function EditOption(baseurl,i,product_id){
 	link= baseurl+'edit_option.php?id='+i+'&product_id='+product_id ;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
           
			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('displayRow'+i).innerHTML = result;  
			document.getElementById('displayRow'+i).style.display = "block";
		   
			
		Shadowbox.deact();
        Shadowbox.init();
	  }	  
        
}			
function ChangeartistOrder(url){
//alert(url);
link= url;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
		result = responseTxt
		//alert(result);
     location.reload(true);
}
}






//********* ATTRIBUTE ************
var AjaxAttributeArr=new Array();
function ShowAttribute(baseurl,cid){
    AjaxAttributeArr.push(cid);
	link= baseurl+'attribute_process.php?cid='+cid;
	var linkComp = link.split( "?");
	var result;
	var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
		
        
      document.getElementById('resultAttribute'+cid).innerHTML = result;  
	  document.getElementById('resultAttribute'+cid).style.display = "block";
      document.getElementById('showAtt'+cid).style.display = "none";
      document.getElementById('HideAtt'+cid).style.display = "block";
        Shadowbox.deact();
        Shadowbox.init();
		}

	}	
function HideAttribute(baseurl,cid,id){
	//AjaxAttributeArr.push(cid);
	for ( var i in AjaxAttributeArr )
	{
	
		if(AjaxAttributeArr[i]==cid){
			AjaxAttributeArr.splice(i,1);

		}
}
	link= baseurl+'system.php?cid='+cid+'&id='+id;
	var linkComp = link.split( "?");
	var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('resultAttribute'+cid).innerHTML = result;  
			document.getElementById('resultAttribute'+cid).style.display = "none";
         document.getElementById('showAtt'+cid).style.display = "block";
         document.getElementById('HideAtt'+cid).style.display = "none";
		
		}

}
function ShowAttributeResult(baseurl,cid,product_id){
 
	link= baseurl+'attribute_result.php?cid='+cid+'&product_id='+product_id;
	var linkComp = link.split( "?");
	var result;
	var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
		
        
      document.getElementById('resultAttribute'+cid).innerHTML = result;  
	  document.getElementById('resultAttribute'+cid).style.display = "block";
      document.getElementById('showAtt'+cid).style.display = "none";
      document.getElementById('HideAtt'+cid).style.display = "block";
        Shadowbox.deact();
        Shadowbox.init();
		}

	}	
function HideAttributeResult(baseurl,cid,id){
	
	link= baseurl+'attribute_result.php?cid='+cid+'&id='+id;
	var linkComp = link.split( "?");
	var result;
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {

			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('resultAttribute'+cid).innerHTML = result;  
			document.getElementById('resultAttribute'+cid).style.display = "none";
         document.getElementById('showAtt'+cid).style.display = "block";
         document.getElementById('HideAtt'+cid).style.display = "none";
		
		}

}
function ShowContactMessageDetails(baseurl,i){
 	link= baseurl+'contact.php?id='+i ;
	var linkComp = link.split( "?");
		var result;
		
				
		var obj = new ajaxObject(linkComp[0], fin);

		obj.update(linkComp[1],"GET");

		obj.callback = function (responseTxt, responseStat) {
           
			// we'll do something to process the data here.
			result = responseTxt
			
			document.getElementById('messageDetails1').innerHTML = result;  
			document.getElementById('messageDetails1').style.display = "block";
		   
			
		Shadowbox.deact();
        Shadowbox.init();
	  }	  
        
} 
function ShowMonths(year){
	 var obj =  document.getElementById('months'+year);
	 if( obj.style.display != 'none' && obj.style.display != '' ){
			obj.style.display = 'none';
		}else{
			obj.style.display = 'block'
		}
  
  
  
}
function ShowNewsOfMonth(month){
	 var obj =  document.getElementById('news'+month);
	 if( obj.style.display != 'none' && obj.style.display != '' ){
			obj.style.display = 'none';
		}else{
			obj.style.display = 'block'
		}
	
}     
