var xmlHttp
var imageid =0;
var toShow=true;
var radio_options ="";

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 stateChanged() 
{ 
	var tmp;
	if (xmlHttp.readyState==4 && xmlHttp.status==200)
	{ 
		if(xmlHttp.responseText != "")
		{
//			alert(xmlHttp.responseText);
			response = xmlHttp.responseText.split("|");
			/* USED IN MICRO FOR USERNAME VALIDATION*/
			if(response[0] == "username")
			{
				if((response[1] == "No Record") && (document.getElementById("errdiv_user").innerHTML == ""))
				{
					document.getElementById("errdiv_user").innerHTML="";	
				}
				else if(response[1] != "No Record")
				{
					document.getElementById("loginname").value="";
					document.getElementById("errdiv_user").innerHTML=response[1];
					document.getElementById("loginname").focus();
				}
				//document.registration.loginname.focus();
			}	
			/* USED IN MICRO FOR EMAIL VALIDATION*/
			else if(response[0] == "email")
			{
				if(response[1] == "No Record")
				{
					document.getElementById("emailresult").innerHTML="";
				}
				else
				{
				str = response[1];  
				str1 = str + " <br><a href='forgotpass.html'>Forgot Password</a>";
				document.getElementById("email").value="";
				if(toShow== true) {               
					document.getElementById("emailresult").innerHTML=str1;}
				else
					document.getElementById("emailresult").innerHTML=str;
				
				document.getElementById("email").focus();
				
				}
			}
			/* USED IN MICRO FOR KEYWORD COUNT*/
			else if(response[0] == "keywords")
			{
				var total1 = response.length-1;
				for (i=1;i<=12;i++)
					{
						j=i-1;
						textid = "text_"+j+"_"+imageid;
						if(i<=total1)
						document.getElementById(textid).value = response[i];
						else
						document.getElementById(textid).value = "";
					}
				var divid = "showimage_"+imageid;
				var caption = document.getElementById("caption_"+imageid).value;
				var copyright= document.getElementById("copyrightinfo_"+imageid).value;
				
				if((caption != "")	&& (copyright !="") && (total1 >= 3) && (document.getElementById('imagestatus_'+imageid).value != 3))
					document.getElementById(divid).innerHTML = "<img src='images/checkmark.gif' title='Image ready for submission'>";
				else if	(document.getElementById('imagestatus_'+imageid).value == 3)
					document.getElementById(divid).innerHTML = "<img src='images/btn_del.jpg' title='Rejected image'>";
				else
					document.getElementById(divid).innerHTML = "<img src='images/smlicon_edit.gif' title='Image with Incomplete Data'>";
			}
			/* USED IN MICRO FOR IMAGE STATUS*/
			else if(response[0] == "ImageStatus")
			{
				var imagestatusid = "imagestatus_"+imageid;
				document.getElementById(imagestatusid).value = response[1];
				//alert("response returned::"+response[1]);
				//alert("imageststua hidden value::"+document.getElementById(imagestatusid).value);
			}
			/* USED IN CLIENT FOR EMAIL VALIDATION*/
			else if(response[0] == "Email")
			{
				document.getElementById("errdiv").innerHTML= response[1];
				if(response[1] != "")
				{
					document.getElementById("email").value = "";
					document.getElementById("email").focus();
				}
			}
			/* USED IN CLIENT FOR COUPON VALIDATION*/
			else if(response[0] == 'Coupon') {
				
				if(response[1] == 'OK') 
				{					
					vaildCoupon(response[2],response[3]);
				}
				else
				{
					document.getElementById("div_chkcoupon").innerHTML= response[1];
					document.getElementById("txt_coupon").value = "";
					document.getElementById("txt_coupon").focus();
				}
				
			}
			/* USER FOR ACCEPTING LIGHTBOX SHARE AT CLIENT SITE	*/
			else if(response[0] == "lightbox_accept")
			{
				document.getElementById("accept_div_"+response[2]).innerHTML = response[1];
			}	
			/* USED IN MICRO */
			else
			{
				if(document.getElementById("processimage")){
					document.getElementById("processimage").style.display = 'none';
					document.getElementById("imagetext").innerHTML="Files Processed";
					document.getElementById("imagelink").innerHTML = '';
				}
			}
		}
	}
}

function vaildCoupon(code,disc){
	var discount = eval(disc);
	var amount = eval(document.getElementById("amount").value);
	document.getElementById("div_chkcoupon").innerHTML= '&nbsp;';
	document.getElementById("div_coupon_name").innerHTML = '<label for="coupon_name"><strong>'+code+'</strong></label>'
	document.getElementById("btn_coupon_apply").disabled = true;
	document.getElementById("coupon_id").value = code;
	document.getElementById("discount").value = discount;
	document.getElementById("cp_discount_row").style.display="";
	autorenewDiscount = document.getElementById("autordisc").value;
	couponDiscount = discount;
	price = document.getElementById("amount").value;
	cp_discount=eval(price*couponDiscount/100);	
	cp_discount = Math.round(cp_discount*100)/100
	price = eval(price - cp_discount);
	price = Math.round(price*100)/100

	amount=price;
	if(document.getElementById("autorenew") && document.getElementById("autorenew").checked){
		amount = price-(price*autorenewDiscount/100);
		amount = Math.round(amount*100)/100
	}
	tax = eval(document.getElementById('tx').value);
	ntax = (amount*tax/100);
	ntax = Math.round(ntax*100)/100
	amount = (amount+ntax).toFixed(2);
	amount = Math.round(amount*100)/100	
	document.getElementById("cp_discount").innerHTML = "($"+cp_discount+")&nbsp;USD";
	document.getElementById("price").innerHTML = "$"+amount+"&nbsp;USD";	
	document.getElementById("tax").innerHTML="$"+ntax+"&nbsp;USD";
}

function stateChanged2() {
	var tmp;
	if (xmlHttp.readyState==4)
	{ 
		tmp = xmlHttp.responseText;
		document.getElementById("errdiv_user").innerHTML= tmp;		
		if(tmp != "")
		{
			document.getElementById("username").value = "";
			document.getElementById("username").focus();
		}
	}
}


function saveImageStatusInSession(imgid,decision,newValue,action)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 
	var url="saveinsession.php?";
	url=url+"&imgid="+imgid+"&decision="+decision+"&newValue="+newValue+"&action="+action;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function(){
					imageStatusInSession(xmlHttp,imgid); };
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function imageStatusInSession(){
	var tmp;
	if (xmlHttp.readyState==4  && xmlHttp.status==200)
	{ 
		tmp = xmlHttp.responseText;
		//alert(tmp);
	}
}


function watermarkImage(imgid,image_id)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
watermark_position = document.getElementById("hid_cell_" + imgid).value;
var url="index.php?page=watermark";
//var url="/scripts/micro/watermark.php";

