function populateproblemcateogry(){
	var desc=document.actiononcase.AvailedProducts;
	var id=Array();

	for(var i=0;i<desc.options.length;i++){
		id[i]=desc.options[i].value;
	}

	var ids=id.join(",");
	var desc=document.actiononcase.problemcategory;
	while(desc.length>1)
	desc.options[1]=null;
	//alert(problemproduct);
	if(ids!=''){
		viewservice("productid="+ids+"&htmlelement=document.actiononcase.problemcategory","./engpopulateproblemcategory.aspx");
	}

}

function viewservice(parameters,url){

	http_requests = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_requests = new XMLHttpRequest();
		if (http_requests.overrideMimeType) {
			http_requests.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_requests = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_requests = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_requests) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_requests.onreadystatechange = processRequestChanges;
	http_requests.open('POST', url, true);
	http_requests.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_requests.setRequestHeader("Content-length", parameters.length);
	http_requests.setRequestHeader("Connection", "close");
	http_requests.send(parameters);
}
function processRequestChanges()
{

	if (http_requests.readyState == 4) {

		if (http_requests.status == 200) {

			var xmldoc = http_requests.responseXML;
			var htmlelement = xmldoc.getElementsByTagName('htmlelement').item(0);
			if(htmlelement)
			{
				var element = htmlelement.childNodes.item(0);
				var desc =element.getAttribute("name");
				var data = xmldoc.getElementsByTagName('data').item(0);

				desc=eval(desc);
				while(desc.length>1){
					desc.options[1]=null;
				}

				if(data.childNodes.length>0){
					for (var iNode = 0,j=0; iNode < data.childNodes.length; iNode++) {
						var node = data.childNodes.item(iNode);
						var optionname=data.childNodes.item(iNode).getAttribute("name");
						var optionid=data.childNodes.item(iNode).getAttribute("id");
						desc.options[(j+1)]=new Option(optionname,optionid);
						j++;
					}
					setproblemcategory();
				}
				document.getElementById('loading').style.visibility="hidden";

			}
			else
			document.getElementById('loading').style.visibility="hidden";

		}
		else
		document.getElementById('loading').style.visibility="hidden";
	}
	else {
		str_output="<table class=bg_grey_band><tr><td><font class=red_font_bold>Loading....</font></td></tr></table>";
		if(document.all)
		{
			document.all["loading"].style.visibility='visible';
			document.all["loading"].innerHTML=str_output;
		}
		if(!document.all && document.getElementById)
		{
			document.getElementById('loading').style.visibility='visible';
			document.getElementById('loading').innerHTML=str_output;
		}

	}

}

function newcase(){
	var customername;
	var customeremail;
	var casestatus;
	var supportengineer;

	var problemsummary=Trim(document.actiononcase.environmentdesc.value);
	var problemdescription=Trim(document.actiononcase.problemdescription.value);
	var int_len1=(Trim(document.actiononcase.environmentdesc.value)).length;
        var int_len2=(Trim(document.actiononcase.problemdescription.value)).length;
	
	if(!check_custenv()){

	}
	else if(!chkdupcusenv())
	{
	}
	/*else if(problemsummary==''){
		alert(str_errormsg_envdesc);
		document.actiononcase.environmentdesc.focus();
	}*/
	else if(int_len1>5000){
                alert(str_errormsg_maxenvdesc);
                document.actiononcase.environmentdesc.focus();
        }
	else if(problemdescription==''){
		alert(str_errormsg_problemdescription);
		document.actiononcase.problemdescription.focus();
	}
        else if(int_len2>5000){
                alert(str_errormsg_maxproblemdescription);
                document.actiononcase.problemdescription.focus();
        }
	else{
		copydata();
		document.actiononcase.submit();
	}

}

