
// Taxonomies Value Objects .....

function Taxonomy(catName,catId,taxName) {

//	Setters ....


    this._catName = catName;
    this._catId = catId;
    this._taxName = taxName;
    
//  Getters ....

    this.getCatName = function()
	  {
	    return this._catName;
	  };
	  
	this.getCatId = function()
	  {
	    return this._catId;
	  };
	
	this.getTaxName = function()
	  {
	    return this._taxName;
	  };
}


//To delete selected items
function delete_items(objectType)
{
		var pId=0;
		var collectionId=0;
		if(getParameter("pId")){
			pId = getParameter("pId");
			pId = pId.replace("#","");
		}	
		if(getParameter("collectionId")){
			collectionId = getParameter("collectionId");
			//alert(collectionId);
		}
	
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		var total_to_delete = new Array();
		for(i=0;i<total_selected_objs.length;i++)
		{
			if(total_selected_objs[i].checked)
			{ 
				total_to_delete[total_to_delete.length] =  total_selected_objs[i].value;
			}
		}
		if(total_to_delete.length>0)
		{
			var name=confirm(ValidatorsM[2]);
			if(name ==true)
			{
				//alert("total_to_delete"+total_to_delete);
				var url = "a1deleteobject_p2.do?odl="+total_to_delete+"&oType="+objectType+"&pId="+escape(pId)+"&collectionId="+collectionId;
				showLoading('rootcontainer');
				simplePost(url,"reloadBodyAfterDelete(common_request)");
			}
		}
		else	
		{
			alert("Please select an item to delete.");
		}
}
document.write("<input type='hidden' id='alllist'>");
document.write("<input type='hidden' id='now'>");
//To Edit selected items
var receivingUnderProcess = false;
var total_to_edit;

var uAgent = navigator.userAgent;

function edit_items(Show,Query,ResultContainer,paginationAreaId,ApplyTo)
{

		var total_selected_objs = document.getElementsByName("selected_obj[]");
		total_to_edit = new Array();
		for(i=0;i<total_selected_objs.length;i++)
		{
			if(total_selected_objs[i].checked)
			{ 
				total_to_edit[total_to_edit.length] =  total_selected_objs[i].value;
			}
		}
		document.getElementById('alllist').value = total_to_edit;
		if(total_to_edit.length<1)
		{
			alert("Please select an item to edit.");
		}
		else
			receive_Edit_Datas(Show,Query,ResultContainer,paginationAreaId,ApplyTo,"alllist");
}
function copy_items(position)
{
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		var total_to_delete = new Array();
		for(i=0;i<total_selected_objs.length;i++)
		{
			if(total_selected_objs[i].checked)
			{ 
				total_to_delete[total_to_delete.length] =  total_selected_objs[i].value;
			}
		}
		if(total_to_delete.length>0)
		{
				layerOn('copy_menu'+position); 
				layerOn('menu_background_b'+position);
				cpmv_removeFilterProjects('copy',position);
		}
		else	
		{
			alert("Please select an item to copy.");
		}
}
function move_items(position)
{
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		var total_to_delete = new Array();
		for(i=0;i<total_selected_objs.length;i++)
		{
			if(total_selected_objs[i].checked)
			{ 
				total_to_delete[total_to_delete.length] =  total_selected_objs[i].value;
			}
		}
		if(total_to_delete.length>0)
		{
				layerOn('move_menu'+position); 
				layerOn('menu_background_a'+position);
				cpmv_removeFilterProjects('move',position);
		}
		else	
		{
			alert("Please select an item to move.");
		}
}
//AJAX CALL
var currentItem = 0;
var DisplayTagArr = new Array();
function receive_Edit_Datas(Show,Query,ResultContainer,paginationAreaId,ApplyTo,Ids)
 {  
 DisplayTagArr = new Array();
 layerOn(Show);
 if(ResultContainer!="")
 	document.getElementById(ResultContainer).innerHTML = "";
 var ie=document.all;
 var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
 
 var url=base_Url+"/editobjects.do?query="+Query+"&query_val="+getValuesForGivenIds(Ids);
 
 request.onreadystatechange=function()
 {
  if(request.readyState==4)
  {
   if(request.status==200)
   { 

  		var headers = request.responseXML.getElementsByTagName('displaynames');
   		for(i=0;i<headers.length;i++)
   		{
   			DisplayTagArr[DisplayTagArr.length] = headers.item(i).firstChild.nodeValue
   		}
   		var temp = DisplayTagArr;
   		DisplayTagArr = new Array();
   		
   		for(i=0;i<temp.length;i++)
   		{
   			DisplayTagArr[DisplayTagArr.length] = request.responseXML.getElementsByTagName(temp[i]);
   		}
    	manageeditpagination(0,ResultContainer,paginationAreaId,ApplyTo);
   }
   else if(request.status==500)
    alert("You found an opportunity for improvement! Please try again later");
   else
    alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
  }
 }

 request.open("POST",url,true);
 request.setRequestHeader("content-type","application/x-www-form-urlencoded");
 request.send(''); 
}

function getTaxonomyDatas(containerName,linkedWith,setTax,taxSel,window)
{
	var url="/editobjects.do?query=COMMON_TAGSQUERY_BASED_ON_SITE&query_val="+getValuesForGivenIds("siteId");
	showLoading(taxSel);
	simplePost(url,"renderTaxonomies(common_request,'"+containerName+"','"+linkedWith+"','"+setTax+"','"+taxSel+"','"+window+"')");
}

function change_feature_photo(obj,collectionId,channelId,listIndex,clipName,pageNo)
{
	
	if(document.getElementById('changeFeatureItem'))
		var imagePath = document.getElementById('changeFeatureItem').style.backgroundImage;
		imagePath=imagePath.replace("url(","");
		imagePath=imagePath.replace(")","");
	
	var url=base_Url+"/changefeaturephoto.do?&collectionId="+collectionId+"&pId="+channelId+"&listIndex="+listIndex+"&pageNumber="+pageNo+"&clipName="+imagePath+"&loc_return=";
	//simplePost(url);
	//alert(url);
	if(obj==""){
		var locReturn=document.getElementById("loc_return").value;	
		window.location.href=url+escape(locReturn);
		}
	else{
		obj.href=url+escape(document.location+"");
		}
}

var trIdArray = new Array();

function renderTaxonomies(request,containerName,linkedWith,setTax,taxSel,window)
{
	
	//var name=prompt("url ",request.responseText);
	//alert("containerName :"+containerName+" linkedwith :"+linkedWith+" setTax: "+setTax+" taxSel :"+taxSel+" window:"+window);
	document.getElementById(setTax).innerHTML="<p class=\"copy09_blue_noul\"><b>Select Tags from a Taxonomy:</b></p>";
	var taxonomyArr = new Array();
	//alert(request.responseXML.getElementsByTagName('displaynames'));
	var headers = request.responseXML.getElementsByTagName('displaynames');
	//alert(headers.length+","+headers);
	for(i=0;i<headers.length;i++)
   		{
   			//alert(headers.item(i).firstChild.nodeValue);
   			taxonomyArr[taxonomyArr.length] = headers.item(i).firstChild.nodeValue
   		}
   		//alert(taxonomyArr.length+","+taxonomyArr);
   	var temp = taxonomyArr;
	taxonomyArr = new Array();
	for(i=0;i<temp.length;i++)
	{
		//alert(temp[i]);
		if(request.responseXML.getElementsByTagName(temp[i]).length>0)
			taxonomyArr[taxonomyArr.length] = request.responseXML.getElementsByTagName(temp[i]);
			
			//alert(request.responseXML.getElementsByTagName(temp[i]))
	}
	   		//alert(taxonomyArr.length+","+taxonomyArr);
	
	if(taxonomyArr.length==0)
	{
		
		document.getElementById(setTax).innerHTML = "<p class=\"copy09_blue_noul\"><b>No taxonomy is linked to this site.</b></p>";
		document.getElementById(taxSel).style.display = 'none';
		return;
	}
	var taxonomy_selection="<p class=\"copy09_blue_noul\">Select a Taxonomy: "+ 
							"<select id='selection_2' class=\"inputelement\" style=\"vertical-align:middle;\" onChange=\"selectionOn(this.value,'"+window+"');displayOn('"+window+"');\">";
							
							
	var taxonomyInnerContent = "<table cellpadding='0' cellspacing='0' style='padding-top: 0px; width: 100%;' id='selTbl'  >";
	

	var lastId = -1;
	var newTd = true;
	var tempCount = 0;
	var categoryArr = new Array();
	try{
		taxonomy_selection+="<option value='none'>"+"--Select--"+"</option>";
			for(i=0;i<taxonomyArr[0].length;i++)
			{
				//alert(taxonomyArr[0].item(i).firstChild.nodeValue);
				//alert(taxonomyArr[1].item(i).firstChild.nodeValue);
				if(lastId!=taxonomyArr[1].item(i).firstChild.nodeValue)
				{	
					//alert("u r here"+i+" times");
					taxonomy_selection+="<option value='"+i+"'>"+taxonomyArr[0].item(i).firstChild.nodeValue+"</option>";	
					taxonomyInnerContent += "<tr id='"+i+"_seltr1"+window+"' style='display: none;'><td colspan='3' style='border-bottom: 1px solid #e4e4e4; background-color:#f2f2f2;padding:3px;'><p class='copy09_blue_noul'><b>"+taxonomyArr[0].item(i).firstChild.nodeValue+"</b></p></td></tr>"+
										    "<tr id='"+i+"_seltr2"+window+"' style='display: none;' valign='top' align='left'>";
					lastId = parseInt(taxonomyArr[1].item(i).firstChild.nodeValue);
					newTd = true;
					
					trIdArray[trIdArray.length] = i;
				}
				else
				{
					//alert("u r in else loop"+i+" times");
					newTd = false;
				}
				tempCount++;
				if(newTd)
				{
					//alert("u r in newtd loop"+i+" times");
					taxonomyInnerContent += "<td style='padding-bottom: 10px;'>"+
											 "<div style='padding: 0px 5px 0px 3px;'>";
					newTd = false;
				}
				
				if(document.getElementById(linkedWith).value.indexOf(taxonomyArr[2].item(i).firstChild.nodeValue)!=-1)
				{
					//alert("u r in linkedWith loop"+i+" times");
					taxonomyInnerContent += "<p class='copy09_blue_noul'><input type='checkbox' checked value='"+taxonomyArr[2].item(i).firstChild.nodeValue.replace("'","#")+"' style='vertical-align:middle;' onClick=\"updateTextValue(this,'"+linkedWith+"')\">"+taxonomyArr[2].item(i).firstChild.nodeValue+"</p>";
					}
				else{
					//alert("u r in linkedWith else loop"+i+" times");				
					taxonomyInnerContent += "<p class='copy09_blue_noul'><input type='checkbox' value='"+taxonomyArr[2].item(i).firstChild.nodeValue.replace("'","#")+"' style='vertical-align:middle;' onClick=\"updateTextValue(this,'"+linkedWith+"')\">"+taxonomyArr[2].item(i).firstChild.nodeValue+"</p>";
					}	
				if(tempCount>5 || lastId!=parseInt(taxonomyArr[1].item(i+1).firstChild.nodeValue))
				{
					//alert("u r in tempCount loop"+i+" times");	
					taxonomyInnerContent +=  "</div></td><td>";
					tempCount = 0;
					newTd = true;
				}
				if(lastId!=parseInt(taxonomyArr[1].item(i+1).firstChild.nodeValue))
				{
					//alert("u r in last if loop"+i+" times");	
					taxonomyInnerContent +=  "</tr>";
					tempCount = 0;
				}
			}
		}catch(e){taxonomyInnerContent += "</div></td></tr>"; }
		
		taxonomy_selection+="</select></p>";
		taxonomyInnerContent += "</table>";
		//alert(taxonomy_selection);
		document.getElementById(taxSel).style.display = 'block';
		document.getElementById(taxSel).innerHTML=taxonomy_selection;
		document.getElementById(containerName).innerHTML = taxonomyInnerContent;
		contName = containerName;
}
var contName;
var selectedValue="";
function selectionOn(selectedvalue,window)
{
	selectedValue=selectedvalue;
	if(selectedValue=="none")
	{
		document.getElementById(contName).style.display = "none";
	}else
	{	
		document.getElementById(contName).style.display = "block";	
		document.getElementById(selectedValue+'_seltr1'+window).style.display='';
		document.getElementById(selectedValue+'_seltr2'+window).style.display='';
	}
	
	selectionOff(window);	
}
function selectionOff(window)
{	
	for(var t=0;t<trIdArray.length;t++)
	{
		if(selectedValue!=trIdArray[t])
		{
			//if(document.getElementById(trIdArray[t]+'_seltr1'))
				document.getElementById(trIdArray[t]+'_seltr1'+window).style.display="none";
				
			//if(document.getElementById(trIdArray[t]+'_seltr2'))	
				document.getElementById(trIdArray[t]+'_seltr2'+window).style.display="none";
		}	
	}
	/*
	if((!selectedValue=="")&&(selectedValue!=='none'))
	{
	document.getElementById(selectedValue+'_seltr1').style.display="none";
	document.getElementById(selectedValue+'_seltr2').style.display="none";
	}*/
}