// this image_id is 8 digit random number
url=url+"&imgid="+imgid+"&position="+watermark_position+"&update_position=1";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){
	stateChanged_watermark(xmlHttp,imgid); };
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged_watermark(xmlHttp,imgid)
{
	if (xmlHttp.readyState==4)
	{ 
//	document.getElementById("hid_cell_"+imgid).innerHTML = xmlHttp.responseText;
	}
}
function checkUser(str)
{ 
if(trim(str)=="")
{
	return true;
}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="chkemail.php";
url=url+"?str="+str+"&flag=1";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function chkCoupon(coupon)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	 coupon_detail = coupon.split("|");
	var url="chkcoupon.php";
	url=url+"?coupon_no="+coupon_detail[0]+"&user_action="+coupon_detail[1];
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function(){
		stateChanged();};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function acceptLightboxShare(share_id)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	// share_id is primary key of shared_lightboxes table
	var url="accept_lightbox.php";
	url=url+"?share_id="+share_id;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function checkEmail(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="chkemail.php";
url=url+"?str="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

/* ADDED 29-APR-2008 USED IN MICRO SITE*/
//function to check duplicate user name
function checkuser(tempuname,olduname)
{
	
	if (tempuname.length==0)
  	{ 
  		//document.getElementById("errdiv_user").innerHTML="Please specify username";
  		return;
  	}
  	if(tempuname == olduname)
  	{
  		//document.getElementById("checkresult").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="chkuname.php";
	var params = "uname="+ tempuname;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}
//functon to fill keywords into text boxes instead of refreshing the entire div
function fillKeywords(imgid)
{
	imageid = imgid;
	xmlHttp=GetXmlHttpObject();
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="save_edit.php";
	var params = "action=fillkeywords&imgid="+imgid;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}
//function to fill the latest status of image to hidden field so that it can be further used correctly.
function getImageStatus(imgid)
{
	imageid = imgid;
	xmlHttp=GetXmlHttpObject();
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="save_edit.php";
	var params = "action=getImageStatus&imgid="+imgid;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}
//function to check duplicate email id
function check_email(tempemail,oldemail,showfpass)
{
	if (tempemail.length==0)
  	{ 
  		return;
  	}
  	if(tempemail == oldemail)
  	{
  		document.getElementById("emailresult").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	toShow = showfpass;
	var url="chkemail.php";
	var params = "email="+ tempemail;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}
// Count number of images in FTP folder
function displaycount()
{
xmlHttp1=GetXmlHttpObject();
if (xmlHttp1==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url = "imagecount.php?dummy=" + Math.random();
	//var params = "page=imagecount";
	xmlHttp1.onreadystatechange=stateChanged;
	xmlHttp1.open("GET",url,true);
	//xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//xmlHttp.setRequestHeader("Content-length", params.length);
	//xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp1.send(null);
}
//Function to process FTP files
function ftpprocess()
{
	xmlHttp=GetXmlHttpObject()
	//displaycount();
	document.getElementById("processimage").style.display = 'block';
	document.getElementById("imagetext").style.display = 'block';
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="index.php";
	var params = "page=ftpcopy";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}
//Function to search mr and vector on the basis of keyword
function searchresult(searchstr,divid,uname,imgname,acttyp,errorMsg,offset,searchtype)
{
	var errorMsgArr = errorMsg.split("|");

  	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="searchprocess.php?actiontyp=" + acttyp + "&searchstr="+ searchstr + "&searchtype="+ searchtype + "&offset="+ offset + "&dummy=" + Math.random();
	xmlHttp.onreadystatechange=function(){
displayresult(xmlHttp,divid,uname,imgname,acttyp,errorMsg,offset,searchstr)
};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//Display Search Ressult
function displayresult(xmlHttp,divid,uname,imgname,acttyp,errorMsg,offset,searchstr)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		var errorMsgArr = errorMsg.split("|");		
		var responsestr = "<table border='0' width='100%' align='center'>";
		var response = eval('(' + xmlHttp.responseText + ')');
		
		var arrlength = response.images.length;
		var j = 1;
		var pagingtext = "";
		var selpage;
		
		if(arrlength>0)
		{
			responsestr = responsestr + "<tr><td colspan='4'><b>" + errorMsgArr[1] + "</b></td><td align='right'><img src='images/micro/close.gif' onclick='javascript:document.getElementById(\"searchresult\").style.display=\"none\";' style='cursor:pointer;' /></td</tr><tr class='orange_bg'><th>" + errorMsgArr[3] + "</th><th>" + errorMsgArr[4] + "</th><th colspan='3'>Release</th></tr>";
			if(acttyp == 'mr')
			{
				for (var i=0;i<arrlength;i++)
				{
					var filepath = "repository/"+ uname + "/releases/prev/" + response.images[i].mrname_preview;
					var href_file_path = "repository/"+ uname + "/releases/" + response.images[i].mrname;
					var imgext = response.images[i].mrname.split(".");
					if(imgext.length >1 && imgext[imgext.length-1].toLowerCase()=='pdf')
					{
						var onclickstr = "";
					}
					else
					{
						var onclickstr = "showLightbox(this,''); return false;";
					}
					
				
					
					checkboxstr ="<td><a  href='" + href_file_path + "' onmouseover = \"doTooltip(event,'" + filepath + "','')\" target='_blank'  onclick =\"" + onclickstr + "\" onmouseout=\"hideTip()\">" + response.images[i].originalname + "</a></td><td align='left'>" + response.images[i].caption + "</td>";
					checkboxstr = checkboxstr + "<td><input type='checkbox' name='chk_m"+j+"' value='" + response.images[i].id + "|" + response.images[i].caption + "|" + response.images[i].originalname + "|0' id='chk_m"+j+"'>"+errorMsgArr[5]+"</td>";
					checkboxstr = checkboxstr + "<td><input type='checkbox' name='chk_p"+j+"' value='" + response.images[i].id + "|" + response.images[i].caption + "|" + response.images[i].originalname + "|1' id='chk_p"+j+"' >"+errorMsgArr[6]+"</td>";
					checkboxstr = checkboxstr + "<td><input type='checkbox' name='chk_a"+j+"' value='" + response.images[i].id + "|" + response.images[i].caption + "|" + response.images[i].originalname + "|2' id='chk_a"+j+"' >"+errorMsgArr[7]+"</td></tr>";
					if(j%2)
					{
						responsestr = responsestr + "<tr class='data_a'>" + checkboxstr; 
					}
					else
					{
						responsestr = responsestr + "<tr>" + checkboxstr; 		
					}
					j++;
				}
				selpage = offset/response.pagesize + 1;
				//alert(selpage);
				for(var tp=0;tp<response.pagestr;tp++)
				{
					var classtype;
					text=tp+1;
					if(text == selpage)
					{
						classtype = 'selected';
					}
					else
					{
						classtype = '';
					}
					pagingtext = pagingtext +  "<a class = '" + classtype + "' onclick= 'searchresult(\"" + searchstr + "\",\"" + divid + "\",\"" + uname + "\",\"" + imgname + "\",\"" + acttyp + "\",\"" + errorMsg + "\",\"" + tp * response.pagesize + "\",4)' style='cursor:pointer'>" + text + "</a> | ";
				}
				responsestr = responsestr + " <tr><td colspan = '2'>" + pagingtext +"</td><td align='right' colspan='3'><table width='0' border='0' cellspacing='' cellpadding='0' aliagn='center'><tr><td align='center'><div class='button_b'><div class='b_left'></div><input name='btn_del' class='b_middle' type='button' value = '"+option[0]+"' onclick='attachmr(" + j + "," + divid + ");'></div></td>"; 
				
				
			}
			else if(acttyp == 'vector')
			{
				for (var i=0;i<arrlength;i++)
				{
					filepath = "repository/"+ uname + "/vectorimages/" + response.images[i].vectorname;
					radiostr = "<td><input type='radio' class='radiobtn' value='" + response.images[i].id + "|" + response.images[i].vectorname + "' id='vector_" + j + divid + "' name='vector_" + divid + "'></td><td><a  href='" + filepath + "' onclick =\"showLightbox(this,''); return false;\" onmouseover = \"doTooltip(event,'" + filepath + "','')\" target='_blank' onmouseout=\"hideTip()\">" + response.images[i].originalname + "</a></td><td>" + response.images[i].caption + "</td>";
					if(j%2)
					{
						responsestr = responsestr + "<tr class='oddrow'>" + radiostr; 
					}
					else
					{
						responsestr = responsestr + "<tr class='evenrow'>" + radiostr; 		
					}
					j++;
				}
				selpage = offset/response.pagesize + 1;
				for(var tp=0;tp<response.pagestr;tp++)
				{
					var classtype;
					text=tp+1;
					if(text == selpage)
					{
						classtype = 'selected';
					}
					else
					{
						classtype = '';
					}
				
				pagingtext = pagingtext +  "<a class = '" + classtype + "' onclick= 'searchresult(\"" + searchstr + "\",\"" + divid + "\",\"" + uname + "\",\"" + imgname + "\",\"" + acttyp + "\",\"" + errorMsg + "\",\"" + tp * response.pagesize + "\")' style='cursor:pointer'>" + text + "</a>|";
				}
				responsestr = responsestr + " <tr><td colspan = '2'>" + pagingtext +"</td><td align='right' colspan='3'><table width='0' border='0' cellspacing='' cellpadding='0' aliagn='center'><tr><td align='center'><div class='button_b'><div class='b_left'></div><input name='btn_del' class='b_middle' type='button' value = '"+option[0]+"' onclick='attachvector(" + divid + ",\"" + imgname + "\");'></div></td></tr></table>";
			}
		}
		else
		{
			responsestr = responsestr + "<tr><td class='error' align='center'>"+errorMsgArr[2];
		}
		//window.parent.document.getElementById('searchresult').style.display = 'block';
		document.getElementById('searchresult').style.display = 'block';
		staticbar();
		responsestr = responsestr + "&nbsp;&nbsp;&nbsp;&nbsp;<td align='center'><div class='button_b'><div class='b_left'></div><input type = 'button' class='b_middle' value = '"+option[1]+"' onclick='javascript:document.getElementById(\"searchresult\").style.display=\"none\";'></div></td></tr></table></td></tr></table>";
		//window.parent.document.getElementById('searchresult').innerHTML = responsestr;		
		document.getElementById('searchresult').innerHTML = responsestr;
	}
}

function attachMrWrapper(counter , imgid , isManage ) {				
	var hidden_images_ids = "";
	var hidden_images_length = "";
	if(isManage != "1" && isManage == ""){
		for(i=0;i<=2;i++)
		{
			if(document.form1.attach_option[i].checked==true)
				radio_options = document.form1.attach_option[i].value;
		}
	}
	if(radio_options == "1" || isManage == "1"){			
		attachmr( counter , imgid , isManage );
	}
	if(radio_options == "2") {		
		hidden_images_ids = window.parent.document.getElementById("hidden_images_ids").value;
		array_images_ids = hidden_images_ids.split("-");
		hidden_images_length = array_images_ids.length;
		for(var j=1;j<=hidden_images_length-1;j++){
			imgid = array_images_ids[j];
			attachmr( counter , imgid ); 
		} 
	}
	if(radio_options == "3"){
		var lastId="0";
		hidden_images_ids = window.parent.document.getElementById("hidden_images_ids").value;
		array_images_ids = hidden_images_ids.split("-");
		hidden_images_length = array_images_ids.length;
		for(var j=1;j<=hidden_images_length-1;j++){
			imgid = array_images_ids[j];
			
			if(j==hidden_images_length-1)
			{
				lastId="1";
			}
			attachmr( counter , imgid, '',lastId); 
		}					
	}
}

//function to attach mr to jpg image
function attachmr(counter,imgid)
{
	xmlHttp=GetXmlHttpObject();
	var mridstr = "";
	var tempcount = 0;
	if(counter<1)
		return;
	
	var mrnamestr = "";
	var mrtypestr = "";
	
	var errorstr = "&nbsp;";
	var propertyidmatch = 0;
	var propertymatchname = "";
	var artworkidmatch = 0;
	
	var modelidmatch = 0;
	var modelmatchname = "";
	var p_chkvalue = new Array();
	var m_chkvalue = new Array();	
	var a_chkvalue = new Array();	
		
	var listlength_property = document.getElementById('property_' + imgid).length;
	var listlength_model = document.getElementById('model_' + imgid).length;	
	var listlength_artwork = document.getElementById('artwork_' + imgid).length;	
	
	var modelInnerHtml = document.getElementById('model_' + imgid).innerHTML;
	var propertyInnerHtml = document.getElementById('property_' + imgid).innerHTML;
	var artworkInnerHtml = document.getElementById('artwork_' + imgid).innerHTML;
	for(var i=1;i<counter;i++)
	{
		var idmatch = false;
				
		if((document.getElementById("chk_p" + i).checked) || (document.getElementById("chk_m" + i).checked) || (document.getElementById("chk_a" + i).checked))
		{
			if(document.getElementById("chk_p" + i).checked == true)
			{
				p_chkvalue = document.getElementById("chk_p" + i).value.split("|");
				propertyidmatch = 0;

				if(propertyInnerHtml.indexOf(imgid+ "_"+p_chkvalue[0])>-1 &&  (p_chkvalue[3] == 1)){
				
					var list = document.getElementById('property_'+imgid);
					var count = list.getElementsByTagName("li").length;
					for(i=0;i<count;i++){
					
						if(list.getElementsByTagName("li")[i].style.display!="none" && list.getElementsByTagName("li")[i].id==imgid+"_"+p_chkvalue[0]){						
							propertyidmatch = 1;
							propertymatchname = p_chkvalue[2];
						}
					}		
				}

				if(!propertyidmatch==1)
				{
					propertyInnerHtml = propertyInnerHtml + '<li id="' + imgid + '_' +  p_chkvalue[0] + '" name="' + imgid + '_' +  p_chkvalue[0] + '"><a href="#" title="Click to remove" onclick="deletemr(' + imgid + ',1,' + p_chkvalue[0] + ');return false;">' +  p_chkvalue[1] + '</a></li>';
					mridstr = mridstr + p_chkvalue[0] + ", ";
					mrtypestr = mrtypestr + p_chkvalue[3]  + ", ";
					mrnamestr = mrnamestr + p_chkvalue[1] + ", ";
				}
			}

try{			
			if(document.getElementById("chk_m" + i).checked == true)
			{
				m_chkvalue = document.getElementById("chk_m" + i).value.split("|");
				modelidmatch = 0;
				if(modelInnerHtml.indexOf(imgid+ "_"+m_chkvalue[0])>-1 &&  (m_chkvalue[3] == 0)){
					var list = document.getElementById('model_'+imgid);
					var count = list.getElementsByTagName("li").length;
					for(i=0;i<count;i++){
						if(list.getElementsByTagName("li")[i].style.display!="none" && list.getElementsByTagName("li")[i].id==imgid+"_"+m_chkvalue[0]){
						
							modelidmatch = 1;
							modelmatchname = m_chkvalue[2];
						}
					}		
				}

				if(!modelidmatch==1)
				{
					modelInnerHtml = modelInnerHtml + '<li id="' + imgid + '_' +  m_chkvalue[0] + '" name="' + imgid + '_' +  m_chkvalue[0] + '"><a href="#" title="Click to remove" onclick="deletemr(' + imgid + ',0,' + m_chkvalue[0] + ');return false;">' +  m_chkvalue[1] + '</a></li>';
					mridstr = mridstr + m_chkvalue[0] + ", ";
					mrtypestr = mrtypestr + m_chkvalue[3]  + ", ";
					mrnamestr = mrnamestr + m_chkvalue[1] + ", ";
				}
			}
			}catch(e){}


			try{			
			if(document.getElementById("chk_a" + i).checked == true)
			{
				a_chkvalue = document.getElementById("chk_a" + i).value.split("|");
				artworkidmatch = 0;
				if(artworkInnerHtml.indexOf(imgid+ "_"+a_chkvalue[0])>-1 &&  (a_chkvalue[3] == 0)){
					var list = document.getElementById('artwork_'+imgid);
					var count = list.getElementsByTagName("li").length;
					for(i=0;i<count;i++){
						if(list.getElementsByTagName("li")[i].style.display!="none" && list.getElementsByTagName("li")[i].id==imgid+"_"+a_chkvalue[0]){
						
							artworkidmatch = 1;
							artworkmatchname = a_chkvalue[2];
						}
					}		
				}

				if(!artworkidmatch==1)
				{
					artworkInnerHtml = artworkInnerHtml + '<li id="' + imgid + '_' +  a_chkvalue[0] + '" name="' + imgid + '_' +  a_chkvalue[0] + '"><a href="#" title="Click to remove" onclick="deletemr(' + imgid + ',2,' + a_chkvalue[0] + ');return false;">' +  a_chkvalue[1] + '</a></li>';
					mridstr = mridstr + a_chkvalue[0] + ", ";
					mrtypestr = mrtypestr + a_chkvalue[3]  + ", ";
					mrnamestr = mrnamestr + a_chkvalue[1] + ", ";
				}
			}
			}catch(e){}
		}
	}
	document.getElementById('model_' + imgid).innerHTML=modelInnerHtml;
	document.getElementById('property_' + imgid).innerHTML=propertyInnerHtml;
	document.getElementById('artwork_' + imgid).innerHTML=artworkInnerHtml;

	// if attacjed files matches
	/*
	if (mridstr.length==0)
  	{ */

		if(propertyidmatch == 1)
		{
			errorstr = errorstr + " File(s) already attached as property release";
		}
		
		if(modelidmatch == 1)
		{
			errorstr = errorstr+ " File(s) already attached as model release";
		}

		if(artworkidmatch == 1)
		{
			errorstr = errorstr+ " File(s) already attached as artwork";
		}

		document.getElementById('response_' + imgid).innerHTML = errorstr; 
		document.getElementById('searchresult').style.display = 'none';
	
	if (mridstr.length != 0)
	{		
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url="processmr.php?actiontyp=attach&mridstr="+ mridstr + "&mrtypestr=" + mrtypestr + "&imgid=" + imgid + "&dummy=" + Math.random();		
		xmlHttp.onreadystatechange=function(){
		showattachmr(xmlHttp,mridstr,imgid,mrnamestr,mrtypestr)
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}
//function to attach vector to jpg file
function attachvector(imgid,imgname)
{
	xmlHttp=GetXmlHttpObject();
	var vectorid = "";
	var vectorname = "";
	//document.getElementById('addedmr_' + imgid).length++;
	for(i=0;i<document.getElementsByName("vector_" + imgid).length;i++)
	{
		if(document.getElementsByName("vector_" + imgid)[i].checked)
		{
			chkvalue = document.getElementsByName("vector_" + imgid)[i].value.split("|");
			vectorid = chkvalue[0];
			vectorname = chkvalue[1];	
			
		}
	}
	if (vectorid.length==0)
  	{ 
		return;
  	}
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="processvector.php?actiontyp=attach&vectorid="+ vectorid + "&imgid=" + imgid + "&vectorname=" + vectorname + "&imgname=" + imgname + "&dummy=" + Math.random();
	xmlHttp.onreadystatechange=function(){
	showattachvector(xmlHttp,imgid)
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//Show attached mr in the listbox
function showattachmr(xmlHttp,mridstr,imgid,mrnamestr,mrtypestr)
{
	var propertyExist =0;
	var modelExist =0;	
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		mrnamearr= mrnamestr.split(",");
		mridarr = mridstr.split(",");
		mrtypearr = mrtypestr.split(","); 
		
		document.getElementById('response_' + imgid).innerHTML = xmlHttp.responseText;
		
		arrlen = mrnamearr.length;
		for(i=0;i<arrlen-1;i++)
		{
			if(trim(mrnamearr[i]) !="")
			{
				if(trim(mrtypearr[i]) == 1) // for property release
				{
					templen = document.getElementById('property_' + imgid).length;
					document.getElementById('property_' + imgid).length++;
					propertyExist = 1; 
				}
				else if(trim(mrtypearr[i]) == 0) // for model release
				{
					templen = document.getElementById('model_' + imgid).length;
					document.getElementById('model_' + imgid).length++;
					modelExist = 1;
				}
				else if(trim(mrtypearr[i]) == 2) // for artwork
				{
					templen = document.getElementById('artwork_' + imgid).length;
					document.getElementById('artwork_' + imgid).length++;
					artworkExist = 1;
				}
					
			}
		}
	}
}
//Show attached vector image
function showattachvector(xmlHttp,imgid)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		if(xmlHttp.responseText == "")
		{
			window.parent.document.getElementById('response_' + imgid).innerHTML = "Vector already attached.";
			document.getElementById('searchresult').style.display = 'none';
		}
		else
		{
			response = xmlHttp.responseText.split("|");
			window.parent.document.getElementById('response_' + imgid).innerHTML = "File attached successfully.";
			document.getElementById('searchresult').style.display = 'none';
			window.parent.document.getElementById('vectorimage_' + imgid).innerHTML = response[0];
			
			
		}
	}
}
//Delete attached mr file
function deletemr(imgid,releaseType,id)
{
	
	xmlHttp=GetXmlHttpObject();
	mridstr ="";
	var errorstr ="";
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
  	
	var url="processmr.php?actiontyp=delete&mridstr="+ id + "&imgid=" + imgid + "&mrtype="+releaseType+"&dummy=" + Math.random();
	xmlHttp.onreadystatechange=function(){
	removedeletedmr(xmlHttp,mridstr,imgid,releaseType,id)
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//Remove delete mr from the listbox
function removedeletedmr(xmlHttp,mridstr,imgid,releaseType,id)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		mridarr = mridstr.split(",");
		document.getElementById('response_' + imgid).innerHTML = xmlHttp.responseText;
		arrlen = mridarr.length;
		//alert(document.getElementsByName(imgid+"_"+id).length);
		
		var list;
		if(releaseType=='0'){
			list = document.getElementById('model_'+imgid);
		}else if(releaseType=='1'){
			list = document.getElementById('property_'+imgid);
		}else if(releaseType=='2'){
			list = document.getElementById('artwork_'+imgid);
		}
		
		var count = list.getElementsByTagName("li").length;
		for(i=0;i<count;i++){
			if(list.getElementsByTagName("li")[i].id==imgid+"_"+id){
				list.getElementsByTagName("li")[i].style.display="none";
			}
		}		
	}
}

//Display attached vector image
function displayimage(imgpath,imgid,imagename)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="processvector.php?actiontyp=display&imgpath=" + imgpath + "&imgid=" + imgid +  "&imagename=" + imagename + "&dummy=" + Math.random();
	xmlHttp.onreadystatechange=function(){
	displayresponse(xmlHttp,imgid)
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function displayresponse(xmlHttp,imgid)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		response = xmlHttp.responseText.split("|");
		window.parent.document.getElementById('response_' + imgid).innerHTML = response[0];
	}
}
//Delete attached vector
function deletevector(imgid,imgname)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="processvector.php?actiontyp=delete&imgid=" + imgid + "&imgname=" + imgname + "&dummy=" + Math.random();
	xmlHttp.onreadystatechange=function(){
	displayresponse(xmlHttp,imgid)
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
//function to display search result in image reclassification
function manage(username,optyp,offset) {
	if(!reclassify_validate(mess,optyp)) {
		document.getElementById('file_error1').innerHTML=''
		return;
	} else {
		document.getElementById('file_error1').innerHTML=''
		document.getElementById('file_error').style.display = 'none';
		var filetype=document.getElementById('filetype').value;
		var order_by = document.getElementById('order_by').value;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
  			alert ("Your browser does not support AJAX!");
  			return;
  		}
		//filename1=trim(document.getElementById('filename').value);
		var params = "filetype=" + filetype + "&order_by=" + order_by + "&optyp=" + optyp +"&offset=" + offset + "&dummy=" + Math.random() + "&username=" + username;
		var url="reclassifysearch.php?" + params;
		xmlHttp.onreadystatechange=function()
		{
			displaysearchresult(xmlHttp,filetype,username,filetype,offset)
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}
function reclassify_validate(errorMsg,optyp)
{
	var action = true;
	var errorMsgArr = errorMsg.split("|");
	var fname = document.getElementById('filetype');
	if(fname.value == 0)
	{
		document.getElementById('file_error').style.display = 'block';
		document.getElementById('searchresult').style.display = 'none';
		document.getElementById('file_error').innerHTML=errorMsgArr[4];
		action=false;
	}
	/*
	else if(fname.value == 4 && optyp==1)
	{
		document.getElementById('file_error').style.display = 'block';
		document.getElementById('searchresult').style.display = 'none';
		document.getElementById('file_error').innerHTML=errorMsgArr[3];
		action=false;
	}*/
	return action;	
}
function displaysearchresult(xmlHttp,filetype,username,optyp,offset) {
	var errorMsg = mess;
	var errorMsgArr = errorMsg.split("|");
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200)) {
		var j = 1;		
		var response = eval('(' + xmlHttp.responseText + ')');
		var arrlength = response.images.length;
		var selpage;
		var filetypetext;
		var onclickstr;
		var mouseoverstr;
		var checkboxstr;
		var pagingcount;
		var pagingtext;
		/*
			Overwrites the values if this function is called from Load page function of Ajaxtabs.js
		*/
		filetype = (response.filetype == ""?filetype:response.filetype);
		username = (response.username == ""?username:response.username);

		//setTimeout('',1250);
		if(arrlength ==0) {
			if(response.pagestr>0){
				manage(username,optyp,response.pagestr);
			}
			else{
			document.getElementById('searchresult').style.display = 'none';
			document.getElementById('file_error1').style.display = 'block';
			document.getElementById('file_error1').innerHTML=errorMsgArr[5];
			}
		} else {			
			document.getElementById('searchresult').style.display = 'block';
			document.getElementById('file_error').style.display = 'none';
			//document.getElementById('reclassifysummary').style.display = 'none';
			
			for(i=0;i<document.getElementById('filetype').length;i++) {
				if(document.getElementById('filetype').options[i].selected == true) {
					filetypetext = document.getElementById('filetype').options[i].text;
				}
			}

			var reclassStr = '<option value="0" selected="selected" >'+ errorMsgArr[11] + '</option>';
			if(filetypetext != errorMsgArr[12])
				reclassStr = reclassStr + '<option value="1">'+ errorMsgArr[12] + '</option>';
			if(filetypetext != errorMsgArr[13])
				reclassStr = reclassStr + '<option value="2">'+ errorMsgArr[13] + '</option>';
			if(filetypetext != errorMsgArr[14])
				reclassStr = reclassStr + '<option value="3">'+ errorMsgArr[14] +'</option>';
			reclassStr = reclassStr + '</select>';

			var responsestr = "<table width='100%' border='0'>";
			if(filetype ==1) {
				filepath = "repository/" + username + "/preview/";
			} else if(filetype ==2) {
				filepath = "repository/" + username + "/releases/prev/";
			} else if(filetype ==3) {
				filepath = "repository/" + username + "/preview/";
			} else if(filetype ==4) {
				filepath = "repository/" + username + "/eps/preview/";
			}
			/*
			else if(filetype ==4)
			{
				filepath = "repository/" + username + "/vectorimages/";
			}*/
			for(i=0;i<arrlength;i++)
			{
				//check for pdf file
				if(filetype == 2)
				{
					var imgext = response.images[i].imagename.split(".");
					var filepath1 = filepath + response.images[i].imagename;	
					mouseoverstr = "trailOn('" + filepath1 + "','','','123453','','credit','1',"+response.images[i].width+","+response.images[i].height+",2)";
					//alert("str1::"+mouseoverstr);
					
					if(imgext.length >1 && imgext[imgext.length-1].toLowerCase()=='pdf') 					{
						onclickstr = "window.open('"+filepath1+"');";
						
					} else {
						onclickstr = "showLightbox(this,'',''); return false;";
					}
					
				} else if(filetype == 4) {
					//alert("str2::"+response.images[i].width);
					onclickstr = "showLightbox(this,'',''," + response.images[i].imagename + "," +response.images[i].id + "," + response.images[i].watermark_location + "); return false;";
					
					var filepath1 = filepath + response.images[i].imagename + "_mp.jpg";
					
					mouseoverstr = "trailOn('" + filepath1 + "','','',"+response.images[i].id+",'','credit','1',"+response.images[i].width+","+response.images[i].height+",1)";
				}
				else {
					//alert("str3::"+response.images[i].width);
					onclickstr = "showLightbox(this,'',''," + response.images[i].imagename + "," +response.images[i].id + "," + response.images[i].watermark_location + "); return false;";
					
					var filepath1 = filepath + response.images[i].imagename + "_p.jpg";
					
					mouseoverstr = "trailOn('" + filepath1 + "','','',"+response.images[i].id+",'','credit','1',"+response.images[i].width+","+response.images[i].height+",1)";
				}
				
				checkboxstr = "<td colspan='2' width='40%' style='text-align:left'><span style='width:150px;float:left'><a  href='" + filepath1 + "' onclick = \"" + onclickstr +"\" onmouseover = \""+ mouseoverstr +"\" target='_blank' onmouseout=\"trailOff()\">" + response.images[i].originalname + "</a></span>";
				if(filetype != '4'){
				checkboxstr = checkboxstr + "<span style='width:75px;float:left;text-align:right;'><select name='raction' id='raction_"+ response.images[i].id +"' onchange='rprocess(this,\"chk_"+ response.images[i].id +"\","+offset+");' initValue='0' >" + reclassStr+"</span>";
				}
				checkboxstr = checkboxstr + "</td>";
				
				if(filetype != '4'){
				checkboxstr = checkboxstr + "<td colspan='2' width='40%'><div id ='caption" + j +"'>";
				checkboxstr = checkboxstr + "<input type='text' stype='width:150px;' id='txt"+response.images[i].id +"' value='" + response.images[i].caption + "' onblur=\"editprocess('" + response.images[i].id + "','" + filetype + "');\" onkeypress=\"callEditProcess('" + response.images[i].id + "','" + filetype + "',event)\"  /></div></td>";
				}else{
					checkboxstr = checkboxstr + "<td colspan='2' width='50%'>&nbsp;</td>";
				}
					checkboxstr = checkboxstr + "<td align='center' align=right><table width='0' border='0' cellspacing='0' cellpadding='0' align=''><tr><td align='center'><div class='button_b'><div class='b_left'></div><input name='btn_del' class='b_middle' type='button' value = 'Delete' onclick=\"deleteimage('"+response.images[i].id +"','"+filetype+"','"+username+"','" + optyp +"','"+response.images[i].originalname+"');\"></div></td></tr></table>";	
						
					
			//	checkboxstr = checkboxstr + "<a  href='#'  title='Delete' style='cursor:pointer' onclick=\"deleteimage('"+response.images[i].id +"','"+filetype+"','"+username+"','" + optyp +"','"+response.images[i].originalname+"');\"><img src='images/micro/delete_caption.jpg' /></a>";		
				
				
				checkboxstr = checkboxstr + "<input type='hidden' value='" + response.images[i].id + "|" + response.images[i].imagename + "|" + response.images[i].originalname + "' id='chk_" + response.images[i].id + "'></td>";
				// check for operation to be performed -- this if for reclassify
				if(j%2)
				{
					responsestr = responsestr + " <tr class = 'data_a'>" + checkboxstr + "</tr>"; 
				}
				else 
				{
					responsestr = responsestr + "<tr class = ''>" + checkboxstr +  "</tr>"; 		
				}
				
				j++;
			}
		}
		selpage = offset/response.pagesize + 1;
		pagingcount = response.recordcount + " " +"images,"
		pagingtext = pagingcount + response.pagenationtext;
		responsestr = responsestr + "<tr><td colspan='5' align='center'><table border=0 width='90%'><tr><td class='footerCenter' align='center' style='color:#000000'>" + pagingtext + "</td></tr></table></td></tr>";
		responsestr = responsestr + "</table>";
		document.getElementById('searchresult').innerHTML = responsestr;
	}
}
//Function to reclassify images
function reclassificationprocess(divid,reclassifiedto,username,optyp,offset)
{
	errorMsg = mess;
	var errorMsgArr = errorMsg.split("|");
	fileidstr = "";
	filenamestr = "";
	fileoriginalnamestr = "";
	var flag = true;
	reclassifiedfrom = document.getElementById('filetype').value;
	if(reclassifiedto == reclassifiedfrom)
	{
		document.getElementById('file_error').style.display = 'block';
		document.getElementById('file_error').innerHTML=errorMsgArr[7];
		return;
	}
	else if(reclassifiedto==0)
	{
		document.getElementById('file_error').style.display = 'block';
		document.getElementById('file_error').innerHTML=errorMsgArr[8];
		return;
	}
	else
	{
		var chkbox = document.getElementById(divid).value;
		tempstr = chkbox.split("|");
		fileidstr = fileidstr + tempstr[0] + ",";
				/*
				For Releases -- filenamestr contain string for release name
				For photograph & illustration -- filenamestr contain string for 8 digit random number
				*/
		filenamestr = filenamestr + tempstr[1] + ","
		fileoriginalnamestr = fileoriginalnamestr + tempstr[2] + ",";  
		document.getElementById('file_error').style.display = 'none';
		
		setTimeout('document.getElementById("reclassifysummary").style.display = "block"',250);
		document.getElementById('reclassifysummary').innerHTML  = "<img src='images/micro/reclassify.gif'>";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
  		{
  			alert ("Your browser does not support AJAX!");
  			return;
  		} 
		var url="reclassificationprocess.php";
		var params = "reclassifiedto=" + reclassifiedto + "&reclassifiedfrom=" + reclassifiedfrom + "&fileidstr=" + fileidstr + "&filenamestr=" +  filenamestr + "&fileoriginalnamestr=" + fileoriginalnamestr;
		
		xmlHttp.onreadystatechange=function()
		{
			reclassificationresponse(xmlHttp,username,optyp,errorMsg,offset)
		};
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);	
	}
}
function reclassificationresponse(xmlHttp,username,optyp,errorMsg,offset)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		document.getElementById('reclassifysummary').style.display = 'block';
		//document.getElementById('file_error').style.display = 'none';
		document.getElementById('reclassifysummary').innerHTML = xmlHttp.responseText;
		manage(username,optyp,offset);
	}
}
//Function to change the color of selected column
function changebgcolor(tblid,tottbl)
{
	for(i=1;i<=tottbl;i++)
	{
		var frmobj = window.frames['imgfrm_' + i];
		if(i != tblid)
		{
			document.getElementById('imgtbl_' + i).bgColor = "#FFFFFF";
			if(frmobj)
			{
				frmobj.document.body.className = "";
				frmobj.document.getElementById('frmtbl').bgColor = "#FFFFFF";
			}
		}
		else
		{
			document.getElementById('imgtbl_' + i).bgColor = "#EEEEEE";
			if(frmobj)
			{
				frmobj.document.body.className = "selected";
				frmobj.document.getElementById('frmtbl').bgColor = "#EEEEEE";
			}
		}
	}
}
function callEditProcess(imgid,filetype,e)
{

	if(window.event)				//For IE
	{
		keycode = window.event.keyCode;
	}
	else							// For Mozilla
	{
		keycode = e.which;
	}

	if(keycode == 13)
	{
	    editprocess(imgid,filetype);
	}
}
//function edit caption
function editcaption(imgid,rowid,filetype)
{
	var oldtxt = document.getElementById('txt' + rowid);
	var newtxt = document.createElement('INPUT');
	newtxt.type = 'text';
	newtxt.id = 'txt' + rowid;
	newtxt.name = 'txt' + rowid;
	newtxt.value = document.getElementById('caption' + rowid).innerHTML;
	if(oldtxt)
	{
		document.getElementById('caption' + rowid).removeChild(newtxt);
	}
		document.getElementById('caption' + rowid).innerHTML = '';
		document.getElementById('caption' + rowid).appendChild(newtxt);
		newtxt.focus();
		//Edited By Rajat to pass KeyCode in on the Fly function
		newtxt.onkeypress = function(e)
		{
			if(window.event)				//For IE
			{
				callEditProcess(window.event.keyCode,imgid,rowid,filetype,errorMsg);
			}
			else							// For Mozilla
			{
				callEditProcess(e.which,imgid,rowid,filetype,errorMsg);
			}
		}
		newtxt.onblur= function()
		{
			editprocess(imgid,rowid,filetype,errorMsg);
		}
}
function editprocess(imgid,filetype)
{
	var errorMsgArr = mess.split("|");
	var captiontxt = document.getElementById('txt' + imgid); 
	var captionstr = captiontxt.value;
	if(trim(captionstr) == '')
	{
		captiontxt.focus();
		document.getElementById('file_error').style.display='block';
		document.getElementById('file_error').innerHTML=errorMsgArr[6];
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="manageprocess.php";
	var params = "imageid=" + imgid + "&captionstring=" + captionstr + "&actiontype=edit" + "&filetype=" + filetype + "&dummy=" + Math.random();
	xmlHttp.onreadystatechange=function()
	{
		manageresponse(xmlHttp,imgid)
	};
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);	
}
function manageresponse(xmlHttp,rowid)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		document.getElementById('file_error').style.display='none';
		var captiontxt = document.getElementById('txt' + rowid);
		if(xmlHttp.responseText == "Edit successful")
		{
			//do nothing
		}
		else
		{
			captiontxt.focus();
		}
	}
}
function deleteimage(imgid,filetype,username,optyp,imgname)
{
	var params="";
	var answer = confirm('Are you sure want to delete?','aa');
	if(answer)
	{
		document.getElementById("waiting_image").style.display = "";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
  		{
  			alert ("Your browser does not support AJAX!");
  			return;
  		} 
		
		if(filetype == '4') //for vector images
		{
			var url="save_edit.php";
			var params = "imgid=" + imgid + "&action=delete_vector" + "&dummy=" + Math.random();
		}
		else if(filetype ==1 || filetype==3) //for images and illustrations images
		{
			var url="save_edit.php";
			var params = "imgid=" + imgid + "&action=deleteimage" + "&dummy=" + Math.random();

		}
		else 		//for deleting releases
		{
			var url="manageprocess.php";
			var params = "imageid=" + imgid + "&actiontype=delete" + "&filetype=" + filetype + "&imagename=" + imgname + "&dummy=" + Math.random();

		}
		xmlHttp.onreadystatechange=function()
	{
		deleteresponse(xmlHttp,username,optyp)
	};
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);	
	}
	else
	{
		return;
	}
}
function deleteresponse(xmlHttp,username,optyp)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		if(xmlHttp.responseText == "image deleted")
		{
			document.getElementById("waiting_image").style.display = "none";			
			manage(username,optyp,0);
		}
	}
}
/*END :: USED IN MICRO SITE*/