function copycustomerdata()
{
        var prd_cnt=eval(document.actiononcase.prd_cnt.value);
        prd_cnt=eval(prd_cnt)+1;
        var cust_env=document.actiononcase.field_cust_env.value;
         var arr_value=Array();
        var arr_values=Array();
        if(cust_env!='')
        {
                var cust_env1=cust_env.split("|");
                var len=cust_env1.length;
                var cust_env2;
                var retval;
                for(j=0;j<prd_cnt-1;j++){
                        for(i=0;i<len;i++){
                                cust_env2=Array();
                                cust_env2=cust_env1[i].split(",");
                                arr_value[i]=get_value(cust_env2,j);
                        }

                arr_values[j]=arr_value.join("&lt;#&gt;");
                }
                str_values=arr_values.join("[#]");
        }
        document.actiononcase.products.value=str_values;
}

function setcustomerenv(int_userid)
{
reset_userproducts();
get_userproducts(int_userid);
}
function checkcustenv()
{
        var prd_cnt=document.actiononcase.prd_cnt.value;
        var int_chk=0;
        for(var i=0;i<prd_cnt;i++)
        {
                field1=document.getElementById("deleteproduct"+i);
                if(field1)
                {
                        int_chk=1;
                }
        }
/*        if(int_chk=='0')
        {
                alert('Please select atleast one Cutomer Environment');
        }
        else
        {*/
                if(!check_custenv()){

                }
		else if(!chkdupcusenv())
        	{
        	}
                else
                {
                copycustomerdata();
                document.actiononcase.submit();
                }
//        }
}




function editcase(){
	var customername;
	var customeremail;
	var casestatus;
	var supportengineer;

	var problemdescription=Trim(document.actiononcase.problemdescription.value);
  var int_len2=(document.actiononcase.problemdescription.value).length;


	if(problemdescription==''){
		alert(str_errormsg_problemdescription);
		document.actiononcase.problemdescription.focus();
	}
  else if(int_len2>5000){
                alert(str_errormsg_maxproblemdescription);
                document.actiononcase.problemdescription.focus();
        }

	else{
		document.actiononcase.submit();
	}

}
function registeruser(){
	var prd_cnt=eval(document.actiononcase.prd_cnt.value);
	prd_cnt=eval(prd_cnt)+1;
	var cust_env=document.actiononcase.field_cust_env.value;
	var arr_values=Array();
	var arr_value=Array();
	var attastr=Array();
	var noansreqd;
	var noans_i=0;
	var noans_arr=Array();


	if(cust_env!=''){
		var cust_env1=cust_env.split("|");
		var len=cust_env1.length;
		var cust_env2;
		var retval;
		for(j=0;j<prd_cnt;j++){
			for(i=0;i<len;i++){
				cust_env2=Array();
				cust_env2=cust_env1[i].split(",");
				arr_value[i]=get_value(cust_env2,j);
			}
			arr_values[j]=arr_value.join("&lt;#&gt;");
		}
		str_values=arr_values.join("[#]");
	}
	document.actiononcase.products.value=str_values;
	document.actiononcase.submit();
}
function change(id,desc,type_id,type_name){
  while(desc.length>1){
        desc.options[1]=null;
    }
  if(id){
   if(type_id[id]){
     for(i=0,j=0;i<type_id[id].length;i++){
        if(!isNaN(type_id[id][i])){
                desc.options[(j)]=new Option(type_name[id][i],type_id[id][i]);
                j++;
        }
        }
      }
   }
 }
function copydata(){
	var prd_cnt=eval(document.actiononcase.prd_cnt.value);
	
	prd_cnt=eval(prd_cnt)+1;
	var cust_env=document.actiononcase.field_cust_env.value;
	var arr_values=Array();
	var arr_value=Array();
	var attastr=Array();
	var noansreqd;
	var noans_i=0;
	var noans_arr=Array();


	if(cust_env!=''){
		var cust_env1=cust_env.split("|");
		var len=cust_env1.length;
		var cust_env2;
		var retval;
		for(j=0;j<prd_cnt;j++){
			for(i=0;i<len;i++){
				cust_env2=Array();
				cust_env2=cust_env1[i].split(",");
				arr_value[i]=get_value(cust_env2,j);
			}
			arr_values[j]=arr_value.join("&lt;#&gt;");
		}
		str_values=arr_values.join("[#]");
	}
	document.actiononcase.products.value=str_values;



}