function updateTextValue(checkObj,linkedWith)
{
	if(checkObj.checked && trim(document.getElementById(linkedWith).value)!="")
	{
		document.getElementById(linkedWith).value = document.getElementById(linkedWith).value+","+checkObj.value.replace("#","'");
	}
	else if(checkObj.checked)
	{
		document.getElementById(linkedWith).value = checkObj.value.replace("#","'");
	}
	else
	{
		document.getElementById(linkedWith).value = removeTerms(document.getElementById(linkedWith).value,checkObj.value.replace("#","'"),"");
		document.getElementById(linkedWith).value = removeTerms(document.getElementById(linkedWith).value,",,",",");
	}
}

function removeTerms(from,remove_this,plus_this)
{
	while(from.indexOf(remove_this) != -1)
	{
		firstpart = from.substring(0,from.indexOf(remove_this));
		secondpart = from.substring(from.indexOf(remove_this)+remove_this.length,from.length);
		from = firstpart+plus_this+secondpart;
	}
	return from;
}

function manageeditpagination(pageNo,ResultContainer,paginationAreaId,ApplyTo)
{
	try{
		document.getElementById('now').value = DisplayTagArr[DisplayTagArr.length-1].item(pageNo).firstChild.nodeValue;
	}catch(e){}
	
	var both = false;
	var prevHTML = "";
	var nxtHTML = "";
	var finalHTML = "";
	if(pageNo>0 && paginationAreaId!="")
	{
		both = true;
		prevHTML = "<a href=\"javascript:manageeditpagination('"+(parseInt(pageNo)-1)+"','"+ResultContainer+"','"+paginationAreaId+"','"+ApplyTo+"');\">Previous</a>";
		//document.getElementById(PrevId).style.visibility = "visible";
		//document.getElementById(PrevId).href = "javascript:manageeditpagination('"+(parseInt(pageNo)-1)+"','"+ResultContainer+"','"+PrevId+"','"+NextId+"','"+ApplyTo+"')";
	}
	else if(paginationAreaId!="")
	{
		both = false;
		prevHTML = "<a href='' style='visibility:hidden'>Previous</a>";
		//document.getElementById(PrevId).style.visibility = "hidden";
	}
	
	if( paginationAreaId!="" && pageNo<(total_to_edit.length-1))
	{
		if(both)
			both = true;
		nxtHTML = "<a href=\"javascript:manageeditpagination('"+(parseInt(pageNo)+1)+"','"+ResultContainer+"','"+paginationAreaId+"','"+ApplyTo+"');\">Next</a>";
		//document.getElementById(NextId).style.visibility = "visible";
		//document.getElementById(NextId).href = "javascript:manageeditpagination('"+(parseInt(pageNo)+1)+"','"+ResultContainer+"','"+PrevId+"','"+NextId+"','"+ApplyTo+"')";
	}
	else if(paginationAreaId!="")
	{
		both = false;
		nxtHTML = "<a href='' style='visibility:hidden'>Next</a>";
		//document.getElementById(NextId).style.visibility = "hidden";
	}
	try{
		if(both)
		{
			finalHTML = prevHTML+"<label>&nbsp;|&nbsp;</label>"+nxtHTML
		}else{
			finalHTML = prevHTML+"<label>&nbsp;&nbsp;&nbsp;</label>"+nxtHTML;
		}
		document.getElementById(paginationAreaId).innerHTML = finalHTML;
	}catch(e){}
	
 	var elementsIds = Split_into_Array(ApplyTo,",");
	var tt;
 	for(i=0;i<DisplayTagArr.length;i++)
	{
		try{
			temp = Split_into_Array(elementsIds[i],"/");
			tt = DisplayTagArr[i].item(pageNo).firstChild.nodeValue;
			if(tt=="&nbsp;")
				tt = " ";
			if(temp[1].indexOf("value")!=-1)
				document.getElementById(temp[0]).value = tt;
			else if(temp[1].indexOf("src")!=-1)
				document.getElementById(temp[0]).src = tt;
			else if(temp[1].indexOf("title")!=-1)
				document.getElementById(temp[0]).title = tt;
			}catch(e){}
	}
	
}
/*
This Code can be used for all save functionalities......
*/

function post_Object_Changes(query,offItem,Ids,to,daoType)
{
	
	var result = "";
	var fieldsArray = Split_into_Array(Ids,",");
	var updateKey = document.getElementById(fieldsArray[(fieldsArray.length-1)]).value;
	var url= "/editsaveobjects.do?query="+query+"&query_val="+getValuesForGivenIds(Ids)+"&update_key="+updateKey+"&object_type="+daoType;
	simplePost(url,"afterChannelSave(common_request,'"+offItem+"','"+to+"','"+fieldsArray[0]+"')");
}

function afterChannelSave(request,offItem,containerName,supplierName)
{	
	if(document.getElementById(offItem).style.visibility == "visible" && document.getElementById(offItem).style.display != "block")
		layerOff(offItem);
	else
		displayOff(offItem);
		
	document.getElementById(containerName).innerHTML = "";
	document.getElementById(containerName).innerHTML = document.getElementById(supplierName).value;
}

function postControlsChanges(val,pos)
{
	var update_key = document.getElementById('objectId').value;
	var collectionId = 0;
	if( document.getElementById("jsCollectionId") ){
		collectionId = document.getElementById("jsCollectionId").value;
	}
	//var url= "editsaveobjects.do?query=PV_EDIT_SAVE_QUERY&query_val="+getValuesForGivenIds("title_field,desc_field,objectId")+"&update_key="+update_key+"&object_type=ObjectDAO";
	var url= "editsaveobjects.do?query=PV_EDIT_SAVE_QUERY&query_val="+getValuesForGivenIds(val)+"&update_key="+update_key+"&object_type=ObjectDAO&ht="+collectionId;

	simplePost(url,"performAfterPost('"+pos+"')");
}


	
function post_Changes(from,query,saveIdList,resultContainer,offItem)
{
 var url;
 var fieldsArray = Split_into_Array(saveIdList,",");
	var updateKey = fieldsArray[(fieldsArray.length-1)];

 	url= "/editsaveobjects.do?query="+query+"&query_val="+getValuesForGivenIds(saveIdList)+"&update_key="+update_key+"&object_type="+object_type;
 
   simplePost(url,"afterSave(common_request,'"+resultContainer+"','"+from+"','"+offItem+"')");
}

function afterSave(request,resultContainer,from,offItem)
{
		var  a = ""+request.responseText;
   		if(trim(a) == "true")
   		{
   			
   			if(from=="all")
   			{
   				document.getElementById(resultContainer).innerHTML ="Edited SuccessFully";
   				layerOff(offItem);
   			}
   			else{
   				document.getElementById(resultContainer).innerHTML ="Edited SucessFully";
   			}
   			reloadBody();
   		}
   		else{
   			document.getElementById(resultContainer).innerHTML ="Problem While Editing.";
   			}
}

