var dynamicRowCount = 5;

function showContact(contact,obj){
	var objContact =  document.getElementById(contact).style;
	if(objContact.display=="block"){
		objContact.display="none";
		obj.src=plusImg.src;
	}else{
		objContact.display="block";
		obj.src=minusImg.src;
	}
}

function addRow(tname,fname,fsize,maxlen){
	addRowWithValue(tname,fname,fsize,maxlen,'');
}
function addRowWithValue(tname,fname,fsize,maxlen,value){	
	//ARGUMENTS : tname= table name, fname = field name, fsize = field size, maxlen = field max length, value= field value.
		var tbl = document.getElementById(tname);
		var lastRow = tbl.rows.length;
		if(lastRow<dynamicRowCount-1){
			var row = tbl.insertRow(lastRow);
			var cellLeft = row.insertCell(0);
			var iteration = lastRow;
			var el = document.createElement('input');
		    el.type = 'text';
		    el.name = fname;
		    el.id = fname+iteration;
		    el.size = fsize;
		    el.maxLength = maxlen;
		    el.value = value;
		    cellLeft.appendChild(el);
		    var cellRight = row.insertCell(1);
		    cellRight.innerHTML = "<img src="+minusImg.src+" id="+lastRow+" onclick='deleteRow(this)' style='cursor: pointer;'/>";
		    document.getElementById(el.id).focus();
		}
	}

function deleteRow(obj){	
	//var tab = obj.parentNode.parentNode.parentNode.parentNode;
	obj.parentNode.parentNode.parentNode.parentNode.deleteRow(obj.parentNode.parentNode.rowIndex);	
}

function populateCustomerValues(obj,name,phone1,phone2,phone3,ext,title,fax1,fax2,fax3,email){
//ARGUMENTS (Primary Contact Details) : obj=currentelement, name= name, phone1= phone areacode, phone2= phone exchange, phone3= phone number, ext= phone extension, title = Title, fax1= fax areacode, fax2= fax exchange, fax3= fax number, email = E-mail
	
	if(obj.checked==true)
	{
		if(name!=null)
			document.getElementById(name).value=document.getElementById(primaryNameId).value;
		if(phone1!=null)
			document.getElementById(phone1).value=document.getElementById(primaryPhoneAreaCodeId).value;
		if(phone2!=null)
			document.getElementById(phone2).value=document.getElementById(primaryPhoneExchangeId).value;
		if(phone3!=null)
			document.getElementById(phone3).value=document.getElementById(primaryPhoneNumberId).value;
		if(ext!=null)
			document.getElementById(ext).value=document.getElementById(primaryPhoneExtensionId).value;
		if(title!=null)
			document.getElementById(title).value=document.getElementById(primaryTitleId).value;
		if(fax1!=null)
			document.getElementById(fax1).value=document.getElementById(primaryFaxAreaCodeId).value;
		if(fax2!=null)
			document.getElementById(fax2).value=document.getElementById(primaryFaxExchangeId).value;
		if(fax3!=null)
			document.getElementById(fax3).value=document.getElementById(primaryFaxNumberId).value;
		if(email!=null)
			document.getElementById(email).value=document.getElementById(primaryEmailId).value;
	}
	else{
			if(name!=null)
				document.getElementById(name).value="";
			if(phone1!=null)
				document.getElementById(phone1).value="";
			if(phone2!=null)
				document.getElementById(phone2).value="";
			if(phone3!=null)
				document.getElementById(phone3).value="";
			if(ext!=null)
				document.getElementById(ext).value="";
			if(title!=null)
				document.getElementById(title).value="";
			if(fax1!=null)
				document.getElementById(fax1).value="";
			if(fax2!=null)
				document.getElementById(fax2).value="";
			if(fax3!=null)
				document.getElementById(fax3).value="";
			if(email!=null)
				document.getElementById(email).value="";
	}
}