function get_value(arr_field,order){
	var fieldname=arr_field[0];
	var fieldtype=arr_field[1];
	if(eval(order)>=0)
	var field=document.getElementById(fieldname+''+order);
	else
	var field=document.getElementById(fieldname);

	var value1;
	if(field){
		if(fieldtype.toUpperCase()=="SELECT"){
			value1=field.options[field.options.selectedIndex].value;
		}
		else if(fieldtype.toUpperCase()=="RADIO" || fieldtype.toUpperCase()=="CHECKBOX"){
			value1=field.value;
		}
		else if(fieldtype.toUpperCase()=="TEXTBOX" || fieldtype.toUpperCase()=="TEXTAREA"){
			value1=field.value;

		}
	}
	return value1;
}


function check_custenv(){
	var cust_env=document.actiononcase.field_cust_env.value;
	var prd_cnt=document.actiononcase.prd_cnt.value;
//	prd_cnt=eval(prd_cnt)+1;
	var i;
	var j;
	if(prd_cnt=='0')
	{
	 	alert('Please select Customer Environment');
                return false;
        }

	if(cust_env!=''){
		var cust_env1=cust_env.split("|");
		var len=cust_env1.length;
		var cust_env2;
		var retval;
		for(j=0;j<prd_cnt;j++){

			for(i=0;i<len;i++){
				cust_env2=Array();

				cust_env2=cust_env1[i].split(",");
				if(cust_env2[2]==1){
					retval=validate_field(cust_env2,j);
					if(retval==false){
						return false;
						break;
					}
					
				}
			}
		}
	}
	return true;
}


function check_env(gen_env){
	var i;
	if(gen_env!=''){
		var gen_env1=gen_env.split("|");
		var len=gen_env1.length;
		
		var gen_env2;
		var retval;
		for(i=0;i<len;i++){
			gen_env2=Array();
			gen_env2=gen_env1[i].split(",");
			if(gen_env2[2]==1){
				retval=validate_field(gen_env2,'-1');
				if(retval==false){
					return false;
					break;
				}
			}
		}
	}
}
var flag=0;
function validate_field(arr_field,order){
	var fieldname=arr_field[0];
	var fieldtype=arr_field[1];
	var checkflag=0;
	if(eval(order)>=0)
	var field=document.getElementById(fieldname+''+order);
	else
	var field=document.getElementById(fieldname);

	var value1;

	if(field){
		if(fieldtype.toUpperCase()=="SELECT"){
		    value1=field.options[field.options.selectedIndex].value;
                    if(fieldname != 'make')  // suresh 02-04-07 
                    {
			if(Trim(value1)==''||Trim(value1)=='0'){
				alert('Please select a '+fieldname);
				field.focus();
				return false;
			}
			else
			{
				flag='1';
				return true;
			}
                    } else { return true; } 

		}
		else if(fieldtype.toUpperCase()=="RADIO" || fieldtype.toUpperCase()=="CHECKBOX"){
			if(field.checked==true)
			{
				flag='1';
				return true;
			}
			else{
				alert('Please select a '+fieldname);
				field.focus();
				return false;
			}
		}
		else if(fieldtype.toUpperCase()=="TEXTBOX" || fieldtype.toUpperCase()=="TEXTAREA"){
			value1=field.value;
                        if((value1=="Model") || (value1=="Serialnumber") || (value1=="Purchasedate(MM-DD-YY)"))
                        {
                        field.value='';
                        value1='';
                        }
                        if(fieldname != 'model')
                        {
			if(Trim(value1)==''){
				alert('Please enter '+fieldname);
				field.focus();
				return false;
			}
			else
			{
				flag='1';
				return true;
			}
                        } else { return true;} 
		}
		
			
		
			
	}
	return true;
}

function switchcustomername(){
	var id=document.actiononcase.customeremail.options[document.actiononcase.customeremail.options.selectedIndex].value;
	var len=document.actiononcase.customername.options.length;
	desc=document.actiononcase.customername;
	for(i=0;i<len;i++){
		if(desc.options[i].value=id)
		desc.options[i].selected=true;
	}
	if(id==''){
		desc.options[0].selected=true;
		reset_userproducts();
	}
	else
	get_userproducts(id);
}