/* This function is used to unset the session the values which are set during download & add to lightbox fail*/ 

function unsetSession()
{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
  			alert ("Your browser does not support AJAX!");
  			return;
  		}
		var url = "unsetSession.php";
		
		xmlHttp.onreadystatechange=function()
		{
			unsetSessionResponse(xmlHttp);
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function unsetSessionResponse(xmlHttp)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		var response = new Array();
		response = xmlHttp.responseText;
		/* add the code if want to handle the respopnse */
		//alert(response);
	}
}

function deleteLightboxImages(lid,image_id_str,isMultipleDelete) 
{
		// image_id comprises of 'userid | imageid' which will be splitted to get the information
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
  			alert ("Your browser does not support AJAX!");
  			return;
  		}
		
		var imageIdArr = new Array();
		var temp = new Array();
		imageIdArr = image_id_str.split(",");
		var lightboxID = lid;
		var image_id = image_id_str;		
		var params = "?image_id="+image_id+"&lightboxID="+lightboxID+"&dummy=" + Math.random();
		var url="deleteLightboxImages.php" + params;
		
		xmlHttp.onreadystatechange=function()
		{
			showLightboxDeleteResponse(xmlHttp,lid);
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
		if(isMultipleDelete == 1)
			arr_length = imageIdArr.length-1;
		else
			arr_length = imageIdArr.length;

			
		for(i=0 ; i< arr_length ; i++)
		{
			temp = imageIdArr[i].split("|");
			// temp[1] will have image id
			document.getElementById(lid+"_"+temp[1]).style.display = "none";
		}

	}