function toHex(str)
{
	var strTest = ""; 
		for(j=0;j<str.length;j++)
		{
			if(str.charCodeAt(j)<255)
			{
				strTest +="%"+str.charCodeAt(j).toString(16).toUpperCase();
			}
			else if((str.charCodeAt(j)>255)&& (str.charCodeAt(j)<7680))
			{
				strTest +="%u0"+str.charCodeAt(j).toString(16).toUpperCase();
			}
			else
			{
				strTest +="%u"+str.charCodeAt(j).toString(16).toUpperCase();
			}
		}
	return  strTest;
}
function handleSpecialChars(input){
input = input.replace(/%/g,"%25");
//input = input.replace(/\$/gi,"%24");
input = input.replace(/&/g,"%26");
input = input.replace(/\?/gi,"%3F");
input = input.replace(/`/gi,"%60");

input = input.replace(/~/g,"%7E");
input = input.replace(/!/g,"%21");
input = input.replace(/#/g,"%23");

input = input.replace(/\^/g,"%5E");
input = input.replace(/\(/g,"%28");
input = input.replace(/\)/g,"%29");
return input;
}
function getValuesForGivenIds(ids)
{
	//alert(ids);
	var result = "";
	var testStr = ""; 
	var fullStr = "";
	var fieldsArray = Split_into_Array(ids,",");

	for(i=0;i<fieldsArray.length;i++)
	{	

		//result += escape(formatStringSpecialChars(document.getElementById(fieldsArray[i]).value));
		result += encodeURIComponent(document.getElementById(fieldsArray[i]).value);
		testStr += toHex(document.getElementById(fieldsArray[i]).value);

			if(i<(fieldsArray.length-1) || fieldsArray.length==1)
			{
			result += escape("<PICKLESEPERATOR>");
			testStr += escape("<PICKLESEPERATOR>");
			}	

	}
	return result;

}

function Split_into_Array(input,seperator)
{
	var temp = new Array();
	while(input.indexOf(seperator)!=-1)
	{
		temp[temp.length] = input.substring(0,input.indexOf(seperator));
		input = input.substring(input.indexOf(seperator)+1,input.length);
	}
	temp[temp.length] = input;
	return temp;
}

/*
End of Save Code Functionalities .....
*/


function copy_item(which)
{
	var sy=document.getElementById('start_yyyy').value;
	var sd=document.getElementById('start_dd').value;
	var sm=document.getElementById('start_mm').value;
	var em=document.getElementById('end_mm').value;
	var ed=document.getElementById('end_dd').value;
	var ey=document.getElementById('end_yyyy').value;
	var site=document.getElementById('channelSite').value;
	receive_copy_items(sy,sd,sm,em,ed,ey,site,"asst",which);
}

function receive_copy_items(syear,sdate,smonth,emonth,edate,eyear,siteId,asset,which)
//function receive_copy_items(syear,sdate,smonth,emonth,edate,eyear)
 {  
var objIds = 0;
var captions;
document.getElementById('tags_result_container').innerHTML = "";
 var ie=document.all;
 var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
 
 var url=base_Url+"/searchProject_p2.do?ajax=Ajax&start_yyyy="+syear+"&start_mm="+smonth+"&start_dd="+sdate+"&end_yyyy="+eyear+"&end_mm="+emonth+"&end_dd="+edate+"&assetType="+asset+"&site="+siteId+"";

 request.onreadystatechange=function()
 {
  if(request.readyState==4)
  {
   if(request.status==200)
   { 
   		objIds = request.responseXML.getElementsByTagName('objectId');
   		captions = request.responseXML.getElementsByTagName('objectCaption');
   		
   		var inner_Text = "<table cellpadding='0' cellspacing='0' border='0'>";
   		//alert(objIds.item(0).firstChild.nodeValue);
   		 for(i=0;i<objIds.length;i++)
   		 {
		 	  inner_Text += "<tr valign='center'>"+
								"<td style='padding: 3px;'><a href=''><img src='skins/main/images/account/icons/fn.gif' border='0'></a></td>"+
								"<td style='padding: 3px;' width='100%'><p><a id='"+objIds.item(i).firstChild.nodeValue+"' href=\"javascript:moveSelected('"+objIds.item(i).firstChild.nodeValue+"','"+which+"')\">"+captions.item(i).firstChild.nodeValue+"</a></p></td>"+
						   "</tr>";
   		 	

   			 
   		 }
   		 inner_Text += "</table>";
   		 document.getElementById('pckle_whitebackground').innerHTML = inner_Text;
   		 document.getElementById('pckle_whitebackground0').innerHTML = inner_Text;
   		 
   }
   else if(request.status==500)
    alert("You found an opportunity for improvement! Please try again later");
   else
    alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
  }
 }
 request.open("POST",url,true);
 request.setRequestHeader("content-type","application/x-www-form-urlencoded");
 request.send(''); 
}

function highlightRow(el, color) {
	color=el.checked?color:'';
	while (el.tagName.toUpperCase() != 'TR' && el != null)
	el = el.parentNode;
	if (el)
	el.style.backgroundColor = color;
	}

function check_uncheck_all(obj,param)
{

	if(param==true){
			obj.checked = true;
	}else if(param==false){
			obj.checked = false;
	}
	
	var objCheck = obj.checked;
	
	if(objCheck )
	{
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		for(i=0;i<total_selected_objs.length;i++)
		{
			total_selected_objs[i].checked = true;
			//highlight_selected_row('therow_'+total_selected_objs[i].value, "#D2FDB7");
			highlightRow(total_selected_objs[i], "#D2FDB7");
		}
	}else{
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		for(i=0;i<total_selected_objs.length;i++)
		{
			total_selected_objs[i].checked = false;
			//highlight_selected_row('therow_'+total_selected_objs[i].value, "#ffffff"); 
			highlightRow(total_selected_objs[i], "#ffffff");
		}
	}
}

function detailed_edit_check_uncheck_all(obj,param)
{

	if(param==true){
			obj.checked = true;
	}else if(param==false){
			obj.checked = false;
	}
	
	var objCheck = obj.checked;
	
	if(objCheck )
	{
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		for(i=0;i<total_selected_objs.length;i++)
		{
			total_selected_objs[i].checked = true;
			highlight_selected_row('therow_'+total_selected_objs[i].value, "#D2FDB7");
		}
	}else{
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		for(i=0;i<total_selected_objs.length;i++)
		{
			total_selected_objs[i].checked = false;
			highlight_selected_row('therow_'+total_selected_objs[i].value, "#ffffff"); 
		}
	}
}


function moveSelected(targetId,which)
{

	var total_selected_objs = document.getElementsByName("selected_obj[]");
	var total_to_edit = new Array();
	for(i=0;i<total_selected_objs.length;i++)
	{
		if(total_selected_objs[i].checked)
		{ 
			total_to_edit[total_to_edit.length] =  total_selected_objs[i].value;
		}
	}
	var parameters;
	if(which=="copy")
	{
		parameters = "ocl="+total_to_edit+"&tctnr="+targetId+"&loct_return="+escape(document.location+"");
	}
	else
	{
		parameters = "oml="+total_to_edit+"&tctnr="+targetId+"&loct_return="+escape(document.location+"");
	}
	if(total_to_edit.length>0)
		{
			if(which=="copy"){
		          var url = "/copyobjects.do?"+parameters;
                    showLoading('rootcontainer');
                    simplePost(url,"reloadBody()");
				}
			else
			{
				 var url = "/moveobjects.do?"+parameters;
                    showLoading('rootcontainer');
                    simplePost(url,"reloadBody()");
				}
		}
	else
		alert("Nothing has been selected.");
}


function change_status(statusId,objectType)
{

	var collectionId=0;
	if(getParameter("collectionId")){
			collectionId = getParameter("collectionId");
			//alert(collectionId);
		}
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	var total_to_change = new Array();
	for(i=0;i<total_selected_objs.length;i++)
	{
		if(total_selected_objs[i].checked)
		{ 
			//alert("total_selected_objs[i].value :"+total_selected_objs[i].value);
			total_to_change[total_to_change.length] =  total_selected_objs[i].value;
		}
	}
	
	if(total_to_change.length>0)
	{
			var url = "changestatusaction.do?obid="+total_to_change+"&obstatl="+statusId+"&obtype="+objectType+"&collectionId="+collectionId;
			simplePost(url,"reloadBodyAfterChangeStatus(common_request)");

			
	}
	else	
	{
		alert("Please select an item to change.");
	}
}

function change_status2(position)
{
	
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	var total_to_change = new Array();
	for(i=0;i<total_selected_objs.length;i++)
	{
		if(total_selected_objs[i].checked)
		{ 
			total_to_change[total_to_change.length] =  total_selected_objs[i].value;
		}
	}
	
	if(total_to_change.length>0)
	{
			layerOn('status'+position); 
			layerOn('menu_background_a'+position);
	}
	else	
	{
		alert("Please select an item to change.");
	}
}


function trim(str){ return str.replace(/^\s*|\s*$/g,'')}


/*         Collection Body Javascript Methods Starts here ....      */



/*function get_page(obj){
	var page_no = obj.options[obj.selectedIndex].value;
	document.getElementById("pageNumber").value = page_no;
	document.getElementById("pageablebody").submit();
}

function sort_column(sort_by){
	document.getElementById("sortBy").value = sort_by;
	document.getElementById("sortOrder").value =1;
	document.getElementById("collectionsbody").submit();
}

function toggle_order(){
	if(document.getElementById("sortOrder").value == 1)
	{
		document.getElementById("sortOrder").value =2;
	}
	else
	{
		document.getElementById("sortOrder").value =1;
	}
	document.getElementById("collectionsbody").submit();
}*/

function highlightRow(el, color) {
	color=el.checked?color:'';
	while (el.tagName.toUpperCase() != 'TR' && el != null)
	el = el.parentNode;
	if (el)
	el.style.backgroundColor = color;
	}
	function checkrow(e,name){
	document.getElementById(name).checked = (document.getElementById(name).checked ? false : true);
	highlightRow(document.getElementById(name), '#D2FDB7');
	}
	
function rolling(inTherow,inTherow2,inColor)
	{
		var a = Split_into_Array(inTherow,"_");
		try
		{
			if(document.getElementById("selected_obj_"+a[1]).checked)
				return;
			
			document.getElementById(inTherow).style.backgroundColor = inColor;
			document.getElementById(inTherow2).style.backgroundColor = inColor;
		}catch(e){}	
	}

function rollingSingleRow(inTherow,inColor)
{
	var a = Split_into_Array(inTherow,"_");		
	try
	{
		if(document.getElementById("SetSelected_"+a[1]).checked)
			return;
		
		document.getElementById(inTherow).style.backgroundColor = inColor;
	}catch(e){}	
}
	
function submitCollection(userId,siteId,parentId,listIndex,userName){
	var caption = '';
	caption = document.getElementById('new_collection_caption').value;
	var tags = document.getElementById('new_collection_tags').value;
	var desc = document.getElementById('new_collection_description').value;
	var collectionstatus=document.getElementById('select__collection_object_state').value;
	//alert("collectionstatus : :"+collectionstatus);
	if(document.getElementById('new_collection_caption').value=='')
	{
		alert('Please Enter Title.');
		document.getElementById('new_collection_caption').focus();
	}
	else
		{	
		
	//	AJAX CALL	
		var request=document.all?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
		var url="createCollection_p2.do?userDisplayName="+escape(userName);
		//var params = 'caption=' +escape(formatStringSpecialChars(caption))+ '&tags=' +tags+ '&desc=' +escape(formatStringSpecialChars(desc))+ '&userId='+userId+'&siteId='+siteId+'&parentId='+parentId+"&userEmail="+userName+"&objectStatus=2";
		var params = 'caption=' +handleSpecialChars(formatStringSpecialChars(caption))+ '&tags=' +tags+ '&desc=' +handleSpecialChars(formatStringSpecialChars(desc))+ '&userId='+userId+'&siteId='+siteId+'&parentId='+parentId+"&userEmail="+userName+"&objectStatus="+collectionstatus;
	
		request.onreadystatechange=function()
		{
			if(request.readyState==4)
				{
					if(request.status==200)
					{
						//alert("Collectionidupload :"+request.responseText);
						document.getElementById('objectId').value = trim(request.responseText);
						document.getElementById('uploadedbycollectionid').value = trim(request.responseText);
						document.getElementById("next_collection_url").value= 'a1aCollection_p2.do?collectionId=' +escape(request.responseText)+ '&listIndex='+escape(listIndex);
						document.getElementById('uploadCaption_lbl').innerHTML = caption;
						if( document.getElementById("hid_upload_tags") )
							document.getElementById("hid_upload_tags").value = tags;
						if( document.getElementById("hid_upload_description") )
							document.getElementById("hid_upload_description").value = desc;
						displayOn('newcollection2');
						displayOff('newcollection');
						layerOn('collection_next');
						//list index needs to be get from request Attribute. ....
					}
					else
						alert(request.status);
				}
		}
		request.open("POST",url,true);
		request.setRequestHeader("content-type","application/x-www-form-urlencoded");
		request.send(params);
	//  END OF AJAX CALL
	

		document.getElementById('new_collection_caption').value = '';
		document.getElementById('new_collection_tags').value = '';
		document.getElementById('new_collection_description').value = '';
			displayOff('newcollection'); 
		 	displayOn('newcollection2');
		}
}

function toggle_nextPage(radio_button){
	if(radio_button==0){
		document.getElementById("collection_next").href = "javascript:new_continue('upload');receive_upload_id();";
	}
	else
	{
		document.getElementById("collection_next").href = "javascript:new_continue('reload');reloadBodyWithPagination()";
	}
}


	//checkallandclearall is test in nitro
function layerOn(menuID)
	{

		if (document.getElementById) 
			{
			document.getElementById(menuID).style.visibility = 'visible';
			
			}
		else if (document.layers && document.layers[menuID]) 
			{
			document.layers[menuID].visibility = 'visible';
			}
		else if (document.all) 
			{
				document.all[menuID].style.visibility = 'visible';
			}
	}


function layerOff(menuID)
	{
		try{
			if (document.getElementById) 
				{
				document.getElementById(menuID).style.visibility = 'hidden';
				}
			else if (document.layers && document.layers[menuID]) 
				{
				document.layers[menuID].visibility = 'hidden';
				}
			else if (document.all) 
				{
				document.all[menuID].style.visibility = 'hidden';
				}
		}catch(e){}		
	}
function CheckandClear(startIndex,endIndex){
var k = 0;
temp = document.test.elements.length ;                
	for (i=startIndex; i <= endIndex; i++){
		if(checkall.checked == 1)
		{
		document.test.elements[k].checked = 1;
		highlightRow(document.getElementById("SetSelected_"+i),'#D2FDB7');
		}
		else 
		{
		document.test.elements[k].checked = 0;
		highlightRow(document.getElementById("SetSelected_"+i),'#FFFFFF');		
	    }
	    k++;
	}
}

function CheckAllmails(startIndex,endIndex)
    {
var k = 0;    
	for (var i=startIndex;i<=endIndex;i++)
 	{
  		var e=document.test.elements[k];
		e.checked = true;	
		document.getElementById("checkall").checked = true;	
		highlightRow(document.getElementById("SetSelected_"+i),'#D2FDB7');
		k++;
   	}
 }
 
 function ClearAllmails(startIndex,endIndex)
    {
var k = 0;        
	for (var i=startIndex;i<=endIndex;i++)
 	{
  		var e=document.test.elements[k];
		e.checked = false;	
		document.getElementById("checkall").checked = false;
		highlightRow(document.getElementById("SetSelected_"+i),'#FFFFFF');	
		k++;
   	}
 
}



/*         Collection Body Javascript Methods Ends Here ....  */



/*     Comments Body Javascript Methods Starts Here  ..... */

	/*function get_page(obj){
		var page_no = obj.options[obj.selectedIndex].value;
		document.getElementById("pageNumber").value = page_no;
		document.getElementById("photovideobody").submit();
	}
	
	function sort_column(sort_by){
		document.getElementById("sortBy").value = sort_by;
		document.getElementById("sortOrder").value =1;
		document.getElementById("photovideobody").submit();
	}
	
	function toggle_order(){
		if(document.getElementById("sortOrder").value == 1)
		{
			document.getElementById("sortOrder").value =2;
		}
		else
		{
			document.getElementById("sortOrder").value =1;
		}
		document.getElementById("photovideobody").submit();
	}*/



/*     Commnets Body Javascript Methods Ends Here ..... */



/*     PhotoVideo Body Javascript Methods Starts Here ..... */





/*	function get_page(obj){
		var page_no = obj.options[obj.selectedIndex].value;
		document.getElementById("pageNumber").value = page_no;
		document.getElementById("photovideobody").submit();
	}
	
	function sort_column(sort_by){
		document.getElementById("sortBy").value = sort_by;
		document.getElementById("sortOrder").value =1;
		document.getElementById("photovideobody").submit();
	}
	
	function toggle_order(){
		if(document.getElementById("sortOrder").value == 1)
		{
			document.getElementById("sortOrder").value =2;
		}
		else
		{
			document.getElementById("sortOrder").value =1;
		}
		document.getElementById("photovideobody").submit();
	}*/
	//checkallandclearall is test in nitro
	function layerOn(menuID,isCenter)
		{
			if (document.getElementById) 
				{
				document.getElementById(menuID).style.visibility = 'visible';
				
				}
			else if (document.layers && document.layers[menuID]) 
				{
				document.layers[menuID].visibility = 'visible';
				}
			else if (document.all) 
				{
				document.all[menuID].style.visibility = 'visible';
				}
			if(isCenter)
			{
				document.getElementById(menuID).style.position = "absolute";
				
				var obj_width = screen.Width/2 - (document.getElementById(menuID).offsetWidth/2);
				var obj_height =  screen.Height/2 - (document.getElementById(menuID).offsetHeight/2);
				
				//alert("Object Left :"+obj_width+"  ::::: Screen Width : "+screen.Width);
				
				
				if(obj_width>screen.Width)
					obj_width = screen.Width -  (document.getElementById(menuID).offsetWidth/2);
				
				if(obj_height>screen.Height)
					obj_height = screen.Height -  (document.getElementById(menuID).offsetHeight/2);
					
				document.getElementById(menuID).style.left = obj_width;
				document.getElementById(menuID).style.top = obj_height;
			}		
				
		}
	function displayOn(objId,isCenter){
	    if(document.getElementById(objId)){
			document.getElementById(objId).style.display = "block";
		}
			
		if(isCenter)
		{
			var obj_width = screen.Width;
			var obj_height =  screen.Height;
			if(document.getElementById(objId)){
				document.getElementById(objId).style.left = obj_width/2 - (document.getElementById(objId).offsetWidth/2);
				document.getElementById(objId).style.top = obj_height/2 - (document.getElementById(objId).offsetHeight/2);
			}	
		}
		
	}
	function displayOff(objId){
		try{
			if(document.getElementById(objId)){
				document.getElementById(objId).style.display = "none";
			}
		}catch(e){}	
	}
		
	function showItAndPlaceIt(objId,obj)
		{
			displayOn(objId);
			setPosition(obj,document.getElementById(objId));
		}
		function setPosition(fr_om,t_o)
		{
			var l = findPosX(fr_om) - (t_o.offsetWidth/2);
		 	var t = findPosY(fr_om)- (t_o.offsetHeight/2);

			if(fr_om.id=="downDesc"){
				t_o.style.left = findPosX(fr_om);			
				t_o.style.top = findPosY(fr_om);
				return;
			}

		 	//if the left position is more than the screen resolution
		 	
		 	if((l+t_o.offsetWidth)>screen.width)
		 		l = screen.width - t_o.offsetWidth-30;
		 	
		 	if(l<0)
		 		l =0;
		 	
		 	if((t+t_o.offsetHeight)>screen.height)	
		 		t = screen.width - t_o.offsetHeight-30;
		 		
		 	if(t<0)
		 		t = 0;

			if(fr_om.id=="uptxt"){
				l = findPosX(document.getElementById('topSelectedDiv'));
				//l = l-330;
				if(ie) 
					t = t-15;
				else
					t = t-5;	
			}
		 			
			t_o.style.left = l;			
			t_o.style.top = t;
			
			
				
		}
	
	function layerOff(menuID)
		{
			try{
				if (document.getElementById) 
					{
					document.getElementById(menuID).style.visibility = 'hidden';
					}
				else if (document.layers && document.layers[menuID]) 
					{
					document.layers[menuID].visibility = 'hidden';
					}
				else if (document.all) 
					{
					document.all[menuID].style.visibility = 'hidden';
					}
				}catch(e){}
		}
		
	function CheckandClear(startIndex,endIndex){
	var k = 0;
	temp = document.test.elements.length ;                
		for (i=startIndex; i <= endIndex; i++){
			if(checkall.checked == 1)
			{
			document.test.elements[k].checked = 1;
			highlightRow(document.getElementById("SetSelected_0"+i),'#D2FDB7');
			}
			else 
			{
			document.test.elements[k].checked = 0;
			highlightRow(document.getElementById("SetSelected_0"+i),'#FFFFFF');		
		    }
		    k++;
		}
	}
	
	function CheckAllmails(startIndex,endIndex)
	    {
	var k = 0;    
		for (var i=startIndex;i<=endIndex;i++)
	 	{
	  		var e=document.test.elements[k];
			e.checked = true;	
			document.getElementById("checkall").checked = true;	
			highlightRow(document.getElementById("SetSelected_"+i),'#D2FDB7');
			k++;
	   	}
	 }
	 
	 function ClearAllmails(startIndex,endIndex)
	    {
	var k = 0;        
		for (var i=startIndex;i<=endIndex;i++)
	 	{
	  		var e=document.test.elements[k];
			e.checked = false;	
			document.getElementById("checkall").checked = false;
			highlightRow(document.getElementById("SetSelected_"+i),'#FFFFFF');	
			k++;
	   	}
	 }
	var last_object ; 

	function highlightRow(el, color) {
	color=el.checked?color:'';
	while (el.tagName.toUpperCase() != 'TR' && el != null)
	el = el.parentNode;
	if (el)
	el.style.backgroundColor = color;
	}
	function checkrow(e,name){
	document.getElementById(name).checked = (document.getElementById(name).checked ? false : true);
	highlightRow(document.getElementById(name), '#D2FDB7');
	}

	function newlabel()
	{
		if (document.getElementById("eaccess").value == "Turned Off")
			{
			document.getElementById("eaccess").value = "";
			document.getElementById("eaccess").disabled = "false";
			document.getElementById("ch").disabled = "false";
			}else{
			document.getElementById("eaccess").value = "Turned Off";
			document.getElementById("eaccess").disabled = "true";
			document.getElementById("ch").enable;
			}
	}
	function layerOnOff(layerName, layerState)
	{
	if (layerState == "on")
		{
		if (document.getElementById) 
			{
			document.getElementById(layerName).style.visibility = 'visible';
			}
		else if (document.layers && document.layers[layerName]) 
			{
			document.layers[layerName].visibility = 'visible';
			}
		else if (document.all) 
			{
			document.all[layerName].style.visibility = 'visible';
			}
		}
	else
		{
		if (document.getElementById) 
			{
			document.getElementById(layerName).style.visibility = 'hidden';
			}
		else if (document.layers && document.layers[layerName]) 
			{
			document.layers[layerName].visibility = 'hidden';
			}
		else if (document.all) 
			{
			document.all[layerName].style.visibility = 'hidden';
			}

		}
	}
	
function buttonchange(inImage, inLocation)
	{
	document.getElementById(inLocation).src = inImage; 	
	}	
//-->
function insertAtCursor(inTextField, inTextToAd) 
	{
	//IE
	var inString = inTextField.value;
	var intIndexOfMatch = inString.indexOf(inTextToAd);
	
	if  (intIndexOfMatch >= 0)
		{
		while (intIndexOfMatch != -1)
			{
			inString = inString.replace(inTextToAd, "");
			intIndexOfMatch = inString.indexOf(inTextToAd);
			}
		inTextField.value = inString;	
		}
		else
		
	if (document.selection) 
		{
		inTextField.focus();
		sel = document.selection.createRange();
		sel.text = inTextToAd;
		}
	//FF
		else if (inTextField.selectionStart || inTextField.selectionStart == 0) 
			{
			var startPos = inTextField.selectionStart;
			var endPos = inTextField.selectionEnd;
			inTextField.value = inTextField.value.substring(0, startPos) + inTextToAd + inTextField.value.substring(endPos, inTextField.value.length);
			} 
			else 
			{
				inTextField.value += inTextToAd;
			}
	}	


/*     PhotoVideo Body Javascript Mthods Ends Here ..... */


function rotate_objects_a1(rotate_direction)
{
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		var total_to_rotate = new Array();
		var videoStatus=0;
		for(i=0;i<total_selected_objs.length;i++)
		{
			var objId = total_selected_objs[i].value;
			var objtype = document.getElementById("rowtype_"+objId).value;
			if( total_selected_objs[i].checked && objtype == 0 )
				videoStatus = 1;

			if(total_selected_objs[i].checked && objtype == 1 )
			{ 
				total_to_rotate[total_to_rotate.length] =  total_selected_objs[i].value;
			}
		}
		if( videoStatus == 1 ){
			alert("Only photos can be rotated.");
		}
		else if(total_to_rotate.length>0 )
		{
			//var url = "/rotateobject_p2.do?odl="+total_to_rotate+"&direction="+rotate_direction+"&loct_return="+escape(document.location+"");
			var url = "/rotateobject_p2.do?odl="+total_to_rotate+"&direction="+rotate_direction;
			showLoading('rootcontainer');
			simplePost(url,"reloadBody()");
		}
		else	
		{
			alert("Please select an item to rotate.");
		}
}


function rotate_objects(object_id,rotate_direction)
{
	//showLoading('img_showing_now');
	showLoading('image_container');
	//document.getElementById('imgSpinning').style.display = "block";
	var url = "/rotateobject_p2.do?odl="+object_id+"&direction="+rotate_direction;
	simplePost(url,"A3ReloadPhoto()");
}
function rotate_objects_widget(object_id,rotate_direction,objSubType,purgeId)
{
		//showLoading(fromObjId);
	if(objSubType=="VIDEO" || objSubType=="video"){
		alert("Videos can't be rotated.");
		return;
	}

	var realUrl = document.getElementById("image_"+object_id).src;
	document.getElementById("image_"+object_id).src = document.getElementById('loading_image').src;
	var url = etsBaseUrl+"/rotateobject_p2.do?odl="+object_id+"&direction="+rotate_direction+"&purgeId="+purgeId+"&objType="+objSubType;
	simplePost(url,"emptyMethod('"+object_id+"','"+escape(realUrl)+"')");
}
function emptyMethod(objId,realImageUrl){
	document.getElementById("image_"+objId).src = unescape(realImageUrl)+"?"+new Date(); 
}
function A3ReloadPhoto()
{
	swithWithImageSize(lastval);
}

/* ..... New Upload Code for all pages ....*/

var val = "";
var currentCount = 0;
var uploadedCount = 0;
var ajaxCount = 0;
var currentStatus = "Pickle has finished uploading your files.";
		

function getBarOld(done,total,imageUrl)
		{
			//alert('done :'+done+', total'+total+', uploadedCount'+uploadedCount);
			done=done.replace('Processing ','');
			if (uploadedCount==0) return "";
			remainingBox="";
			if (done=="P" || done=="F" || parseInt(done)==parseInt(total))
			{
				remainingPercentage = 0;
				donePercentage = 100;
			}
			else
			{
				remainingPercentage = parseInt((total-done)/total*100);
				donePercentage = parseInt(100-remainingPercentage); 
				remainingBox = "<div style=\"width=:"+remainingPercentage+"%; height:20px; float:left;\" ><img src=\""+base_Url+"/skins/main/images/account/dot.gif\" width=\""+remainingPercentage+"%\" height=\"20px\" /></div>" ;
			}
			
			//document.getElementById('alertText').innerHTML = "Done :"+ done+", Total :"+total;
			
			if(((uploadDone && !processingStarts) || done=="P") && isCompleted>1){
				remainingBox = "<div style=\"width:100%; height:20px;\"><img src=\""+base_Url+"/skins/main/images/account/dot.gif\" width=\"100%\" height=\"20px\" /></div>" ;
				donePercentage = 0;
				//uploadDone=false;
				processingStarts=true;
			}
			
			//alert('remainingPercentage :'+remainingPercentage+', donePercentage'+donePercentage);
			
			bar="<div id=\"proS-bor\"><div style=\"width:"+donePercentage+"%; height: 20px; font-size: 0%; background-image:url("+base_Url+imageUrl+"); float:left;\" ><img src=\""+base_Url+"/skins/main/images/account/dot.gif\" width=\""+donePercentage+"%\" height=\"20px\" /></div>"+remainingBox +"<div style=\"clear: both;\"></div></div>";
			
			return bar;
		
		}

function getBar(done,total,imageUrl)
		{
			//alert('done :'+done+', total'+total+', uploadedCount'+uploadedCount);
			done=done.replace('Processing ','');
			if (uploadedCount==0) return "";
			remainingBox="";
			if (done=="P" || done=="F" || parseInt(done)==parseInt(total))
			{
				remainingPercentage = 0;
				donePercentage = 100;
			}
			else
			{
				remainingPercentage = parseInt((total-done)/total*100);
				donePercentage = parseInt(100-remainingPercentage); 
				remainingBox = "<div style=\"width=:"+remainingPercentage+"%; height:20px; float:left;\" ><img src=\""+base_Url+"/skins/main/images/account/dot.gif\" width=\""+remainingPercentage+"%\" height=\"20px\" /></div>" ;
			}
			
			//document.getElementById('alertText').innerHTML = "Done :"+ done+", Total :"+total;
			
			if(((uploadDone && !processingStarts) || done=="P") && isCompleted>1){
				remainingBox = "<div style=\"width:100%; height:20px;\"><img src=\""+base_Url+"/skins/main/images/account/dot.gif\" width=\"100%\" height=\"20px\" /></div>" ;
				remainingPercentage = 100;
				donePercentage = 0;
				//uploadDone=false;
				processingStarts=true;
			}
			
			//alert('remainingPercentage :'+remainingPercentage+', donePercentage'+donePercentage);
			
			//bar="<div id=\"proS-bor\"><div style=\"width:"+donePercentage+"%; height: 20px; font-size: 0%; background-image:url("+base_Url+imageUrl+"); float:left;\" ><img src=\""+base_Url+"/skins/main/images/account/dot.gif\" width=\""+donePercentage+"%\" height=\"20px\" /></div>"+remainingBox +"<div style=\"clear: both;\"></div></div>";
			bar="<div id=\"proS-bor\"><div class=\"proS-done\" style=\"width:"+donePercentage+"%;\" ><img src=\""+base_Url+"/skins/main/images/account/dot.gif\" width=\""+donePercentage+"%\" height=\"20px\" /></div>"+remainingBox +"<div style=\"clear: both;\"></div></div>";
			
			//newdiv.style.width = "100%";
			
	
			if(uplProcessStatus==false){
				donePercentage = uplPercentage;
				remainingPercentage = parseInt(uplTotal)-parseInt(uplPercentage);
				if( document.getElementById("test") ){				
					document.getElementById("test").innerHTML = "Latest Done :"+donePercentage+", Remain :"+remainingPercentage;
				}
			}
			
			if(newUploadLayer){
			
				if( imageUrl !='' ){
					if(parseInt(donePercentage)>0){
						var bImg = document.getElementById('proS-done-div').style.backgroundImage;
						if(trim(escape(bImg))=="")
							document.getElementById('proS-done-div').style.backgroundImage="url('"+base_Url+imageUrl+"')";
					}else{
						document.getElementById('proS-done-div').style.backgroundImage = "";
						//alert("backgroundImage :"+document.getElementById('proS-done-div').style.backgroundImage); 
					}
				}
				
				document.getElementById("proS-done-div").style.width = donePercentage+"%";
				document.getElementById("proS-done-img").width = donePercentage+"%";
	
				document.getElementById("proS-remain-div").style.width = remainingPercentage+"%";
				document.getElementById("proS-remain-img").width = remainingPercentage+"%";
				
				if(trim(remainingBox)==""){
					displayOff('proS-remain-div');
				} 			
			}
	
			return bar;
		
		}


var uploadstatusUrl = "";
var alreadyInQueue = false;
function checkStatus(val)
{
	if(alreadyInQueue)
		return;
	alreadyInQueue = true;
	if(isCancel==true)
	{
		return false;
	}
	
	uploadstatusUrl = document.getElementById('uploadstatusUrl').value;
	
	var browLoca = document.location+"";
	
	if(browLoca.indexOf(":80/") == -1){
		uploadstatusUrl = uploadstatusUrl.replace(":80/","/");
	}	
	
	if(val=="" || val==undefined){
		uploadstatusUrl += "=0&ajaxCount=0"
	}	
	else{
		if(document.getElementById("upload_file_count")){
			uploadstatusUrl += "="+document.getElementById("upload_file_count").value+"&"+val;			
		}else{
			uploadstatusUrl += val;
		}	
	}	
	
	
	if( uploadDone==true){
		uploadstatusUrl = uploadstatusUrl.replace( "step=upload","step=processing" );
	}
	//alert( uploadstatusUrl );
	//document.getElementById('alertText').innerHTML = uploadstatusUrl;
	simplePost(uploadstatusUrl,"reDrawProegressBar(common_request,"+val+")");
}
var notsmell = false;
var uploadDone = false;
var processingStarts = false;
var isCompleted = 0; 
var isCancel = false;
var iFrameId = "";
var oldStatus = "";
var uplProcessStatus = false;
var uplPercentage = 0;
var uplTotal = 100;

var remainingPercentage = 100;
var donePercentage = 0;
var isPhotoVideo = false;

function reDrawProegressBar(request,isWidget)
{
	if(document.getElementById("ispv")){
		if(document.getElementById("ispv").value == "1"){
			isPhotoVideo = true;
		}
	}
	alreadyInQueue = false;
	var trClassName = "copy12_noul"; 
	if(uploadFromWidget){
		trClassName = "copy12_noul";
	}
	
	if(notsmell){return;};
	
	//alert( request.responseText);
	//document.getElementById('alertText').innerHTML = request.responseText;
	var responseArray = request.responseText.split(";");
    currentCount = responseArray[0];   
    uploadedCount = responseArray[1];   
	currentStatus = responseArray[2];	
	
	if(isWidget){
		currentStatus = currentStatus.replace( adminBaseUrl,base_Url); 
	}
	
	if( currentCount=='P' ){
		uploadDone = true;
	}
	
	if(currentCount=='null' && currentCount!='F'){
		var subTextVal = currentStatus;
		var ofIndex = trim(subTextVal).indexOf("of");
		if(ofIndex!=-1){
			currentCount = subTextVal.substring(0,ofIndex);
		}
	}
	
	currentUploadPerc = responseArray[3];
	
	if(currentUploadPerc==undefined){
		uplProcessStatus = true;
		remainingPercentage = 100;
		donePercentage = 0;		
	}else{
		uplPercentage = currentUploadPerc;
	}
	
	
	val = "="+currentCount+"&ajaxCount="+(new Date()).getTime();
	
	if (currentCount==0 && currentStatus.indexOf('uploaded') !=-1)
	{
		//currentStatus = "Processing 0 of "+uploadedCount+" files<img src='skins/main/images/account/upload/e_ani.gif'>";
		//currentStatus = "We're uploading your files now <img src='skins/main/images/account/upload/e_ani.gif'>";
		currentStatus = "<p>We're uploading your files now<img src='"+base_Url+"/skins/main/images/account/upload/e_ani.gif'/></p>";
	}
	
	var uploadNewLayer = false;
	var uploadLimit = "5GB";
	if(isWidget) uploadLimit = "250MB";
	
	if(uploadedCount==0 && trim(currentStatus)=="Your upload failed to complete.  Please try again."){
		if(!isWidget){
			currentStatus = "<font color='red'>You cannot upload more than "+uploadLimit+".<br />";
			currentStatus += "Please select under "+uploadLimit+" and upload again.";	
			currentStatus += "</font>";
		}else{
			//uploadNewLayer = true;
			currentStatus = "<font color='red'>You can't upload more than 250 MB. Please reduce the size of your upload and try again.</font>";
			//displayOn('cgp-id-page-itemsaved');
			//document.getElementById('errorTextMsg').innerHTML = "You can't upload more than 100 MB. Please reduce the size of your upload and try again.";
			//clearProcessingStatus();
		}
	}	
	else if (uploadedCount==0)
	{
		//currentStatus = "<br><B><font color='red'>No files were uploaded.  Please try again.</font><b>";
		if(!isWidget){
			currentStatus = "<p><font color='red'>Please select a file.</font><p>";
		}		
	}
	document.getElementById("processingStatus").style.display = 'block';
	
	if(uploadFromWidget && document.getElementById('progressbarstatuscontrol')){
		alignPageCenter('progressbarstatuscontrol');
	}
	
	//alert('currentStatus :'+currentStatus);
	
	//var procstat = document.getElementById("processingStatus");
	var processContent = "";
	
	
	if(!isWidget){
			


		var getProgressBarWidget = "";
		if(((uploadDone && !processingStarts) || currentCount=="P")){
			isCompleted++;
		}
		if(((uploadDone && !processingStarts) || currentCount=="P") && isCompleted>1){			
			currentStatus="Now optimizing the files you uploaded";
			//getProgressBarWidget = "<center>"+getBar(currentCount,uploadedCount,'/skins/main/images/account/widget_upload_bar.gif')+"</center><center>Now optimizing the files you uploaded</center><br />";
			uploadstatusUrl = uploadstatusUrl.replace( "step=upload","step=processing" );
		}
		//getProgressBarWidget = getBar(currentCount,uploadedCount,'/skins/main/images/account/upload_bar.gif');//+"<p>"+currentStatus+"</p>";
		getProgressBarWidget = getBar(currentCount,uploadedCount,'/skins/main/images/account/upload_bar.gif');//+"<p>"+currentStatus+"</p>";
		if(currentStatus.indexOf("been uploaded")!=-1 
			&& currentStatus.indexOf("upload/e_ani.gif")==-1 ){
			currentStatus +=   "<img src='"+base_Url+"/skins/main/images/account/upload/e_ani.gif'/>";
		}
		if( escape(trim(oldStatus)) != escape(trim(currentStatus)) ){
			try{
				document.getElementById("proS-status").innerHTML = currentStatus;
			}catch(e){}
			oldStatus = currentStatus;
		}
		
	}else{
	
		var getProgressBarWidget = "";
		
		if(((uploadDone && !processingStarts) || currentCount=="P")){
			isCompleted++;
		}
		
		if(((uploadDone && !processingStarts) || currentCount=="P") && isCompleted>1){			
			currentStatus="Now optimizing the files you uploaded";
			//getProgressBarWidget = "<center>"+getBar(currentCount,uploadedCount,'/skins/main/images/account/widget_upload_bar.gif')+"</center><center>Now optimizing the files you uploaded</center><br />";
			uploadstatusUrl = uploadstatusUrl.replace( "step=upload","step=processing" );
		}else{
			
			//getProgressBarWidget = "<center>"+getBar(currentCount,uploadedCount,'/skins/main/images/account/widget_upload_bar.gif')+"</center><center>"+currentStatus+"</center><br />";
		}

		var projectSiteId = 2;
		if(document.getElementById("projectSiteId")){
			projectSiteId = document.getElementById("projectSiteId").value;
		}
		
		if(parseInt(projectSiteId) == 2){
			getProgressBarWidget = getBar(currentCount,uploadedCount,'/skins/main/images/account/widget_upload_bar.gif');//+"<p>"+currentStatus+"</p>";
		}else if( parseInt(projectSiteId) == 4){	
			getProgressBarWidget = getBar(currentCount,uploadedCount,'/skins/main/images/diy/widget_upload_bar.gif');//+"<p>"+currentStatus+"</p>";
		}else{
			getProgressBarWidget = getBar(currentCount,uploadedCount,'');//+"<p>"+currentStatus+"</p>";	
		}
		

		if(currentStatus.indexOf("been uploaded")!=-1 
			&& currentStatus.indexOf("upload/e_ani.gif")==-1 ){
			currentStatus +=   "<img src='"+base_Url+"/skins/main/images/account/upload/e_ani.gif'/>";
		}

		
		if( escape(trim(oldStatus)) != escape(trim(currentStatus)) ){
			try{
				document.getElementById("proS-status").innerHTML = currentStatus;
			}catch(e){}
			oldStatus = currentStatus;
		}	
		}
		/*
		getProgressBarWidget = getBar(currentCount,uploadedCount,'/skins/main/images/account/widget_upload_bar.gif')+"<p>"+currentStatus+"</p>";
		document.getElementById("uploadStatusTD").innerHTML = "";
		document.getElementById("uploadStatusTD").innerHTML = getProgressBarWidget;
		*/
		//old code document.getElementById("uploadStatusTD").appendChild(getProgressBarWidget);
		
	//}
	
	/* Exist admin code now admin and public pages use ths same popup
	if(!isWidget){
	
		document.getElementById("uploadStatusBar").innerHTML = "";
		
		var newdiv = document.createElement("div");
		newdiv.setAttribute('id','processingStatus');
		newdiv.setAttribute('align','center');		
		newdiv.style.width = "100%";
		newdiv.className = 	"copy12_noul";	
		newdiv.style.zIndex = "40000";
		newdiv.innerHTML = processContent;
		document.getElementById("uploadStatusBar").appendChild(newdiv);
	}
	*/	
	
	/*if (currentCount!="F")
			{
				setTimeout('checkStatus()',1000);
			}
			else 
			{
				updateUploadedObjects();
			}*/
			if(currentCount=="F")
			{
				alreadyInQueue = true;
			}
			if (currentCount!="F")
			{
				//setTimeout('checkStatus('+isWidget+')',1000);
			}
			else 
			{
				//alert(isWidget);
				if(request.responseText.indexOf("<br>")!=-1)
				{	
						notsmell = true;
						try{
							//document.getElementById('canbutton').style.display = 'block';
						}catch(e){}
				}
				else if(!isWidget){
					if(uploadedCount==0 || trim(currentStatus)=="Your upload failed to complete.  Please try again."){
						try{
							//document.getElementById('canbutton').style.display = 'block';
						}catch(e){}
					}else{
						updateUploadedObjects();
					}
				}else{
					if(document.getElementById('afterUpload'))
					{
						if(uploadedCount==0 || trim(currentStatus)=="Your upload failed to complete.  Please try again."){
							try{
								//document.getElementById('canbutton').style.display = 'block';
							}catch(e){}
						}else{
							if(isPhotoVideo){
								updatePhotoVideoMetaData();
							}else{
							
							
								// clear cookie
								if( document.getElementById('gProjectType') && document.getElementById('gProjectType').value=='8' ){
									SNI.Community.Widgets.Delete_Cookie('USER_TITLE', '/', '');
									SNI.Community.Widgets.Delete_Cookie('USER_DESC', '/', '');
									SNI.Community.Widgets.Delete_Cookie('USER_TAGS', '/', '');
									SNI.Community.Widgets.Delete_Cookie('USER_SPACE', '/', '');
									//alert('Before photoVidoeEventLog :');
									photoVidoeEventLog();
									
									delete_nour_preserveData();
								}
								else{
									document.location = document.getElementById('afterUpload').value;
								}
							}
						}
						//uploadStatusTD
					}
					else{
						//alert('Inside Else After Upload');
						if(uploadedCount==0 || trim(currentStatus)=="Your upload failed to complete.  Please try again."){
							try{
								//document.getElementById('canbutton').style.display = 'block';
							}catch(e){}
						}else{
							
							document.location = base_Url+"/collectionafterupload.do?uid="+uploadId+"&wid="+document.getElementById('wid').value+"&cid="+document.getElementById('cid').value;
							//alert( document.location );
						}						
					}	
				}
			}
	setTimeout('checkStatus('+isWidget+')',1000);
}

function clearProcessingStatus()
{
	if(uploadFromWidget){
		isCancel = true;
		displayOff('progressbarstatuscontrol');
		displayOff('processingStatus');
		displayOff('grey_background');
		try{document.getElementById(iFrameId).document.execCommand('Stop');}catch(e){}
		try{document.getElementById(iFrameId).window.stop();}catch(e){}
		
		for( var i=0;i<11;i++){
			try{
				document.getElementsByName('up-search'+i)[0].value = "";
			}catch(e){}
		}
		
		/*
		var img = "<img src='"+base_Url+"/deleteuploaded.do?uid="+uploadId+"' style='display:none'>";
		document.getElementsByTagName('head')[0].innerHTML += img;
		*/
		var delUrl = base_Url+"/deleteuploaded.do?uid="+uploadId;
		simplePost(delUrl,"afterUploadCancel()");
	
	}else{
		layerOn('grey_background');
		displayOff('progressbarstatuscontrol');
		displayOff('processingStatus');
		receive_upload_id();
		displayOn('a1_upload');
	}	
}

function afterUploadCancel(){
	
	if( document.getElementById('gProjectType') && document.getElementById('gProjectType').value=='8' ){
		
		// write the cookies
		
		var user_title = document.getElementById('caption').value;
		var user_description = document.getElementById('desc').value;
		var user_tags = document.getElementById('public_tags').value;
		var typeOfSpace = '';
		
		if( document.getElementById('spacetypelist') )
			typeOfSpace = document.getElementById('spacetypelist').value;
		
		SNI.Community.Widgets.Set_Cookie( "USER_TITLE",user_title, '365', '/', '', '' );
		SNI.Community.Widgets.Set_Cookie( "USER_DESC",user_description, '365', '/', '', '' );
		SNI.Community.Widgets.Set_Cookie( "USER_TAGS",user_tags, '365', '/', '', '' );
		SNI.Community.Widgets.Set_Cookie( "USER_SPACE",typeOfSpace, '365', '/', '', '' );
		
		
		preserverNoURUserInputs();
			
		
		var a = document.location + "";
		if(a.indexOf("#")!=-1)
			a = a.substring(0,a.indexOf("#"));
		if( a.indexOf("iscancel")==-1 )
			document.location = a+"?iscancel=true";
		else
			document.location = a;
		
	}
	else{
		
		var a = document.location + "";
		if(a.indexOf("#")!=-1)
			a = a.substring(0,a.indexOf("#"));
		document.location = a;
	}
}


function preserverNoURUserInputs(){
	
	// delete old and load again
	delete_nour_preserveData();
	
	if( document.getElementById('userEmail_txt') && document.getElementById('userEmail_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "userEmail_txt",document.getElementById('userEmail_txt').value, '365', '/', '', '' );
			
	if( document.getElementById('displayName_txt') && document.getElementById('displayName_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "displayName_txt",document.getElementById('displayName_txt').value, '365', '/', '', '' );
		
	if( document.getElementById('firstName_txt') && document.getElementById('firstName_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "firstName_txt",document.getElementById('firstName_txt').value, '365', '/', '', '' );		

	if( document.getElementById('lastName_txt') && document.getElementById('lastName_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "lastName_txt",document.getElementById('lastName_txt').value, '365', '/', '', '' );		

	if( document.getElementById('streetAddress_txt') && document.getElementById('streetAddress_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "streetAddress_txt",document.getElementById('streetAddress_txt').value, '365', '/', '', '' );		

	if( document.getElementById('streetAddress2_txt') && document.getElementById('streetAddress2_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "streetAddress2_txt",document.getElementById('streetAddress2_txt').value, '365', '/', '', '' );		

	if( document.getElementById('city_txt') && document.getElementById('city_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "city_txt",document.getElementById('city_txt').value, '365', '/', '', '' );		

	if( document.getElementById('state_txt') && document.getElementById('state_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( "state_txt",document.getElementById('state_txt').value, '365', '/', '', '' );		
	if( document.getElementById('statelist') && document.getElementById('statelist').value !='' )
		SNI.Community.Widgets.Set_Cookie( "statelist",document.getElementById('statelist').value, '365', '/', '', '' );	

	if( document.getElementById('country_txt') && document.getElementById('country_txt') !='' )
		SNI.Community.Widgets.Set_Cookie( "country_txt",document.getElementById('country_txt').value, '365', '/', '', '' );		
	if( document.getElementById('countrylist') && document.getElementById('countrylist') !='' )
		SNI.Community.Widgets.Set_Cookie( "countrylist",document.getElementById('countrylist').value, '365', '/', '', '' );
		
	if( document.getElementById('zipCode_txt') && document.getElementById('zipCode_txt') !='' )
		SNI.Community.Widgets.Set_Cookie( 'zipCode_txt',document.getElementById('zipCode_txt').value, '365', '/', '', '' );		

	if( document.getElementById('phone_txt') && document.getElementById('phone_txt') !='' )
		SNI.Community.Widgets.Set_Cookie( 'phone_txt',document.getElementById('phone_txt').value, '365', '/', '', '' );		

	if( document.getElementById('phone2_txt') && document.getElementById('phone2_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'phone2_txt',document.getElementById('phone2_txt').value, '365', '/', '', '' );		

	if( document.getElementById('gender_txt') && document.getElementById('gender_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'gender_txt',document.getElementById('gender_txt').value, '365', '/', '', '' );
	if( document.getElementById('genderlist') && document.getElementById('genderlist').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'genderlist',document.getElementById('genderlist').value, '365', '/', '', '' );		
			
	if( document.getElementById('aboutme_txt') && document.getElementById('aboutme_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'aboutme_txt',document.getElementById('aboutme_txt').value, '365', '/', '', '' );	
	
	if( document.getElementById('custom_txt') && document.getElementById('custom_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'custom_txt',document.getElementById('custom_txt').value, '365', '/', '', '' );
		
	if( document.getElementById('custom2_txt') && document.getElementById('custom2_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'custom2_txt',document.getElementById('custom2_txt').value, '365', '/', '', '' );	
	
	
	// drop down fields
	if( document.getElementById('month_txt') && document.getElementById('month_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'month_txt',document.getElementById('month_txt').value, '365', '/', '', '' );
	if( document.getElementById('monthlist') && document.getElementById('monthlist').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'monthlist',document.getElementById('monthlist').value, '365', '/', '', '' );

	if( document.getElementById('date_txt') && document.getElementById('date_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'date_txt',document.getElementById('date_txt').value, '365', '/', '', '' );
	if( document.getElementById('datelist') && document.getElementById('datelist').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'datelist',document.getElementById('datelist').value, '365', '/', '', '' );

	if( document.getElementById('year_txt') && document.getElementById('year_txt').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'year_txt',document.getElementById('year_txt').value, '365', '/', '', '' );
	if( document.getElementById('yearlist') && document.getElementById('yearlist').value !='' )
		SNI.Community.Widgets.Set_Cookie( 'yearlist',document.getElementById('yearlist').value, '365', '/', '', '' );
		
		var ids= '';
		var nameArr = document.getElementsByTagName("input");
		for( var i=0;i<nameArr.length;i++){
			var obj = nameArr[i];
			if ( obj.type=="checkbox" && obj.name=="hgtv-ideas" ){
				if( obj.checked == true )
					ids += obj.id + ",";
			}
		}
		//alert ( ids );
		SNI.Community.Widgets.Set_Cookie( 'opinidlist',ids, '365', '/', '', '' );				
}

function delete_nour_preserveData(){
	
	SNI.Community.Widgets.Delete_Cookie('userEmail_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('displayName_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('firstName_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('lastName_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('streetAddress_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('streetAddress2_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('zipCode_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('phone_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('phone2_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('aboutme_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('custom_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('custom2_txt', '/', '');
	SNI.Community.Widgets.Delete_Cookie('opinidlist', '/', '');
}
var globalVal;
var newUploadLayer = false;
function showProgress(isFirst,val)
{
	if(isCancel==true)
	{
		notsmell = true;
		return false;
	}else
		notsmell = false;

	if(document.getElementById('proS-done-div')){
		newUploadLayer = true;
	}
			
	if(uAgent.indexOf("MSIE 6.0") != -1){
		if(newUploadLayer){
			document.getElementById('proS-done-div').style.height = "19.5px";
			document.getElementById("proS-done-img").height = "19.5px";
		}	
	}

	try{
		layerOn('grey_background');
	}catch(e){}
	
	document.getElementById("processingStatus").style.display = 'block';
	document.getElementById('progressbarstatuscontrol').style.zIndex = "10000";
	document.getElementById('proS-done-div').style.backgroundImage = "";
	alignPageCenter('progressbarstatuscontrol');		
	document.getElementById('progressbarstatuscontrol').style.display = "block";
	checkStatus(val);
	setTimeout('checkStatus('+val+')',10000)
	
}
function alignPageCenter(objId)
{
	try{
		//document.body.appendChild(document.getElementById(objId));
		document.getElementById(objId).style.position = "absolute";
		var obj_left = (screen.width/4) ;
		var obj_top = (screen.height/4) ;
		var obj_top2 = (screen.height/2);
		if(objId=='a1_upload'){
			document.getElementById(objId).style.top = obj_top - 90;
			document.getElementById(objId).style.left = obj_left - 50;
		}
		else// if(objId=='progressbarstatuscontrol')
		{	
			document.getElementById('progressbarstatuscontrol').style.top = (obj_top+100)+"px";
			//document.getElementById(objId).style.left = obj_left - 50;
		}
		//else{
		//	document.getElementById(objId).style.top = obj_top;
		//	document.getElementById(objId).style.left = obj_left;
		//}
	}catch(e){alert(e);}	
}

function alignPageCenterWidget(objId)
{
	document.body.appendChild(document.getElementById(objId));
	document.getElementById(objId).style.position = "absolute";
	//alert(document.getElementById(objId).offsetWidth);
	var obj_Height = document.getElementById(objId).offsetHeight;
	var obj_Width = document.getElementById(objId).offsetWidth;
	//alert('obj_Height :'+obj_Height+' obj_Width :'+obj_Width);
	
	var obj_left = (screen.width/2) - (obj_Width/2);
	var obj_top = (screen.height/2) - (obj_Height/2);
	
	document.getElementById(objId).style.top = obj_top+"px";
	document.getElementById(objId).style.left = obj_left+"px";
}


var uploadFromWidget = false;
 function uploadCompleted(val,upfrom)
{
	uploadFromWidget = upfrom;
	if(!isCancel)
	{ 
		var a = document.location+"";
		if(document.getElementById('a1_upload')){
			document.getElementById('a1_upload').style.display = "none";
		}
		showProgress(true,val);
	}
}

function updatePhotoVideoMetaData(){
	//document.getElementById(
	var pvSyatemTag = "N/A";
	var pvCaption = "N/A";
	var userTagList="N/A";
	var objectText = "N/A";
	var pvUplaodId = "0";
	
	if(document.getElementById("pvuid")){
		pvUplaodId = document.getElementById("pvuid").value;
	}
	
	if(document.getElementById("spacetypelist")){
		pvSyatemTag = document.getElementById("spacetypelist").value; 
	}
	
	if(document.getElementById("caption")){
		pvCaption = document.getElementById("caption").value;
	}
	
	if(document.getElementById("public_tags")){
		userTagList = document.getElementById("public_tags").value;
	}
	
	if(document.getElementById("desc")){
		objectText = document.getElementById("desc").value;
	}	
	
	var uploadNonUr = "false";
	if(document.getElementById("uploadNonUr")){
		uploadNonUr = document.getElementById("uploadNonUr").value;
	}
		
	var para = "";
	var displayName="";
	var emailAddress="";
	para += pvSyatemTag;
	para += "<PICKLESEPERATOR>"+pvCaption;
	para += "<PICKLESEPERATOR>"+userTagList;
	para += "<PICKLESEPERATOR>"+objectText;
	if(uploadNonUr=="true"){
		if(document.getElementById("displayName_txt")){
			displayName = document.getElementById("displayName_txt").value; 
		}
		if(document.getElementById("userEmail_txt")){
			emailAddress = document.getElementById("userEmail_txt").value; 
		}
		para += "<PICKLESEPERATOR>"+displayName;
		para += "<PICKLESEPERATOR>"+emailAddress;
	}	
	para += "<PICKLESEPERATOR>"+pvUplaodId;

	if(uploadNonUr=="true"){
		var url= "/editsaveobjects.do?query=PV_EDIT_META_DATA_NONUR&query_val="+escape(para);
		simplePost(url,"updatePhotoVideoUserInfo()");
	}else{
		var url= "/editsaveobjects.do?query=PV_EDIT_META_DATA&query_val="+escape(para);	
		simplePost(url,"photoVideoAfterUpload()");
	}	
}

function photoVideoAfterUpload(){
	document.location = document.getElementById('afterUpload').value;
}

function synChronousPost(url, passData) {
  if (window.XMLHttpRequest) {              
    AJAX=new XMLHttpRequest();              
  } else {                                  
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
    AJAX.open("POST", url, false);
    AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    AJAX.send(passData);
    return AJAX.responseText;                                         
  } else {
     return false;
  }                                             
}


function photoVidoeEventLog(){
	var url= "/p2_pveventlog.do?spacetypelist="+escape(SNI.Community.Widgets.fbPVCategory)+"&wid="+SNI.Community.Widgets.fbPVWidgetId+"&oid="+SNI.Community.Widgets.fbPVObjectId;
	simplePost(url,"photoVideoAfterUpload()");	
}


function updatePhotoVideoUserInfo()
{
	//alert("here");
	var emailAddress = "";
	var DisplayName = "";
	var FirstName="";
	var LastName = "";
	var StreetAddress1 = "";
	var StreetAddress2 = "";
	var City = "";
	var State = "";
	var Country = "";
	var ZipCode = "";
	var Phone1 = "";
	var Phone2 = "";
	var month = "";
	var date = "";
	var year = "";
	var Gender = "";
	var AboutMe = "";
	var Customtxt1="";
	var Customtxt2="";
	var  urlst="";
	var optCount=0;
	var pvuid="";
	var originalprojectId="";
	var userid="";
	/*var userInfoArray=new Array('userEmail_txt','displayName_txt','firstName_txt','lastName_txt','streetAddress_txt','streetAddress2_txt','city_txt','state_txt','country_txt','zipCode_txt');
	var urlst=""
	
	
	for(i=0;i<userInfoArray.length;i++)
	{
		var userInfoArray[i]="";
		if(document.getElementById(userInfoArray[i])){
			userInfoArray[i] = document.getElementById(userInfoArray[i]).value;
		alert(userInfoArray[i]);
		}
		urlst+=userInfoArray[i]=escape(userInfoArray[i]);
	}*/
	
	if(document.getElementById("userEmail_txt")){
		emailAddress = document.getElementById("userEmail_txt").value;
		urlst="userEmail_txt="+escape(emailAddress);
		//alert("emailAddress :"+emailAddress);
	}
	
	if(document.getElementById("displayName_txt")){
		DisplayName = document.getElementById("displayName_txt").value; 
		urlst+="&displayName_txt="+escape(DisplayName);
		//alert("DisplayName :"+DisplayName);
	}
	
	if(document.getElementById("firstName_txt")){
		FirstName = document.getElementById("firstName_txt").value;
		urlst+="&firstName_txt="+escape(FirstName);
		//alert("FirstName :"+FirstName);
	}
	
	if(document.getElementById("lastName_txt")){
		LastName = document.getElementById("lastName_txt").value;
		urlst+="&lastName_txt="+escape(LastName);
		//alert("LastName :"+LastName);
	}
	
	if(document.getElementById("streetAddress_txt")){
		StreetAddress1 = document.getElementById("streetAddress_txt").value;
		urlst+="&streetAddress_txt="+escape(StreetAddress1);
		//alert("StreetAddress1 :"+StreetAddress1);
	}	
	
	if(document.getElementById("streetAddress2_txt")){
		StreetAddress2 = document.getElementById("streetAddress2_txt").value;
		urlst+="&streetAddress2_txt="+escape(StreetAddress2);
			//alert("StreetAddress2 :"+StreetAddress2);
	}	
	
	if(document.getElementById("city_txt")){
		City = document.getElementById("city_txt").value;
		urlst+="&city_txt="+escape(City);
			//alert("City :"+City);
	}	
	
	if(document.getElementById("state_txt")){
		State = document.getElementById("state_txt").value;
		urlst+="&state_txt="+escape(State);
			//alert("State :"+State);
	}	
	
	if(document.getElementById("country_txt")){
		Country = document.getElementById("country_txt").value;
		urlst+="&country_txt="+escape(Country);
		//alert("Country :"+Country);
	}	
	
	if(document.getElementById("zipCode_txt")){
		ZipCode = document.getElementById("zipCode_txt").value;
		urlst+="&zipCode_txt="+escape(ZipCode);
		//alert("ZipCode :"+ZipCode);
	}	
	
	if(document.getElementById("phone_txt")){
		Phone1 = document.getElementById("phone_txt").value;
		urlst+="&phone_txt="+escape(Phone1);
		//alert("Phone1 :"+Phone1);
	}	
	
	if(document.getElementById("phone2_txt")){
		Phone2 = document.getElementById("phone2_txt").value;
		urlst+="&phone2_txt="+escape(Phone2);
		//alert("Phone2 :"+Phone2);
	}	
	
	if(document.getElementById("month_txt")){
		month = document.getElementById("month_txt").value;
		urlst+="&month_txt="+escape(month);
		//alert("month :"+month);
	}	
	
	if(document.getElementById("date_txt")){
		date = document.getElementById("date_txt").value;
		urlst+="&date_txt="+escape(date);
		//alert("date :"+date);
	}	
	
	if(document.getElementById("year_txt")){
		year = document.getElementById("year_txt").value;
		urlst+="&year_txt="+escape(year);
		//alert("year :"+year);
	}	
	
	if(document.getElementById("gender_txt")){
		Gender = document.getElementById("gender_txt").value;
		urlst+="&gender_txt="+escape(Gender);
		//alert("Gender :"+Gender);
	}	
	
	if(document.getElementById("aboutme_txt")){
		AboutMe = document.getElementById("aboutme_txt").value;
		urlst+="&aboutme_txt="+escape(AboutMe);
		//alert("AboutMe :"+AboutMe);
	}	
	if(document.getElementById("custom_txt")){
		Customtxt1 = document.getElementById("custom_txt").value;
		urlst+="&custom_txt="+escape(Customtxt1);
		//alert("Customtxt1 :"+Customtxt1);
	}	
	
	if(document.getElementById("custom2_txt")){
		Customtxt2 = document.getElementById("custom2_txt").value;
		urlst+="&custom2_txt="+escape(Customtxt2);
		//alert("Customtxt2 :"+Customtxt2);
	}
	
	if(document.getElementById("optCount")){
		optCount = document.getElementById("optCount").value;
		urlst+="&optCount="+escape(optCount);
		//alert("optCount :"+optCount);
	}
	
	for(i=0;i<optCount;i++)
	{
		urlst+="identifier"+i+"="+document.getElementById("identifier"+i).value;
	}
	
	if(document.getElementById("pvuid")){
		pvuid = document.getElementById("pvuid").value;
		urlst+="&pvuid="+escape(pvuid);
		//alert("pvuid :"+pvuid);
	}
	
	if(document.getElementById("userid")){
		userid = document.getElementById("userid").value;
		urlst+="&userid="+escape(userid);
		//alert("userid :"+userid);
	}
	
	if(document.getElementById("originalprojectId")){
		originalprojectId = document.getElementById("originalprojectId").value;
		urlst+="&originalprojectId="+escape(originalprojectId);
		//alert("originalprojectId :"+originalprojectId);
	}
	
	
	var url= "/pvcreatuserinfo.do?"+urlst;
	//var name=prompt("url",url);
	simplePost(url,"photoVideoAfterUpload()");
}

function updateUploadedObjects()
{
	var collectionId = 0;
	if(getParameter("collectionId"))
		collectionId = parseInt(getParameter("collectionId"));
	else
		collectionId = parseInt(document.getElementById('objectId').value);
	var url = "changestatusaction.do?obid="+collectionId+"&obstatl=2&obtype=collection";
	
	//simplePost(url,"callEditSaveObjects("+collectionId+")");
	callEditSaveObjects(collectionId);
}

function callEditSaveObjects(colId){
	var para = "";

	if(document.getElementById('upload_taglist'))
	{
		para += document.getElementById('upload_taglist').value;
	}else{
		para += "N/A";
	}

	if(document.getElementById('object_producer'))
	{
		if(trim(document.getElementById('object_producer').value).length == 0)
			para += "<PICKLESEPERATOR>0";
		else
			para += "<PICKLESEPERATOR>"+document.getElementById('object_producer').value;
	}else{
		para += "<PICKLESEPERATOR>0";
	}
	if(document.getElementById('select_object_state'))
	{
		para += "<PICKLESEPERATOR>"+document.getElementById('select_object_state').value;
	}else{
		para += "<PICKLESEPERATOR>0";
	}
	if(document.getElementById('uid'))
	{
		para += "<PICKLESEPERATOR>"+document.getElementById('uid').value;
	}else{
		para += "<PICKLESEPERATOR>N/A";
	}
	try{
		document.getElementById('a1_upload').style.display = "none";
	}catch(e){}

	var url= "/editsaveobjects.do?query=POST_UPLOAD_QUERY&query_val="+escape(para);
	simplePost(url,"dochangefeatureitem("+colId+")");
}
function dochangefeatureitem(colId)
{
var url= "/editsaveobjects.do?query=UPDATE_FEATURED_ITEM&query_val="+colId+"<PICKLESEPERATOR>";
//alert( url );
simplePost(url,"doA2AfterUpload("+colId+")");
}




function doA2AfterUpload(colId)
{
	//var url= "/editsaveobjects.do?query=UPDATE_FEATURED_ITEM&query_val="+colId+"<PICKLESEPERATOR>";
	//var name=prompt("doa2after",url)
	//simplePost(url,"");
	//var name1=prompt("url in doA2AfterUpload : "+url);
	//var url = base_Url+"/detailedEdit.do?uid="+document.getElementById('uid').value+"&pId="+getParameter("pId")+"&loc_return="+escape((document.location+"").replace(/&forceCache=true/g, ""));;
	//window.location = url;
	var objectType;
	var documentUrl=(document.location+"").replace(/&forceCache=true/g, "");
	var url = base_Url+"/detailedEdit.do?uid="+document.getElementById('uid').value+"&pId="+getParameter("pId");
	if ( document.getElementById('upload_taglist_coll')!=null ){
		url += "&tags="+document.getElementById('upload_taglist_coll').value;
	}
	else if ( document.getElementById('upload_taglist')!=null ){
		url += "&tags="+document.getElementById('upload_taglist').value;
	}
	
	url +="&collectionName="+document.getElementById('uploadCaption_lbl').innerHTML;	
	if(document.getElementById('setObjectType'))//To display the relevant Tab in A1 Page
	{	
		documentUrl=(document.location+"").replace(/&forceCache=true/g, "");
		objectType=document.getElementById('setObjectType').value;
		if(documentUrl.indexOf("&ot")!=-1)
		{
			documentUrl = documentUrl.substring(0,documentUrl.indexOf("&ot"));
		}
		url +="&loc_return="+escape(documentUrl+"&ot="+objectType);
	}else
	{
		url +="&loc_return="+escape(documentUrl);
	}
	//url +="&loc_return="+escape((document.location+"").replace(/&forceCache=true/g, "")+"&ot=2");
	//alert(url);
	//var name2=prompt("url in doA2AfterUpload+detailedEdit : "+url);
	window.location = url;
}



function edit_items(obj){
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	var total_to_edit = new Array();
	for(i=0;i<total_selected_objs.length;i++)
	{
		if(total_selected_objs[i].checked )
		{ 
			total_to_edit[total_to_edit.length] =  total_selected_objs[i].value;
		}
	}
	if(total_to_edit.length>0)
	{
		var temp_url = document.location+"";
		if(temp_url.indexOf("?")!=-1)
		{
			temp_url = temp_url.substring(temp_url.indexOf("?")+1,temp_url.length);
		}
		var url = base_Url+"/detailedEdit.do?form=edittags&odl="+total_to_edit+"&"+temp_url+"&loc_return="+escape((document.location+"").replace(/&forceCache=true/g, ""));;
		//obj.href = url;
		window.location = url;
	}
	else{
		alert("Please select an item to edit.");
	}
}

function collection_edit_items(obj){
	
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	var total_to_edit = new Array();
	for(i=0;i<total_selected_objs.length;i++)
	{
		if(total_selected_objs[i].checked )
		{ 
			total_to_edit[total_to_edit.length] =  total_selected_objs[i].value;
		}
	}
	if(total_to_edit.length>0)
	{
		var temp_url = document.location+"";
		if(temp_url.indexOf("?")!=-1)
		{
			temp_url = temp_url.substring(temp_url.indexOf("?")+1,temp_url.length);
		}
		var url = base_Url+"/detailedEdit.do?form=edittags&page=collections&odl="+total_to_edit+"&"+temp_url+"&loc_return="+escape((document.location+"").replace(/&forceCache=true/g, ""));;
		//obj.href = url;
		window.location = url;
	}
	else{
		alert("Please select an item to edit.");
	}
}

function cms_edit_items(obj){
	
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	var total_to_edit = new Array();
	for(i=0;i<total_selected_objs.length;i++)
	{
		if(total_selected_objs[i].checked )
		{ 
			total_to_edit[total_to_edit.length] =  total_selected_objs[i].value;
		}
	}
	if(total_to_edit.length>0)
	{
		var temp_url = document.location+"";
		if(temp_url.indexOf("?")!=-1)
		{
			temp_url = temp_url.substring(temp_url.indexOf("?")+1,temp_url.length);
		}
		var url = base_Url+"/cmsEdit.do?odl="+total_to_edit+"&"+temp_url+"&loc_return="+escape((document.location+"").replace(/&forceCache=true/g, ""));;
		//obj.href = url;
		window.location = url;
	}
	else{
		alert("Please select an item to edit.");
	}
}

function cancel_cms_edit(url)
{
	url=base_Url+"/"+url;
	window.location=url;
}

function remove(this_value,from_text)
{
	str = str.replace(/&forceCache=true/g, "");
}

function save_edit_object( obj ){
	var total_edit_objs = document.getElementsByName("save_edit_obj[]");
	var total_to_edit = new Array();
	for(i=0;i<total_edit_objs.length;i++)
	{
		total_to_edit[total_to_edit.length] =  total_edit_objs[i].value;
	}
	document.getElementById("save_edit_action").value = "save";
	document.getElementById("save_edit_object_list_id").value = total_to_edit;
	document.saveedit_form.submit();
}


function save_cms_object( obj ){
	var total_edit_objs = document.getElementsByName("save_edit_obj[]");
	var total_to_edit = new Array();
	for(i=0;i<total_edit_objs.length;i++)
	{
		total_to_edit[total_to_edit.length] =  total_edit_objs[i].value;
	}
	document.getElementById("save_edit_object_list_id").value = total_to_edit;
	document.savecmsedit_form.submit();
}

function cancle_save_edit_object( obj ){
	document.getElementById("save_edit_action").value = "cancel";
	document.saveedit_form.submit();
}
function a3_delete_objects(obj,objectId,cpp)
{
	var pId=0;
	var pid=0;
	if(getParameter("pId")){
		pId = getParameter("pId");
		pId = pId.replace("#","");
	}	
	if(getParameter("pid")){
		pid = getParameter("pid");
		pid = pid.replace("#","");
	}
	
	cpp = base_Url + "/" + cpp;
	var url = base_Url + "/a1deleteobject_p2.do?odl="+objectId+"&pId="+escape(pId)+"&oType=&loc_return="+escape(cpp)+"&collectionId="+pid;
	var name=confirm(ValidatorsM[2]);
	if(name ==true)
	{
		document.location = url;
		//obj.href = url;
	}
}

function coll_widget_delete_objects(obj,objectId,parentObjId,parentObjType,objType)
{
	var cpp = document.location+"&viewall=block";;
	//var url = base_Url + "/a1deleteobject_p2.do?odl="+objectId+"&parentObjectId="+parentObjId+"&parentObjectType="+parentObjType+"&oType=&loc_return="+escape(cpp);
	var url = base_Url + "/a1deleteobject_p2.do?odl="+objectId+"&parentObjectId="+parentObjId+"&parentObjectType="+parentObjType+"&oType="+objType+"&loc_return="+escape(cpp);
	
	var name=confirm(ValidatorsM[2]);
	if(name ==true)
	{
		document.location = url+"&viewall=block";
	}
}

function rotate_objects_detail_edit(obj,rotate_direction)
{

		var total_selected_objs = document.getElementsByName("selected_obj[]");
		var total_to_rotate = new Array();
		var videoStatus=0;
		for(i=0;i<total_selected_objs.length;i++)
		{
			var objId = total_selected_objs[i].value;
			var objtype = document.getElementById("rowtype_"+objId).value;
			if( total_selected_objs[i].checked && objtype == 0 )
				videoStatus = 1;

			if(total_selected_objs[i].checked && objtype == 1 )
			{ 
				total_to_rotate[total_to_rotate.length] =  total_selected_objs[i].value;
			}
		}
		if( videoStatus == 1 ){
			alert("Only photos can be rotated.");
		}
		else if(total_to_rotate.length>0 )
		{
			//showLoading('detail_edit_container');
						
			var url = base_Url + "/rotateobject_p2.do?odl="+total_to_rotate+"&direction="+rotate_direction+"&loc_return="+escape(document.location+"");
			//var url = base_Url + "/rotateobject_p2.do?odl="+total_to_rotate+"&direction="+rotate_direction;
			//obj.href=url;
			
			window.location = url;
		}
		else	
		{
			alert("Please select an item to rotate.");
		}
}



function select_edit_all()
{
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	for(i=0;i<total_selected_objs.length;i++)
	{
		total_selected_objs[i].checked = true;
		highlight_selected_row('therow_'+total_selected_objs[i].value, "#D2FDB7");
	}
}
function deselect_edit_all()
{
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	for(i=0;i<total_selected_objs.length;i++)
	{
		total_selected_objs[i].checked = false;
		highlight_selected_row('therow_'+total_selected_objs[i].value, "#ffffff"); 
	}
}
var currEditObj=null;
var currHidEditObj=null;

function detail_edit_tags_layerOn(menuID)
{
	var oldTags = "";
	var first=0;
	var total_selected_objs = document.getElementsByName("selected_obj[]");
	var total_to_edit = new Array();
	for(i=0;i<total_selected_objs.length;i++)
	{
		if(total_selected_objs[i].checked )
		{ 
			if ( first==0 ){
				oldTags = document.getElementById( "etag_"+total_selected_objs[i].value).value;
				first = 1;
			}
			total_to_edit[total_to_edit.length] =  total_selected_objs[i].value;
		}
	}
	if(total_to_edit.length>0)
	{
		if (document.getElementById) 
		{
			document.getElementById(menuID).style.visibility = 'visible';
			
		}
		else if (document.layers && document.layers[menuID]) 
		{
			document.layers[menuID].visibility = 'visible';
		}
		else if (document.all) 
		{
			document.all[menuID].style.visibility = 'visible';
		}
		currEditObj = "tag_selected";
		if( document.getElementById('detailedEditcollectionFinalTags') !=null ){
			document.getElementById('detailedEditcollectionFinalTags').value="";
		}
	}
	else{
		alert("Please select an item to tag.");
	}
}
function detail_edit_layerOn(menuID,obj){
	currEditObj = document.getElementById(obj);
	currHidEditObj = document.getElementById("disabled_"+obj);

	if (document.getElementById) 
	{
		document.getElementById(menuID).style.visibility = 'visible';
		
	}
	else if (document.layers && document.layers[menuID]) 
	{
		document.layers[menuID].visibility = 'visible';
	}
	else if (document.all) 
	{
		document.all[menuID].style.visibility = 'visible';
	}
	// update the current value
	if( document.getElementById('detailedEditcollectionFinalTags') !=null ){
		document.getElementById('detailedEditcollectionFinalTags').value=currEditObj.value;
	}
}

function detail_edit_apply_selected(){
	
	if( currEditObj != null && currEditObj!="tag_selected"){
		if( document.getElementById('detailedEditcollectionFinalTags') !=null ){
			currEditObj.value = document.getElementById('detailedEditcollectionFinalTags').value;
			currHidEditObj.value = document.getElementById('detailedEditcollectionFinalTags').value;
		}
		currEditObj=null
		currHidEditObj = null;
	}
	else if( currEditObj=="tag_selected"){
		var total_selected_objs = document.getElementsByName("selected_obj[]");
		var total_to_edit = new Array();
		for(i=0;i<total_selected_objs.length;i++)
		{
			if(total_selected_objs[i].checked )
			{ 
				total_to_edit[total_to_edit.length] =  total_selected_objs[i].value;
				var temp = "";
				if( document.getElementById("etag_"+total_selected_objs[i].value).value !=null)
					document.getElementById("etag_"+total_selected_objs[i].value).value += " " + document.getElementById('detailedEditcollectionFinalTags').value;
					document.getElementById("disabled_etag_"+total_selected_objs[i].value).value += " " + document.getElementById('detailedEditcollectionFinalTags').value;
			}
		}
	}
}
function highlight_selected_row(rootCon, color) {
	document.getElementById(rootCon).style.backgroundColor = color;
}

function save_changefeaturephoto_object(obj,collectionId){
	
	var total_save_objs = document.getElementsByName("save_cfp_obj[]");
	var locReturn=document.getElementById("loc_return").value;
	
	var total_to_save=new Array();
	for(i=0;i<total_save_objs.length;i++)
	{
		if(total_save_objs[i].checked)
		{
			
			total_to_save[total_to_save.length]=total_save_objs[i].value;
		}
	}
	//alert(total_to_save);
	if(total_to_save.length>0)
	{
	
		var url = base_Url+"/savechangefeaturephoto.do?sdl="+total_to_save+"&collectionid="+collectionId+"&loc_return="+escape(locReturn);
	
		window.location.href=url;
		
	}else
	{
		alert("Please select an item.");
	}
}




function formatString(str)
  { 
 	str = str.replace(/%0A/g, "<br>");	
 	str = str.replace(/%20/g, "&nbsp;");
 	str = unescape(str);
 	return str;
  }
  
//Formatting the string specially for MS Word 
function formatStringSpecialChars(str)
{
	if(str.length>0)
	{

	str=ConvertSpecialChars(str);
	str=ConvertLatin2ToAsciiChars(str);
	}
	return str;
}

function ConvertSpecialChars(str) 
	{

		if(str.length > 0){	  
		  str = str.replace(new RegExp(String.fromCharCode(8216),"g"),"'");
		  str = str.replace(new RegExp(String.fromCharCode(8217),"g"),"'");
		  str = str.replace(new RegExp(String.fromCharCode(8220),"g"),"\"");
		  str = str.replace(new RegExp(String.fromCharCode(8221),"g"),"\"");

		  return str;	  
		  }
	}


function ConvertLatin2ToAsciiChars(str) 
{

		str = str.replace(/\r\n/g,"\n");

        var utftext = "";

        for (var n = 0; n < str.length; n++) 
        {

            var c = str.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }
       
       return str;
}

/* 
function ConvertAsciiToLatin2Chars(eid, heid) {
    if(document.getElementById(heid) != undefined){	
		utftext = document.getElementById(heid).value;		
		
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

       document.getElementById(eid).innerHTML = string;
       }
    }
  */




function processHTMLLink (str)
{

  var finalHTML = "";
  var tt = str.split(" ");	
  for(i=0;i<tt.length;i++)
  {

  	if(tt[i].indexOf("http://")!=-1 || tt[i].indexOf("www.")!=-1)
  	{
  		finalHTML += "&nbsp;<a href='"+tt[i]+"'>"+tt[i]+"</a>";
   	}else {
  		if(i!=0)
  			finalHTML += " ";
  			
  		finalHTML += tt[i];
  	}
  }
  return finalHTML;
}

function performAfterPost(pos)
{

try{
var descText="";
//alert("you ar in postperform function");
//alert(pos);
if(document.getElementById('objectcaptioncontainer'))
	document.getElementById('objectcaptioncontainer').innerHTML = formatString(document.getElementById('title_field'+pos).value);
if(document.getElementById('labelId'))
	document.getElementById('labelId').innerHTML = formatString(document.getElementById('title_field'+pos).value);
if(document.getElementById('colName'))
	document.getElementById('colName').innerHTML = formatString(document.getElementById('title_field'+pos).value);

	//document.getElementById('objectdesccriptioncontainer').innerHTML = formatString(escape(document.getElementById('desc_field').value));
if(document.getElementById('desc_field'+pos))
{	
	descText=document.getElementById('desc_field'+pos).value;
 	descText=replaceAll(descText,"\n","<br>")
 }
	//document.getElementById('objectdesccriptioncontainer').innerHTML = formatString(document.getElementById('desc_field').value);
	document.getElementById('objectdesccriptioncontainer').innerHTML = formatString(descText);  

 if(document.getElementById('edittitle').style.visibility == "visible" && document.getElementById('edittitle').style.display != "block")
  layerOff('edittitle');
 else
  displayOff('edittitle');
 }catch(e){
 //alert(e.message);
 }
 
 //displayOff('edittitle');
}

function load_a3_page( urlParameter){
	//alert("url:" + urlParameter );
	var url = base_Url + "/" + urlParameter;
	if( document.getElementById('objectcaptioncontainer') != null )
		//url += "&collection_name=" + escape(document.getElementById('objectcaptioncontainer').innerHTML);
		//url += "&collection_name=" + escape(document.getElementById('labelId').innerHTML);
		url += "&collection_name=" + document.getElementById('labelId').innerHTML;
	//alert( "url:" + url );	
	document.location.href = url; 
}

function load_change_diaplay( obj, urlParameter){
	if( document.getElementById("collectionId") !=null){
		document.getElementById("collectionId").value = getParameter("collectionId");
	}
	if( document.getElementById("loc_return") !=null){
		document.getElementById("loc_return").value = document.location;
	}
	if( document.getElementById("pageNumber") !=null){
		document.getElementById("pageNumber").value ="1";
	}
	document.photovideobody.method="POST";   
   	document.photovideobody.action="changeDisplayOrder.do?pId="+getParameter("pId")+"&listIndex="+getParameter("listIndex")+"&channelPno="+getParameter("channelPno");
   	document.photovideobody.submit();
}

function openInNewWindow(url,title,wtype){
	if(wtype == 1){
	var table=document.getElementById('destChannelListTbody');
	//alert( table.rows.length );
	if( table.rows.length <=1 )
	{
		alert("Please select at least one channel.");
		return;
	}
	}
	window.open(url,title);
}
function openWPPreviewWindow(url,title){
	window.open(url,title);
}
function replaceAll(OldString,FindString,ReplaceString)
		{
  		var SearchIndex = 0;
  		var NewString = ""; 
  		while (OldString.indexOf(FindString,SearchIndex) != -1)  
  		  {
    		NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
    		NewString += ReplaceString;
    		SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length);         
 			}
  		NewString += OldString.substring(SearchIndex,OldString.length);
  		return NewString;
	 }
	 
function moderation_change_status(baseUrl, objId,statusId,objectType,collectionId)
{  
 var ie=document.all;
 var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
 
 var url= baseUrl+"/changestatusaction.do?obid="+objId+"&obstatl="+statusId+"&obtype="+objectType+"&collectionId="+collectionId;
 
 request.onreadystatechange=function()
 {
  if(request.readyState==4)
  {
   if(request.status==200)
   {
    var htmlContent = "";
   	if(trim(collectionId)=="0"){
   		htmlContent = "This comment is now archived.";
   		if(trim(statusId)==2){
   			htmlContent = "This comment is now live.";
   		}
   	}else{
   		htmlContent = "This collection is now archived.";
   		if(trim(statusId)==2){
   			htmlContent = "This collection is now live.";
   		}
   	}
   	document.getElementById('processing').innerHTML = htmlContent; 
   }
   else if(request.status==500)
    alert("You found an opportunity for improvement! Please try again later");
   else
    alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
  }
 }
 request.open("POST",url,true);
 request.setRequestHeader("content-type","application/x-www-form-urlencoded");
 request.send(''); 
}	 

function moderation_deleteComments(baseUrl,commentIds,cObjId)
{
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();

	var val = commentIds+"<PICKLESEPERATOR>";
	var updateKey = commentIds ;
	var object_type = "CommentsDAO";
	var url = baseUrl+"/editsaveobjects.do?query=COM_EDIT_DELETE_QUERY&query_val="+escape(val)+"&update_key="+escape(updateKey)+"&object_type="+object_type+"&ht="+cObjId;
	request.onreadystatechange=function()
	{
	 if(request.readyState==4)
	 {
	  if(request.status==200)
	  {
	  	document.getElementById('processing').innerHTML = "This comment has been deleted."; 
	  }
	  else if(request.status==500)
	    alert("You found an opportunity for improvement! Please try again later");
	  else
	    alert("There appears to be a connectivity problem. Please check your internet connection.");
	  }
	 }
	 request.open("POST",url,true);
	 request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	 request.send(''); 
	
}
function a3change_status(total_to_change,statusText,statusId,objectType,collectionId)
		{
			
			var url = "changestatusaction.do?obid="+total_to_change+"&obstatl="+statusId+"&obtype="+objectType+"&collectionId="+collectionId;
			var callBack="reloadBodyForA3DeleteChangeStatus(common_request,'"+statusText+"');"
			simplePost(url,callBack);
		}
		
		function reloadBodyForA3DeleteChangeStatus(request,statusText)
		{
				/*var featureItemBoolean=request.responseXML.getElementsByTagName('isFeatureItem');
				var deleteArr = new Array();
				for(i=0;i<featureItemBoolean.length;i++)
   				{
   					if(featureItemBoolean.item(i).firstChild.nodeValue=="true")
   					{
   						alert("You can't delete a featured item or make its status inactive.\nPlease choose a different featured item before making this change.");
   					}
   					else
   					{
   						alert("The status has been changed to " +statusText+".");
   						document.getElementById('statusid').innerHTML= "<nobr>Status:"+statusText+"</nobr>";
   					}
   				}*/
   				alert("The status has been changed to " +statusText+".");
   				document.getElementById('statusid').innerHTML= "<nobr>Status: "+statusText+"</nobr>";
		}