function switchcustomeremail(){
	var id=document.actiononcase.customername.options[document.actiononcase.customername.options.selectedIndex].value;
	var len=document.actiononcase.customeremail.options.length;
	desc=document.actiononcase.customeremail;
	for(i=0;i<len;i++){
		if(desc.options[i].value=id)
		desc.options[i].selected=true;
	}

	if(id==''){
		desc.options[0].selected=true;
		reset_userproducts();
	}
	else
	get_userproducts(id);

}

function remove_customerproduct()
{
        var prd_cnt=document.actiononcase.prd_cnt.value;
        var field1;
        var field2;
        var field3;
        var value;
        var selcount=0;
        for(var i=0;i<prd_cnt;i++){
                field1=document.getElementById("deleteproduct"+i);
                //field2=document.getElementById("cust_env"+i);
                //      alert(field2+''+i);
                if(field1){
                        if(field1.checked==true){
                        selcount++;
                        }
                }
        }
        if(selcount==0 || prd_cnt==0)
        {
                alert(str_errmsg_selprod);
        }
        for(var i=0;i<prd_cnt;i++){
                field1=document.getElementById("deleteproduct"+i);

                if(field1){
                        if(field1.checked==true){

                                field2=document.getElementById("cust_env"+i);

                                if(field2){
                                        field2.innerHTML='';
                                        field2.style.display="none";
                                        }
                        }
                }
        }

}


function reset_userproducts(){
	var prd_cnt=document.actiononcase.prd_cnt.value;
	
	for(var i=0;i<prd_cnt;i++){
		field2=document.getElementById("cust_env"+i);
		if(field2){
			field2.innerHTML='';
			field2.style.display="none";
		}

	}
	
	field2=document.getElementById("customer_environment");
	if(field2)
		field2.innerHTML='';

//	populate_problemproducts();
}


function reset_custenv(){
	var new_div;
	var cust_env=document.getElementById("customer_environment");

	var temp= document.getElementById("temp");


	if(arr_custenv.length>0){
	for(var str_div in arr_custenv){
	
		new_div=document.getElementById('cust_env'+str_div);
		if(new_div){
			new_div.innerHTML=arr_custenv[str_div];
		}
		else{
			new_div=temp.cloneNode(true);
			new_div.setAttribute("id","cust_env"+str_div);
			cust_env.appendChild(new_div);
			new_div.innerHTML=arr_custenv[str_div];
		}
	}
	}
	setcustenv();
//	setprodenv();
//	populate_problemproducts();
}

function setcustenv(){

	var strNR=document.getElementById("norecord");

	var prd_cnt=document.actiononcase.prd_cnt.value;
	if(prd_cnt!='0')
	{
		if(strNR)
        	{
	        strNR.innerHTML='';
        	}
	}
	prd_cnt=prd_cnt+1;
	var cust_env=document.actiononcase.field_cust_env.value;
	var str_values=document.actiononcase.products.value;
	//alert(str_values);
	var prob_prod=document.actiononcase.problemproduct.value;
	var arr_values=Array();
	var arr_value=Array();

	if(cust_env!=''){
		var cust_env1=cust_env.split("|");
		var len=cust_env1.length;
		var cust_env2;
		var retval;
		var val1;
		//alert(str_values);
		arr_values=str_values.split("[#]");
		//alert(arr_values.length);
		var k;
		for( j in arr_values){
			val1=arr_values[j];
			//alert(val1);
			arr_value=val1.split("&lt;#&gt;");
			//alert(arr_value);
			if(arr_value[0]!=''){
				for(i in cust_env1){
					//alert(arr_value[i]);
					cust_env2=Array();
					cust_env2=cust_env1[i].split(",");
					set_value(cust_env2,j,arr_value[i]);
				}
			}

		}

	}

	var arr_probprod=prob_prod.split(",");
	var probfield;
	if(arr_probprod.length>0){
		for(int_i in arr_probprod){
			probfield=document.getElementById("problemproduct"+arr_probprod[int_i]);
			if(probfield){
				probfield.checked=true;
			}

		}
	}
	probfield=document.getElementById("problemproduct0");

	if(probfield){

		probfield.onchange();
	}
	//alert('end of custenv');
	return 1;

}