function showLightboxDeleteResponse(xmlHttp,lid)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		var response = new Array();
		response = xmlHttp.responseText;
		document.getElementById("td_img_count_"+lid).innerHTML = response;
		document.getElementById("span_image_count").innerHTML = response;
		
		var reload1 = "1";
		var count = document.getElementsByTagName("input").length;
		for(i=0;i<count;i++){
			if(document.getElementsByTagName("input")[i].name == "chk_array" && document.getElementsByTagName("input")[i].checked==false){
				reload1="0";
			}
		}
		
		if(reload1=="1"){	
				document.location.reload();
		}	
		
	}
}


//Remove images from the manage
function deleteManageImages(imgid,id,image_id,status)
{
	var verify_del = confirm('Are you sure you want to delete?');
	if (verify_del == true)
	{
		xmlHttp=GetXmlHttpObject();
		var errorstr ="";
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		} 
	  
		var url="delete_images.php?actiontyp=delete&uid="+ id + "&imgid=" + imgid + "&image_id=" + image_id + "&status=" + status + "&dummy=" + Math.random();
		xmlHttp.onreadystatechange=function(){
		removedeletedImages(xmlHttp,imgid,id,image_id)
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
}


function removedeletedImages(xmlHttp,imgid,id,image_id)
{
	
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		
		//document.getElementById('delres').innerHTML = xmlHttp.responseText;
		document.getElementById('row_' + imgid).innerHTML  = xmlHttp.responseText;
		
			
	}
}