function setprodenv(){
	var prod_env=document.actiononcase.field_prod_env.value;
	var arr_value;
	if(prod_env!=''){
		var prod_env1=prod_env.split("|");
		var len=prod_env1.length;
		var value1;
		var field1vl;
		for( j in prod_env1){
			val1=prod_env1[j];
			arr_value=Array();
			arr_value=val1.split(",");
			fieldv1=arr_value[0];
			//alert(arr_value);
			if(arr_prodenv[fieldv1])
			set_value(arr_value,'-1',arr_prodenv[fieldv1]);

		}
	}

}

function populate_problemproducts(){
	if(isNaN(document.actiononcase.prd_cnt.value) || Trim(document.actiononcase.prd_cnt.value)=='')
	var prd_cnt=0;
	else
	var prd_cnt=document.actiononcase.prd_cnt.value;
	var mapcategory=document.actiononcase.mapproblemcategory.value;
	var field1;
	var problemproducts=document.actiononcase.problemproduct.value;
	var arr_assprobprod=Array();
	if(problemproducts!=''){
		arr_assprobprod=problemproducts.split(",");
	}
	var arr_assprobprod1=Array();
	for(var i in arr_assprobprod){
		arr_assprobprod1[arr_assprobprod[i]]=1;
	}

	var arr_probprod=Array();
	arr_assprobprod=Array();
	//alert(prd_cnt);
	for(i=0;i<prd_cnt;i++){
		field1=document.getElementById(mapcategory+i);

		if(field1){
			if(arr_assprobprod1[field1.options[field1.options.selectedIndex].value]==1)
			arr_assprobprod[field1.options[field1.options.selectedIndex].value]=field1.options[field1.options.selectedIndex].text;
			else
			arr_probprod[field1.options[field1.options.selectedIndex].value]=field1.options[field1.options.selectedIndex].text;
		}
	}
	if(document.actiononcase.noprod.value!='1')
	{
	var desc2=document.actiononcase.AvailedProducts;
	if(desc2){
	while(desc2.options.length>0){
		desc2.options[0]=null;
	}
	}
	var desc=document.actiononcase.AvailableProducts;
	if(desc){
	while(desc.options.length>0){
		desc.options[0]=null;
	}
	}
	var j=0;
	for( i in arr_probprod){
		if(i!='0'){
			desc.options[j]=new Option(arr_probprod[i],i);
			j++;
		}
	}
	j=0;
	for (i in arr_assprobprod){
		if(i!='0'){
			desc2.options[j]=new Option(arr_assprobprod[i],i);
			j++;
		}
	}
	//populateproblemcateogry();
	}
}


function set_value(arr_field,order,value1){
	var fieldname=arr_field['0'];
	var fieldtype=arr_field['1'];

	if(eval(order)>=0)
	var field=document.getElementById(fieldname+''+order);
	else
	var field=document.getElementById(fieldname);
	//	alert(fieldname+' '+order+' '+value1+''+field);
	if(field && value1!=''){
		if(fieldtype.toUpperCase()=="SELECT"){
			for(var j=0;j<field.options.length;j++){
				if(field.options[j].value==value1)
				field.options[j].selected=true;
			}
		}
		else if(fieldtype.toUpperCase()=="RADIO" || fieldtype.toUpperCase()=="CHECKBOX"){
			if(field.value==value1)
			field.checked=true;
		}
		else if(fieldtype.toUpperCase()=="TEXTBOX" || fieldtype.toUpperCase()=="TEXTAREA"){
			field.value=value1;

		}
	}
}

function change_selectvalue(field,value1){
	var len=field.options.length;
	for(var i=0;i<len;i++){
		if(field.options[i].value==value1)
		field.options[i].selected=true;
	}

}


function casestatusonchange(){
	var supportengineer = document.actiononcase.supportengineer.options[document.actiononcase.supportengineer.selectedIndex].value;
	var status=document.actiononcase.casestatus.options[document.actiononcase.casestatus.selectedIndex].value;
	if(status!='N')
	document.actiononcase.oldstatus.value=status;
	if(supportengineer!='' && (status=='' || status=='N')){
		alert('Status cannot be changed to New as a Support Engineer is assigned to it');
		if(Trim(document.actiononcase.oldstatus.value)!='' && Trim(document.actiononcase.oldstatus.value)=='E'){
			document.actiononcase.casestatus.value=document.actiononcase.oldstatus.value;
		}
		else if(Trim(document.actiononcase.oldstatus.value)!='' && Trim(document.actiononcase.oldstatus.value)!='E'){
			document.actiononcase.casestatus.value=document.actiononcase.oldstatus.value;
		}
		else
		document.actiononcase.casestatus.value='A';
	}
}


function statusonchange(){

	var supportengineer = document.actiononcase.supportengineer.options[document.actiononcase.supportengineer.selectedIndex].value;
	var status=document.actiononcase.casestatus.options[document.actiononcase.casestatus.selectedIndex].value;
	var engsuggestion="";
	engsuggestion=document.actiononcase.engineersuggestion.value;

	if(status!='N')
	document.actiononcase.oldstatus.value=status;
	if(supportengineer!='' && (status=='' || status=='N')){

		if(engsuggestion!='')
		alert(str_errmsg_statustopending);
		else
		alert(str_errmsg_statustoassigned);

		if(Trim(document.actiononcase.oldstatus.value)!='' && Trim(document.actiononcase.oldstatus.value)=='N'){
			document.actiononcase.casestatus.value='A';
		}
		else if(Trim(document.actiononcase.oldstatus.value)!=''){
			document.actiononcase.casestatus.value=document.actiononcase.oldstatus.value;
		}
		else if(engsuggestion!='')
		document.actiononcase.casestatus.value='P';
		else
		document.actiononcase.casestatus.value='A';
	}
}
function setuserid(int_userid){
	get_userdetails(int_userid);
}

function get_userproducts(int_userid)
{
	xajax_getuserproducts(int_userid,"field_cust_env,products,prd_cnt");
}
function get_userdetails(int_userid){
	xajax_getuserdetails(int_userid,"customername_text,customeremail_text");
}

function setuserdetails(int_userid){
	reset_userproducts();
	var desc=document.actiononcase.customername;

	while(desc.options.length>1){
		desc.options[1]=null;
	}
	desc.options[1]=new Option(document.actiononcase.customername_text.value,int_userid);
	desc.options[1].selected=true;

	desc=document.actiononcase.customeremail;
	while(desc.options.length>1){
		desc.options[1]=null;
	}
	desc.options[1]=new Option(document.actiononcase.customeremail_text.value,int_userid);
	desc.options[1].selected=true;
	get_userproducts(int_userid);

}
function disp(){
	//alert('hi123');
	reset_custenv();

}


function lookup(type)
{
	var width;
	var url = "";
	if(type=='USERPOPUPUSERSEARCH')
	url = "../Users/ctengusersearch.aspx?senttype="+type;
	else
	url = "../engineer/engcustomersearch.aspx?senttype="+type;
	//alert(url);
	if(Trim(url) != "")
	{
		ColorWindow=window.open(url,'LookUp','width=650,height=500,screenX=20,screenY=35,top=20,left=35,scrollbars=yes,resizable=yes');
		ColorWindow.focus();
	}
}



function uncheckEC()
{
	if(document.actiononcase.EscPresent.value == "1")
	{
		document.actiononcase.chkEsc.checked = false;
	}

	if(document.actiononcase.ClosePresent.value == "1")
	{
		document.actiononcase.chkClosed.checked = false;
	}
}

function uncheckRE()
{
	if(document.actiononcase.RMAPresent.value == "1")
	{
		document.actiononcase.chkRMA.checked = false;
	}

	if(document.actiononcase.EscPresent.value == "1")
	{
		document.actiononcase.chkEsc.checked = false;
	}
}

function uncheckRC()
{
	if(document.actiononcase.RMAPresent.value == "1")
	{
		document.actiononcase.chkRMA.checked = false;
	}

	if(document.actiononcase.ClosePresent.value == "1")
	{
		document.actiononcase.chkClosed.checked = false;
	}
}