/* Added by Amita - 13th Apr 2010  - Remove associated automatic keywords from manage section of approver on image by image basis */
function deleteAutomaticKeywordOfImage(auto_id,image_id)
{
	var user_confirm = confirm("Are you sure want to delete this automatic keyword?");
	if(user_confirm){
		xmlHttp=GetXmlHttpObject();
		mridstr ="";
		var errorstr ="";
		if (xmlHttp==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	} 
	  
	  	var url="deleteAutomaticKeywordOfImage.php?actiontyp=delete&auto_id="+auto_id+"&image_id=" + image_id+"&dummy=" + Math.random();
	  	xmlHttp.onreadystatechange=function(){
		removeDeletedAutomaticKeyword(xmlHttp,auto_id)
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function removeDeletedAutomaticKeyword(xmlHttp,auto_id)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		var tr;
		tr = document.getElementById('tr_'+auto_id);
		if(tr){
			tr.style.display="none";
		}
		
	}
}
/* END::Added by Amita - 13th Apr 2010 */

//Delete attached releases
function deleterelease(imgid,releaseType,id,tmpVal)
{
	if(tmpVal=="1")
	{
		var isTmp="tmp";
	}
	else
	{
		var isTmp="";
	}
	xmlHttp=GetXmlHttpObject();
	mridstr ="";
	var errorstr ="";
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
  	
  	if(isTmp=="tmp"){
		var url="remove_releases.php?actiontyp=delete"+isTmp+"&mridstr="+ id + "&imgid=" + imgid + "&mrtype="+releaseType+"&dummy=" + Math.random();
	}
	else
	{
		var url="processmr.php?actiontyp=delete&mridstr="+ id + "&imgid=" + imgid + "&mrtype="+releaseType+"&dummy=" + Math.random();
	}

	if(isTmp == "tmp"){
		xmlHttp.onreadystatechange=function(){
		removedeletedmrn(xmlHttp,mridstr,imgid,releaseType,id,isTmp)
		};
	}else{
		xmlHttp.onreadystatechange=function(){
		removedeletedmr(xmlHttp,mridstr,imgid,releaseType,id)
		};		
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//Remove delete mr from the listbox
function removedeletedmrn(xmlHttp,mridstr,imgid,releaseType,id,isTmp)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		mridarr = mridstr.split(",");
		document.getElementById('response_' + imgid).innerHTML = xmlHttp.responseText;
		arrlen = mridarr.length;
		var test = isTmp+"releases_"+imgid;
		var list;
		list = document.getElementById(isTmp+'releases_'+imgid);
		
		var count = list.getElementsByTagName("li").length;
		for(i=0;i<count;i++){
			if(list.getElementsByTagName("li")[i].id == imgid+"_"+id && list.getElementsByTagName("li")[i].value == releaseType){
				list.getElementsByTagName("li")[i].style.display="none";
			}
		}	
	}
}


function deletetmprelease(imgid,releaseType,id)
{
	xmlHttp=GetXmlHttpObject();
	mridstr ="";
	var errorstr ="";
	if (xmlHttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
  	
	var url="remove_releases.php?actiontyp=deletetmp&mridstr="+ id + "&imgid=" + imgid + "&mrtype="+releaseType+"&dummy=" + Math.random();
	xmlHttp.onreadystatechange=function(){
	removedeletedtmpmr(xmlHttp,mridstr,imgid,releaseType,id)
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


//Remove delete mr from the listbox
function removedeletedtmpmr(xmlHttp,mridstr,imgid,releaseType,id)
{
	if (xmlHttp.readyState == 4 && (xmlHttp.status==200))
	{
		mridarr = mridstr.split(",");
		document.getElementById('response_' + imgid).innerHTML = xmlHttp.responseText;
		arrlen = mridarr.length;
		
		var list;
		list = document.getElementById('tmpreleases_'+imgid);
		
		var count = list.getElementsByTagName("li").length;
		for(i=0;i<count;i++){
			if(list.getElementsByTagName("li")[i].id==imgid+"_"+id){
				list.getElementsByTagName("li")[i].style.display="none";
			}
		}
	}
}

function saveImageStatus(imgid,decision,newValue)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
		  alert ("Your browser does not support AJAX!");
		  return;
	  } 
	var url="saveimagestatus.php?";
	url=url+"&imgid="+imgid+"&decision="+decision+"&newValue="+newValue;
	//alert(url)
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function(){
					imageStatus(xmlHttp,imgid); };
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function imageStatus(xmlHttp,imgid){
	var tmpstr;
	if (xmlHttp.readyState==4  && xmlHttp.status==200)
	{ 
		tmpstr = xmlHttp.responseText;
		document.getElementById("response_"+imgid).innerHTML=tmpstr;
	}
	else
	{
		document.getElementById("response_"+imgid).innerHTML='<img src="images/spinner_grey.gif" />';
	}
	
}