function chkpopupemp(customer){
	if(customer==''){
		customer=document.actiononcase.customeremail.options[document.actiononcase.customeremail.options.selectedIndex].value;
	}
	if(customer==''){
		alert('Please select customer name or email to view their information');
		return false;
	}
	else{
		url=infourl+'?customerid='+customer;
		ColorWindow=window.open(url,'Change','width=450,height=300,screenX=20,screenY=35,top=20,left=35,scrollbars=yes,resizable=yes');
		ColorWindow.focus();
	}
}


function remove_product(){
	var prd_cnt=document.actiononcase.prd_cnt.value;
	var field1;
	var field2;
	var field3;
	var value;
	var selcount=0;
	for(var i=0;i<prd_cnt;i++){
		field1=document.getElementById("deleteproduct"+i);
		//field2=document.getElementById("cust_env"+i);
		//	alert(field2+''+i);
		if(field1){
			if(field1.checked==true){
			selcount++;
			}
		}
	}

	if(selcount==0 || prd_cnt==0)
	alert(str_errmsg_selprod);
	int_check=0;
	for(var i=0;i<prd_cnt;i++){

		field1=document.getElementById("deleteproduct"+i);

		if(field1){
			if(field1.checked==true){

				field2=document.getElementById("cust_env"+i);

				if(field2){
					field2.innerHTML='';
					field2.style.display="none";
				}


			}
		}
	}
	int_divchk=0;
	for(var i=0;i<prd_cnt;i++)
	{
		field3=document.getElementById("cust_env"+i)
		if(field3)
		{
			if(field3.innerHTML !='')
			int_divchk++;
		}
	}
	if(int_divchk=='0')
	{
		document.actiononcase.prd_cnt.value='0';
	}
	
	//populate_problemproducts();
}


function showattachments(lstall, lstsel)
{
	var lstallindex;
	var lstselindex;
	var lstallvalue;
	var lstselvalue;
	var url;

	lstallindex = lstall.selectedIndex;

	if (lstallindex >= 0)
	{
		lstallvalue = lstall[lstallindex].value;
		url = './engshowattachment.aspx?AttachID=' + lstallvalue;
		newWindow(url, 'Attach_1');
	}

	lstselindex = lstsel.selectedIndex;

	if (lstselindex >= 0)
	{
		lstselvalue = lstsel[lstselindex].value;
		url = './engshowattachment.aspx?AttachID=' + lstselvalue;
		newWindow(url, 'Attach_2');
	}
}

function add_newproduct(){
	
	var cust_env=document.getElementById("customer_environment");
	var strNR=document.getElementById("norecord");
	if(strNR)
	{
	strNR.innerHTML='';
	}
	if(isNaN(document.actiononcase.prd_cnt.value) || Trim(document.actiononcase.prd_cnt.value)=='')
	var prd_cnt=0;
	else
	var prd_cnt=eval(document.actiononcase.prd_cnt.value);

	var temp= document.getElementById("temp");

	var newnode=temp.cloneNode(true);
	newnode.setAttribute("id","cust_env"+prd_cnt);
	cust_env.appendChild(newnode);
	document.actiononcase.prd_cnt.value=prd_cnt+1;
	xajax_get_customer_environment(prd_cnt);
}


function resetcase(){
	var prd_cnt=document.actiononcase.prd_cnt.value;
	for(var i=0;i<prd_cnt;i++){
		field2=document.getElementById("cust_env"+i);

		if(field2){
			field2.innerHTML='';
			field2.style.display="none";
		}

	}
	field2=document.getElementById("customer_environment");
	field2.innerHTML='';

//	populate_problemproducts();
	var desc=document.actiononcase.customername;
	while(desc.options.length>1){
		desc.options[1]=null;
	}
	desc=document.actiononcase.customeremail;
	while(desc.options.length>1){
		desc.options[1]=null;
	}	
	attachments=document.actiononcase.SelectedAttachments;
	for(var int_i=0;int_i<document.actiononcase.SelectedAttachments.length;int_i++){
	attachments.options[int_i].selected=true;
	}
	swapoptions(true, document.actiononcase.SelectedAttachments, document.actiononcase.AvailableAttachments);
/*	while(attachments.options.length>0){
	attachments.options[0]=null;
	}*/
	document.actiononcase.reset();
}
function createcasereset()
{
	var prd_cnt=document.actiononcase.prd_cnt.value;
        for(var i=0;i<prd_cnt;i++){
                field2=document.getElementById("cust_env"+i);

                if(field2){
                        field2.innerHTML='';
                        field2.style.display="none";
                }

        }
        field2=document.getElementById("customer_environment");
        field2.innerHTML='';
        document.actiononcase.reset();

}

function editreset(){
	document.actiononcase.prd_cnt.value=document.actiononcase.org_prd_cnt.value;
	var prd_cnt=document.actiononcase.prd_cnt.value;
	for(var i=0;i<prd_cnt;i++){
		field2=document.getElementById("cust_env"+i);

		if(field2){
			field2.innerHTML='';
			field2.style.display="none";
		}

	}
	field2=document.getElementById("customer_environment");
	field2.innerHTML='';
	document.actiononcase.reset();
	reset_custenv();
	attachments=document.actiononcase.SelectedAttachments;
	for(var int_i=0;int_i<document.actiononcase.SelectedAttachments.length;int_i++){
	attachments.options[int_i].selected=true;
	}
	swapoptions(true, document.actiononcase.SelectedAttachments, document.actiononcase.AvailableAttachments);


}

function showDIV(int_divid)
{
	
	str_divobj=document.getElementById("cust_env"+int_divid);
	if(str_divobj)
	{
		str_divobj.style.display='';
	}
}

function chkdupcusenv()
{
	  var prd_cnt=document.actiononcase.prd_cnt.value;
          var elements2get=document.getElementById("field_cust_env").value;
          var arr_elements=elements2get.split('|');
	  var arr_divchk= new Array();
	  var int_dup='0';
	  for(var int_i=0;int_i<prd_cnt;int_i++)
	  {
		var chkbox="deleteproduct"+int_i;

           if(document.getElementById(chkbox))
           {
		var content1=''
        	for(var int_j=0;int_j<arr_elements.length;int_j++){
                var arr_content=arr_elements[int_j].split(",");
                var elementname=arr_content[0]+int_i;
                if(arr_content[1]=='select'){
                if(int_j=='0')
                 content1=content1+document.getElementById(elementname).options[document.getElementById(elementname).selectedIndex].text;
                else
                {
                 if(int_j=='2')
                 {
                 content1=content1+" -> "+ document.getElementById(elementname).options[document.getElementById(elementname).selectedIndex].text;
                 }
                 else
                        content1=content1+" -> "+ document.getElementById(elementname).options[document.getElementById(elementname).selectedIndex].text;
                }
                }
                else{
                if(int_j=='0')
                        content1=content1+document.getElementById(elementname).value;
                else
                        content1=content1 +" -> "+document.getElementById(elementname).value;
                }
		}
          
          int_avail=0;
          for(int_ab=0;int_ab<arr_divchk.length;int_ab++)
          {
                if(arr_divchk[int_ab].toLowerCase()==content1.toLowerCase())
                {
                        alert('The selected Problem Product already exist');
                        int_avail=1;
                        return false;
                }
		

          }
          arr_divchk[int_dup++]=content1;
	  }
	 }
	 return true;
	

}
// suresh 26-3-07 dashboard changes
function edit_product(){
        var prd_cnt=document.actiononcase.prd_cnt.value;
        var selcount=0;
        for(var i=0;i<prd_cnt;i++){
                document.getElementById("category"+i).disabled=false;
                document.getElementById("type"+i).disabled=false;
                document.getElementById("make"+i).disabled=false;
                document.getElementById("model"+i).disabled=false;
                document.getElementById("serialnumber"+i).disabled=false;
                document.getElementById("product"+i).disabled=false;
                var table1 = document.getElementById("purchasedate"+i);
                if(table1) {
                    document.getElementById("purchasedate"+i).disabled=false;
                }
        }
} // suresh 26-3-07 dashboard changes end


